Академический Документы
Профессиональный Документы
Культура Документы
SCIENCE
PRACTICAL FILE
PROGRAM 03
#include<iostream.h>
#include<coni
o.h>
#include<stdi
o.h> struct
bl{int no; char
name[20];
float unit,bill;
}a;
void
main()
{clrscr();
cout<<"Enter
consumer number:";
cin>>a.no;
cout<<"Enter
consumer name:";
gets(a.name);
cout<<"Enter no. of
units consumed:";
cin>>a.unit;
if(a.unit<=100)
a.bill=a.unit*0.4;
if(a.unit>100 && a.unit<=200)
a.bill=(a.unit-100)*0.5+40;
if(a.unit>200 && a.unit<=300)
a.bill=(a.unit-200)*0.75+90;
if(a.unit>300)
a.bill=(a.unit-300)*1+165;
cout<<"\nBill";
cout<<"\nConsumer
No:"<<a.no;
cout<<"\nName:"<<
a.name;
cout<<"\nUnits
consumed:"<<a.unit;
cout<<"\nNet
amount=Rs"<<a.bill;
getch();
}
//Output 1
Enter consumer number:12
Enter consumer name:Ankur Bannerjee
Enter no. of units consumed:164
Bill
Consumer No:12
Name:Ankur Bannerjee
Units consumed:164
Net amount=Rs72
//Output 2
Enter consumer number:23
Enter consumer name:S.Srinivas
Enter no. of units consumed:284
Bill
Consumer No:23
Name:S.Srinivas
Units consumed:284
Net amount=Rs153
//Output 3
Enter consumer number:29
Enter consumer name:Ravi Kumar Singh
Enter no. of units consumed:336
Bill
Consumer No:29
Name:Ravi
Kumar Singh
Units
consumed:336
Net
amount=Rs201
Program 06
C++ program to create Employee and
Student inheriting from Person using
Hierarchical Inheritance
#include <iostream>
#include <conio.h>
using namespace std;
class person
{
char name[100],gender[10];
int age;
public:
void getdata()
{
cout<<"Name: ";
fflush(stdin); /*clears input stream*/
gets(name);
cout<<"Age: ";
cin>>age;
cout<<"Gender: ";
cin>>gender;
}
void display()
{
cout<<"Name: "<<name<<endl;
cout<<"Age: "<<age<<endl;
cout<<"Gender: "<<gender<<endl;
}
};
int main()
{
student s;
employee e;
cout<<"Student"<<endl;
cout<<"Enter data"<<endl;
s.getdata();
cout<<endl<<"Displaying data"<<endl;
s.display();
cout<<endl<<"Employee"<<endl;
cout<<"Enter data"<<endl;
e.getdata();
cout<<endl<<"Displaying data"<<endl;
e.display();
getch();
return 0;
}
Output
Student
Enter data
Name: Ravi
Age: 17
Gender: Male
Name of College/School: KV
Level: 12
Displaying data
Name: Ravi
Age: 17
Gender: Male
Name of College/School: KV
Level: 12
Employee
Enter data
Name: Manish
Age: 24
Gender: male
Name of Company: Xyz Consultant
Salary: 100000
Displaying data
Name: Mary
Age: 24
Gender: Female
Name of Company: Xyz Consultant
Salary: 1000000
SQL
1.Write an SQL command for the queries for the
questions relation SHOP shown below:
N Shop_na Sale Area Cust Rat Cit
o. me % ing y
1 S.M.Sons 250000 West 68.6 C Del
hi
2 Dharohar 500000 South 81.8 A Mu
mb
ai
3 Kriti Art 300000 North 79.8 B Kol
kat
a
4 Ripple 380000 North 88.0 B Mu
mb
ai
5 Best 456000 East 92.0 A Del
Stores hi
6 Crystal 290000 South 66.7 A Kol
kat
a
-Show the names of all shops which are in the
South area and cust-percent < 75
-To display number of shops in each city.
-To display list of all the shops with sale > 300000
in ascending order of Shop_Name.
-To display Shop_name,Area and Rating for only
thos shops whose sale is between 350000 and
400000 (including both 350000 and 400000).
-To count the no. shops whose rating is A
ANSWER
1.SELECT Shop_name
2.FROM SHOP WHERE
Area='South' AND
Cust%<75;
3.SELECT City,Count(*)
4.FROM SHOP
GROUP BY
City;
5.SELECT Shop_name
6.FROM SHOP
7.WHERE Sale>300000
8.ORDER BY Shop_name;
9.SELECT Shop_name,Area,Rating
10. FROM SHOP
11. WHERE Sale BETWEEN(350000 AND
400001);
12. SELECT Count(*)
13. FROM SHOP
14. WHERE Rating='A';
ANSWER
1.SELECT Emp_name
2.FROM EMPDETS
3.ORDER BY Salary desc;
4.SELECT count(*)
5.FROM EMPDETS
6.WHERE Salary>15000 AND Experience>5;
7.SELECT Avg(Salary)
8.FROM EMPDETS
9.GROUP BY Department;
OUTPUT:
QUERY-3: Display DISTINCT SAL of Employees
from table EMP.
ANSWER:SELECT DISTINCT SAL FROM EMP;
PROGRAM 04
/*WAP TO COPY CONTENTS OF STORY.TXT INTO PARA.TXT*/
#include<iostream.h>
#include<stdio.h>
#include<fstream.h>
class STORY
{char plot[100];
public:
void enter()
{gets(plot);}
void display()
{puts(plot);}};
void main()
{STORY s;
ofstream file("story.txt",ios::out);
s.enter();
file.write((char*)&s,sizeof(s));
file.close();
cout<<endl;
ifstream fi("story.txt",ios::in);
fstream fo("para.txt",ios::out||ios::in);
fi.read((char*)&s,sizeof(s));
fo.write((char*)&s,sizeof(s));
fi.close();
cout<<"Copied text stored in para.txt:-"<<endl;
fo.read((char*)&s,sizeof(s));
s.display();
fo.close();
}
OUTPUT
PROGRAM 05
#include<iostream.h>
void main()
{int n,i;
cout<<"Enter the limit=";
cin>>n;
if(n==0)
cout<<"1";
else
{cout<<"1";
for(i=1;i<=n;i++)
cout<<"+x^"<<(2*i-1)<<"/"<<i<<"!";
}
}
PROGRAM 16
/*TO FIND SUM OF GIVEN ROWS AND COLUMN*/
#include<iostream.h>
void main()
{int a[3][3],i,j,sumr,sumc;
cout<<"Enter the matrix :-"<<endl;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>a[i][j];
cout<<"Showing the matrix:-";
for(i=0;i<3;i++)
{cout<<endl;
for(j=0;j<3;j++)
cout<<a[i][j];}
cout<<endl;
for(i=0;i<3;i++)
{sumr=0;
for(j=0;j<3;j++)
sumr+=a[i][j];
cout<<"Sum of row
no."<<i+1<<"="<<sumr<<endl;}
for(j=0;j<3;j++)
{sumc=0;
for(i=0;i<3;i++)
sumc+=a[i][j];
cout<<"Sum of column
no."<<j+1<<"="<<sumc<<endl;}
}
OUTPUT
PROGRAM 17
Program to search an element of an array using Binary
search
#include<iostream.h>
#include<process.h>
#include<conio.h>
void main()
{ clrscr();
int A[50], n,p;
cout<<"Enter the Size of array : ";
cin>>n;
binary_search(A,n,p);
getch();
}
else
L=mid+1;
}//end of while loop
if(L>U)
{cout<<"\n\nUnsuccessful search.";
cout<<"\n\n\n\nWant to search again. : ";
cin>>ch;
if(ch=='y'||ch=='Y')
{cout<<"\n\n\n\nEnter the element to be
searched : ";
cin>>p;
goto lb;}
else
exit(1);
}
}
PROGRAM 25
/*sorting using bubble sort*/
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int A[80],n;
cout<<"Enter desired size of array (<80): ";
cin>>n;
cout<<"\n\nEnter the array : \n";
for(int i=0; i<n; i++)
cin>>A[i];
bubble_sort(A,n);
getch();
}
PROGRAM 26
/*MULTIPLICATION OF MATRICES*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[5][5],b[5][5],c[5][5],m,n,p,q,i,j,k;
cout<<"Enter rows and columns of first matrix:";
cin>>m>>n;
cout<<"Enter rows and columns of second
matrix:";
cin>>p>>q;
if(n==p)
{
cout<<"\nEnter first matrix:\n";
for(i=0;i<m;++i)
for(j=0;j<n;++j)
cin>>a[i][j];
cout<<"\nEnter second matrix:\n";
for(i=0;i<p;++i)
for(j=0;j<q;++j)
cin>>b[i][j];
cout<<"\nThe new matrix is:\n";
for(i=0;i<m;++i)
{
for(j=0;j<q;++j)
{
c[i][j]=0;
for(k=0;k<n;++k)
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
cout<<c[i][j]<<" ";
}
cout<<"\n";
}
}
else
cout<<"\nSorry!!!! Matrix multiplication can't be
done";
getch();
}