Вы находитесь на странице: 1из 34

COMPUTER

SCIENCE
PRACTICAL FILE

SUBMITTED BY: RAVI


KUMAR SINGH
CLASS: XII
B
ROLL NO:
9197866
PROGRAM 02
//Program to input employee data & print payslip
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h> struct
date
{int dd,mm,yy;
};
struct perk1 {float
da,hra;
int bonus;
};
struct emp {int no; char
name[20],desig[20]; date
dob; float basic,net;
perk1 perk;
}e;
void main()
{
clrscr();
cout<<"Enter the employee number:";
cin>>e.no;
cout<<"Enter the employee name:";
gets(e.name);
cout<<"Enter date of birth in dd mm
yyyy format:";
cin>>e.dob.dd>>e.dob.mm>>e.dob.yy;
cout<<"Enter basic salary:";
cin>>e.basic;
e.perk.bonus=800;
e.perk.da=0.15*e.basic;
e.perk.hra=0.12*e.basic;
e.net=e.basic+e.perk.bonus+e.perk.da+
e.perk.hra; if(e.net>=25000)
strcpy(e.desig,"Manager");
if(e.net>=15000 && e.net<25000)
strcpy(e.desig,"Executive");
if(e.net<15000) strcpy(e.desig,"Non
executive");
cout<<"\nPayslip";
cout<<"\nEmployee no.:"<<e.no;
cout<<"\nName:"<<e.name;
cout<<"\nDate of
birth:"<<e.dob.dd<<"/"<<e.dob.mm<<"/"<<e.do
b.yy; cout<<"\nDesignation:"<<e.desig;
cout<<"\nBasic="<<e.basic;
cout<<"\nDA="<<e.perk.da;
cout<<"\nHRA="<<e.perk.hra;
cout<<"\nBonus="<<e.perk.bonus; cout<<"\nNet
salary="<<e.net;
getch(); }
//Output 1
Enter the employee number:1
Enter the employee name:Ravi Kumar Singh
Enter date of birth in dd mm yyyy format:29 8
1990
Enter basic salary:20000
Payslip
Employee no.:1
Name:Ravi Kumar Singh
Date of birth:29/8/1990
Designation:Manager
Basic=20000
DA=3000
HRA=2400
Bonus=800
Net salary=26200
//Output 2
Enter the employee number:2
Enter the employee name:Arvind Sreekumar
Enter date of birth in dd mm yyyy format:12 3
1990
Enter basic salary:15000
Payslip
Employee no.:2
Name:Arvind Sreekumar
Date of birth:12/3/1990
Designation:Executive
Basic=15000
DA=2250
HRA=1800
Bonus=800
Net salary=19850
//Output 3
Enter the employee number:3
Enter the employee name:Khushali Bagga
Enter date of birth in dd mm yyyy format:24 12
1990
Enter basic salary:8000
Payslip
Employee no.:3
Name:Khushali Bagga
Date of birth:24/12/1990
Designation:Non executive
Basic=8000
DA=1200
HRA=960
Bonus=800
Net salary=10960

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;
}
};

class student: public person


{
char institute[100], level[20];
public:
void getdata()
{
person::getdata();
cout<<"Name of College/School: ";
fflush(stdin);
gets(institute);
cout<<"Level: ";
cin>>level;
}
void display()
{
person::display();
cout<<"Name of College/School:
"<<institute<<endl;
cout<<"Level: "<<level<<endl;
}
};

class employee: public person


{
char company[100];
float salary;
public:
void getdata()
{
person::getdata();
cout<<"Name of Company: ";
fflush(stdin);
gets(company);
cout<<"Salary: Rs.";
cin>>salary;
}
void display()
{
person::display();
cout<<"Name of Company:
"<<company<<endl;
cout<<"Salary: Rs."<<salary<<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';

2. .Write a SQL commands:-


TABLE :
EMPDETS
Expe
Emp_nam rienc
Emp_no e Department Salary e
E01 Ahmed Accts 15000 3
Hussain
E02 Ravinder System 35000 5
Singh
E03 Jully Bhatt System 20000 5
E04 Shiva Accts 15000 7
Mathur
E05 Sonia Jolly Accts 12000 3
E06 Sumita Purchas 18000 10
Singh e TABLE :
LEAVE
Emp_no Leave
E01 3
E04 5
E05 5
E06 1

i. To display all employee names in descending order


of salary.
ii.Display the no. of employee whose salary > 15000
and experience > 5 years.
iii. Display the average salary of each
department. iv. To display Emp_no, Emp_name,
leave for all employees who have taken leave.
v. Increase the salary of all employees of
Accts Department by 1000. vi. Delete the
employee details whose experience is less
than 3 yr.
vii.Insert a new row in leave with details E02,3

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;

10. SELECT LEAVE.Emp_no, Emp_name, Leave


11. FROM EMPDETS,LEAVE
12. WHERE EMPDETS.Emp_no=LEAVE.Emp_no

13. UPDATE EMPDETS


14. SET Salary=Salary+1000
15. WHERE Department=Accts;

16. DELETE FROM EMPDETS


17. WHERE Experience<3;

18. INSERT INTO LEAVE


19. VALUES(E02,3);
3. Display all the records from table EMP.
ANSWER:SELECT * FROM EMP;
OUTPUT:

QUERY-1: Display EMPNO and ENAME of all


Employees from table EMP.
ANSWER:SELECT EMPNO, ENAME FROM EMP;
OUTPUT:
QUERY-2: Display ENAME, SAL and SAL added with
COMM from table EMP.
ANSWER:SELECT ENAME, SAL, SAL+COMM FROM
EMP;

OUTPUT:
QUERY-3: Display DISTINCT SAL of Employees
from table EMP.
ANSWER:SELECT DISTINCT SAL FROM EMP;

QUERY-4: Show the Structure of table DEPT.


ANSWER:SELECT * FROM DEPT;
OUTPUT:

QUERY-4: Write a Query to display ENAME and SAL


of Employees whose salary is greater than or equal
to 3000.00 from table EMP.
ANSWER:SELECT ENAME, SAL FROM EMP WHERE
SAL>=3000;
OUTPUT:

QUERY-5: Write a Query to display Employee


name, salary and department number who are not
getting commission from table EMP.
ANSWER:SELECT ENAME, SAL, DEPTNO FROM
EMP WHERE COMM IS NULL;
OUTPUT:

QUERY-6: Write a Query to display Employee


number, name, salary and salary*12 as Annual
Salary whose commission is NOT NULL from table
EMP.
ANSWER:SELECT EMPNO, ENAME, SAL, SAL*12
FROM EMP WHERE COMM IS NOT NULL;
OUTPUT:

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

/*TO PRINT A SERIES*/

#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;

cout<<"\n\nEnter the elements : \n\n";


for(int i=0; i<n; i++)
cin>>A[i];

cout<<"\n\nArray formed is : ";


for(i=0; i<n; i++)
cout<<A[i]<<" ";

cout<<"\n\nEnter the element to be searched : ";


cin>>p;

void binary_search(int A[], int n, int p);


//declaration

binary_search(A,n,p);

getch();
}

void binary_search(int A[], int n, int p)


{ int L,U,mid; char ch;
lb: L=0; U=n-1;

while(L<=U) //i.e loop will continue if L<=u. if


L>U loop will end
{ mid=(L+U)/2;
if(A[mid]==p)
{ cout<<"\n\nElement "<<p<<" found. Search
Successful.";
cout<<"\n\nSubscript = "<<mid<<"
\n\nPosition = "<<mid+1;
break;
}
else if(p<=A[mid])
U=mid-1;

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];

cout<<"\n\nArray of elements is as shown


below : \n\n";
for(i=0; i<n; i++)
cout<<A[i]<<" ";
cout<<"\n\nNow Elements will be arranged in
ascending order using bubble sort :\n\n";

void bubble_sort(int A[],int n);

bubble_sort(A,n);

getch();
}

void bubble_sort (int A[], int n)


{ int temp; int count=0;
for(int i=0; i<n; i++)
{
for(int j=0; j<n-1; j++)
{ if(A[j+1]<A[j])
{ count++;
temp=A[j+1];
A[j+1]=A[j];
A[j]=temp;
cout<<"\n\nArray for iteration
"<<count<<" is : \n\n";
for(int k=0; k<n; k++)
cout<<A[k]<<" ";
}
}
}
}

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();
}

Вам также может понравиться