You are on page 1of 57

LIST OF PRACTICALS CLASS XII SUBJECT : COMPUTER SCIENCE Q1. Define a class PhoneBill in C++ with the following descriptions.

Private members: CustomerName of type character array PhoneNumber of type long No_of_units of type int Rent of type int Amount of type float. calculate( ) This member function should calculate the value of amount as Rent+ cost for the units. Where cost for the units can be calculated according to the following conditions. No_of_units Cost First 50 calls Free Next 100 calls 0.80 @ unit Next 200 calls 1.00 @ unit Remaining calls 1.20 @ unit Public members: * A constructor to assign initial values of CustomerName as “Raju”, PhoneNumber as 259461, No_of_units as 50, Rent as 100, Amount as 100. * A function accept( ) which allows user to enter CustomerName, PhoneNumber, No_of_units and Rent and should call function calculate( ). * A function Display( ) to display the values of all the data members on the screen. Solution: #include <iostream.h> #include <conio.h> #include <stdio.h> #include<string.h> class phonebill { private: char CustomerName[20]; long PhoneNumber; int No_of_units ; int Rent; float Amount; void calculate(); public: phonebill() { PhoneNumber=259461; No_of_units=50; strcpy(CustomerName,"Raju"); Rent=100; Amount=100; } void accept(); void display(); }; void phonebill:: calculate()

{ if(No_of_units<=50) Amount=Rent; else if(No_of_units>=51 && No_of_units<=150) Amount = Rent+(No_of_units-50)*0.80; else if(No_of_units>=151 && No_of_units<=350) Amount=Rent+100*.80+(No_of_units-150)*1.00; else Amount=Rent+No_of_units*1.20; } void phonebill::accept() { cout<<"\n enter user name"; gets(CustomerName); cout<<"\n enter phone no." ; cin>>PhoneNumber; cout<<"\n enter no.of units"; cin>>No_of_units; cout<<"\n enter rent"; cin>>Rent; calculate(); } void phonebill:: display() { cout<<"\n user name"<<CustomerName; cout<<"\n phone no."<<PhoneNumber; cout<<"\n no.of units"<<No_of_units; cout<<"\n rent"<<Rent; cout<<"\n amount"<<Amount; } void main() { clrscr(); phonebill x; x.accept(); clrscr(); x.display(); getch(); } Output: enter user name Akash enter phone no. 298283 enter no.of units 150 enter rent 100 user name Akash phone no. 298283 no.of units 280 rent 100 amount 310

Q2. Define a class Tour in C++ with the description given below : Private Members : TCode of type string Noofadults of type integer Noofkids of type integer Kilometres of type integer Totalfare of type float Public Members : • A constructor to assign initial values as follows : TCode with the word “NULL” NoofAdults as 0 NoofKids as 0 Kilometres as 0 TotalFare as 0 • A function AssignFare ( ) which calculates and assigns the value of the data member TotalFare as follows : For each Adult Fare(Rs) For Kilometres 500 >=1000 300 <1000 &>=500 200 <500 For each Kid the above Fare will be 50% of the Fare mentioned in the above table For example : If Kilometres is 850, Noofadults = 2 and Noofkids = 3 Then TotalFare should be calculated as Numofadults * 300 + Noofkids * 150 i.e. 2*300 + 3*150=1050 • A function EnterTour( ) to input the values of the data members TCode, NoofAdults, NoofKids and Kilometres; and invoke the Assign Fare( ) function. • A function ShowTour( ) which displays the content of all the data members for a Tour. Solution: #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> class Tour { private: char TCode[5]; int NoofAdults; int NoofKids; int Kilometres; float TotalFare; public: Tour(); void AssignFare(); void EnterTour(); void ShowTour(); }; void Tour::Tour(void) { strcpy(TCode,"NULL"); NoofAdults=0;

NoofKids=0; Kilometres= 0; TotalFare=0.0f; } void Tour::EnterTour(void) { cout<<"\nEnter value of travel Code "; cin>>TCode; cout<<"\nEnter no. of adults "; cin>>NoofAdults; cout<<"\nEnter No of kids "; cin>>NoofKids; cout<<"\nEnter distance"; cin>>Kilometres; AssignFare(); } void Tour::AssignFare(void) { float fare=0.0f; if(Kilometres>1000) { fare = NoofAdults*500+NoofKids*250; } else if(Kilometres>=500) { fare = NoofAdults*300+NoofKids*150; } else fare = NoofAdults*200+NoofKids*100; Totalfare=fare; } void Tour::ShowTour(void) { cout<<"\n\n\n\n\n\n\nTravel List is as follows :"; cout<<"\n Travel Code: "<<TCode; cout<<"\n Number Of Adults: "<<NoofAdults; cout<<"\n Number of kids: "<<NoofKids; cout<<"\n Kilometres: "<<Kilometres; cout<<"\n Total Fare:"<<TotalFare; } void main() { clrscr(); Tour x; x.EnterTour(); x.ShowTour(); getch(); } Output: Enter value of travel Code 101 Enter no. of adults 2 Enter No of kids 3

Enter distance 850 Travel List is as follows Travel Code: 101 Number Of Adults: 2 Number of kids: 3 Kilometres: 850 Total Fare:1050 Q3. Define a class ELECTION with the following specifications : Private members : Data : candidate_name , party , vote_received Public members : Functions : INPUT( ) – to input data DISPLAY( ) – to display the details of the winner WINNER( ) – To return the details of the winner through the object after comparing the votes received by three candidates . Write a suitable main ( ) function to input data in 3 objects of ELECTION type and display the details of the winning candidate. Solution: #include<iostream.h> #include<conio.h> #include<stdio.h> class ELECTION { private: char cname[20]; char party[30]; long voterecevied; public: void input() { cout<<"\n Enter candidates name"; gets(cname); cout<< "\n Enter party of the candidate name"; gets(party); cout<<"\n Enter the amount of vote recevied by the candidate"; cin>>voterecevied; cout<<"\n\n\n\n"; } void display() { clrscr(); cout<<"\n Winning candidate"; cout<<"\n Candidate name"<<cname; cout<< "\n Party of the candidate "<<party; cout<<"\n The amount of vote recevied by the candidate"<<voterecevied; } ELECTION WINNER(ELECTION X,ELECTION Y,ELECTION Z) { if((X.voterecevied>Y.voterecevied) && (X.voterecevied>Z.voterecevied)) {

} else return(Z).b[50]. A. W.W.display().WINNER(A. . W=W.n.input(). Solution: //program to merge two arrays in a single array //Array A is in Ascending Order & Array B is in Descending Order //Array C must be in Descending Order #include<iostream.input().voterecevied>X. C.C).return(X).voterecevied) && (Y. int a[50].h> #include<conio.B. n.B.B.voterecevied)) { return(Y).voterecevied>Z. } Output: Enter candidates name Abhinav Enter party of the candidate name BJP Enter the amount of vote recevied by the candidate45861 Enter candidates name Rahul Enter party of the candidate name RJD Enter the amount of vote recevied by the candidate56445 Enter candidates name Rajeev Enter party of the candidate name CONGRESS Enter the amount of vote recevied by the candidate46466 Winning candidate Candidate name Rahul Party of the candidate RJD The amount of vote recevied by the candidate56466 Q4.k. Suppose A. } }.C are arrays of size m. B. Array A is stored in ascending order and array B is in descending order. clrscr().c[100]. getch().input(). Write a program using function to receive 3 arrays and their sizes to store the elements of A and B into C in descending order. } else if ((Y.C.h> void main() { int m. m+n respectively. void main() { ELECTION A.

j.j<n. } //printing contents of merged array cout<<"\nMerged arrays are as following. j=0. } . } if(i>=0) { while(i>=0) c[k++]=a[i--].i<m. for(j=0. } getch().i>=0 && j<n. k=0.. cin>>a[i].i<(m+n). clrscr(). for(i=0.i++) { cout<<"\nEnter value of "<<i+1<<" value of Array A ". i=i-1. } else { while(j<n) c[k++]=b[j++]. } else { c[k]=b[j]. } k=k+1. } cout<<"\n\n\nEnter values for Array B in Descending Order\n". cout<<"\nEnter values for Array A in Ascending Order\n". for(.\n". cin>>b[j].) //Shifting array A and B to Array C { if(a[i]>=b[j]) { c[k]=a[i]. // entering size of array cout<<"\nEnter the size of 1st array A"..j++) { cout<<"\nEnter value of "<<j+1<<" value of Array B ". cout<<"\nEnter the size of 2nd array B".int i.i++) { cout<<c[i]<<"\n".. cin>>n. for(i=0. j=j+1. } i=m-1. cin>>m.

int a[50]. cin>>b[j]. cin>>a[i].C are arrays of size m.i++) { cout<<"\nEnter value of "<<i+1<<" value of Array A ".k. for(i=0.n..h> void main() { int m. cin>>n. Solution: //program to merge two arrays in a single array //Array A is in Ascending Order & Array B is in Descending Order //Array C must be in Descending Order #include<iostream.i<m. Write a program using function to receive 3 arrays and their sizes to store the elements of A and B into C in descending order. Suppose A. } cout<<"\n\n\nEnter values for Array B in Descending Order\n"..c[100]. cout<<"\nEnter the size of 2nd array B". cin>>m. cout<<"\nEnter values for Array A in Ascending Order\n".j<n.B. 5 4 3 3 2 1 Q5.. n.b[50].Output: Enter the size of 1st array A3 Enter the size of 2nd array B3 Enter values for Array A in Ascending Order Enter value of 1 value of Array A 1 Enter value of 2 value of Array A 2 Enter value of 3 value of Array A 3 Enter values for Array B in Descending Order Enter value of 1 value of Array B 5 Enter value of 2 value of Array B 4 Enter value of 3 value of Array B 3 Merged arrays are as following. clrscr(). m+n respectively.j.h> #include<conio. for(j=0. Array A is stored in descending order and array B is in ascending order. int i. // entering size of array cout<<"\nEnter the size of 1st array A".j++) { cout<<"\nEnter value of "<<j+1<<" value of Array B ". .

. j=0. for(. 16 14 13 . } //printing contents of merged array cout<<"\nMerged arrays are as following.. } Output: Enter the size of 1st array A3 Enter the size of 2nd array B3 Enter values for Array A in Descending Order Enter value of 1 value of Array A 13 Enter value of 2 value of Array A 12 Enter value of 3 value of Array A 11 Enter values for Array B in Ascending Order Enter value of 1 value of Array B 10 Enter value of 2 value of Array B 14 Enter value of 3 value of Array B 16 Merged arrays are as following. } k=k+1. } else { while(j<n) c[k++]=b[j++].} i=m-1. i=i-1. } if(i>=0) { while(i>=0) c[k++]=a[i--]. } getch(). for(i=0. k=0. } else { c[k]=b[j].i>=0 && j<n..\n".. j=j+1..) //Shifting array A and B to Array C { if(a[i]>=b[j]) { c[k]=a[i]..i<(m+n).i++) { cout<<c[i]<<"\n".

i++)//Loop for Bubble Sorting { for(j=0. } } } .h> struct Examinee { long RollNo.Score) { tmp=x[j]. x[j]=x[j+1].j<(n-1). }. Write program using a function SORTSCORE( ) in C++ to sort an array of structure Examinee in descending order of Score using BUBBLE Sort. float Score.h> #include<process.12 11 10 Q6. char Name[20]. void SORTSCORE(Examinee x[]. x[j+1]=tmp. float Score. Note : Assume the following definition of structure Examinee struct Examinee { long RollNo.h> #include<stdio.j. Name Score 1002 Anika Jain 345 1001 Ravyank Kapur 300 1003 Gearge Peter 297 1005 Farida Khan 289 Solution: //Bubble sorting of Structures #include<iostream.h> #include<conio.int n) { int i. char Name[20]. Sample content of of the array (before sorting) Roll NO. for(i=0. Examinee tmp.Score<x[j+1].j++) { if(x[j]. }.i<n. Name Score 1001 Ravyank Kapur 300 1005 Farida Khan 289 1002 Anika Jain 345 1003 Gearge Peter 297 Sample content of of the array (after sorting) Roll NO.

RollNo. cout<<"Enter number of Examinees". Definitions of the structure is as follows struct Employee { . for(i=0. cout<<"\nEnter Roll No. Examinee x[100]. cin>>x[i].i<n. Write a C++ function to arrange the same with the help of Selection sort. } SORTSCORE(x. } Output: Enter number of Examinees3 Enter value for Examinee 1 Enter Roll No.i++) { cout<<"\nEnter value for Examinee "<<i+1<<"\n". int i.Name<<"\t"<<x[i]. cin>>n. An array E containing elements of structure Employee is required to be arranged in descending order of salary. cout<<"\nEnter Name ".Name).Score.cout<<"\nExaminees after sorting are \n". ".i<n.Score<<"\n". The array and its size is required to be passed as parameters to the functions.RollNo<<"\t"<<x[i].n.n). 1 Enter Name Akash Enter Score 300 Enter value for Examinee 2 Enter Roll No.i++) { cout<<x[i]. cout<<"\nEnter Score ". cin>>x[i]. 3 Enter Name Gagan Enter Score 345 Examinees after sorting are 3 Gagan 345 1 Akash 300 2 Fariha 280 Q6(A). gets(x[i]. getch(). for(i=0. } } void main() { clrscr(). 2 Enter Name Fariha Enter Score 280 Enter value for Examinee 3 Enter Roll No.

int n) { int i. for(i=0. } } tmp=x[i]. } } void main() { clrscr().pos. for(j=i+1. pos=j. } cout<<"\nRecords after sorting are \n".i++) { cout<<x[i].i++)//Exchange Selection sort { big=x[i]. for(i=0. x[pos]=tmp. x[i]=x[pos]. Employee tmp. }.salary.empno<<"\t"<<x[i]. cin>>n.int empno.salary<<"\n".h> //inclusion of header file #include<stdio.i<n. cout<<"\nEnter Employee Name ". char Ename[20].i<n. }. ". cout<<"Enter number of Employees ".h> //inclusion of header file #include<conio. int i. for(i=0. .j.h> //inclusion of header file struct Employee { int empno.i++) { cout<<"\nEnter values for employee "<<i+1<<"\n". float salary. Employee x[100]. void sort(Employee x[].salary.n. float salary.j++) { if(x[j].salary>big) { big=x[j].i<n. char Ename[20].Ename<<"\t"<<x[i]. Solution: //Program for sorting using selection sort #include<iostream.empno. cin>>x[i].big.j<n. cout<<"\nEnter Employee No.

} Output: Enter number of Employees 3 Enter values for employee 1 Enter Employee No. } sort(x. } for(i=1. "<<i<<"\n". 2 Enter Employee Name Dilip Enter Salary 3200 Enter values for employee 3 Enter Employee No.gets(x[i]. .j.i++) //loop for insertion sorting { tmp=sal[i].i++) { cout<<"enter salary of employee no. (Use insertion sort technique to sort the salaries) Solution: //Arranging salaries stored in an array using Insertion sort #include<iostream.h> #include<conio. cin>>n. sal[0]=INT_MIN. 3 Enter Employee Name Suresh Enter Salary 1100 Records after sorting are 2 Dilip 3200 1 Amar 2100 3 Suresh 1100 Q7.h> #include<limits.i<=n.Ename). Write a program to accept salaries of some employees in an array of size accepted from user and display the salaries in ascending order. int sal[100]. getch().i.n). cout<<"Enter number of employees ". cin>>x[i]. j=i-1.tmp. for(i=1. cin>>sal[i].salary.i<=n. 1 Enter Employee Name Amar Enter Salary 2100 Enter values for employee 2 Enter Employee No.h> void main() { clrscr().n. cout<<"\nEnter Salary ".

} getch().h> void main() { clrscr(). cin>>s. j--.k=0. (Use Binary search technique for searching) Solution: //Searching using Binary Search Technique #include<iostream. } cout<<"\nEnter Employee No. for(i=0. 4 3000 Salaries after sorting are 1400 2100 3000 3400 Q8. of Employee "<<i+1<<"\n". to search".h> #include<process. for(i=1. cout<<"\nEnter No. 3 1400 enter salary of employee no. of Employees". } sal[j+1]=tmp.h> #include<conio. int a[100]. 2 3400 enter salary of employee no.n.i++) { cout<<"Enter Employee No. If it.end. is present then display it’s position.i<n. cin>>n.i++) { cout<<sal[i]<<"\n".i<=n. 1 2100 enter salary of employee no. } cout<<"\nSalaries after sorting are \n". .s.while(tmp<sal[j]) { sal[j+1]=sal[j].i. } Output: Enter number of employees 4 enter salary of employee no. cin>>a[i].beg=0.mid. Write a program to store some employee numbers in an array and then accept an employee number and then search and display whether the given employee number is present in the array or not. end=n-1.

of Employee 3 1240 Enter Employee No.e. if the array content is 543 678 129 Output through the function should be : Diagonal One : 5 7 9 Diagonal Two : 3 7 1 Solution: #include<iostream.i++) . [Assuming the 2D Array to be a square matrix with odd dimension i. break.found at "<<mid+1<<" position". of Employee 4 1270 Enter Employee No.found at 2 position Q9. } getch(). cout<<"Employee No. of Employee 1 1200 Enter Employee No. to search1220 Employee No. for(i=0.j. 3×3.] Example. cout<<"\n\n\nDiagonal1 : \t". if(a[mid]==s) { k=1. } Output: Enter No. not Found". else end=mid-1.int size) { int i.h> //inclusion of header file #include<conio.h> //inclusion of header file void showdiagonal(int a[100][100]. 5×5. of Employee 2 1220 Enter Employee No. of Employees4 Enter Employee No. } if(k==0) { cout<<"Employee No.i<size.while(beg<=end) { mid=(beg+end)/2. 7×7 etc. } else if(s>a[mid]) beg=mid+1. Write a function in C++ which accepts a 2D array of integers and its size as arguments and displays the elements which lie on diagonals.

j<size.j<size.i<size.i<size.i++) { for(j=0.j++) { if((i+j)==(size-1)) { cout<<a[i][j]<<"\t". } } } } void main() { clrscr().size). } showdiagonal(a. } Output: Enter size of array (odd)3 ".{ cout<<a[i][i]<<"\t".i. } cout<<"\n\n\n\n\nDiagonal Two :\t". cin>>size. } else { cout<<"\nArray must have size odd ".j++) { cout<<a[i][j]<<"\t". } } cout<<"\n Original array is \n".j.j<size. . for(i=0.j++) { cout<<"Enter value of "<<i+1<<" row and "<<j+1<<" column cin>>a[i][j]. int a[100][100].i<size. for(i=0. if(size%2!=0) { cout<<"\nEnter values for array \n".i++) { for(j=0. for(i=0. } cout<<"\n".i++) { for(j=0. } getch(). cout<<"\nEnter size of array (odd)".size.

[Assuming the 2D Array to be a square matrix with odd dimension i. for(i=0. for(i=0. 3×3. 7×7 etc.. 5×5.int r.Enter values for array Enter value of 1 row and 1 column Enter value of 1 row and 2 column Enter value of 1 row and 3 column Enter value of 2 row and 1 column Enter value of 2 row and 2 column Enter value of 2 row and 3 column Enter value of 3 row and 1 column Enter value of 3 row and 2 column Enter value of 3 row and 3 column Original array is 11 12 13 14 15 16 17 18 19 Diagonal1 : 11 15 15 19 17 11 12 13 14 15 16 17 18 19 Diagonal Two : 13 Q10.i.] Example.i++) { cout<<a[i][k]<<"\t".h> //inclusion of header file #include<conio. cout<<"\n\n\nContents of Middle Row are\n".int c) { int i.j.h> //inclusion of header file void show_mid(int a[100][100].k. } } void main() { clrscr(). } cout<<"\n\n\n\n\nContents of Middle Column are \n". . k=r/2. if the array content is 354 769 218 Output through the function should be : Middle Row : 7 6 9 Middle Column : 5 6 1 Solution: #include<iostream.i++) { cout<<a[k][i]<<"\t". int a[100][100].c.i<c.e.i<r. Write a function in C++ which accepts a 2D array of integers and its size as arguments and displays the elements of middle row and the elements of middle column..r.

} cout<<"\n".j++) { cout<<"Enter value of "<<i+1<<" row and "<<j+1<<" column cin>>a[i][j].c).i<r. } } cout<<"\nOriginal array is \n". Write a program using a function SWAPARR( ) in C++ to swap(interchange) the first row elements with the last row elements.j<c.cout<<"\nEnter no. for(i=0. Example : If the two dimensional array contains : 5 6 3 2 1 2 4 9 2 5 8 1 9 7 5 8 After swapping of the content of first row and last row. of rows and columns of array 3 3 Enter values for array Enter value of 1 row and 1 column Enter value of 1 row and 2 column Enter value of 1 row and 3 column Enter value of 2 row and 1 column Enter value of 2 row and 2 column Enter value of 2 row and 3 column Enter value of 3 row and 1 column Enter value of 3 row and 2 column Enter value of 3 row and 3 column Original array is 11 12 13 14 15 16 17 18 19 Contents of Middle Row are 14 15 16 Contents of Middle Column are 12 15 18 11 12 13 14 15 16 17 18 19 ". it should be as follows: . of rows and columns of array ". } Output: Enter no. getch(). Q11.r. for(i=0. cin>>r>>c.j++) { cout<<a[i][j]<<"\t". cout<<"\nEnter values for array \n".i++) { for(j=0.j<c.i++) { for(j=0. for a two dimensional integer array passed as the argument of the function.i<r. } show_mid(a.

h> //inclusion of header file void swaparr(int a[100][100].j++) { cout<<"enter value of "<<i+1<<" row and "<<j+1<<" column ".i++) { for(j=0.i. } } void main() { clrscr().9 1 2 5 7 2 5 6 5 4 8 3 8 9 1 2 Solution: #include<iostream. } swaparr(a. } cout<<"\n". of rows and columns of array ". } } cout<<"\nOriginal array is \n".i<r. int a[100][100]. cout<<"\nEnter values for array \n". for(i=0. } cout<<"\n".r.tmp. cin>>r>>c. cout<<"\nEnter no.j<c.i<r.h> //inclusion of header file #include<conio. a[r-1][j]=tmp.c. a[0][j]=a[r-1][j]. cin>>a[i][j]. .i++) { for(j=0. for(i=0.j++) { cout<<a[i][j]<<"\t".i++) { for(j=0. for(j=0.j.j++) { cout<<a[i][j]<<"\t".j++) { tmp=a[0][j].int r.c).j<c.j<c. } cout<<"\nAfter swapping first and last rows array is\n".j<c.j.int c) { int i.r. for(i=0.i<r.

Write a function in C++ which accepts an integer array and its size as arguments / parameters and assign the elements into a two dimensional array of integers in the following format (size must be odd) If the array is 1 2 3 4 5 If the array is 10 15 20 The output must be The output must be 10005 10 0 20 02040 0 15 0 00300 10 0 20 02040 10005 Solution: #include<iostream. } else 1 2 3 4 5 6 7 8 9 .c<size.getch(). k=k+1. of rows and columns of array 3 3 Enter values for array enter value of 1 row and 1 column enter value of 1 row and 2 column enter value of 1 row and 3 column enter value of 2 row and 1 column enter value of 2 row and 2 column enter value of 2 row and 3 column enter value of 3 row and 1 column enter value of 3 row and 2 column enter value of 3 row and 3 column Original array is 1 2 3 4 5 6 7 8 9 After swapping first and last rows array is 7 8 9 4 5 6 1 2 3 Q12. for(r=0.int size) { int b[100][100].k=0.r.h> #include<conio. } Output: Enter no.c++) { if(r==c) { b[r][c]=a[k].r++) { for(c=0.r<size.c.h> void perform(int a[100].

k=k-1.i<size.r++) { for(c=0. for(i=0.r++) { for(c=0. for(r=0. int a[100].c<size.i++) { cout<<"\n enter the value of "<<i+1<< "number:".r<size.c++) { cout<<b[r][c]<<"\t". } } void main() { clrscr(). } OUTPUT: enter the size of the array5 enter the value of 1number:1 enter the value of 2number:2 enter the value of 3number:3 enter the value of 4number:4 enter the value of 5number:5 Contents of array B is 1 0 0 0 5 0 2 0 4 0 .size. getch(). cin>>a[i]. } } } k=size-1.c++) { if((r+c==(size-1))) { b[r][c]=a[k]. for(r=0.c<size.i.r<size.{ b[r][c]=0. } } } cout<<"\nContents of array B is \n". } perform(a. cin>>size. } cout<<"\n".size). cout<<"\n enter the size of the array".

5.2.3.i. } cout<<"\nContents of array B is \n". Write a function in C++ which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format: If the array is 1. } cout<<"\n".i++) { cout<<"\n enter the value of "<<i+1<< "number:". cout<<"\n enter the size of the array". for(i=0.size. int a[100]. cin>>x.c<size.i<size.k=0.h> void perform(int a[100].c<size.c.4. } for(c=i+1.r=0. r=r+1.c++) { b[r][c]=a[k]. } k=0.x.c<=size. k=k+1.3 The resultant 2D array is The resultant 2D array is 100000 100 120000 120 123000 123 123400 123450 123456 Solution: #include<iostream.r++) { for(c=0.int size) { int b[100][100].2. } } void main() { clrscr(). .0 0 1 0 2 0 3 0 0 0 4 0 0 0 5 Q13. for(r=0.c++) { cout<<b[r][c]<<"\t".r<size.i++) { for(c=0.i.6 if the array is 1.c++) { b[r][c]=0.h> #include<conio.i<x. for(i=0.

cout<<"\nEnter the text for Data File \n".15.ios::in).getline(s. gets(s).ios::out).cin>>a[i]. if the content of the file DIALOGUE. . Is this book good? Then the output of the program should be 2.h> #include<conio. } perform(a. } } cout<<"\n\n\nTotal No. H<<s. char s[15]. H.close(). clrscr(). H. int c=0. getch(). while(!A. Solution: //Program to print total no. perform(). char s[80]. of "is" #include<fstream. if((s[0]=='i' || s[0]=='I') && (s[1]=='S' || s[1]=='s')) { c++.TXT".' ').TXT.h> #include<stdio.open("DIALOGUE.x). } OUTPUT: enter the size of the array3 enter the value of 1number:1 enter the value of 2number:2 enter the value of 3number:3 Contents of array B is 1 0 0 1 2 0 1 2 3 Q14 Write a function in C++ to print the count of the word is as an independent word in at text file DIALOGUE.eof()) { A. } void main() { ofstream H.TXT". of is="<<c. For example.open("DIALOGUE.h> void perform() { ifstream A. getch(). A. TXT is This is his book.

DAT and creates a file named BASKET.close().GameName.read((char*)&y. Write a function in C++ that would read contents from the file GAME. while(!A.write((char*)&y.sizeof(Game)). is this book good? Total No.DAT". H. gets(x.open("GAME. if(strcmp(y. char Participant[30]. B. B. ifstream A.h> #include<stdio. }. containing records of the following structure type struct Game { char GameName [20]. void COPYGAME() { Game y."Basket Ball")==0) { B.close(). ofstream H.h> #include<fstream.DAT copying only those records from GAME.DAT". do { cout<<"\nEnter Name of Game". ofstream B. A. char Participant [30].h> #include<string.DAT.} Output: Enter the text for Data File This is his book.open("GAME. Game x. .GameName). } void main( ) { clrscr(). }.ios::binary|ios::out). int ch. } } A.eof()) { A. Solution: #include<conio.sizeof(Game)).ios::binary|ios::out).ios::binary|ios::in).h> struct Game { char GameName[20].DAT". of is=2 Q15 Given a binary file GAME.DAT where the game name is “Basket Ball”.open("BASKET.

gets(x.DAT is as follows:\n". cin>>ch. } while(ch==1). COPYGAME( ). c=c+1.read((char*)&x.sizeof(Game)).open("BASKET. GG. ifstream GG. } Output: Enter Name of GameBasket Ball Enter Name Of Participant Amar Press 1 to enter more records else to stop 1 Enter Name of GameCricket Enter Name Of Participant Dhanraj Press 1 to enter more records else to stop 1 Enter Name of GameBasket Ball Enter Name Of Participant Mukesh Press 1 to enter more records else to stop 2 Contents Of BASKET.Participant).sizeof(Game)). int c=0.open("BASKET.i<(c-1). cout<<"\n\nName of Game "<<x. that reads the file FIRST. while(!GG.cout<<"\nEnter Name Of Participant ". to .write((char*)&x.Participant. } G. write a program using a function named vowelwords( ).read((char*)&x. ifstream G. cout<<"\nContents Of BASKET.eof()) { GG. H. H.close().GameName.DAT is as follows: Name of Game Basket Ball Name Of Participant Amar Name of Game Basket Ball Name Of Participant Mukesh Q16 Create a text file named FIRST.TXT. cout<<"\nPress 1 to enter more records else to stop ".sizeof(Game)).DAT". } GG.DAT". getch().TXT which contains some text written into it. cout<<"\nName Of Participant "<<x.ios::binary|ios::in).close().close().i.TXT and creates a new file named SECOND.i++) { G. for(i=1. G.ios::binary|ios::in).

' ').getline(s. with ‘a’. For example if the file FIRST.TXT". if(s[0]=='a'||s[0]=='e'||s[0]=='i'||s[0]=='o'||s[0]=='u') { B<<s<<"\n".TXT shall contain: umbrella and overcoat it Solution: #include<stdio. B. ‘u’).20. ’I’. ‘o’. } void main() { .h> #include<conio.h> void vowelwords() { char s[20]. B.contain only those words from the file FIRST. A.open("FIRST.open ("SECOND.eof()) { A.TXT which start with a lowercase vowel (i. ifstream A. while(!A. } } A.close().TXT contains Carry umbrella and overcoat when it rains Then the file SECOND.TXT".ios::out). ’e’.ios::in).e.close(). ofstream B.

vowelwords().TXT \n".TXT is as follows : umbrella and overcoat it Q17. } getch().ios::binary|ios::in). gets(st).ios::binary|ios::out).DAT which should contains the records of the following structure type: struct Student . Create a binary file STUDENT.open("SECOND. X<<st. } Output: Enter Text to store in FIRST.TXT Carry umbrella and overcoat when it rains Contents of SECOND.TXT". X.open("FIRST. cout<<"\nEnter Text to store in FIRST. cout<<st<<" ". while(!Y.TXT". ifstream Y. X.close(). ofstream X.clrscr(). char st[80]. Y. cout<<"\n\n\nContents of SECOND.eof()) { Y>>st.TXT is as follows :\n".

eof()) { A.m3=35.m2<<"\t"<<x. . }.i++) { C. }.DAT".sizeof(Student)).rno<<"\t"<<x. for(int i=0. c=c+1. Solution: #include<fstream.open("TEMP. B.close(). } A.open("STUDENT.DAT and modify the marks to 35 if anybody’s any marks are less than 35.open("STUDENT.m3<35) x. void perform() { int c=0.m2=35.sizeof(Student)). if(x. A.ios::in).\tM1 \tM2 \tM3 \n".m3. remove("STUDENT.m3<<"\n".i<(c-1).h> #include<stdio. if(x.{ int rno.write((char*)&x.DAT"). B.m1=35. B.m2. cout<<"\n\nContents After Updating is as follows :".sizeof(Student)).m2<35) x. cout<<"\nRNo. ifstream C.DAT".read((char*)&x. cout<<x.m3. float m1.h> struct Student { int rno.close().DAT".m2. rename("TEMP. } C.m1<<"\t"<<x. while(!A. Write a program using function in C++ that would read contents from the file STUDENT.m1<35) x. if(x.DAT").ios::out). C.read((char*)&x.close().h> #include<conio.DAT". float m1. Student x.ios::in). ifstream A. ofstream B."STUDENT.

rno<<"\t"<<z. cin>>ch. D. while(ch==1) { cout<<"\nEnter rno of student ". Student z.close(). cout<<"\nPress 1 to enter more records else to stop". cout<<"\nEnter marks of 3 subjects".m1<<"\t"<<z.i++) { E.sizeof(Student)).} void main() { clrscr().open("STUDENT. ifstream E. for(int i=0. } E. cout<<"\n\nContents Before Updating is as follows :". M1 M2 M3 .ios::out). cout<<"\nRNo. E. getch(). D. cin>>z.sizeof(Student)).rno.v=0.m2<<"\t"<<z. perform().m1>>z.read((char*)&z. } D. M1 M2 M3 1 45 23 56 2 87 56 11 3 67 89 90 Contents After Updating is as follows : RNo. v=v+1.m3. cin>>z.write((char*)&z.m3<<"\n". ofstream D.ios::in). } Output: Enter rno of student 1 Enter marks of 3 subjects45 23 56 Press 1 to enter more records else to stop1 Enter rno of student 2 Enter marks of 3 subjects87 56 11 Press 1 to enter more records else to stop1 Enter rno of student 3 Enter marks of 3 subjects67 89 90 Press 1 to enter more records else to stop2 Contents Before Updating is as follows : RNo.open("STUDENT.DAT".close(). cout<<z.DAT".i<v. int ch=1.\tM1 \tM2 \tM3 \n".m2>>z.

cout<<"\nEnter Phone number". Solution: #include<conio. containing records of the following class Directory : class Directory { char Name[20] .h> class Directory { private: char Name[20]. public . // to accept values void Show( ) . . cout<<"\nArea code "<<AreaCode.DAT. // to display values int CheckCode(char AC[ ]). void Register( ) . char phone_No[15].AC). gets(AreaCode). char Address[30] .h> #include<fstream. char Address[30].DAT to TELEBACK. char AreaCode[5] .// to compare area code with accepted argument }. gets(Address).h> #include<string. Write a program to store object of above class in the data file at first and then using a function COPYABC( ) in C++ copy all those records having AreaCode as “123” from TELEPHON. } void Show( ) { cout<<"\n\nName of customer "<<Name.DAT. public: void Register( ) { cout<<"\nEnter Name of customer". char phone_No[15] . char AreaCode[5]. gets(phone_No). gets(Name). cout<<"\nPhone number "<<phone_No.1 2 3 45 87 67 35 56 89 56 35 90 Q18 Given a binary file TELEPHON. cout<<"\nEnter Area code". } }. cout<<"\nAddress of customer "<<Address. cout<<"\nEnter Address of customer ". } int checkcode(char AC[]) { return strcmp(AreaCode.h> #include<stdio.

x. H. if(x.DAT".DAT". while(!A.open("TELEBACK. B. cout<<"\nContents Of Teleback.read((char*)&x.ios::binary|ios::in). . int ch.read((char*)&x. H. ofstream B.ios::binary|ios::in).close(). cin>>ch.i++) { G. } GG.Register(). B.dat is as follows:\n".write((char*)&x. G. ifstream A.i<(c-1).open("TELEPHON. A.eof()) { A.sizeof(x)).ios::binary|ios::in). int c=0.write((char*)&x. ofstream H. } } A.open("TELEPHON. } void main( ) { clrscr().eof()) { GG. for(i=1. } while(ch==1).i. COPYABC( ). GG.ios::binary|ios::out). do { x.sizeof(x)).ios::binary|ios::out). Directory x. H. ifstream G.close().void COPYABC() { Directory x.DAT".checkcode("123")==0) { B.open("TELEBACK.Show(). while(!GG.sizeof(x)). } getch().sizeof(x)).close().read((char*)&x. cout<<"\nPress 1 to enter more records else to stop ".close(). ifstream GG.DAT".sizeof(x)).open("TELEBACK. c=c+1.DAT".

The Program should contain the following functions: i) push( ). char Itemname[20]. delete and display dynamically allocated Queue containing nodes of the following given structure: struct NODE { int Itemno. }. Write a program to store.h> #include<string. .dat is as follows: Name of customer Amar Address of customer Patna Area code 123 Phone number 123456 Name of customer Wilson Address of customer Danapur Area code 123 Phone number 789656 Q19.h> #include<process.h> struct Node { int Itemno.h> #include<stdio. char Itemname[20].} Output: Enter Name of customerAmar Enter Address of customer Patna Enter Area code123 Enter Phone number123456 Press 1 to enter more records else to stop 1 Enter Name of customerSuresh Enter Address of customer Khagaul Enter Area code254 Enter Phone number345212 Press 1 to enter more records else to stop 1 Enter Name of customerWilson Enter Address of customer Danapur Enter Area code123 Enter Phone number789656 Press 1 to enter more records else to stop 2 Contents Of Teleback. Solution: //QUEUE USING LINKED LIST #include<iostream. NODE *Link.h> #include<conio.to insert new element in Queue ii) pop( ) – to delete an element from the Queue iii) display() – to display the element of Queue.

.". ptr->Link=NULL.. *newptr. void Display(Node*). void main() { top=rear=NULL. Display(top). if(newptr==NULL) { cout<<"\nCannot create new node!!! Aborting!!\n". strcpy(ptr->Itemname. exit(1).. cin>>Itemno. cout<<"\nEnter name ". return ptr. } while(ch=='y' || ch=='Y'). } push_at_end(newptr).nm). Node* Create_New_Node(int.". char nm[]) { ptr=new Node.Itemname). cout<<"\nEnter Itemno.".. N to exit. cout<<"\nPress Y to enter more nodes. *ptr. } Node* Create_New_Node(int ino. while(ch=='y' || ch=='Y') { cout<<"\nEnter information for the new node. } void push_at_end(Node *np) . do { cout<<"\nThe Queue now is :\n". cout<<"\nWant to pop an element? (Y/N). } *top. gets(Itemname). newptr=Create_New_Node(Itemno. if(ch=='Y' || ch=='y') pop(). void push_at_end(Node*). void pop(). clrscr().*rear. ptr->Itemno=ino. cout<<"\nNow the Queue is:\n". Display(top)..Node *Link. cin>>ch. cin>>ch.char[]).". char ch='y'. } clrscr().. *save. int rno.name[20].

... N to exit.. N to exit. np=np->Link. } } Output: Enter information for the new node. else { ptr=top. rear=np. top=top->Link.{ if(top==NULL) { top=np. } cout<<"!!!\n". Enter Itemno.y Enter information for the new node.. delete ptr. } } void Display(Node *np) { while(np!=NULL) { cout<<np->Itemno<<" "<<np->Itemname<<"\n".n .1 Enter name Lux Now the Queue is: 1 Lux !!! Press Y to enter more nodes.2 Enter name Liril Now the Queue is: 1 Lux 2 Liril !!! Press Y to enter more nodes. } else { rear->Link=np. } void pop() { if(top==NULL) cout<<"UNDERFLOW !!!\n".. rear=np... Enter Itemno.

void main() { top=NULL. Book *Next.h> #include<conio. void pop().The Queue now is : 1 Lux 2 Liril !!! Want to pop an element? (Y/N). cout<<"\nEnter Book No.. *newptr. char ch='y'. char BName[20]. void Display(Book*). Solution: //STACK USING LINKED LIST-Insertion in the beginning of Stack #include<iostream. char Bname[20].bn[20]. void push(Book*). Book *Next.. Write a program to store.h> #include<stdio. } *top.y The Queue now is : 2 Liril !!! Want to pop an element? (Y/N).h> struct Book { int Bno. while(ch=='y' || ch=='Y') { cout<<"\nEnter information for the new node. }.n Q20.. . *ptr.to insert new element in stack ii) pop( ) – to delete an element from the stack iii) display() – to display the element of stack.h> #include<string. delete and display dynamically allocated Stack of Books implemented with the help of the following structure: struct Book { int BNo. clrscr().char nm[])."..". *save. Book* Create_New_Node(int n.h> #include<process... int n. The Program should contain the following functions: i) push( ).

top=np. if(ch=='Y' || ch=='y') pop(). } push(newptr). }while(ch=='y' || ch=='Y'). cin>>ch. ptr->Bno=n.. } Book* Create_New_Node(int n. exit(1). } clrscr(). Display(top). gets(bn).". cout<<"\nEnter Book Name ".cin>>n. cin>>ch.bn). strcpy(ptr->Bname. cout<<"\nWant to pop an element? (Y/N). Display(top). N to exit. np->Next=save.char nm[]) { ptr=new Book. ptr->Next=NULL.. do { cout<<"\nThe Stack now is :\n". cout<<"\nNow the Stack is:\n". if(newptr==NULL) { cout<<"\nCannot create new node!!! Aborting!!\n".. } void push(Book *np) { if(top==NULL) { top=np. } else { save=top. cout<<"\nPress Y to enter more nodes..". newptr=Create_New_Node(n.nm). return ptr. } } .

N to exit. } void pop() { if(top==NULL) cout<<"UNDERFLOW !!!\n".2 Enter Book Name Bhagya Now the Stack is: 2 Bhagya 1 Himmat !!! Press Y to enter more nodes.1 Enter Book Name Himmat Now the Stack is: 1 Himmat !!! Press Y to enter more nodes.. } cout<<"!!!\n"..y The Stack now is : . } } Output: Enter information for the new node..y Enter information for the new node.n The Stack now is : 2 Bhagya 1 Himmat !!! Want to pop an element? (Y/N).. N to exit.. Enter Book No... np=np->Next.. else { ptr=top. Enter Book No..void Display(Book *np) { while(np!=NULL) { cout<<np->Bno<<"\t"<<np->Bname<<"\n". top=top->Next.. delete ptr.

h> #include <conio.h> //inputs the header files #include <process. } } void stk::pop() { int i. deleted is "<<arr[r]. The Program must be written using classes and objects and it must contain the following functions: i) push( ). //end of class void stk::push(int n) { if (r>98) { cout<<"\nOverflow!! STACK is Full".n Q21. r=r-1.. }. arr[r]=n. if(r<0) { cout<<"\nStack is Empty. UNDERFLOW!!!". } else { cout<< "\nNo. } else { r=r+1. } void push(int). } } .1 !!! Himmat Want to pop an element? (Y/N). stk() //constructor { r=-1. void pop().to insert new element in stack ii) pop( ) – to delete an element from the stack iii) display() – to display the element of stack. void display().. int r. Write a program using arrays to implement STACK as an array. Solution: //PROGRAM TO IMPLEMENT THE STACK// #include <iostream. arr[r]=NULL.h> class stk //begin of class { public: int arr[100].

void stk::display() { if (r==-1) { cout<<"Stack is Empty". case 2: ob. } } //end of while } OUTPUT: 1. ob.Delete 3. cin>>ch. } } } void main() //begin of main function { int ch.display().Delete".pop(). break.Display . while(1) { cout<<"\n\n\n\n1. stk ob. cout<<"\nEnter Choice: ".i<=r.n. cout<<"\n4. switch(ch) //begin of switch case { case 1: cout<<"\nEnter No. case 3: ob.Display". clrscr(). break.push(n). to insert in Stack ".Insert 2.Exit". break. default: cout<<"\nWrong Choice".i++) { cout<<arr[i]<<"\t". cout<<"\n2. cin>>n. } else { for(int i=0.Insert". cout<<"\n3. case 4: exit(0).

deleted is 22 1.Exit Enter Choice: 1 Enter No.Display 4. Solution: //PROGRAM TO IMPLEMENT THE QUEUE// #include <iostream.h> //inputs the header files #include <process.Insert 2.Delete 3.Insert 2.Exit Enter Choice: 2 No.4.Delete 3.Insert 2. The Program must be written using classes and objects and it must contain the following functions: i) push( ).Delete 3. to insert in Stack 11 1.Exit Enter Choice: 3 11 1. to insert in Stack 22 1. que() //constructor { . Write a program using arrays to implement QUEUE as an array.Delete 3.h> class que //begin of class { public: int arr[100].to insert new element in queue ii) pop( ) – to delete an element from the queue iii) display() – to display the element of queue.Insert 2.h> #include <conio. int r.Exit Enter Choice: 4 Q22.Display 4.Exit Enter Choice: 1 Enter No.Display 4.Display 4.

for(i=0. } else { r=r+1.i++) { cout<<arr[i]<<"\t". } } void que::display() { if (r==-1) { cout<<"Queue is Empty".}. } else { cout<< "\nNo. } arr[r]=NULL. if (r<0) { cout<<"\nQueue is Empty. r=-1. } void push(int).i<=r. //end of class void que::push(int n) { if (r>98) { cout<<"\nQueue Overflow!! Queue is Full".i<r. } else { for (int i=0. } } void que::pop() { int i. } } } .i++) { arr[i]=arr[i+1]. arr[r]=n. r=r-1. UNDERFLOW!!!". deleted is "<<arr[0]. void display(). void pop().

Delete". case 4: exit(0). while(1) { cout<<"\n1. cin>>n. cout<<"\n2.Exit Enter Choice: 1 Enter No. cin>>ch.Delete 3.pop().Delete 3. que ob. switch(ch) //begin of switch case { case 1: cout<<"\nEnter No. case 2: ob.Insert".Exit Enter Choice: 1 Enter No. } } //end of while } Output: 1. to insert in Queue ". break. default: cout<<"\nWrong Choice".Insert 2.Display". break. cout<<"\n3.void main() //begin of main function { int ch.Display .push(n).Display 4. break. case 3: ob. clrscr().Exit".display(). to insert in Queue 22 1. cout<<"\n4.Insert 2.Display 4.Insert 2. to insert in Queue 11 1.n. ob. cout<<"\nEnter Choice: ".Delete 3.

rear.Display 4.Delete 3. cirque(int s) { front=-1. int front.to insert new element in circular queue ii) pop( ) – to delete an element from the queue iii) display() – to display the element of circular queue.Display 4. //end of class void cirque::insert(int n) { if ((front==0 && rear==size-1)||(front==rear+1)) { cout<<"\nQueue Overflow!! Queue is Full".h> //inputs the header files #include <process.h> #include <conio. rear=-1.Exit Enter Choice: 4 Q23.size. Solution: //PROGRAM TO IMPLEMENT THE CIRCULAR QUEUE// #include <iostream. }.4.Insert 2. void del(). void display(). Write a program using arrays to implement CIRCULAR QUEUE as an array. } else if(rear==size-1) rear=0.h> class cirque //begin of class { public: int arr[100].Delete 3. The Program must be written using classes and objects and it must contain the following functions: i) push( ).Exit Enter Choice: 3 22 1. . deleted is 11 1.Insert 2. } else if(rear==-1) { front=rear=0. } void insert (int). size=s.Exit Enter Choice: 2 No.

for(i=front. if (front==-1) { cout<<"\nQueue is Empty". arr[rear]=n.i<=rear.i++) cout<<arr[i]. else front++.i++) cout<<" ". } .i<front.else rear++. arr[front]=NULL.i<front. if(front==rear) front=-1.i++). rear=-1.i<=rear. } void cirque::del() { int i.i<size. deleted is "<<arr[front]. { cout<<arr[i]<<" ". } else if(rear>=front) { for (i=0.i++) cout<<arr[i]<<" ". } for(i=front. } } else { for(i=0. } } void cirque::display() { int i=0. if (rear==-1) { cout<<"Queue is Empty".i++) { cout<<". elseif(front==(size-1)) front=0. } else { cout<< "\nNo.". for(.

Delete". to insert in Queue 11 1. case 3: ob. cout<<"\nEnter Choice: ". cout<<"\n2. to insert in Queue 22 1.Exit Enter Choice: 1 Enter No. break. switch(ch) //begin of switch case { case 1: cout<<"\nEnter No.display().Delete 3. cin>>n. ob.Display".Exit Enter Choice: 1 Enter No. cirque ob(5).Exit". clrscr(). cin>>ch. default: cout<<"\nWrong Choice".Insert 2. } } } Output: 1. break. cout<<"\n3.n.Display 4. case 2: ob.del(). break.Insert .Delete 3. to insert in Circular Queue ". case 4: exit(0).Insert 2.Display 4.insert(n). while(1) { cout<<"\n1.} void main() //begin of main function { int ch.Insert". cout<<"\n4.

void main() { clrscr().h> #include<conio.h> struct Student { long RollNo.Delete 3. .2. cout<<"\nEnter Roll No.i<10.h> #include<process.Insert 2.Display 4.Display 4.Display 4. for(i=0.i++) { c=0.Exit Enter Choice: 4 Q24. int m1.Delete 3.(Max.Exit Enter Choice: 2 No.m3.i<10. gets(x[i].m2.h> #include<stdio.i++) { cout<<"\nEnter value for Student "<<i+1<<"\n". int i. ".Exit Enter Choice: 3 22 1. Passing Marks =33) Solution: //Array of Structures #include<iostream. for(i=0. An array of structure stores details of 10 students (rno.c. cout<<"\nEnter Name ". } cout<<"\n\nList of students whom are failed in more than 1 subjects are \n". cin>>x[i]. cout<<"\nEnter marks of 3 subjects ".RollNo. marks in three subjects) Write a program to create such an array and print out a list of students who have failed in more than one subject. }.m1>>x[i]. Student x[10].m3.m2>>x[i]. deleted is 11 1. name. cin>>x[i]. char Name[20].Name).Delete 3.Insert 2. Marks =100.

i)/f). for (i=1.h> double SUMFUN(double X. double s=0.m1<<"\t"<<x[i]. if(x[i].m3<<"\n".j. for(j=1.h> #include <conio. } } getch().i++) { f=1.RollNo<<"\t"<<x[i].f. } . Write a program using function SUMFUN() having parameters X (of type double) and n (of type integer) with a return type as double to find the sum of the series given below : X + X2/3! + X3/5! + …………. 3 Enter Name Watson Enter marks of 3 subjects 67 34 79 List of students whom are failed in more than 1 subjects are 2 Suresh 32 12 67 Q25.i<=n. 1 Enter Name Akash Enter marks of 3 subjects 87 79 56 Enter value for Student 2 Enter Roll No.0.Name<<"\t"<<x[i]. } Output: Enter value for Student 1 Enter Roll No. if(x[i].m2<33) c=c+1.if(x[i].int n) { int i. 2 Enter Name Suresh Enter marks of 3 subjects 32 12 67 Enter value for Student 3 Enter Roll No.j<=((2*i)-1).+ Xn/(2N-1)! Solution: //Finding sum of series by accepting arguments in function and return a value #include <iostream.m3<33) c=c+1.j++) { f=f*j. } s=s+(pow(X. if(c>1) { cout<<x[i].h> #include<math.m2<<"\t"<<x[i].m1<33) c=c+1.

} void main() { double X. } Output: Enter the value of X and n 3 2 Sum of series=4. (ii) To display the details of the books in descending order of their price. cout<<"\nSum of series="<<ans.20). cout<<"\nEnter the value of X and n ".Price number(2).n).'Maths'. Table created. Solution: SQL> create table BOOKS(Book_ID varchar2(3). Issues where Books. Price. Book name.70.ans.BookName varchar2(15). . Qty. (vii)SELECT Price from Books. Table: BOOKS Book_ID BookName AuthorNam Publisher Price Qty e L01 Maths Raman ABC 70 20 L02 Science Agarkar DEF 90 15 L03 Social Suresh XYZ 85 30 L04 Computer Sumita ABC 75 7 L05 Telugu Nannayya DEF 60 25 L06 English Wordsworth DEF 55 12 Table: ISSUES Book_ID Qty_Issued L02 13 L04 5 L05 21 (i) To show Book name. (v) SELECT sum(price) FROM Books WHERE Publisher = “DEF”. clrscr(). Publisher.Qty number(2)).'Raman'. getch().'ABC'.return(s). SQL> insert into BOOKS values('L01'.Book_ID=Issues. min(price) FROM Books GROUP BY Publisher.5 SECTION B Q1.AuthorName varchar2(20). (viii)SELECT Count(Distinct Publisher) FROM Books. Write the SQL commands for (i) to (iv) and outputs for (v) to (viii) on the basis of tables BOOKS and ISSUES. Author name and Price of books of ABC publisher. cin>>X>>n. Qty_Issued from both the tables with their matching Book ID. 1 row created. ans=SUMFUN(X. (vi)SELECT Publisher.Book_ID AND Qty_Issued=5. int n.Publisher varchar2(15). (iii) To decrease the Qty_Issued from ISSUES table by 3 (all rows must decrease). (iv) To display the Book Id.

ISSUES where BOOKS.25). 1 row created.'Agarkar'. SQL>select BOOKS.BookName. SQL> insert into BOOKS values('L04'. SQL> create table ISSUES(Book_ID varchar2(3).Book_Id=ISSUES. BOO BOOKNAME AUTHORNAME PUBLISHER ----------------.55.'Telegu'.Publisher.'Wordworth'. SQL> insert into ISSUES values('L05'. BOOKNAME AUTHORNAME PRICE ------------------------------------------Maths Raman 70 Computer Sumita 75 (ii) SQL> select * from BOOKS order by price desc.7). 1 row created.AuthorName.'DEF'.Book_Id.--------------.Price.Qty.------------------L02 Science DEF 90 15 10 L04 Computer ABC 75 7 2 L05 Telegu DEF 60 25 18 SQL> select sum(price) from Books where Publisher='DEF'. SQL> update ISSUES set Qty_Issued=Qty_Issued-3. 1 row created.'English'.'Sumita'.---------------------------------L02 Science Agarkar DEF L03 Social Suresh XYZ L04 Computer Sumita ABC L01 Maths Raman ABC L05 Telegu Nannayya DEF L06 English Wordworth DEF 6 rows selected. 3 rows updated.'XYZ'.Qty_Issued number(2)). 1 row created.'Social'. SQL>insert into BOOKS values('L03'.90.30).21). 1 row created. 1 row created.Book_ID BOO BOOKNAME PUBLISHER PRICE QTY QTY_ISSUED ----------------.60. Table created.15).'Suresh'.Qty_Issued from BOOKS.13). 1 row created.'Computer'.'ABC'. SQL> insert into BOOKS values('L06'.'Nannayya'. 1 row created.85. (i) SQL>select BookName.'DEF'. SQL> insert into ISSUES values('L04'.SQL> insert into BOOKS values('L02'. SQL> insert into ISSUES values('L02'.5).'Science'.'DEF'.---------. SQL> insert into BOOKS values('L05'. SUM(PRICE) ---------205 PRICE ---------90 85 75 70 60 55 QTY ---------15 30 7 20 25 12 (iii) (iv) (v) .12).Price from BOOKS where Publisher='ABC'.75.

SUM(SALARY) FROM EMPSALARY GROUP BY DESIGNATION HAVING COUNT(*)>2.(vi) SQL> select Publisher.SALARY FROM EMPLOYEES. EMPSALARY where DESIGNATION=’Salesman’ AND EMPLOYEES.EMPID. First Street Howard 105 Mary Jones 842 Vine Ave Losantiville 152 Sam Tones 33 Elm St.Book_ID=Issues. no rows selected (vii) (viii) SQL> select count(Distinct Publisher) from Books. Paris 215 Sarah Ackerman 440 U. EMPLOYEES EMPID FIRSTNAME LASTNAME ADDRESS CITY 010 George Smith 83. . (vii) SELECT DESIGNATION. PUBLISHER MIN(PRICE) -----------------------ABC 70 DEF 55 XYZ 85 SQL> select price from Books. (iii) To display the Firstname.EMPID=EMPSALARY. where Total salary is calculated as Salary+Benefits. Lastname. (vi) SELECT COUNT(DISTINCT DESIGNATION) FROM EMPSALARY.Issues where Books. 110 Upton 244 Manila Sengupta 24 Friends Street New Delhi 300 Robert Samuel 9 Fifth Cross Washington 335 Henry Williams 12 Moore Street Boston 400 Rachel Lee 121 Harrison St. (ii) To display the contents of EMPLOYEES table in descending Order of FIRSTNAME.S. Consider the following tables EMPLOYEES and EMPSALARY. New York 441 Peter Thompson 11 Red Road Paris EMPSALARY EMPID SALARY BENEFIT DESIGNATION 010 75000 15000 Manager 105 65000 15000 Manager 152 80000 25000 Director 215 75000 12500 Manager 244 50000 12000 Clerk 300 45000 10000 Clerk 335 40000 10000 Clerk 400 32000 7500 Salesman 441 28000 7500 Salesman (i) To display Firstname. (iv) To display the Minimum salary among Managers and Clerks from the table EMPSALARY. Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii). COUNT(DISTINCTPUBLISHER) -----------------------3 Q2. (viii) SELECT SUM(BENEFIT) FROM EMPLOYEES WHERE DESIGNATION=’Clerk’. Lastname and Toatal salary of all Managers from the tables EMPLOYEES and EMPSALARY. Address and City of all employees living in Paris from the table EMPLOYEES.Book_ID AND Qty_Issued=5.min(Price) from Books GROUP BY Publisher. (v) SELECT FIRSTNAME.

Solution: SQL> create table EMPLOYEES(EMPID NUMBER(3).'George'. FIRSTNAME LASTNAME ADDRESS CITY --------------------------------------------------------Sam Tones 33elm St.'Tones'. SQL> insert into empsalary values(010.'New York'). Paris .'Manager').'Robert'.15000.'.benefit number(5).7500. SQL> insert into empsalary values(215.'9 Fifth Cross'. 1 row created.'440 U.28000.12500.'Boston').'Lee'.'Ackerman'. SQL> INSERT INTO EMPLOYEES VALUES(244.address. SQL> INSERT INTO EMPLOYEES VALUES(105.45000. SQL> INSERT INTO EMPLOYEES VALUES(152.'11 Red Road'.'Sarah'.10000. SQL> create table EMPSALARY(EMPID number(3).50000.ADDRESS VARCHAR2(25). SQL> insert into empsalary values(335. 1 row created.7500. SQL> insert into empsalary values(300. SQL> INSERT INTO EMPLOYEES VALUES(441.12000.80000. (i) SQL> select firstname.'842.'Williams'.S.'Clerk').'Director'). SQL> INSERT INTO EMPLOYEES VALUES(010.'Henry'. SQL> INSERT INTO EMPLOYEES VALUES(300. 1 row created.75000.32000.'Jones'.'Losantiville'). 1 row created. Vine Ave'.75000. Table created.'24 Friends Street'.'Sam'.'Rachel'.'Sengupta'.'Clerk').LASTNAME VARCHAR2(10).'Samuel'.'12 Moore Street'. 1 row created.lastname. 1 row created.'thompson'.'Clerk').First Street'. SQL> insert into empsalary values(152.city from employees where city='Paris'.'Mary'. SQL> INSERT INTO EMPLOYEES VALUES(215.FIRSTNAME VARCHAR2(10).'Upton'). 1 row created.CITY VARCHAR2(15)).40000. 1 row created. 1 row created.'.'Paris').salary number(5). 1 row created.'Salesman').'Peter'.25000. SQL> INSERT INTO EMPLOYEES VALUES(400. 1 row created. 1 row created. 1 row created.'New Delhi'). SQL> insert into empsalary values(441.'Howard').'Manager'). 1 row created.'Manila'.'Salesman').10000. 1 row created. 110'.'83.'Smith'.'Washington').'33elm St. SQL> insert into empsalary values(244.'121 Harrison St. designation varchar2(10)). 1 row created.65000. SQL> insert into empsalary values(105. Table created.'Paris'). 1 row created. 1 row created. SQL> insert into empsalary values(400.'Manager'). SQL> INSERT INTO EMPLOYEES VALUES(335.15000.

FIRSTNAME LASTNAME Tot.First Street Howard 335 Henry Williams 12 Moore Street Boston 244 Manila Sengupta 24 Friends Street New Delhi 105 Mary Jones 842. New York 300 Robert Samuel 9 Fifth Cross Washington 152 Sam Tones 33elm St.--------------10 George Smith 83.SALARY FROM EMPLOYEES. EMPID FIRSTNAME LASTNAME ADDRESS CITY ---------------------------------------------------. SELECT SUM(BENEFIT) FROM EMPLOYEES WHERE DESIGNATION='Clerk' .EMPID=EMPSALARY. FIRSTNAME SALARY ------------------Rachel 32000 Peter 28000 (vi) SQL> SELECT COUNT(DISTINCT DESIGNATION) FROM EMPSALARY.empsalary S where E. COUNT(DISTINCTDESIGNATION) -------------------------4 (vii) SQL> SELECT DESIGNATION. Vine Ave Losantiville 441 Peter thompson 11 Red Road Paris 400 Rachel Lee 121 Harrison St.lastname.Empid=S. EMPSALARY where DESIGNATION= 'Salesman' AND EMPLOYEES. sal" from employees E.Empid AND designation ='Manager'. salary+benefit "Tot. DESIGNATIO SUM(SALARY) -------------------Clerk 135000 Manager 215000 (viii) SQL> SELECT SUM(BENEFIT) FROM EMPLOYEES WHERE DESIGNATION='Clerk'. 110 Upton 9 rows selected. (iii) SQL> select firstname.EMPID. sal ---------------------------George Smith 90000 Mary Jones 80000 Sarah Ackerman 87500 (iv) SQL> select designation.min(salary) from empsalary group by designation having designation = 'Manager' or designation='Clerk'.SUM(SALARY) FROM EMPSALARY GROUP BY DESIGNATION HAVING COUNT(*)>2.S. DESIGNATIO MIN(SALARY) -------------------Clerk 40000 Manager 65000 (v) SQL>SELECT FIRSTNAME.Peter thompson 11 Red Road Paris (ii) SQL> select * from employees order by firstname. Paris 215 Sarah Ackerman 440 U.

. AIRLINES from FLIGHTS. SELECT FL_NO. TABLE : FLIGHTS FL_NO IC301 IC799 MC101 IC302 AM812 IC899 AM501 MU499 IC701 STARTING MUMBAI BANGALORE INDORE DELHI KANPUR MUMBAI DELHI MUMBAI DELHI ENDING DELHI DELHI MUMBAI MUMBAI BANGALORE KOCHI TRIVANDRUM MADRAS AHMEDABAD TABLE : FARES FL_NO 1C701 MU499 AM501 IC899 1C302 1C799 MC101 i. Study the following tables FLIGHTS and FARES and write SQL commands for the questions (i) to (iv) and give outputs for SQL queries (v) to (vi). v. vi. Display the FLNO and fare to be paid for the flights from DELHI to MUMBAI using the tables FLIGHTS and FARES. iii.* ERROR at line 1: ORA-00904: invalid column name Q3. where the fare to be paid = FARE +FARE*TAX%/100. Arrange the contents of the table FLIGHTS in the ascending order of FL_NO. SELECT count (distinct ENDING) from FLIGHTS. ii. Display the minimum fare “Indian Airlines” is offering from the table FARES. AIRLINES Indian Airlines Sahara Jet Airways Indian Airlines Indian Airlines Indian Airlines Deccan Airlines FARE 6500 9400 13450 8300 4300 10500 3500 TAX% 10 5 8 4 10 10 4 NO_FLIGHTS 8 2 3 8 3 1 1 3 4 NO STOPS 0 1 0 0 1 4 5 3 0 Display FL_NO and NO_FLIGHTS from “KANPUR” to “BANGALORE” from the table FLIGHTS.FL_NO. iv. NO_FLIGHTS. FARES where STARTING=”DELHI” and FLIGHTS.FL_NO=FARES.

RecName FROM Sender A. RecName FROM Recipient WHERE SenderID = ’MU02' OR SenderID=’ND50'.RecCity = ‘Mumbai’. (v) SELECT DISTINCT SenderCity FROM Sender. Consider the following tables Consignors and Consignee. RecAddress FROM Recipient WHERE RecCity NOT IN (‘Mumbai’. RecName.SenderlD = B. (viii) SELECT RecID . (iv) To display number of Recipients from each city. Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii). Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii) (i) To display the names of all Senders from Mumbai. TABLE : CONSIGNORS . ‘Kolkata’). B. SenderAddress. RecAddress for every Recipient. (ii) To display the RecID). SenderName.SenderlD AND B. Consider the following tables. Q5. (vi) SELECT A.Q4. SenderName. Recipient B WHERE A. (vii) SELECT RecName. (iii) To display Recipient details in ascending order of RecName.

CNEENAME FROM CONSIGNEE WHERE CNORID='MU15' OR CNORID='ND01'. SQL> insert into consignee values('ND08'. SQL> create table consignee(CneeID char(4).'5. SQL> insert into consignee values('MU05'.'Mumbai'). SQL> insert into consignors values('MU15'.'16/J. (vi) SELECT A.'27-K.CneeName varchar2(15).CneeAddress varchar2(20).'5/A.South Street'. (iii) To display consignee details in ascending order of CneeName.'ND02'.'Amit Kumar'. SQL> insert into consignee values('KO19'.'Kolkata'). SQL> insert into consignors values('ND01'. (v) SELECT DISTINCT City FROM CONSIGNEE. CneeName. .'Rahul Kishore'. 1 row created.'Mumbai'). SQL>insert into consignors values('ND02'.'MU15'.CnorID = B.CnorID char(4).CneeName FROM Consignors A. Table created.’ (ii) To display the CneelD.'ND01'. CnorName. (viii) SELECT CNEEID. 1 row created.Westend'. CneeAddress FROM Consignee WHERE CneeCity NOT IN (‘Mumbai’.PalmAvenue'.CneeCity = ‘Mumbai’.'New Delhi'). (iv) To display number of consignors from each city. B.CneeCity varchar2(15)). Moore Enclave'. CneeAddress for every Consignee. CnorAddress. (vii) SELECT CneeName.'R Kohli'. Solution: SQL> CREATE TABLE CONSIGNORS(CnorID char(4). Table created. SQL>insert into consignors values('MU50'. 1 row created.'Mumbai').CnorName.CnorlD AND B.'New Delhi').CnorName varchar2(15). Consignee B WHERE A.'123. 1 row created.'A P Roy'.City varchar2(15)).'R Singhal'.'2A. ABC Enclave'.ParkAvenue'.CnorAddress varchar2(20). 1 row created.'P Dhingra'. 1 row created. Central Avenue'.'New Delhi').'24.'S Kaur'.(i) To display the names of all Consignors from Mumbai. ‘Kolkata’).

---------------------------------. Central Avenue ND48 MU50 B P Jain 13.ParkAvenue ND08 Amit Kumar 123. SQL> insert into consignee values('MU32'.'B P Jain'. 1 row created.'13. 1 row created. CNEECITY --------------Kolkata Mumbai New Delhi (vi) SQL>SELECT A.-------------------KO19 MU15 A P Roy 2A.A Vihar MU05 R Singhal 24.ParkAvenue MU32 ND02 S Mittal P245.Westend B P Jain 13.A Vihar'. Moore Enclave MU32 Amit Kumar 123.PalmAvenue P Dhingra 16/J. Block D.'S Mittal'.CneeAddress from Consignors C.CNEENAME FROM Consignors A.CnorAddress.1 row created.AB Colony CNEECITY --------------Kolkata New Delhi New Delhi Mumbai Mumbai (iv) SQL>select city.A Vihar ND08 ND02 P Dhingra 16/J.AB Colony'.'Mumbai'). CNEE CNORNAME CNORADDRESS CNEENAME CNEEADDRESS -----------------. Consignee B WHERE A. Moore Enclave MU05 ND01 Rahul Kishore 5. Central Avenue ND48 S Kaur 27-K.'P245.CNORNAME.---------Mumbai 2 New Delhi 2 (v) SQL> SELECT DISTINCT City FROM CONSIGNEE. SQL> insert into consignee values('ND48'.CnorID.South Street A P Roy 2A.'New Delhi').'ND02'. CITY COUNT(*) --------------. CNORNAME --------------R Kohli S Kaur (ii) SQL> select CneeID.CnorName.CNORID AND B.CNEECITY = 'Mumbai'.'MU50'. (i) SQL> select CnorName from Consignors where city='Mumbai'. CNORNAME CNEENAME .CneeName.CNORID= B.PalmAvenue S Mittal P245. B.AB Colony (iii) SQL> select * from consignee order by CneeName. CNEE CNOR CNEENAME CNEEADDRESS --------------------. Block D.-------------------KO19 R Kohli 5/A. Block D.CnorID=E. ABC Enclave Rahul Kishore 5. count(*) from consignors group by city. Consignee E where C. SELECT DISTINCT City FROM CONSIGNEE * ERROR at line 1: ORA-00904: invalid column name SQL> SELECT DISTINCT CNEECITY FROM CONSIGNEE.

CnorName. CNEE CNEENAME -----------------MU05 Rahul Kishore KO19 A P Roy .CNEENAME FROM CONSIGNEE WHERE CNORID='MU15' OR CNORID='ND01'. B.CnorName. Consignee B WHERE A. B.--------------R Singhal Amit Kumar --------------Rahul Kishore S Mittal SQL> SELECT A. Block D. Moore Enclave B P Jain 13. Consignee B WHERE A.CneeCity = 'Mumbai' * ERROR at line 1: ORA-00904: invalid column name (vii) SQL> SELECT CneeName. 'Kolkata'). SELECT A.CnorlD AND B.CnorID = B.CneeName FROM Consignors A.CnorlD AND B.CneeName FROM Consignors A. CneeAddress FROM Consignee WHERE CneeCity NOT IN ('Mumbai'.A Vihar (viii) SQL> SELECT CNEEID.CnorID = B.CneeCity = 'Mumbai'. CNEENAME CNEEADDRESS ---------------------------------P Dhingra 16/J.