0% found this document useful (0 votes)
51 views133 pages

NUISANCE

Uploaded by

Clark Kent
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views133 pages

NUISANCE

Uploaded by

Clark Kent
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 133

COMPUTER

pROJECT
FILE
PREPARED BY :
RAM KRIPAL SINGH
XII – A
SESSION : 2009-2010
RYAN INTERNATIONAL SCHOOL

22/12/2009
ACKNOWLEDGEMENT

I wish to express my deep gratitude and sincere thanks to the Principal, Ms.Sandhya
Sabu, Ryan International School, Mayur Vihar Phase-III for her encouragement and
for all the facilities that she provided for this work. I sincerely appreciate this
magnanimity by taking me into her fold for which I shall remain indebted to her. I
extend my hearty thanks to Ms. Nupur Gupta, computer science teacher, who guided
me to the successful completion of this project. I take this opportunity to express my
deep sense of gratitude for her invaluable guidance, constant encouragement,
constructive comments, sympathetic attitude and immense motivation, which has
sustained my efforts at all stages of this project work.

I can’t forget to offer my sincere thanks to my classmates who helped me to carry out
this project work successfully & for their valuable advice & support, which I received
from them time to time.

Ram Kripal Singh


XII - A

2
INDEX

1.ARRAYS……………………………………………4
2.FUNCTION OVERLOADING……………….23
3.LINKED LISTS, STACKS AND QUEUES…..42
4.DATAFILE HANDLING………………………..64
5.STRUCTURES …………………………………….90
6.CLASSES AND OBJECTS………………………..97
7.SQL………………………………………………….119
8.BIBLIOGRAPHY…………………………………134

ARRAYS
Q.1

#include<iostream.h>
#include<conio.h>
void add(int P[100][100],int Q[100][100],int x, int y,int a,int s);
void subtract(int P[100][100],int Q[100][100],int x, int y,int a,int s);

3
void multiply(int P[100][100],int Q[100][100],int x, int y,int a,int s);
void getdata(int P[100][100],int x, int y);
void printdata(int P[100][100],int x, int y);
int i, j;
void main()
{ clrscr();
char ch;
int a, b, c, d, choice;
int A[100][100], B[100][100];
cout<<"\nEnter rows of first matrix: ";
cin>>a;
cout<<"\nEnter columns of first matrix: ";
cin>>b;
cout<<"\nEnter rows of second matrix: ";
cin>>c;
cout<<"\nEnter columns of second matrix: ";
cin>>d;
cout<<"\nEnter elements of first matrix: ";
getdata(A,a,b);
cout<<"\nEnter elements of second matrix: ";
getdata(B,c,d);
cout<<"\nDisplaying first matrix: ";
printdata(A,a,b);
cout<<"\nDisplaying second matrix: ";
printdata(B,c,d);
do
{
cout<<"\n\tChoose the operations to be done on both matrices:\n ";
cout<<"\n1. Addition\n2. Subtraction\n3. Multiplication";
cout<<"\nEnter your choice(1, 2 or 3): ";
cin>>choice;
switch (choice)
{ case 1: add(A,B,a,b,c,d);
break;
case 2: subtract(A,B,a,b,c,d);
break;
case 3: multiply(A,B,a,b,c,d);
break;
default : cout<<"\nYou have entered a wrong number!!!";
break;
}
cout<<"\nDo you want to perform more operations(y/n): ";
cin>>ch;
} while(ch=='y'||ch=='Y');
getch();
}

4
void add(int P[100][100],int Q[100][100],int x, int y,int a,int s)
{ if(x==a||y==s)
{ cout<<"\nMatrix can be added!!!";
cout<<"\nNew matrix after addition:\n ";
for(i=0;i<x;i++)
{ cout<<"\n";
for(j=0;j<y;j++)
cout<<P[i][j]+Q[i][j]<<" ";
}
}
else
cout<<"\nMatrices cannot be added!!!";
}
void subtract(int P[100][100],int Q[100][100],int x, int y,int a,int s)
{ if(x==a||y==s)
{ cout<<"\nMatrix can be subtracted!!!";
cout<<"\nNew matrix after subtraction:\n";
for(i=0;i<x;i++)
{ cout<<"\n";
for(j=0;j<y;j++)
cout<<P[i][j]-Q[i][j]<<" ";
}
}
else
cout<<"\nMatrices cannot be subtracted!!!";
}
void multiply(int P[100][100],int Q[100][100],int x, int y,int a,int s)
{
int C[100][100];
if(y==a)
{ cout<<"\nMatrices can be multiplied!!!";
cout<<"\nNew matrice after multiplication:\n";
for(i=0;i<x;i++)
{ cout<<"\n";
for(j=0;j<s;j++)
{
C[i][j]=0;
for(int k=0;k<y;k++)
C[i][j]=C[i][j]+(P[i][k]*Q[k][j]);
cout<<C[i][j]<<" ";
}
}
}
else
cout<<"\nMatrices cannot be multiplied!!!";
}

5
void getdata(int P[100][100],int x, int y)
{ for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
cin>>P[i][j];
}
}
void printdata(int P[100][100],int x, int y)
{ for(i=0;i<x;i++)
{ cout<<"\n";
for(j=0;j<y;j++)
cout<<P[i][j]<<" ";
}
}

OUTPUT:

Enter rows of first matrix: 2

Enter columns of first matrix: 3

Enter rows of second matrix: 2

Enter columns of second matrix: 3

Enter elements of first matrix: 3


4
5
6
7
8

Enter elements of second matrix: 1


2
2
2
3
4

Displaying first matrix:


3 4 5
6 7 8
Displaying second matrix:
1 2 2
2 3 4

6
Choose the operations to be done on both matrices:

1. Addition
2. Subtraction
3. Multiplication
Enter your choice(1, 2 or 3): 1

Matrix can be added!!!


New matrix after addition:

4 6 7
8 10 12
Do you want to perform more operations(y/n): n

Q.2

#include<iostream.h>
#include<conio.h>
void transpose(int a[100][100],int p,int q);
int rsum(int a[100][100],int p,int q,int r);
int csum(int a[100][100],int p,int q,int c);
void getdata(int a[100][100],int p,int q);
void printdata(int a[100][100],int p,int q);
int i, j;
void main()
{ clrscr();
char ch;
int m,n,choice,R,g,h;
int x[100][100];
cout<<"\nEnter no. of rows: ";
cin>>m;
cout<<"\nEnter no.of columns: ";
cin>>n;
cout<<"\nEnter elements of the matrix: ";
getdata(x,m,n);
cout<<"\nDisplaying matrix elements: ";
printdata(x,m,n);
do
{
cout<<"\n\tChoose the operation you want to perform on the matrix:\n";
cout<<"\n1. Transpose\n2. Row sum\n3. Column sum";
cout<<"\nEnter your choice(1, 2 or 3): ";
cin>>choice;
switch(choice)
{ case 1: transpose(x,m,n);
7
break;
case 2: cout<<"\nEnter the row whose sum is to be calculated:";
cin>>g;
R=rsum(x,m,n,g-1);
cout<<"\nSum of elements of "<<g<<" row is:"<<R;
break;
case 3: cout<<"\nEnter the column whose sum is to be calculated:";
cin>>h;
R=csum(x,m,n,h-1);
cout<<"\nSum of elements of "<<h<<" column is:"<<R;
break;
default: cout<<"\nSorry!!Wrong choice";
break;
}
cout<<"\nDo want to perform more operations(y/n): ";
cin>>ch;
}while(ch=='y'||ch=='Y');
getch();
}
void transpose(int a[100][100],int p,int q)
{ cout<<"\nNew matrix after transpose: ";
for(i=0;i<p;i++)
{ cout<<"\n";
for(j=0;j<q;j++)
cout<<a[j][i]<<" ";
}
}
void getdata(int a[100][100],int p, int q)
{ for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
cin>>a[i][j];
}
}
void printdata(int a[100][100],int p, int q)
{ for(i=0;i<p;i++)
{ cout<<"\n";
for(j=0;j<q;j++)
cout<<a[i][j]<<" ";
}
}
int rsum(int a[100][100],int p,int q,int r)
{ int s=0;
if(r<=p)
{
for(i=0;i<q;i++)

8
s=s+a[r][i];
return s;
}
else
{cout<<"\nYou have entered a wrong row no.!!!";return 0;}
}
int csum(int a[100][100],int p,int q,int c)
{ int s=0;
if(c<=q)
{
for(i=0;i<p;i++)
s=s+a[i][c];
return s;
}
else
{cout<<"\nYou have entered a wrong column no.!!!";return 0;}
}

OUTPUT:

Enter no. of rows: 1

Enter no.of columns: 2

Enter elements of the matrix: 1


2

Displaying matrix elements:


1 2
Choose the operation you want to perform on the matrix:

1. Transpose
2. Row sum
3. Column sum
Enter your choice(1, 2 or 3): 1

New matrix after transpose:


1 -6141
Do want to perform more operations(y/n): Y

Choose the operation you want to perform on the matrix:

1. Transpose
2. Row sum
3. Column sum

9
Enter your choice(1, 2 or 3): 2

Enter the row whose sum is to be calculated:1

Sum of elements of 1 row is:3


Do want to perform more operations(y/n): N

Q.3

#include<iostream.h> //HEADER FILES


#include<conio.h>
#include<process.h>
void suma(int a[10][10], int b);
void sumb(int a[10][10], int b);
void main()
{
clrscr();
int a[10][10],m,i,j,asum,bsum;
cout<<"\nInput the dimensions of matrix-a (SQUARE MATRIX) : \n";
cin>>m;
cout<<"\nInput matrix-a : \n";
for(i=0;i<m;i++) //to input matrix-a
{
for(j=0;j<m;j++)
{
cin>>a[i][j];
}
}
cout<<"\n Matrix-a:\n";
for(i=0;i<m;i++) //to print matrix-a
{
cout<<"\n";
for(j=0;j<m;j++)
{
cout<<" "<<a[i][j];
}
}
cout<<"\n Sum of the elements above the main diagonal is:";
suma(a,m);
cout<<"\n Sum of the elements below the main diagonal is:";
sumb(a,m);
getch();
}
void suma(int a[10][10], int m)

10
{
int i,j;
int asum=0;
for(i=0;i<m;i++)
{for(j=0;j<m;j++)
{if(i<j)
asum+=a[i][j];
}
}
cout<<asum;
}
void sumb(int a[10][10],int m)
{
int i,j;
int bsum=0;
for(i=0;i<m;i++)
{for(j=0;j<m;j++)
{if(i>j)
bsum+=a[i][j];
}
}
cout<<bsum;
}

OUTPUT:

Input the dimensions of matrix-a (SQUARE MATRIX) :


2

Input matrix-a :
1
2
2
2

Matrix-a:

12
22
Sum of the elements above the main diagonal is:2
Sum of the elements below the main diagonal is:2

Q.4

11
/* To illustrate searches in an array */

#include<iostream.h>
#include<conio.h> //for clrscr() & getch()
int Lsearch(int[], int, int); //function to search for the given element
int Bsearch(int [], int, int);//i.e.Bsearch(the array, its size, search_item)
void main()
{
char ch;
int a,AR[50], ITEM, N, index; //array can hold max.50 elements
do{
clrscr();
cout<<"\nEnter the desired array size (max.50)...";
cin>>N;
cout<<"\nEnter Array Elements (in ascending order)\n";
for(int i=0; i<N; i++)
{
cin>>AR[i];
}
cout<<"\nEnter element to be searched for....";
cin>>ITEM;
cout<<"\n Which type of search do you want to implement ?\n1. Binary
Search\n2. Linear Search\n";
cin>>a;
switch(a)
{
case 1 : index=Bsearch(AR,N,ITEM);
if(index!=-1)
{
cout<<"\nElement found at index: "<<index
<<", Position: "<<index+1;
}
else if(index==-1)
{
cout<<"\nSorry! Given element could not be found.\n";
}
break;
case 2 : index=Lsearch(AR,N,ITEM);
if(index!=-1)
{
cout<<"\nElement found at index: "<<index
<<", Position: "<<index+1;
}
else if(index==-1)
{
cout<<"\nSorry! Given element could not be found.\n";

12
}
break;
}
cout<<"\nWant to continue (y/n)?: ";
cin>>ch;
getch();
}while((ch=='y')||(ch=='Y'));
cout<<"Thank You...!";
getch();
}

int Bsearch(int AR[], int size, int item)//function to perform binary search
{
int beg, last, mid;
beg=0;
last=size-1;
while(beg<=last)
{
mid=(last+beg)/2;
if(item==AR[mid])
return mid;
else if(item>AR[mid])
beg=mid+1;
else
beg=mid-1;
}
return -1; //the control will reach here only when item is not found
}
int Lsearch(int AR[], int size, int item) //function to perform linear search
{
for(int i=0; i<size; i++)
{
if(AR[i]==item)
return i;
}
return -1; //the control will reach here only when item is not found
}

OUTPUT:

Enter the desired array size (max.50)...3

Enter Array Elements (in ascending order)


1

13
2
3

Enter element to be searched for....2

Which type of search do you want to implement ?


1. Binary Search
2. Linear Search
1

Element found at index: 1, Position: 2


Want to continue (y/n)?: n
Thank You...!

Q.5

/* To illustrate insertion ( with position ) in an array */


#include<iostream.h>
#include<conio.h> //for clrscr() & getch()
#include<process.h> //for exit()
int FindPos(int[], int, int); //function to determine the right position for new element
void main()
{
char s;
do
{
int AR[50], ITEM, N, index; //array can hold maximum 50 elements
clrscr();
cout<<"How many elements do you want to create array with?(max. 50)...";
cin>>N;
cout<<"\nEnter Array elements (in increasing order)\n";
for(int i=0; i<N; i++)
{
cin>>AR[i];
}
char ch='y';
while((ch=='y')||(ch=='Y'))
{
cout<<"\nEnter Element to be inserted...";
cin>>ITEM;
if(N==50)
{
cout<<"Overflow!!";
exit(1);
}

14
index=FindPos(AR, N, ITEM);
for(i=N; i>index; i--)
{
AR[i]=AR[i-1]; //shift elements to create room for new element
}
AR[index]=ITEM; //item inserted
N+=1; //Number of elements updated
cout<<"\n Want to insert more elements? (y/n): ";
cin>>ch;
}
cout<<"\nThe array is now as shown below.....\n";
for(i=0;i<N;i++)
cout<<AR[i]<<" ";
cout<<endl;
cout<<"\nWant to continue with new array? (y/n): ";
cin>>s;
}while((s=='y')||(s=='Y'));
getch();
}

int FindPos(int AR[], int size, int item) //function to determine the position for new
element
{
int pos;
if(item<AR[0])
pos=0;
else
{
for(int i=0; i<size-1; i++)
{
if(AR[i]<=item && item<AR[i+1])
{
pos=i+1;
break;
}
}
if(i==size-1)
pos=size;
}
return pos;
}

OUTPUT:

How many elements do you want to create array with?(max. 50)...3

15
Enter Array elements (in increasing order)
1
2
3

Enter Element to be inserted...4

Want to insert more elements? (y/n): n

The array is now as shown below.....


1 2 3 4

Want to continue with new array? (y/n): n

Q.6

/* To illustrate deletion ( with position ) in an array */


#include<iostream.h>
#include<conio.h> //for clrscr() & getch()
#include<process.h> //for exit()
int Lsearch(int[], int, int); //function to search for the given element
void main()
{
char s;
do
{
int AR[50], ITEM, N, index; //array can hold maximum 50 elements
clrscr();
cout<<"How many elements do you want to create array with?(max. 50)...";
cin>>N;
cout<<"\nEnter Array elements (in increasing order): \n";
for(int i=0; i<N; i++)
{
cin>>AR[i];
}
char ch='y';
while((ch=='y')||(ch=='Y'))
{
cout<<"\nEnter Element to be deleted...";
cin>>ITEM;
if(N==0)
{
cout<<"Underflow!!";
exit(1);

16
}
index=Lsearch(AR, N, ITEM);
if(index!=-1)
AR[index]=0;
else
cout<<"Sorry!! No such element in the array.\n";

cout<<"\nThe array now is as shown below...\n";


cout<<"Zero (0) signifies deleted element\n";
for(i=0; i<N; i++)
cout<<AR[i]<<" ";
cout<<"\n";
cout<<"After this emptied space will be shifted to the end of array\n";
for(i=index; i<N; i++)
{
AR[i]=AR[i+1]; //shift elements to bring empty space at the end of
array
}
N-=1; //Number of elements updated
cout<<"\n Want to delete more elements? (y/n): ";
cin>>ch;
}
cout<<"\nThe array after shifting All emptied spaces towards right is....\n";
for(i=0;i<N;i++)
cout<<AR[i]<<" ";
cout<<endl;

cout<<"\nWant to continue with new array? (y/n): ";


cin>>s;
}while((s=='y')||(s=='Y'));
getch();
}

int Lsearch(int AR[], int size, int item) //function to perform linear search
{
for(int i=0; i<size; i++)
{
if(AR[i]==item)
return i;
}
return -1; //the control will reach here only when item is not found
}

OUTPUT:

How many elements do you want to create array with?(max. 50)...4

17
Enter Array elements (in increasing order):
1
2
3
4

Enter Element to be deleted...4

The array now is as shown below...


Zero (0) signifies deleted element
1230
After this emptied space will be shifted to the end of array

Want to delete more elements? (y/n): N

The array after shifting All emptied spaces towards right is....
1 2 3

Want to continue with new array? (y/n): N

Q.7

/* To illustrate different type of Sorting in an array */


#include<iostream.h>
#include<conio.h> //for clrscr() & getch()
void BubbleSort(int[], int); //function for bubble sort
void SelSort(int[], int); //function for selection sort
void InsSort(int[], int); //function for insertion sort
void main()
{
clrscr();
char b,a,s;
int AR[50],ar1[50], ITEM, N, index; //array can hold maximum 50 elements
int c;
start:
cout<<"\nEnter the no. of elements you want in an array: ";
cin>>N;
cout<<"\nEnter Array elements: \n";
for(int i=0; i<N; i++)
{
cin>>ar1[i];

18
begin:
for(i=0; i<N; i++)
{
AR[i]=ar1[i];

}
cout<<"Which type of sorting do you want ? (Array will be sorted in icnreasing
order only )\n1. Bubble Sorting\n2. Selection Sorting\n3. Insertion Sorting \nOr Press
'Q/q' to QUIT: ";
cin>>c;
while(c!='q'||c!='Q')
{
switch (c)
{
case 1 :
BubbleSort(AR, N); //function call
cout<<"\n\nThe Sorted array is as shown below...\n";
for(i=0; i<N; i++)
{
cout<<AR[i]<<" ";
cout<<"\n";
}
break;

case 2 :

SelSort(AR, N); //function call


cout<<"\n\nThe Sorted array is as shown below...\n";
for(i=0; i<N; i++)
{
cout<<AR[i]<<" ";
cout<<"\n";
}
break;
case 3 :

InsSort(AR, N); //function call


cout<<"\n\nThe Sorted array is as shown below...\n";
for(i=0; i<N; i++)
{
cout<<AR[i]<<" ";
cout<<"\n";
}
break;
}

19
cout<<"\nDo you want to sort the same array with some other sorting method ?
(y/n)";
cin>>a;
if(a=='y'||a=='Y')
{
goto begin;
}
cout<<"\nDo you want to try sorting on some other array ? (y/n)";
cin>>b;
if(b=='y'||b=='Y')
{
goto start;
}
goto end;
}
end:
cout<<"\nOk then Thank You... Bye bye ";
getch();
}

void BubbleSort(int AR[], int size) //function to perform bubble sort


{
int tmp, ctr=0;
for(int i=0;i<size; i++)
{
for(int j=0; j<(size-1)-i; j++)
{
if(AR[j]>AR[j+1])
{
tmp=AR[j];
AR[j]=AR[j+1];
AR[j+1]=tmp;
}
cout<<"Array after iteration - "<<++ctr<<" is: \n";
for(int k=0; k<size; k++)
cout<<AR[k]<<" ";
cout<<"\n";
}
}
}

void SelSort(int AR[], int size) //function to perform selection sort


{
int small, pos, tmp;
for(int i=0; i<size-1; i++)
{

20
small=AR[i];
pos=i;
for(int j=i+1; j<size; j++)
{
if(AR[j]<small)
{
small=AR[j];
pos=j;
}
}
tmp=AR[i];
AR[i]=AR[pos];
AR[pos]=tmp;
cout<<"\nArray after pass - "<<i+1<<" is: \n";
for(j=0; j<size; j++)
cout<<AR[j]<<" ";
}
}
void InsSort(int AR[], int size) //function to perform insertion sort
{
int tmp, j;

for(int i=1; i<size; i++)


{
tmp=AR[i];
j=i-1;
while((tmp<AR[j])&&(j>=0))
{
AR[j+1]=AR[j];
j=j-1;
}
AR[j+1]=tmp;
cout<<"Array after pass - "<<i<<" is: \n";
for(int k=0;k<size; k++)
cout<<AR[k]<<" ";
cout<<"\n";
}
}

OUTPUT:

Enter the no. of elements you want in an array: 5

Enter Array elements:


2

21
3
1
4
7
Which type of sorting do you want ? (Array will be sorted in icnreasing order
ly )
1. Bubble Sorting
2. Selection Sorting
3. Insertion Sorting
Or Press 'Q/q' to QUIT: 1
Array after iteration - 1 is:
23147
Array after iteration - 2 is:
21347
Array after iteration - 3 is:
21347
Array after iteration - 4 is:
21347
Array after iteration - 5 is:
12347
Array after iteration - 6 is:
12347
Array after iteration - 7 is:
12347
Array after iteration - 8 is:
12347
Array after iteration - 9 is:
12347
Array after iteration - 10 is:
12347

The Sorted array is as shown below...


1
2
3
4
Array after iteration - 4 is:
21347
Array after iteration - 5 is:
12347
Array after iteration - 6 is:
12347
Array after iteration - 7 is:
12347
Array after iteration - 8 is:

22
12347
Array after iteration - 9 is:
12347
Array after iteration - 10 is:
12347

The Sorted array is as shown below...


1
2
3
4

Q.8

//PROGRAM TO MERGE 2 ARRAYS INTO ONE WITH DIFFERENT


COMBINATIONS
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int A[20],B[20],C[40];
int m,n;
int ptr1,ptr2,ptr3;
int i;
cout<<"\nEnter the size of lists 1 & 2:";
cin>>n>>m;
cout<<"\nEnter list 1 :";
for(i=0;i<n;i++)
cin>>A[i];
cout<<"\nEnter list 2 :";
for(i=0;i<m;i++)
cin>>B[i];
ptr1=ptr2=ptr3=0; //initialize pointers
while(ptr2<n&&ptr2<m)
{
if(A[ptr1]<B[ptr2])
C[ptr3++]=A[ptr1++];
else
C[ptr3++]=B[ptr2++];
}
//copy rest of the elements of list 2
while(ptr2<m)
C[ptr3++]=B[ptr2++];

23
//copy rest of elements of list 1
while(ptr1<n)
C[ptr3++]=A[ptr1++];
//print the C merges list
cout<<"\n The C list is ...";
for(i=0;i<m+n;i++)
cout<<C[i]<<" ";
getch();
return 0;
}

OUTPUT:

Enter the size of lists 1 & 2:4


3

Enter list 1 :1
2
3
4

Enter list 2 :1
7
8

The C list is ...1 1 2 3 4 7 8

Q.9

#include<iostream.h>
#include<conio.h>
void pair(int A[], int size) //(array and size)
{
int count=0;
for(int i=0;i<=size;i++)
{
for(int k=i;k<=size;k++)
{
if(A[i]+A[k]==50)
{count++;
cout<<"\nPair no."<<count<<":- "<<A[i]<<" and "<<A[k]<<endl;
}
}
}

24
if(count==0)
cout<<"\n\nNO PAIR FOUND WITH SUM=50...!!!"<<endl;
} //end of pair

void odd(int A[],int size)


{
int count=0;
cout<<"\nChecking odd no...!!"<<endl;
for(int i=0;i<size;i++)
{
if((A[i]%2)!=0)
count++;
}
cout<<"Total no. of odd no. are :- "<<count;
}

void even(int A[],int size)


{
int count=0;
cout<<"\nChecking even no...!!"<<endl;
for(int i=0;i<size;i++)
{
if((A[i]%2)==0)
count++;
}
cout<<"Total no. of odd no. are :- "<<count;
}

void divisible(int A[],int size)


{
int count=0;
cout<<"\nChecking no. divisible by 30..!!"<<endl;
for(int i=0;i<size;i++)
{
if((A[i]%30)==0)
count++;
}
cout<<"Total no. of odd no. are :- "<<count;
}

void largest(int A[],int size)


{
int large=A[0];
for(int i=0;i<size;i++)
{

25
if(large<A[i])
large=A[i];
}
cout<<"\nTHE LARGEST NO. IN THE ARRAY IS :- "<<large;
}

void smallest(int A[],int size)


{
int small=A[0];
for(int i=0;i<size;i++)
{
if(small>A[i])
small=A[i];
}
cout<<"\nTHE LARGEST NO. IN THE ARRAY IS :- "<<small;
}

void average(int A[],int size)


{
int avg=0;
for(int i=0;i<size;i++)
{
avg+=A[i];
}
avg=avg/size;
cout<<"\nTHE AVERAGE OF THE ARRAY IS :- "<<avg;
}

void main()
{
clrscr();
char rep;
int A[30],size,choice;
b:
cout<<"\nENTER THE NO. OF ELEMENTS YOU WANT IN YOUR
ARRAY"<<endl;
cin>>size;
cout<<"\nSTART ENTERING THE ELEMENTS.."<<endl;
for(int i=0;i<size;i++)
{
cin>>A[i];
cout<<endl;
}
do
{

26
cout<<"\n\tMENU\n\n1.Pair of integre having sum=50\n\n2.No. of odd
no.\n\n3.No of even no.\n\n4.No. Divisible by 30 \n\n5.Largest no.\n\n6.Smallest
no.\n\n7.Avreage of the array\n\nENTER YOUR CHOICE.....";
cin>>choice;
switch(choice)
{
case 1:pair(A,size);
break;
case 2:odd(A,size);
break;
case 3:even(A,size);
break;
case 4:divisible(A,size);
break;
case 5:largest(A,size);
break;
case 6:smallest(A,size);
break;
case 7:average(A,size);
break;
default:cout<<"\nWRONG INPUT"<<endl;
}
a:
cout<<"\nDo you want to continue on same array(y/n)...."<<endl;
cin>>rep;
}while(rep=='y');
if(rep!='n')
{
cout<<"SORRY WRONG INPUT TRY AGAIN...."<<endl;
goto a;
}
c:
clrscr();
cout<<"\nDo you want to change the array(y/n)...."<<endl;
cin>>rep;
if(rep=='y')
goto b;
else if(rep!='n')
{
cout<<"SORRY WRONG INPUT TRY AGAIN...."<<endl;
goto c;
}

getch();
}

27
OUTPUT:

ENTER THE NO. OF ELEMENTS YOU WANT IN YOUR ARRAY


2

START ENTERING THE ELEMENTS..


1

MENU

1.Pair of integre having sum=50


2.No. of odd no.
3.No of even no.
4.No. Divisible by 30
5.Largest no.
6.Smallest no.
7.Avreage of the array

ENTER YOUR CHOICE.....2

Checking odd no...!!


Total no. of odd no. are :- 1
Do you want to continue on same array(y/n)....y

MENU

1.Pair of integre having sum=50


2.No. of odd no.
3.No of even no.
4.No. Divisible by 30
5.Largest no.
6.Smallest no.
7.Avreage of the array

ENTER YOUR CHOICE.....7

THE AVERAGE OF THE ARRAY IS :- 1


Do you want to continue on same array(y/n)....
n

Q.10
28
#include<iostream.h> //HEADER FILES
#include<conio.h>
#include<process.h>
void nonzero(int A[10][10],int m,int n)
{int count=0;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(A[i][j]!=0)
count++;
}
}
cout<<"TOTAL NO. OF NON-ZERO ELEMENT ARE:- "<<count<<endl;
}

void allsum(int A[10][10],int m,int n)


{int tot=0;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
tot=tot+A[i][j];
}
}
cout<<"TOTAL SUM OF ALL ELEMENT ARE:- "<<tot<<endl;
}

void above(int A[10][10],int m,int n)


{
int asum=0,i,j;
for(i=0;i<m;i++)
{for(j=0;j<n;j++)
{if(i<j)
asum+=A[i][j];
}
}
cout<<"\n Sum of the elements above the main diagonal is:";
cout<<asum<<endl;
}

void below(int A[10][10],int m,int n)


{
int bsum=0,i,j;
for(i=0;i<m;i++)

29
{for(j=0;j<n;j++)
{if(i>j)
bsum+=A[i][j];
}
}
cout<<"\n Sum of the elements below the main diagonal is:";
cout<<bsum<<endl;
}

void diag(int A[10][10],int m,int n)


{int prod=1;
for(int i=0;i<m&&n;i++)
prod=prod*A[i][i];
cout<<"\n\nPRODUCT OF ELEMENTS WITH i=j IS:- "<<prod<<endl;
}

void main()
{
clrscr();
int A[10][10],m,n,i,j,asum,bsum;
cout<<"\n Input row and column of matrix-a: \n";
cin>>m>>n;
cout<<"\n Input matrix-a\n";
for(i=0;i<m;i++) //to input matrix-a
{
for(j=0;j<n;j++)
{
cin>>A[i][j];
}
}
cout<<"\n Matrix-a:\n";
for(i=0;i<m;i++) //to print matrix-a
{
cout<<"\n";
for(j=0;j<n;j++)
{
cout<<" "<<A[i][j];
}
}
int choice;
a:
cout<<"\n\n\tMENU\n\n1.No. of non zero element\n\n2.Sum of all\n\n3.Sum abv
diagonal\n\n4.Sum below daigonal\n\n5.Product of diagonal\n\n\nENTER YOU
CHOICE....";
cin>>choice;
switch(choice)

30
{
case 1:nonzero(A,m,n);
break;
case 2:allsum(A,m,n);
break;
case 3:above(A,m,n);
break;
case 4:below(A,m,n);
break;
case 5:diag(A,m,n);
break;
default:cout<<"WRONG INPUT"<<endl;
}
char rep;
cout<<"\nDo you want to continue with same array(y/n)..."<<endl;
cin>>rep;
if(rep=='y')
goto a;
cout<<"\nDo you want to some other array(y/n)..."<<endl;
cin>>rep;
if(rep=='y')
main();
getch();
}

OUTPUT:

Input row and column of matrix-a:


2
3

Input matrix-a
1
2
3
4
5
6

Matrix-a:

123
456

MENU

31
1.No. of non zero element
2.Sum of all
3.Sum abv diagonal
4.Sum below daigonal
5.Product of diagonal

ENTER YOU CHOICE....1


TOTAL NO. OF NON-ZERO ELEMENT ARE:- 6

Do you want to continue with same array(y/n)...


y

MENU

1.No. of non zero element


2.Sum of all
3.Sum abv diagonal
4.Sum below daigonal
5.Product of diagonal

ENTER YOU CHOICE....2


TOTAL SUM OF ALL ELEMENT ARE:- 21

Do you want to continue with same array(y/n)...


n

Do you want to some other array(y/n)...


n

FUNCTION OVERLOADING

Q.1

/* To print the pyramid of digits */

#include<iostream.h>

32
#include<conio.h>
void pyramid()
{
static int n=0;
int m,p,q;
n++; // loop to count the number of function call

// loop to print spaces


for(p=1;p<=n;p++)
{
for(q=0;q<=n-p;q++)
cout<<" ";

// loop to print digits


m=p;
for(q=1;q<=p;q++)
cout<<m++<<" ";
cout<<endl;
}
cout<<endl;
}
void main()
{
clrscr();
char ch;
do
{
int N;
cout<<"\nHow many pyramids ? : ";
cin>>N;
for(int i=0;i<N;i++)
pyramid();
cout<<"\nWant to continue (y/n)? : ";
cin>>ch;
}while((ch=='y')||(ch=='Y'));
getch();
}

OUTPUT:

How many pyramids ? : 4


1

1
23

33
1
23
345

1
23
345
4567

Want to continue (y/n)? : Y

How many pyramids ? : 1


1
23
345
4567
56789

Want to continue (y/n)? : N

Q.2

/* To calculate area of a triangle or a rectangle or a square or a circle


using an area() function. */

#include<iostream.h>
#include<conio.h> // for clrscr()
#include<math.h> // for sqrt()
#include<process.h> // for exit

float area(float a,float b,float c)


{ // function definition
float s,ar;
s=(a+b+c)/2;
ar=sqrt(s*(s-a)*(s-b)*(s-c));
return ar;
}
float area(float a,float b)
{ /// function definition
return a*b;
}
float area(float a)

34
{ //function definition
return a*a;
}
float circle(float a)
{ //function definition
return 3.14*a*a;
}

void main()
{
clrscr(); // main begins
float r,s1,s2,s3,ar;
int choice;
char ch='y';
do // while loop begins
{
cout<<"\n ************AREA MAIN MENU************* \n"
<<" 1.Triangle \n"
<<" 2.Square \n"
<<" 3.Rectangle \n"
<<" 4.Circle \n"
<<" 5.Exit \n";

while(ch=='y'||ch=='Y')
{ // while loop begins
cout<<" Enter your choice(1-5):";
cin>>choice;
cout<<"\n";
switch(choice)
{ // switch begins
case 1 : cout<<"\n Enter 3 sides:";
cin>>s1>>s2>>s3;
ar=area(s1,s2,s3);
cout<<"\n The required area of the triangle is "
<<ar<<" sq.units"<<"\n";
break;

case 2 : cout<<"\n Enter a side :";


cin>>s1;
ar=area(s1);
cout<<"\n The required area of the square is "
<<ar<<" sq.units"<<"\n";
break;

case 3 : cout<<"\n Enter Length & breadth:";


cin>>s1>>s2;

35
ar=area(s1,s2);
cout<<"\n The required area of the rectangle is "
<<ar<<" sq.units"<<"\n";
break;

case 4 : cout<<"\n Enter the radius of the circle: ";


cin>>r;
ar=circle(r);
cout<<"\n The required area of the circle is "<<ar<<" sq.
units . \n";
break;
case 5 : exit(0);
default:
cout<<"\n SORRY WRONG CHOICE !!\n";

}; // end of switch

cout<<"\n Want to continue(y/n)? : ";


cin>>ch;
} // while loop ends

}while((choice>0 && choice<4) && (ch=='y' || ch=='Y')); // do while loop ends

getch();
} // main ends

OUTPUT:

************AREA MAIN MENU*************


1.Triangle
2.Square
3.Rectangle
4.Circle
5.Exit
Enter your choice(1-5):1

Enter 3 sides:2
3
4

The required area of the triangle is 2.904737 sq.units

Want to continue(y/n)? : Y

36
Enter your choice(1-5):3

Enter Length & breadth:5


6

The required area of the rectangle is 30 sq.units

Want to continue(y/n)? : Y
Enter your choice(1-5):4

Enter the radius of the circle: 4

The required area of the circle is 50.240002 sq. units .

Want to continue(y/n)? : N

Q.3

#include<iostream.h>
#include<conio.h> // for clrscr()
#include<math.h> // for sqrt()

float area(float a,float b)


{ /// function for cylinder
return 2*3.14*a*b;
}
float area(float a)
{ //function sphere
return 4*3.14*a*a;
}

float area(int a,int b)


{ //function for cone
return a*b*3.14;
}

float volume(float a,float b)


{ /// function for cylinder
return 3.14*a*a*b;
}

37
float volume(float a)
{ //function sphere
return (4/3)*3.14*a*a*a;
}

float volume(int a,int b)


{ //function for cone
return 0.333*a*a*b*3.14;
}

void main()
{
clrscr(); // main begins
float s1,s2,s3,ar;
int s4,s5,choice;
char ch='y';
do // while loop begins
{
cout<<"\n ************AREA MAIN MENU************* \n"
<<" 1.Cylinder \n"
<<" 2.Sphere \n"
<<" 3.Cone \n";

while(ch=='y'||ch=='Y')
{ // while loop begins
cout<<" Enter your choice(1-3):";
cin>>choice;
cout<<"\n";
switch(choice)
{ // switch begins
case 1 : cout<<"\n Enter radius and height of cylinder:";
cin>>s1>>s2;
ar=area(s1,s2);
cout<<"\n The required area of the cylinder is "
<<ar<<" sq.units"<<"\n";
break;

case 2 : cout<<"\n Enter a radius :";


cin>>s3;
ar=area(s3);
cout<<"\n The required area of the sphere is "
<<ar<<" sq.units"<<"\n";
break;

case 3 : cout<<"\n Enter slant ht. & radius:";


cin>>s4>>s5;

38
ar=area(s4,s5);
cout<<"\n The required area of the cone is "
<<ar<<" sq.units"<<"\n";
break;

default:
cout<<"\n SORRY WRONG CHOICE !!\n";

}; // end of switch

cout<<"\n Want to continue(y/n)? : ";


cin>>ch;
} // while loop ends

cout<<"\n ************VOLUME MAIN MENU************* \n"


<<" 1.Cylinder \n"
<<" 2.Sphere \n"
<<" 3.Cone \n"
<<" 4.Exit \n";
ch='y';
while(ch=='y'||ch=='Y')
{ // while loop begins
cout<<"\n Enter your choice(1-3):";
cin>>choice;
cout<<"\n";
switch(choice)
{ // switch begins
case 1 : cout<<"\n Enter radius and height of cylinder:";
cin>>s1>>s2;
ar=volume(s1,s2);
cout<<"\n The required volume of the cylinder is "
<<ar<<" sq.units"<<"\n";
break;

case 2 : cout<<"\n Enter a radius :";


cin>>s3;
ar=volume(s3);
cout<<"\n The required volume of the sphere is "
<<ar<<" sq.units"<<"\n";
break;

case 3 : cout<<"\n Enter slant ht. & radius:";


cin>>s4>>s5;

39
ar=volume(s4,s5);
cout<<"\n The required volume of the cone is "
<<ar<<" sq.units"<<"\n";
break;

default:
cout<<"\n SORRY WRONG CHOICE !!\n";

}; // end of switch

cout<<"\n Want to continue(y/n)? : ";


cin>>ch;
} // while loop ends

cout<<"\n\nDo you want to start again(y/n)..!!";


cin>>ch;
clrscr();
}while(ch=='y' || ch=='Y'); // do while

getch();
}

OUTPUT:

************AREA MAIN MENU*************


1.Cylinder
2.Sphere
3.Cone
Enter your choice(1-3):1

Enter radius and height of cylinder:4


5

The required area of the cylinder is 125.599998 sq.units

Want to continue(y/n)? : Y
Enter your choice(1-3):2

Enter a radius :3

The required area of the sphere is 113.040001 sq.units

Want to continue(y/n)? : Y

40
Enter your choice(1-3):3

Enter slant ht. & radius:5


6

The required area of the cone is 94.199997 sq.units

Want to continue(y/n)? : N

Do you want to start again(y/n)..!!nfds


g

LINKED LISTS

Q.1

//program that creates linked list class


#include<iostream.h>
#include<process.h>
#include<conio.h> //for cirscr()
class Linkobj { public:
char info;
Linkobj*next; //pointer to next element
Linkobj() //constructor function
{ info=0;
41
next=NULL;
}
Linkobj(char ch)
{ info=ch;
next=NULL;
}
Linkobj*getnext() { return next;} //Function returning next pointer
void getinfo(char & ch) {ch=info;} //Function giving info
//Function letting you change info part of the element
void change (char ch){info=ch;}
}; //end of Linkobj definition
//This class actually implements the (singly) linked List
class Linklist:public Linkobj
{ Linkobj*start; //pointer pointing to the first node
public:
Linklist(){start=NULL;} //constructor function
//Destructor function that destroys the list
~Linklist();
//Function to insert an element
void Store(char ch); //#1
//Function to delete an element
void remove(char ch); //#2
//Function to traverse
void display(); //#3
//Function to serarch a value
Linkobj*find(char ch); //#4 it returns a pointer to matching element
//Function to get start pointer
Linkobj*getstart() { return start;} //#5
};
Linklist::~Linklist()
{ if(start)
{ Linkobj*p=start;
while(p)
{ p=p->next;
delete start;
start=p;
}
}
}
//Function to insert an element
void Linklist::Store(char ch) //definition of #1
{ Linkobj *newptr, *save, *ptr;
newptr=new Linkobj; //allocate memory for the new node
if(!newptr) //if ptr is NULL
{ cout<<"Allocation Error !\n";
exit(1);

42
}
newptr->info=ch;
newptr->next=NULL;
//Find appropriate position for insertion
if(!start) //If start is NULL
start = newptr; //creation of list takes place
else if(ch<start->info)
{ //to be inserted in the begining of the list
save=start;
start=newptr;
newptr->next=save;
}
else { //find the exact position for insertion
save=start;ptr=start;
while(ptr)
{ if(ch>ptr->info)
{ save=ptr;
ptr=ptr->next;
}
else{ //insert in between two nodes
save->next=newptr;
newptr->next=ptr;
break; //jump out of loop
} //end of else part
} //end of while loop
//insert at the end if ptr is NULL
if(!ptr)
save->next=newptr;
} //end of outer else
}
//Remove an element from the list and update start pointer if required
void Linklist::remove(char ch) //definition of #2
{ Linkobj*ptr, *save;
//Find the matching element
save=ptr=start;
while(ptr)
{ if(ptr->info==ch)
break; //jump out of loop
else { save=ptr;
ptr=ptr->getnext();
}
}
if(!ptr) //if ptr is NULL
cout<<"Sorry!"<<ch<<"not found !!\n";
else //delete the matching node
{ if(ptr==start) //check whether first node is to be deleted

43
{ start=start->getnext(); //update start
delete ptr;
}
else
{ save->next=ptr->next;
delete ptr;
}
}
}
//Traverse through the entire list and display elements
void Linklist::display() //definition of #3
{ Linkobj*ptr;
ptr=start;
while(ptr)
{ cout<<ptr->info<<"->";
ptr=ptr->next;
}
cout<<"END!"<<"\n";
}
Linkobj*Linklist::find(char ch) //definition of #4
{ Linkobj*ptr;
ptr=start;
while(ptr)
{ if(ch==ptr->info) //if found
return ptr;
ptr=ptr->next;
}
return NULL; //not in list
}

OUTPUT:

enter information of the element


1

creating link list


press enter to continue
new node created successfully
press enter to continue
now inserting it to the list
press enter to continue
the list is
1->!!!
wanna enter more??????????
Y
enter information of the element

44
2
creating link list
press enter to continue
new node created successfully
press enter to continue
now inserting it to the list
press enter to continue
the list is
2->1->!!!
wanna enter more??????????
N
the list now is2->1->!!!
wanna delete first node?
y
the list now is1->!!!
wanna delete first node?
n

Q.2

/* PROGRAM-11
To implement the use of queue class.*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Queue {
int Queue[30]; //Queue declaration
int front ,rear; //Front and rear pointers of the Queue
int n;
public:
Queue() //constructor
{
front=rear=0; //Indicates that Queue is empty
n=29;
}
void add(int val, int size);
int delet();
void display(); //Prototype of function to display
}; //contents of the Queue
void Queue::add(int val, int size)
{
if(rear<size)
{

45
Queue[++rear]=val;
}
else
cout<<"\n The Queue is full";
}
//This function returns a value -9999 if the Queue is empty
int Queue::delet()
{
int v;
if(front!=rear)
{
v=Queue[++front];
return v;
}
else
{
cout<<"\n Queue is empty";
return (-9999);
}
}
void Queue::display()
{
int i;
if(front<rear)
{
cout<<"\n";
for(i=front+1;i<=rear;i++)
cout<<Queue[i]<<" ";
}
}
main()
{
Queue ObjQ;
int val; //Value to be added or deleted
int choice;
int size;
clrscr();
cout<<"\n Enter the size of the Queue : ";
cin>>size;
do
{
cout<<"\n MENU";
cout<<"\n";
cout<<"\n 1) Add ";
cout<<"\n 2) Delete ";
cout<<"\n 3) Display ";

46
cout<<"\n 4) Quit ";
cout<<"\n";
cout<<"\n Enter your choice: ";
cin>>choice;

switch(choice)
{
case 1: cout<<"\n Enter the value to be added: ";
cin>>val;
ObjQ.add(val,size);
break;
case 2:
val=ObjQ.delet();
if(val!=-9999)
cout<<"\n The deleted value is......"<<val;
break;
case 3:cout<<"The Queue is....\n";
ObjQ.display();
break;
}
}
while(choice!=4);
return 0;
}

OUTPUT:

Enter the size of the Queue : 5

MENU

1) Add
2) Delete
3) Display
4) Quit

Enter your choice: 1

Enter the value to be added: 5

MENU

1) Add
2) Delete
3) Display

47
4) Quit

Enter your choice: 1

Enter the value to be added: 4


MENU

1) Add
2) Delete
3) Display
4) Quit

Enter your choice: 1

Enter the value to be added: 3


MENU

1) Add
2) Delete
3) Display
4) Quit

Enter your choice: 1

Enter the value to be added: 2

MENU

1) Add
2) Delete
3) Display
4) Quit

Enter your choice: 3


The Queue is....

5432
MENU

1) Add
2) Delete
3) Display
4) Quit

Enter your choice: 4

48
Q.3

//a program to implement the use of stack class.

#include<iostream.h>
#include<conio.h> //FOR clrscr(),
getch()
#include<stdio.h>

class stack //stack class declared


{
int stack[30] ;
int top ;
int n ;
public :
stack() //constructor().
{
top =-1 ;
n = 30 ;
}

void push( int val ) ; //function prototype.


int pop() ;
void display() ;
};

void stack::push( int val ) //function definition


{
if( top<n )
{
top++ ;
stack[top] = val ;
}
else
cout << " \n Thae stack is full " ;
}

int stack::pop()
{
int v ;
if( top >=0 )
{
v = stack[top] ;
top-- ;

49
return v ;
}
else
{
cout << " \n Stack is empty " ;
return( -9999 );
}
}

void stack::display()
{
int i ;
if( top>= 0 )
{
cout << " \n " ;
for( i=top; i>=0 ; i-- )
cout << stack[i] << " " ;
}
cout << " Enter a key " ;
getch() ;
fflush(stdin) ;
}

void main()
{
stack objstk ;
int choice ;
int val ;
clrscr() ;
do // do while loop started.
{
cout << " \n\n \t Menu " ;
cout << " \n\n 1. Push " ;
cout << " \n 2. Pop " ;
cout << " \n 3. Display " ;
cout << " \n 4. Quit " ;
cout << " \n\n Enter your choice :- " ;
cin >> choice ;
switch( choice ) //switch case started.
{
case 1 :
cout << " \n Enter the value to be pushed " ;
cin >> val ;
objstk.push( val ) ;
break ;
case 2 :

50
val = objstk.pop() ;
if( val!=-9999 )
cout << " \n The popped value is " << val ;
break ;
case 3 :
cout << " \n The stack is " ;
objstk.display() ;
break ;
}
}while(choice!=4) ;
getch();
}

OUTPUT:

Menu

1. Push
2. Pop
3. Display
4. Quit

Enter your choice :- 1

Enter the value to be pushed 2

Menu

1. Push
2. Pop
3. Display
4. Quit

Enter your choice :- 1

Enter the value to be pushed 4

Menu

1. Push
2. Pop
3. Display
4. Quit

51
Enter your choice :- 1

Enter the value to be pushed 6

Menu

1. Push
2. Pop
3. Display
4. Quit

Enter your choice :- 1

Enter the value to be pushed 8

Menu

1. Push
2. Pop
3. Display
4. Quit

Enter your choice :- 1

Enter the value to be pushed 10

Menu

1. Push
2. Pop
3. Display
4. Quit

Enter your choice :- 3

Menu

1. Push
2. Pop
3. Display
4. Quit

52
Enter your choice :- 3

The stack is
10 8 6 4 2 Enter a key

Menu

1. Push
2. Pop
3. Display
4. Quit

Enter your choice :- 2

The popped value is 10

Menu

1. Push
2. Pop
3. Display
4. Quit

Enter your choice :- 4

Q.4

//a program to add and delete an element in a linked queue


pr-lsq-02
#include<iostream.h>
#include<conio.h> //for clrsr()
#include<process.h> //for exit()
struct Node{ int info;
Node*next;
}*front, *newptr, *save, *ptr, *rear;
Node *Create_New_Node(int);
void Insert( Node* );
void Display(Node*);
void DelNode_Q();
/*--------------------------------------------------
|The front points to the beginning of linked-Queue, rear points to the last node
| Funtion Create_new_Node() creates a new node dynamically.
| Funtion insert()insert this node in the Linked-queue

53
| Funtion Display()displays the Linked-Queue
| Funtion Delnode_Q() deletes a node from the beginning of Linked-Queuebeing
poited to by front pointer
/*-------------------------------------------------*/
void main()
{ front=rear=NULL; //In the beginning Linked-Queue is empty, thus, pointers are
NULL
int inf; char ch='Y';
while(ch=='y'||ch=='Y')
{ clrscr();
cout<<"\n Enter INFormation for the new node...";
cin>>inf;
newptr=Create_New_Node(inf);
if(newptr==NULL)
{ cout<<"\nCannot create new node!!!Aborting!!\n";
exit(1);
}
Insert(newptr);
cout<<"\nPress Y to enter more nodes' N to exit...\n";
cin>>ch;
}
clrscr();
do
{ cout<<"\n The Linked-Queue now is(Front...to...Rear):\n";
Display(front);
cout<<"Want to delete first node?(y/n)...";
cin>>ch;
if(ch=='y'||ch=='Y')
DelNode_Q();
}while(ch=='y'||ch=='Y');
}
void DelNode_Q() //funtion to delete a node from the beginning of
Linked-Queue
{ if(front==NULL)
cout<<"UNDERFLOW!!!\n";
else
{ ptr=front;
front=front->next;
delete ptr;
}
}
void Display(Node*np) //funtion to display Linked-Queue
{ while(np!=NULL)
{cout<<np->info<<"->";
np=np->next;
}

54
cout<<"!!!\n";
}
Node*Create_New_Node(int n) //Funtion to create new node dynamically
{ ptr=new Node;
ptr->info=n;
ptr->next=NULL;
return ptr;
}
void Insert(Node*np) //Funtion to insert node in the Linked-Queue
{ if(front==NULL)
{front=rear=np; }
else
{rear->next=np; rear=np; }
}

OUTPUT:

Enter INFormation for the new node...4

Press Y to enter more nodes' N to exit...


Y

Enter INFormation for the new node...5

Press Y to enter more nodes' N to exit...


N

The Linked-Queue now is(Front...to...Rear):


4->5->!!!
Want to delete first node?(y/n)...
n

Q.5

//program for implementation of linked stack


pr-lsq-03
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>
//Declares a stack structure

55
struct node
{
int data;
node *link;
};
//Function prototype declaration for add stack, delete stack, and show stack
node *push(node *top,int val); //Add stack
node *pop(node *top,int&val); //Delete stack
void show_Stack(node *top); //Show stack
//Main programming logic
void main()
{
node *top;
int val;
int choice;
char opt='Y'; //to continue the do loop in case
top=NULL; //Initialisation of Stack
clrscr();
do
{
cout<<"\n\t\t Main Menu";
cout<<"\n\t1. Addition of Stack";
cout<<"\n\t2. Deletion from Stack";
cout<<"\n\t3. Traverse of Stack";
cout<<"\n\t4. Exit from Menu";
cout<<"\n\nEnter Your choice from above";
cin>>choice;
switch(choice)
{
case 1:do
{
cout<<"Enter the value to be added in the stack";
cin>> val;
top= push(top, val);
cout<<"\nDo you want to add more element<Y/N>?";
cin>>opt;
} while(toupper(opt)=='Y');
break;
case 2:
opt='Y'; //Initialize for the second loop
do
{
top=pop(top,val);
if(val!=-1)
cout<<"Value deleted from Stack is"<<val;
cout<<"\nDo you want to delete more element<Y/N>?";

56
cin>>opt;
} while(toupper(opt)=='Y');
break;
case 3:
show_Stack(top);
break;
case 4:
exit(0); break;
}

}
while(choice!=4);
getch();
}
//Function body for add stack elements
node *push(node *top, int val)
{
node *temp;
temp=new node;
temp->data=val;
temp->link=NULL;
if(top==NULL)
top=temp;
else
{
temp->link=top;
top=temp;
}
return(top);
}
//function body for delete stack elements
node *pop(node *top,int&val)
{
node *temp;
clrscr();
if(top==NULL)
{
cout<<"Stack empty";
val=-1;
}
else
{
temp=top;
top=top->link;
val=temp->data;
temp->link=NULL;

57
delete temp;
}
return(top);
}
//Function bady to show stack elements
void show_Stack(node *top)
{
node *temp;
temp=top;
clrscr();
cout<<"The values are\n";
while(temp!=NULL)
{
cout<<"\n"<<temp->data;
temp=temp->link;
}
}

OUTPUT:

Main Menu
1. Addition of Stack
2. Deletion from Stack
3. Traverse of Stack
4. Exit from Menu

Enter Your choice from above1


Enter the value to be added in the stack4

Do you want to add more element<Y/N>?Y


Enter the value to be added in the stack5

Do you want to add more element<Y/N>?N

Main Menu
1. Addition of Stack
2. Deletion from Stack
3. Traverse of Stack
4. Exit from Menu

Enter Your choice from above2

Value deleted from Stack is5

58
Do you want to delete more element<Y/N>?Y

Value deleted from Stack is4


Do you want to delete more element<Y/N>?N

Main Menu
1. Addition of Stack
2. Deletion from Stack
3. Traverse of Stack
4. Exit from Menu

Enter Your choice from above4

Q.6

//to create a linked list and insert elements according to user's choice
#include<iostream.h>
#include<conio.h> //for clrcsr()
#include<process.h> //for exit()
struct Node{int info;
Node *next;
}*start, *newptr, *save, *ptr, *rear;

Node *Create_New _Node(int);


void insert_End(Node*);
void Display(Node*);
/*------------------------------------------------
| The start points to the beginning of the list, rear points to the last node
|
| Function Create_New_Node()takes one integer argument, allocates memory to
| create a new node and returns the pointer to the new node.(return type :
| Node *).
|
| Function insert_End() takes Node* type pointer as argument and insert this
| node in the end of list.
|
| Function Display () takes Node * type pointer as argument and displays the
| list from this pointer till the end of the list.
__________________________________________________*/

void main()
{ start = rear = NULL; //in the beginning list is empty
int inf;
char ch='y';

59
while (ch=='y'||ch=='y')
{ clrscr();
cout<<"\n Enter INFOrmation for the new Node...";
cin>>inf;
cout <<"\n Creating New Node!! Press Enter to continue...";
getch();
newptr=Create_New_Node(inf);
if(newptr!=NULL)
{ cout<<"\n\nNew Node Created Successfully. Press Enter to continue...";
getch();
}
else
{ cout<<"\nCannot create new node!!! Aborting!!\n";
getch();
exit(1);
}
cout<<"\n\nNow inserting this node in the end of list...\n";
cout<<"Press Enter to continue...\n";
getch();
insert_End(newptr);
cout<<"\nNow the list is :\n";
Display(start);
cout <<"\n Press Y to enter more nodes, N to exit...\n";
cin>>ch;
}
}

Node* Create_New_Node(int n)
{
ptr=new Node;
ptr->info=n;
ptr->next=NULL;
return ptr;
}
void insert_End(Node*np)
{ if(start==NULL)
{ start=np;
rear=np;
}
else
{ rear->next=np;
rear=np;
}
}
void Display(Node*np) //function to Display list
{ while(np!=NULL)

60
{ cout<<np->info<<"->";
np=np->next;
}
cout<<"!!!\n";
}

OUTPUT:

Enter INFOrmation for the new Node...3

Creating New Node!! Press Enter to continue...

New Node Created Successfully. Press Enter to continue...

Now inserting this node in the end of list...


Press Enter to continue...

Now the list is :


3->!!!

Press Y to enter more nodes, N to exit...


y

Enter INFOrmation for the new Node...4

Creating New Node!! Press Enter to continue...

New Node Created Successfully. Press Enter to continue...

Now inserting this node in the end of list...


Press Enter to continue...

Now the list is :


3->4->!!!

Press Y to enter more nodes, N to exit...


n

Q.7

#include<Stack.h>
#include<Strng.h>
#include<iostream.h>
#include<conio.h>

61
void main()
{
Stack theStack;
String reverse("reverse");

cout << "\nEnter some strings. Reverse will collect the strings\n";
cout << "for you until you enter the string \"reverse\". Reverse\n";
cout << "will then print out the strings you have entered, but in\n";
cout << "reverse order. Begin entering strings now.\n";

for(;;)
{
char inputString[255];
cin >> inputString;
String& newString = *( new String( inputString ) );
if( newString != reverse )
{
theStack.push( newString );
}
else
{
break;
}
}

cout << "\nThe strings you entered (if any) are:\n";


while( !(theStack.isEmpty()) )
{
Object& oldString = theStack.pop();
cout << oldString << "\n";
delete &oldString;
}
getch();
}

OUTPUT:

62
DATA FILE HANDLING

Q.2

#include<fstream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>

class applicant
{ int a_rno;
char a_name[20];
int a_score;

public:
void getd()
{ cout<<"\nEnter the roll no.";

63
cin>>a_rno;
cout<<"\nEnter the name..";
cin>>a_name;
cout<<"\n Enter the score...";
cin>>a_score;
}

void disp()
{ cout<<a_rno<<""<<a_name<<""<<a_score<<"\n";
}
int retroll()
{ return a_rno;
}
char* retnm()
{ return a_name;
}
int retscore()
{ return a_score;
}
};
void writeobj()
{ fstream fout;
fout.open("app.dat",ios::out|ios::binary);
applicant a;
char ch='y';
while(ch!='n')
{ a.getd();
fout.write((char*)&a,sizeof(a));
cout<<"\nDo you want to enter another object details...(y/n)..\n";
ch=getche();
}
fout.close();
}
void searchroll()
{ int r,f=0;
cout<<"\nEnter the roll no ....";
cin>>r;
fstream fin;
fin.open("app.dat",ios::in|ios::binary);
applicant a;
fin.read((char*)&a,sizeof(a));
while(!fin.eof())
{ if(a.retroll()==r)
{ f=1;
cout<<"\n This is the record....";
a.disp();

64
break;
}
fin.read((char*)&a,sizeof(a));
}
if(f==0)
{ cout<<"\n Record not found........";
}
}
void readobj()
{ fstream fin;
fin.open("app.dat",ios::in|ios::binary);
applicant a ;
fin.read((char*)&a,sizeof(a));
cout<<"\nThese are the records......";
while(!fin.eof())
{ a.disp();
fin.read((char*)&a,sizeof(a));
}
fin.close();
}
void chnge()
{ int r,ctr=0;
cout<<"\nEnter any roll no you want to modify...";
cin>>r;
fstream fin;
fin.open("app.dat",ios::in|ios::binary|ios::out);
applicant a;
while(!fin.eof())
{ fin.read((char*)&a,sizeof(a));
if(a.retroll()==r)
{ break;
}
ctr++;
}

fin.seekp(ctr*sizeof(a),ios::beg);
a.getd();
fin.write((char*)&a,sizeof(a));
fin.close();

void main()
{ int ch;
clrscr();

65
do
{ cout<<"\nWhat do you want to do?"
"\n1.write objects"
"\n2.read the objects"
"\n3.search for a particular roll no."
"\n4.modify data..."
"\n5.display the contents of the file .."
"\n6.exit\n";
cin>>ch;
switch(ch)
{ case 1: writeobj();
break;
case 2: readobj();
break;
case 3: searchroll();
break;
case 4: chnge();
break;
case 5: readobj;
break;
}
}while(ch!=6);
getch();
}

OUTPUT:

What do you want to do?


1.write objects
2.read the objects
3.search for a particular roll no.
4.modify data...
5.display the contents of the file ..
6.exit
1

Enter the roll no.28

Enter the name..ram

Enter the score...99

Do you want to enter another object details...(y/n)..


y
Enter the roll no.29

66
Enter the name..ramneek

Enter the score...78

Do you want to enter another object details...(y/n)..


n
What do you want to do?
1.write objects
2.read the objects
3.search for a particular roll no.
4.modify data...
5.display the contents of the file ..
6.exit
2

These are the records......28ram99


29ramneek78

What do you want to do?


1.write objects
2.read the objects
3.search for a particular roll no.
4.modify data...
5.display the contents of the file ..
6.exit
3

Enter the roll no ....28

This is the record....28ram99

What do you want to do?


1.write objects
2.read the objects
3.search for a particular roll no.
4.modify data...
5.display the contents of the file ..
6.exit
6

Q.3

#include<fstream.h>

67
#include<conio.h>
#include<string.h>
#include<stdio.h>

class floppybox
{ int size;
char name[20];

public:
void getd()
{ cout<<"\nEnter the size";
cin>>size;
cout<<"\nEnter the name..";
gets(name);
}

void showdata()
{ cout<<size<<""<<name<<"\n";

}
int retsize()
{ return size;
}
char* retnm()
{ return name;
}

};
void writeobj()
{ fstream fout;
fout.open("flop.dat",ios::out|ios::binary);
floppybox a;
char ch='y';
while(ch!='n')
{ a.getd();
fout.write((char*)&a,sizeof(a));
cout<<"\nDo you want to enter another object details...(y/n)..\n";
ch=getche();
}
fout.close();
}
void searchsize()
{ int r,f=0;
cout<<"\nEnter the size ....";
cin>>r;

68
fstream fin;
fin.open("flop.dat",ios::in|ios::binary);
floppybox a;
fin.read((char*)&a,sizeof(a));
while(!fin.eof())
{ if(a.retsize()==r)
{ f=1;
cout<<"\n This is the record....";
a.showdata();
break;
}
fin.read((char*)&a,sizeof(a));
}
if(f==0)
{ cout<<"\n Record not found........";
}
}
void readobj()
{ fstream fin;
fin.open("flop.dat",ios::in|ios::binary);
floppybox a ;
fin.read((char*)&a,sizeof(a));
cout<<"\nThese are the records......";
while(!fin.eof())
{ a.showdata();
fin.read((char*)&a,sizeof(a));
}
fin.close();
}
void chnge()
{ int r,ctr=0;
cout<<"\nEnter the size you want to modify...";
cin>>r;
fstream fin;
fin.open("flop.dat",ios::in|ios::binary|ios::out);
floppybox a;
while(!fin.eof())
{ fin.read((char*)&a,sizeof(a));
if(a.retsize()==r)
{ break;
}
ctr++;
}

fin.seekp(ctr*sizeof(a),ios::beg);
a.getd();

69
fin.write((char*)&a,sizeof(a));
fin.close();

void main()
{ int ch;
clrscr();

do
{ cout<<"\nWhat do you want to do?"
"\n1.write objects"
"\n2.read the objects"
"\n3.search for a particular roll no."
"\n4.modify data..."
"\n5.display the contents of the file .."
"\n6.exit\n";
cin>>ch;
switch(ch)
{ case 1: writeobj();
break;
case 2: readobj();
break;
case 3: searchsize();
break;
case 4: chnge();
break;
case 5: readobj;
break;
}
}while(ch!=6);
getch();
}

OUTPUT:

What do you want to do?


1.write objects
2.read the objects
3.search for a particular size??
4.modify data...
5.display the contents of the file ..
6.exit
1

Enter the size34

70
Enter the name..ram

Do you want to enter another object details...(y/n)..


y
Enter the size12

Enter the name..rks

Do you want to enter another object details...(y/n)..


n
What do you want to do?
1.write objects
2.read the objects
3.search for a particular size??
4.modify data...
5.display the contents of the file ..
6.exit
2

These are the records......34ram


12rks

What do you want to do?


1.write objects
2.read the objects
3.search for a particular size??
4.modify data...
5.display the contents of the file ..
6.exit
6

Q.4

void writeobj()
{ fstream fout;
fout.open(“stud.dat”,ios::out|ios::binary);
student s;
char ch=”y”;
while(ch!=’n’)
{ s.enterdata();
fout.write((char*)&s,sizeof(s));
cout<<”\nDo you want to enter another object details>>>\n”;
ch=getche();

71
}
fout.close();
}
void readobj()
{ fstream fin;
fin.open(“stud.dat”,ios::in|ios::binary);
sudent s ;
fin.read((char*)&s.sizeof(s));
cout<<”\nThese are the records……..”;
while(!fin.eof())
{ s.displaydata();
fin.read((char*)&s,sizeof(s));
}
fin.close():
}
void searchadmo()
{ int r,f=0;
char n[20];
cout<<”\nEnter the admiision no ……………:”;
cin>>n;
fstream fin;
fin.open(“stu.dat”,ios::in|ios::binary);
student s;
fin.read((char*)&s,sizeof(s));
while(!fin.eof())
{ if(strcmp(s.s_admno==r)
{ f=1;
cout<<”\nThis is the record………..”;
s.displaydatat();
break;
}
fin.read((char*)&s,sizeof(s));
}
if(f==0)
{ cout<<”\nRecord not found….”;
}
}

void modifyobj()
{ int r ;
cout<<”\nEnter the admno you want to modify …….:”;
cin>>r;
fstream file;
file.open(“stud.dat”,ios::in|ios::out|ios::binary);
student s;
while(!file.eof())

72
{ file.read((char*)&s,sizeof(S));
if(s.s_admno==r)
{ break;
}
file.seekp(-1*sizeof(s),ios::cur);
s.enterdata();
file.write((char*)&s,sizeof(s));
}
file.close();
}

Q.5

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<process.h>
class info

{ char count[20];
char captl[20];
public:
void getd()
{ cout<<"\nEnter the country.....:\n";
cin>>count;
cout<<"\nEnter the capital.......:\n";
cin>>captl;
}
void disp()
{ cout<<count<<" "<<captl<<"\n";
}
char*retcount()
{ cout<<count;
return count;
}
char*retcaptl()
{ cout<<captl;
return captl;
}
};

void createobj()
{ fstream fout;
fout.open("inf.dat",ios::out|ios::binary);

73
info s;
char ch='y';
while(ch!='n')
{ s.getd();
fout.write((char*)&s,sizeof(s));
cout<<"\nDo you want to enter more details...(y/n)...\n";
ch=getche();
}
fout.close();

}
void searchcaptl()
{ char r[20];
int f=0;
cout<<"\n Enter the name of the country....:\n";
cin>>r;
fstream fin;
fin.open("inf.dat",ios::in|ios::binary);
info s;
fin.read((char*)&s,sizeof(s));
while(!fin.eof())
{ if(strcmp(s.retcount(),r)==0)
{

f=1;
cout<<"\nthis is the capital...:\n";
s.retcaptl();
break;
}
fin.read((char*)&s,sizeof(s));
}
if(f==0)
{ cout<<"\nRecord not found.....:";
}
}
void searchcount()
{ char r[20];
int f=0;
cout<<"\nEnter the name of the capital.......:\n";
cin>>r;
fstream fin;
fin.open("inf.dat",ios::in|ios::binary);
info s;
fin.read((char*)&s,sizeof(s));
while(!fin.eof())
{ if(strcmp(s.retcaptl(),r)==0)

74
{ f=1;
cout<<"\n this is the name of the country.....:\n";
s.retcount();
break;
}
fin.read((char*)&s,sizeof(s));
}
if(f==0)
{ cout<<"\n REcord not found...:\n";
}
}

void main()
{ int q;
clrscr();
while(q!=4)
{
cout<<"\nEnter you choice....."
"\n1.Enter data...."
"\n2.Determine the country for a capital..."
"\n3.Determine the capital for a gien country ...."
"\n4.quit..........\n";
cin>>q;

switch(q)
{ case 1: createobj();
break;
case 2: searchcount();
break;
case 3: searchcaptl();
break;
case 4: exit(0);
} getch();
}
getch();
}

OUTPUT:

Enter you choice.....


1.Enter data....
2.Determine the country for a capital...
3.Determine the capital for a gien country ....
4.quit..........

75
1

Enter the country.....:


india

Enter the capital.......:


delhi

Do you want to enter more details...(y/n)...


n
Enter you choice.....
1.Enter data....
2.Determine the country for a capital...
3.Determine the capital for a gien country ....
4.quit..........
2

Enter the name of the capital.......:


delhi
delhi
this is the name of the country.....:
india
Enter you choice.....
1.Enter data....
2.Determine the country for a capital...
3.Determine the capital for a gien country ....
4.quit..........
4

Q.6

#include<fstream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>

class student
{ int roll;
char name[20];
int mrks;
char gender[20];

public:

76
void getd()
{ cout<<"\nEnter the name........: ";
gets(name);
cout<<"\nEnter roll no....: ";
cin>>roll;
cout<<"\nEnter the mrks...: ";
cin>>mrks;
cout<<"\nEnter the gender....(m/f)?: ";
gets(gender);

void showdata()
{ cout<<name<<" "<<roll<<" "<<mrks<<" "<<gender<<"\n";

}
int retroll()
{ return roll;
}

};
void writeobj()
{ fstream fout;
fout.open("stud.dat",ios::out|ios::binary);
student a;
char ch='y';
while(ch!='n')
{ a.getd();
fout.write((char*)&a,sizeof(a));
cout<<"\nDo you want to enter another object details...(y/n)..\n";
ch=getche();
}
fout.close();
}
void searchroll()
{ int r,f=0;
cout<<"\nEnter the roll no ....";
cin>>r;
fstream fin;
fin.open("stud.dat",ios::in|ios::binary);
student a;
fin.read((char*)&a,sizeof(a));
while(!fin.eof())
{ if(a.retroll()==r)

77
{ f=1;
cout<<"\n This is the record....";
a.showdata();
break;
}
fin.read((char*)&a,sizeof(a));
}
if(f==0)
{ cout<<"\n Record not found........";
}
}
void readobj()
{ fstream fin;
fin.open("stud.dat",ios::in|ios::binary);
student a ;
fin.read((char*)&a,sizeof(a));
cout<<"\nThese are the records......";
while(!fin.eof())
{ a.showdata();
fin.read((char*)&a,sizeof(a));
}
fin.close();
}
void chnge()
{ int r,ctr=0;
cout<<"\nEnter the roll no you want to modify...";
cin>>r;
fstream fin;
fin.open("stud.dat",ios::in|ios::binary|ios::out);
student a;
while(!fin.eof())
{ fin.read((char*)&a,sizeof(a));
if(a.retroll()==r)
{ break;
}
ctr++;
}

fin.seekp(ctr*sizeof(a),ios::beg);
a.getd();
fin.write((char*)&a,sizeof(a));
fin.close();

void main()

78
{ int ch;
clrscr();

do
{ cout<<"\nWhat do you want to do?"
"\n1.write objects"
"\n2.read the objects"
"\n3.search for a particular roll no."
"\n4.modify data..."
"\n5.display the contents of the file .."
"\n6.exit\n";
cin>>ch;
switch(ch)
{ case 1: writeobj();
break;
case 2: readobj();
break;
case 3: searchroll();
break;
case 4: chnge();
break;
case 5: readobj;
break;
}
}while(ch!=6);
getch();
}

OUTPUT:

What do you want to do?


1.write objects
2.read the objects
3.search for a particular roll no.
4.modify data...
5.display the contents of the file ..
6.exit
1

Enter the name........: RAM


Enter roll no....: 28
Enter the mrks...: 99
Enter the gender....(m/f)?: m

Do you want to enter another object details...(y/n)..


n

79
What do you want to do?
1.write objects
2.read the objects
3.search for a particular roll no.
4.modify data...
5.display the contents of the file ..
6.exit
2

These are the records......RAM 28 99 m

What do you want to do?


1.write objects
2.read the objects
3.search for a particular roll no.
4.modify data...
5.display the contents of the file ..
6.exit
3

Enter the roll no ....28

This is the record....RAM 28 99 m

What do you want to do?


1.write objects
2.read the objects
3.search for a particular roll no.
4.modify data...
5.display the contents of the file ..
6.exit
6

Q.7

#include<fstream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>

class employee
{ int code;
char name[20];
float salary ;

80
public:
void getd()
{ cout<<"\nEnter the name........: ";
gets(name);
cout<<"\nEnter code....: ";
cin>>code;
cout<<"\nEnter salary...: ";
cin>>salary;
}

void showdata()
{ cout<<name<<" "<<code<<" "<<salary<<"\n";

}
int retcode()
{ return code;
}
float retsal()
{ return salary;
}

};
void writeobj()
{ fstream fout;
fout.open("emp.dat",ios::out|ios::binary);
employee a;
char ch='y';
while(ch!='n')
{ a.getd();
fout.write((char*)&a,sizeof(a));
cout<<"\nDo you want to enter another object details...(y/n)..\n";
ch=getche();
}
fout.close();
}
void searchcode()
{ int r,f=0;
cout<<"\nEnter the code ....";
cin>>r;
fstream fin;
fin.open("emp.dat",ios::in|ios::binary);
employee a;
fin.read((char*)&a,sizeof(a));

81
while(!fin.eof())
{ if(a.retcode()==r)
{ f=1;
cout<<"\n This is the record....";
a.showdata();
break;
}
fin.read((char*)&a,sizeof(a));
}
if(f==0)
{ cout<<"\n Record not found........";
}
}
void readobj()
{ fstream fin;
fin.open("emp.dat",ios::in|ios::binary);
employee a ;
fin.read((char*)&a,sizeof(a));
cout<<"\nThese are the records......";
while(!fin.eof())
{ a.showdata();
fin.read((char*)&a,sizeof(a));
}
fin.close();
}
void chnge()
{ int r,ctr=0;
cout<<"\nEnter the code you want to modify...";
cin>>r;
fstream fin;
fin.open("emp.dat",ios::in|ios::binary|ios::out);
employee a;
while(!fin.eof())
{ fin.read((char*)&a,sizeof(a));
if(a.retcode()==r)
{ break;
}
ctr++;
}

fin.seekp(ctr*sizeof(a),ios::beg);
a.getd();
fin.write((char*)&a,sizeof(a));
fin.close();

82
void main()
{ int ch;
clrscr();

do
{ cout<<"\nWhat do you want to do?"
"\n1.write objects"
"\n2.read the objects"
"\n3.search for a particular roll no."
"\n4.modify data..."
"\n5.display the contents of the file .."
"\n6.exit\n";
cin>>ch;
switch(ch)
{ case 1: writeobj();
break;
case 2: readobj();
break;
case 3: searchcode();
break;
case 4: chnge();
break;
case 5: readobj;
break;
}
}while(ch!=6);
getch();
}

OUTPUT:

What do you want to do?


1.write objects
2.read the objects
3.search for a particular roll no.
4.modify data...
5.display the contents of the file ..
6.exit
1

Enter the name........: RAM


Enter code....: 12
Enter salary...: 120000

Do you want to enter another object details...(y/n)..

83
n
What do you want to do?
1.write objects
2.read the objects
3.search for a particular roll no.
4.modify data...
5.display the contents of the file ..
6.exit
2
These are the records......RAM 12 120000

What do you want to do?


1.write objects
2.read the objects
3.search for a particular roll no.
4.modify data...
5.display the contents of the file ..
6.exit
4

Enter the code you want to modify...12

Enter the name........: RKS


Enter code....: 7
Enter salary...: 12345678

What do you want to do?


1.write objects
2.read the objects
3.search for a particular roll no.
4.modify data...
5.display the contents of the file ..
6.exit
6

Q.8

#include<fstream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>

class donor
{ char name[20];
float dob;

84
char addrs[20];
int phne ;
char bldgrp[10];

public:
void getd()
{ cout<<"\nEnter the name........: ";
gets(name);
cout<<"\nEnter dob....: ";
cin>>dob;
cout<<"\nEnter address...: ";
gets(addrs);
cout<<"\nEnter the phone no..: ";
cin>>phne;
cout<<"\nEnter the blood group.: ";
gets(bldgrp);
}

void showdata()
{ cout<<name<<" "<<dob<<" "<<addrs<<" "<<phne<<" "<<bldgrp<<"\n";

}
char* retbldgrp()
{ return bldgrp;
}
char *retname()
{ return name;
}

};
void writeobj()
{ fstream fout;
fout.open("donr.dat",ios::out|ios::binary);
donor a;
char ch='y';
while(ch!='n')
{ a.getd();
fout.write((char*)&a,sizeof(a));
cout<<"\nDo you want to enter another object details...(y/n)..\n";
ch=getche();
}
fout.close();
}
void searchbldgrp()

85
{ int f=0;
char r[20];
cout<<"\nEnter the blood group ....";
cin>>r;
fstream fin;
fin.open("donr.dat",ios::in|ios::binary);
donor a;
fin.read((char*)&a,sizeof(a));
while(!fin.eof())
{ if(strcmp(a.retbldgrp(),r)==0)
{ f=1;
cout<<"\n This is the record....";
a.showdata();
break;
}
fin.read((char*)&a,sizeof(a));
}
if(f==0)
{ cout<<"\n Record not found........";
}
}
void readobj()
{ fstream fin;
fin.open("donr.dat",ios::in|ios::binary);
donor a ;
fin.read((char*)&a,sizeof(a));
cout<<"\nThese are the records......";
while(!fin.eof())
{ a.showdata();
fin.read((char*)&a,sizeof(a));
}
fin.close();
}
void chnge()
{ char r[20];
int ctr=0;
cout<<"\nEnter the name you want to modify...";
cin>>r;
fstream fin;
fin.open("donr.dat",ios::in|ios::binary|ios::out);
donor a;
while(!fin.eof())
{ fin.read((char*)&a,sizeof(a));
if(strcmp(a.retname(),r)==0)
{ break;
}

86
ctr++;
}

fin.seekp(ctr*sizeof(a),ios::beg);
a.getd();
fin.write((char*)&a,sizeof(a));
fin.close();

void main()
{ int ch;
clrscr();

do
{ cout<<"\nWhat do you want to do?"
"\n1.write objects"
"\n2.read the objects"
"\n3.search for a particular roll no."
"\n4.modify data..."
"\n5.display the contents of the file .."
"\n6.exit\n";
cin>>ch;
switch(ch)
{ case 1: writeobj();
break;
case 2: readobj();
break;
case 3: searchbldgrp();
break;
case 4: chnge();
break;
case 5: readobj;
break;
}
}while(ch!=6);
getch();
}

OUTPUT:

What do you want to do?


1.write objects
2.read the objects
3.search for a particular roll no.

87
4.modify data...
5.display the contents of the file ..
6.exit
1

Enter the name........: ram

Enter dob....: 21.09.1993


Enter address...: h-28c dilshad garden
Enter the blood group.: b+
Enter the phone no..: 9873981342

Do you want to enter another object details...(y/n)..


n

What do you want to do?


1.write objects
2.read the objects
3.search for a particular roll no.
4.modify data...
5.display the contents of the file ..
6.exit
2

ram 21.09.1993 h-28c dilshad garden b+ 9873981342

What do you want to do?


1.write objects
2.read the objects
3.search for a particular roll no.
4.modify data...
5.display the contents of the file ..
6.exit
6

88
STRUCTURES
Q.1

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct honour
{char name[26];
char awardtype[26];
unsigned long amt;
};
honour obj[10];
void enter(void);
void display(void);
void winners(void);
void first(void);
int i,n;
void main()
{ clrscr();
cout<<"\nEnter no. of winners: ";
cin>>n;
enter();
display();
winners();
first();
89
getch();
}
void enter(void)
{ cout<<"\nEnter winner's info: ";
for(i=0;i<n;i++)
{cout<<"\n\nEnter info for element no. "<<i+1<<" :";
cout<<"\n\nEnter winner's name: ";
gets(obj[i].name);
cout<<"\n\nEnter type of award: ";
gets(obj[i].awardtype);
cout<<"\n\nEnter prize amount: ";
cin>>obj[i].amt;}
}
void display(void)
{ cout<<"\nDisplaying information: ";
for(i=0;i<n;i++)
{cout<<"\n\nElement- "<<i+1<<" :";
cout<<"\n\nName: ";
puts(obj[i].name);
cout<<"\n\nAward type: ";
puts(obj[i].awardtype);
cout<<"\n\nPrize amount: "<<obj[i].amt;}
}
void winners(void)
{ cout<<"\nDisplaying all those winners who have won prizes of more than
50,000: ";
for(i=0;i<n;i++)
{if(obj[i].amt>=50000)
{cout<<"\n\nName: ";
puts(obj[i].name);
cout<<"\n\nAward type: ";
puts(obj[i].awardtype);
cout<<"\n\nPrize amount: "<<obj[i].amt;
}
}
}
void first(void)
{ int a=0;
int pos;
for(i=0;i<n;i++)
{ if(obj[i].amt>a)
{a=obj[i].amt; pos=i;};
}
cout<<"\nDisplaying biggest prize winner: ";
cout<<"\n\nName: ";
puts(obj[pos].name);

90
cout<<"\n\nAward type: ";
puts(obj[pos].awardtype);
cout<<"\n\nPrize amount: "<<obj[pos].amt;
}

OUTPUT:

Enter no. of winners: 2

Enter winner's info:


Enter info for element no. 1 :
Enter winner's name: RAM
Enter type of award: high score
Enter prize amount: 100000

Enter info for element no. 2 :

Enter winner's name: rks


Enter type of award: best citizen
Enter prize amount: 9000000

Displaying all those winners who have won prizes of more than 50,000:

Name: RAM
Award type: high score
Prize amount: 100000

Name: rks
Award type: best citizen
Prize amount: 9000000

Displaying biggest prize winner:

Name: RAM
Award type: high score
Prize amount: 100000

Q.2

#include<iostream.h>
#include<conio.h>
#include<stdio.h>

91
struct electric
{
int custno;
char name[20];
float units_cnsmed;
float bill;
}e[3];
void main()
{
clrscr();
int i;
float amt;
for(i=0;i<3;++i)
{
cout<<"enter customer number"<<"\n";
cin>>e[i].custno;
cout<<"enter name"<<"\n";
gets(e[i].name);
cout<<"enter no of units consumed"<<"\n";
cin>>e[i].units_cnsmed;
}
cout<<"\n\nYour bill is:”;

for(i=0;i<3;++i)
{
cout<<"name"<<e[i].name;
cout<<"no of units consumed"<<e[i].units_cnsmed;
if(e[i].units_cnsmed<=100)
{
amt=( e[i].units_cnsmed*0.4);

cout<<"bill is Rs.";
cout<<amt<<"\n";

}
else
if((e[i].units_cnsmed>100)&&(e[i].units_cnsmed<=300))
{
amt=e[i].units_cnsmed*0.5;
cout<<"bill is Rs.";
cout<<amt<<"\n";
}
else
if((e[i].units_cnsmed>300)&&(e[i].units_cnsmed<=600))
{
amt=e[i].units_cnsmed*0.75;

92
cout<<"bill is Rs.";
cout<<amt<<"\n";
}
else
if((e[i].units_cnsmed>600)&&(e[i].units_cnsmed<=1000))
{
amt=e[i].units_cnsmed*1;
cout<<"bill is Rs.";
cout<<amt<<"\n";
}
else
{
amt=e[i].units_cnsmed*1.50;
cout<<"bill is Rs.";
cout<<amt<<"\n";
}
}
getch();
}

OUTPUT:

enter customer number


7
enter name
ram
enter no of units consumed
90
enter customer number
8
enter name
rks
enter no of units consumed
70
enter customer number
9
enter name
anuj
enter no of units consumed
10

Your bill is:


name ram no of units consumed 90 bill is Rs. 36

name rks no of units consumed 70 bill is Rs. 28

93
name anuj no of units consumed 10 bill is Rs. 4

Q.3

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct team
{char name[26];
int matchplayed;
int age;
float average;
char category;
};
team obj[15];
int n,i;
void enter(void);
void display(void);
void categorise(void);
void main()
{clrscr();
cout<<"\nEnter no. of team members: ";
cin>>n;
enter();
display();
categorise();
getch();
}
void enter(void)
{cout<<"\nEnter information: ";
for(i=0;i<n;i++)
{ cout<<"\nMember- "<<i+1;
cout<<"\nName: ";
gets(obj[i].name);
cout<<"\nMatches played: ";
cin>>obj[i].matchplayed;
cout<<"\nAge: ";
cin>>obj[i].age;
cout<<"\nAverge score: ";
cin>>obj[i].average;
}
}
void display(void)
{ cout<<"\nDisplaying information: ";

94
for(i=0;i<n;i++)
{cout<<"\nMember- "<<i+1;
cout<<"\nName: ";
puts(obj[i].name);
cout<<"\nMatches played: "<<obj[i].matchplayed;
cout<<"\nAge: "<<obj[i].age;
cout<<"\nAverage score: "<<obj[i].average;
}
}
void categorise(void)
{ cout<<"\nDisplaying name and category: ";
for(i=0;i<n;i++)
{ if(obj[i].age>35)
obj[i].category='R';
else
obj[i].category='A';
cout<<"\nName: ";
puts(obj[i].name);
cout<<"\nCategory: "<<obj[i].category;
}
}

OUTPUT:

Enter no. of team members: 2

Enter information:
Member- 1
Name: ram
Matches played: 55
Age: 19
Averge score: 400

Member- 2
Name: rks
Matches played: 38
Age: 29
Averge score: 500

Displaying information:
Member- 1

Name: ram
Matches played: 55

95
Age: 19
Average score: 400
Member- 2

Name: rks
Matches played: 38
Age: 29
Average score: 500
Displaying name and category:

Name: ram
Category: A

Name: rks
Category: A

CLASSES
Q.1

#include<iostream.h>
#include<conio.h>
#include
class bank_acc{ float balance;
int acc_no;
char acc_type;
public:
char name[50];
void initialize(void)
{ cout<<"Enter your name:";
gets(name);
cout<<"Enter your account number:";
cin>>acc_no;
cout<<"Enter which type of account you want to operate upon"
<<"C for current and S for saving:";
cin>>ch;
cout<<"Initial balance was:";
cin>>balance;
return;
}
void deposit(void)
{ cout<<"Enter the amount you want to deposit:";
cin>>amt;
96
cout<<"\nyour initial balance was: "<<balance;
nbalance=balance+amt;
cout<<"\nyour new balance is:"<<nbalance;
return;
}
void withdraw(void)
{ cout<<"Enter the amount you want to withdraw :";
cin>>w_amt;
namount=balance-w_amt;
if(namount>1000)
cout<<"your balance is now:"<<namount;
else
cout<<"AMOUNT CAN NOT BE WITHDRAWN!!!";
return;
}
void display(void)
{ cout<<"Name of the account operator:"<<

{
clrscr();
getch();
}

OUTPUT:

name
ram
accno
122
acc type saving/current(s/c)
s
balance
2000

enter amount to be deposited


3000

amount deposited
ur current balance is Rs. 5000
enter amount to be withdrawn
2000

97
amount withdrawn IS Rs. 2000
ur current balance is Rs. 3000
account number
122
account holder
anuj
account types
balance(Rs.)3000

Q.2

/*PROGRAM-6
To simulate result preparation system for 20 students.*/

#include<iostream.h>
#include<conio.h> //for clrscr() and getch()
#include<stdio.h> //for gets() and puts()
const int obj=2;
const int size=3;
class student
{
int rollno;
char name[21];
float marks[size];
float perc;
char grade;
public:
student() //Constructor
{}
~student() //Destructor
{}
void getval(void);
void calculate(void);
void prnresult(void);
};
//Function Definitions follow
void student::getval(void)

98
{
char ch;
cout<<"Enter Data";
cout<<"\n"<<"Roll No.:";
cin>>rollno;
cin.get(ch);
cout<<"Name:";
gets(name);
for(int i=0;i<size;i++)
{
cout<<"Marks for subject"<<i+1<<":";
cin>>marks[i];
}
cout<<"\n";
}
void student::calculate(void)
{
float total;
total=marks[0]+marks[1]+marks[2];
perc=total/3;
if(perc<50)
grade='F';
else if(perc<60)
grade='D';
else if(perc<75)
grade='C';
else if(perc<90)
grade='B';
else
grade='A';
}
void student::prnresult(void)
{
cout<<"\n";
cout<<"Rollno:"<<rollno;
cout<<"\nName:";
puts(name);
cout<<"Marks in subject 1:"<<marks[0];
cout<<"\nMarks in subject 2:"<<marks[1];
cout<<"\nMarks in subject 3:"<<marks[2];
cout<<"\nTotal Marks:"<<marks[0]+marks[1]+marks[2];
cout<<"\nPercentage:"<<perc;
cout<<"\nGrade:"<<grade;
cout<<"\n\n";
}
student std10[obj]; //object as an array declared

99
void main()
{
clrscr();
int i=0;
//Read information of 20 students
for(i=0;i<obj;i++)
{
cout<<"Student"<<i+1<<"\n";
std10[i].getval();
}
//Calculate and print results of students
for(i=0;i<obj;i++)
{
std10[i].calculate();
cout<<"\n Result of student"<<i+1<<"\n";
std10[i].prnresult();
}
getch();
}

OUTPUT:

Student1
Enter Data
Roll No.:1
Name:Hina
Marks for subject1:89
Marks for subject2:90
Marks for subject3:91

Student2
Enter Data
Roll No.:2
Name:Suvidha
Marks for subject1:56
Marks for subject2:57
Marks for subject3:58

Result of student1

Rollno:1
Name:Hina
Marks in subject 1:89
Marks in subject 2:90
Marks in subject 3:91

100
Total Marks:270
Percentage:90
Grade:A

Result of student2

Rollno:2
Name:Suvidha
Marks in subject 1:56
Marks in subject 2:57
Marks in subject 3:58
Total Marks:171
Percentage:57
Grade:D

Q.3

//program reads student information using class student and


//displays all the data members
#include<iostream.h>
#include<conio.h>
class student{ int admno; //private by default
char Sname[20];
float m_eng,m_maths,m_sc;
float total;
float Ctotal(float eng,float maths,float sc)
{ total=eng+maths+sc;
return(total);
}
public:
void takedata(); //outline function
void showdata()
{ cout<<"\t\t\tSTUDENT'S INFORMATION\n"
<<Sname<<"'s marks are as follows"
<<"\nmarks in English:"<<m_eng<<"\n"
<<"marks in Maths:"<<m_maths<<"\n"
<<"marks in Science:"<<m_sc<<"\n"
<<"total marks obtained:"<<Ctotal(m_eng,m_maths,m_sc)<<"\n";
}
}std1; //object of type student created
void student::takedata(void)
{ cout<<"enter the name of the student";

101
cin>>Sname;
cout<<"enter the marks in the subjects\n"
<<"(a).English";
cin>>m_eng;
cout<<"\n(b).Maths";
cin>>m_maths;
cout<<"\n(c).Science";
cin>>m_sc;
}
void main() //main function body
{ clrscr();
float tot;
std1.takedata();
std1.showdata();
getch();
}

OUTPUT:

enter the name of the studentram


enter the marks in the subjects

(a).English90

(b).Maths99

(c).Science100

STUDENT'S INFORMATION
ram's marks are as follows
marks in English:90
marks in Maths:99
marks in Science:100
total marks obtained:289

Q.4

//program to read and display information aboput employees and managers.


//employee is the base and Manager is the sub class.
#include<iostream.h>
#include<conio.h> //for clrscr()
const int LEN=25;
class Employee{ private:
char name[LEN];
unsigned long enumb;

102
public:
void getdata()
{ cout<<"Enter Name:";
cin.getline(name,LEN);
cout<<"Enter Employee Number:";
cin>>enumb;
}
void putdata()
{ cout<<"Name:"<<name<<"\t";
cout<<"Emp.Number:"<<enumb<<"\t";
cout<<"Basic Salary:"<<basic;
}
protected:
float basic;
void getbasic()
{ cout<<"Enter Basic:";cin>>basic;}
};
class Manager : public Employee
{ private:
char title[LEN];
public:
void getdata()
{ Employee::getdata(); //To resolve identity as
//Manager also has a getdata()
getbasic();
char ch=cin.get();
cout<<"Enter Title:";
cin.getline(title,LEN);cout<<"\n";
}
void putdata()
{ Employee::putdata();
cout<<"|NTitle:"<<title<<"\n";
}
};
int main()
{ clrscr();
Manager m1, m2;
cout<<"Manager1\n"; m1.getdata();
cout<<"Manager2\n"; m2.getdata();
cout<<"\t\tManager1 Details\n"; m1.putdata();
cout<<"\t\tManager2 Details\n"; m2.putdata();
getch();
return 0;
}

OUTPUT:

103
Manager1
Enter Name:ram
Enter Employee Number:7
Enter Basic:40000
Enter Title:manager

Manager2
Enter Name:rks
Enter Employee Number:8
Enter Basic:10000000
Enter Title:ceo

Manager1 Details
Name:ram Emp.Number:7 Basic Salary:40000|NTitle:manager
Manager2 Details
Name:rks Emp.Number:8 Basic Salary:10000000|NTitle:ceo

Q.5

//TO IMPLEMENT MULTILEVEL INHERITANCE


#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class employee
{
public:
char name[25];
int empno;
char add[35];
void read()
{
cout<<"\n Enter employee number :";
cin>>empno;
cout<<"\n Enter employee name :";
getch();
gets(name);
cout<<"\n Enter employee address :";
gets(add);
}
void disp()
{
cout<<"\n Employee number :"<<empno

104
<<"\n Employee name :";
cout.write(name,25);
cout<<"\n Employee address :";
cout.write(add,35);
}
};
class customer:public employee
{
public:
char cust_name[25];
char cust_add[35];
int cust_code;
void getdata()
{
read();
cout<<"\n Enter customer code :";
cin>>cust_code;
cout<<"\n Enter customer name :";
gets(cust_name);
cout<<"\n Enter customer address :";
gets(cust_add);
}
void putdata()
{
disp();
cout<<"\n Customer code :"<<cust_code
<<"\n Customer name :";
cout.write(cust_name,25);
cout<<"\n Customer address :";
cout.write(cust_add,25);
}
};
class emp_cust:public customer
{
int amt;
int price;
int bal;
public:
void get()
{
getdata();
cout<<"\n Enter the actual price to be given by the customer :";
cin>>price;
cout<<"\n Enter the amount given by customer: ";
cin>>amt;
}

105
void calc()
{
bal=amt-price;
}
void show()
{
putdata();
cout<<"\nActual price given by the customer : "<<price;
cout<<"\nAmount given by the customer : "<<amt;
cout<<"\nAmount returned by the employee to the customer :"<<bal;
}
}ec;
void main()
{
clrscr();
cout<<"\nEnter the employee and customer information :\n ";
ec.get();
ec.calc();
cout<<"\nEmployee and customer information is as follows : \n";
ec.show();
}

OUTPUT:

Enter the employee and customer information :

Enter employee number :7

Enter employee name :am

Enter employee address :dilshad garden

Enter customer code :8

Enter customer name :rks

Enter customer address :nsp

Enter the actual price to be given by the customer :400

Enter the amount given by customer: 500

Q.6
106
//Program for the railway reservation using concept of inheritance
#include<iostream.h>
#include<conio.h>
class train{ int number; //train number
int seats_1; //total seats in 1st class
int seats_2; //total seats in 2nd class
int seats_3; //total seats in 3rd class
public:
train(int i,int k,int j,int l)
{ number=i;
seats_1=j;
seats_2=k;
seats_3=l;
}
//access functions
int getnum(void)
{ return number; }
int getseats_1(void)
{ return seats_1; }
int getseats_2(void)
{ return seats_2; }
int getseats_3(void)
{return seats_3; }
};
class reservation:public train
{ int bkd_1; //seats reserved in 1st class
int bkd_2; //seats reserved in 2nd class
int bkd_3; //seats reserved in 3rd class
public:
reservation(int i,int j,int k,int l):train(i,j,k,l)
{ bkd_1=bkd_2=bkd_3=0; }
void book(char type,int num);
void cancel(char type,int num);
void disp_status(void);
};
void reservation::book(char type,int num)
{ switch(type)
{ case'1': bkd_1+=num; //add num to bkd_1
break;
case'2': bkd_2+=num; //add num to bkd_2
break;
case'3': bkd_3=num; //add num to bkd_3
break;
default: cout<<"wrong class!";
break;

107
}
}
void reservation::cancel(char type,int num)
{ switch(type)
{ case'1': bkd_1-=num;
break;
case'2': bkd_2-=num;
break;
case'3': bkd_3-=num;
break;
default: cout<<"wrong class!\n";
break;
}
}
void reservation::disp_status(void)
{ cout<<"\t\tTrain Number:"<<getnum()<<"\n";
cout<<"class\tTotal seats\tReserved\tUnreserved\n";
int val1,val2,val3,val_bkd_1,val_bkd_2,val_bkd_3;
val1=getseats_1();
val2=getseats_2();
val3=getseats_3();
val_bkd_1=val1-bkd_1;
val_bkd_2=val2-bkd_2;
val_bkd_3=val3-bkd_3;
cout<<"1\t"<<val1<<"\t\t"<<bkd_1<<"\t\t"<<val_bkd_1<<"\n";
cout<<"2\t"<<val2<<"\t\t"<<bkd_2<<"\t\t"<<val_bkd_2<<"\n";
cout<<"3\t"<<val3<<"\t\t"<<bkd_3<<"\t\t"<<val_bkd_3<<"\n";
}
int main()
{ clrscr();
int num;
cout<<"Enter Train Number:\n"; cin>>num;
cout<<"enter total number of seats in 1st class\n";
int s1; cin>>s1;
cout<<"enter total number of seats in 2nd class\n";
int s2; cin>>s2;
cout<<"enter total number of seats in 3rd class\n";
int s3; cin>>s3;
reservation tr(num,s1,s2,s3);
char cl_type;
int choice,seats;
do
{ cout<<"\nMain Menu\n";
cout<<"1.Reservation\n";
cout<<"2.Cancellation\n";
cout<<"3.Display status\n";

108
cout<<"4.exit\n";
cout<<"Enter your choice:";
cin>>choice; cout<<"\n";
switch(choice)
{ case 1: cout<<"Which class?(1/2/3):";
cin>>cl_type;
cout<<"\nHow many seats?";
cin>>seats; cout<<"\n";
tr.book(cl_type,seats);
break;
case 2: cout<<"Which class?(1/2/3):";
cin>>cl_type;
cout<<"\nHow many seats?";
cin>>seats; cout<<"\n";
tr.cancel(cl_type,seats);
break;
case 3: tr.disp_status();
break;
case 4: break;
default: cout<<"Wrong choice";
}; //end of switch
}while(choice>=1&&choice<=3);
getch();
return 0;
} //end of main

OUTPUT:

Enter Train Number:


2461
enter total number of seats in 1st class
20
enter total number of seats in 2nd class
30
enter total number of seats in 3rd class
40

Main Menu
1.Reservation
2.Cancellation
3.Display status
4.exit
Enter your choice:1

Which class?(1/2/3):2

109
How many seats?4

Main Menu
1.Reservation
2.Cancellation
3.Display status
4.exit
Enter your choice:2

Which class?(1/2/3):1

How many seats?4

Main Menu
1.Reservation
2.Cancellation
3.Display status
4.exit
Enter your choice:4

Q.7

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class travel
{
int travel_code;
char place[20];
int no_of_travelers;
int no_of_buses;
public:
travel()
{
travel_code=201;
strcpy(place,"nainital");
no_of_travelers=10;
no_of_buses=1;
}
void newtravel()
{
cout<<"enter travel code"<<"\n";

110
cin>>travel_code;
cout<<endl;
cout<<"enter place"<<"\n";
gets(place);
cout<<endl;
cout<<"enter no of travelers"<<"\n";
cin>>no_of_travelers;
cout<<endl;

if(no_of_travelers<20)
no_of_buses=1;
else
if((no_of_travelers>=20)&&(no_of_travelers<40))
no_of_buses=2;
else
{
no_of_buses=3;
}
}
void showtravel()
{
cout<<"travelcode"<<"\n"<<travel_code<<"\n";
cout<<"place"<<"\n"<<place<<"\n";
cout<<"no of travelers"<<"\n"<<no_of_travelers<<"\n";
cout<<"no of buses"<<"\n"<<no_of_buses<<"\n";
}

};
void main()
{
clrscr();
travel t;
t.newtravel();
t.showtravel();
getch();
}

OUTPUT:

enter travel code


7

enter place
delhi

111
enter no of travelers
10

travelcode
7
place
delhi
no of travelers
10
no of buses
1

Q.8

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class bowler
{
char first_name[20];
char last_name[20];
int over_bowled;
char no_of_maidens[];
int maiden;
int runs_given[][7];
int wickets_taken;
int runs;
char ch[3][7];
int total_runs;
int total_wickets;
int total_maiden;
char r;
char w;
char d;
public:
void initial() ;
void display();
};
void bowler::initial()
{
cout<<"enter first name"<<"\n";
gets(first_name);
cout<<endl;
cout<<"enter last name"<<"\n";

112
gets(last_name);
cout<<endl;
cout<<"enter overs bowled"<<"\n";
cin>>over_bowled;
cout<<endl;
runs=0;
wickets_taken=0;
maiden=0;
for(int i=0;i<over_bowled;++i)
{
cout<<"INFORMATION OF"<<" "<<i+1<<"
"<<"OVER"<<"\n";
cout<<"is the over maiden?????(y/n)"<<"\n";
cin>>no_of_maidens[i];
if(no_of_maidens[i]=='y')
{
cout<<"WELL DONE MAN!!!!!!!!!!!!!!!"<<"\n";
++maiden;
}

else
cout<<"give over details"<<"\n";
cout<<"enter runs given and wicket taken"<<"\n";
for(int j=0;j<6;++j)
{
cout<<"bowl"<<" "<<j+1<<" ";
cout<<"runs or dot ball or wicket(r/w/d)"<<"\n";
cin>>ch[i][j];
cout<<endl;
if(ch[i][j]=='r')
{
cout<<"enter runs given"<<"\n";
cin>>runs_given[i][j];
if(runs_given[i][j]==6)

runs+=6;
else
if(runs_given[i][j]==4)

runs+=4;
else
if(runs_given[i][j]==2)

runs+=2;
else
++runs;

113
}

else
if(ch[i][j]=='d')
{
cout<<"OOOOOOOO JUST MISSED"<<"\n";
}
else
{
cout<<"OUWAZEEEEEEEEEEE!!!!!"<<"\n";
++wickets_taken;
cout<<endl;
}

}
}

void bowler::display()
{
cout<<"name"<<"\n"<<first_name<<" "<<last_name<<"\n";
cout<<"total runs"<<" "<<runs<<"\n";
cout<<"total wickets"<<" "<<wickets_taken<<"\n";
cout<<"total maidens"<<" "<<maiden<<"\n";
}
void main()
{
clrscr();
bowler b;
b.initial();
b.display();
getch();
}

OUTPUT:

enter first name


ram

enter last name

114
singh

enter overs bowled


1

INFORMATION OF 1 OVER
is the over maiden?????(y/n)
n
give over details
enter runs given and wicket taken

bowl 1 runs or dot ball or wicket(r/w/d)


r
enter runs given
1
bowl 2 runs or dot ball or wicket(r/w/d)
r
enter runs given
2
bowl 3 runs or dot ball or wicket(r/w/d)
r
enter runs given
4
bowl 4 runs or dot ball or wicket(r/w/d)
d
OOOOOOOO JUST MISSED
bowl 5 runs or dot ball or wicket(r/w/d)
r
enter runs given
6
bowl 6 runs or dot ball or wicket(r/w/d)
r
enter runs given
6

name
ram singh
total runs 20
total wickets 1
total maidens 110

Q.12

//TICKET SELLING BOOTH


#include<iostream.h>

115
#include<conio.h>
#include<string.h>
#include<stdio.h>
class tic
{
int count;
int no_of_ppl;
float tot_amt;
public:
void input();
void display()
{
cout<<"\n\nTOTAL NO OF PEOPLE VISITED :- "<<no_of_ppl;
cout<<"\nTOTAL AMOUNT OF MONEY COLLECTED :- "<<tot_amt;
cout<<"\nTOTAL NUMBER OF TICKETS SOLD OUT :- "<<count;
}
};
void tic::input()
{
count=0;
no_of_ppl=0;
tot_amt=0;
char rep;
for(int i=0;i<10;i++)
{
cout<<"\nPERSON NO."<<i+1<<" IS ENTERING THE TICKET IS
SOLD(y/n)?"<<endl;
a:
cin>>rep;
if(rep=='y')
{
no_of_ppl=no_of_ppl+1;
tot_amt=tot_amt+(2.5);
count=count+1;
}
else if(rep=='n')
{no_of_ppl=no_of_ppl+1;
}
else{
cout<<"WRONG CHOICE, ENTER AGAIN"<<endl;
goto a;
}
}
}
void main()
{

116
clrscr();
tic day;
day.input();
day.display();
getch();
}

OUTPUT:

PERSON NO.1 IS ENTERING THE TICKET IS SOLD(y/n)?


N
WRONG CHOICE, ENTER AGAIN
n

PERSON NO.2 IS ENTERING THE TICKET IS SOLD(y/n)?


y

PERSON NO.3 IS ENTERING THE TICKET IS SOLD(y/n)?


y

PERSON NO.4 IS ENTERING THE TICKET IS SOLD(y/n)?


y

PERSON NO.5 IS ENTERING THE TICKET IS SOLD(y/n)?


n

PERSON NO.6 IS ENTERING THE TICKET IS SOLD(y/n)?


y

PERSON NO.7 IS ENTERING THE TICKET IS SOLD(y/n)?


n

PERSON NO.8 IS ENTERING THE TICKET IS SOLD(y/n)?


y

PERSON NO.9 IS ENTERING THE TICKET IS SOLD(y/n)?


n

PERSON NO.10 IS ENTERING THE TICKET IS SOLD(y/n)?


y

TOTAL NO OF PEOPLE VISITED :- 10


TOTAL AMOUNT OF MONEY COLLECTED :- 15
TOTAL NUMBER OF TICKETS SOLD OUT :- 6

117
SQL

Q1. Write SQL commands for (a) to (f) and Write the outputs for (g)on the basis of
table HOSPITAL.
TABLE: HOSPITAL

No. Name Age Department Date of admn Charges Sex


1 Sandeep 65 Surgery 23/02/98 300 M
2 Ravina 24 Orthopedic 20/01/98 200 F
3 Karan 45 Orthopedic 19/03/98 200 M
4 Tarun 12 Surgery 01/01/98 300 M
5 Zubin 36 ENT 12/01/98 250 M
6 Ketaki 16 ENT 24/02/99 300 F
7 Ankita 29 Cardiology 20/02/98 800 F
8 Zareen 45 Gynecology 22/02/98 300 F
9 Kush 19 Cardiology 13/01/98 800 M
10 Shailja 31 Nuclear 19/02/98 400 F
Medicine

a) To show all information about the patients of Cardiology department.


Ans : Select * from hospital where department = ‘ cardiology’;
No. Name Age Department Date of Charges Sex
admn
7 Ankita 29 Cardiology 20/02/98 800 F
9 Kush 19 Cardiology 13/01/98 800 M
b) To list the names of female patients who are in orthopedic department.
Ans : Select name from hospital
where sex=’F’ and department =’orthopedic’;

118
Name
Ravina
c) To list names of all patients with their due date of admission in ascending
order.
Ans : select ename from hospital
Order by date of admn ASC;
Name
Tarun
Zubin
Kush
Ravina
Shailja
Ankita
Zareen
Sandeep
Ketaki
Karan

d) To display patients name, charges, age for male patients only.


Ans : Select name, charges, age from hospital where sex = ‘m’;
Name Charges Age
Sandeep 300 65
Karan 200 45
Tarun 300 12
Zubin 250 36
Kush 800 19

e) To count the number of patients with age>30.


Ans : Select count(name) from hospital where age>30;
5
f) To insert a new row in the HOSPITAL table with the following data:
11,”Mustafa”, 37,”ENT”, {25/02/98}, 250,”M”
Ans: insert into hospital (No, name, age, department, age of Amdn,
charges.sex)
values(11,’mushtafa’,37,’ENT’,27-feb-98,250’.,’m’);
g) Give the output of following SQL statements:
i) Select count (distinct department) from HOSPITAL.
Ans : COUNT(DISTINCTDEPARTMENT)
6
ii) Select MAX (age) from HOSPITAL where Sex=”M”.
Ans: MAX(age)
65
iii) Select AVG (charges) from HOSPITAL where Sex=”F”.
Ans : AVG(Charges)
400

119
iv) Select SUM (charges) from HOSPITAL where date of adm<{12/08/98}
Ans : SUM(Charges)

3650

Q.2

Relation teacher

No. Name. Age Dept. Date of Salary Sex


join
1. Jugal 34 Computer 10/01/97 12000 M
2. Sharmila 31 History 24/03/98 20000 F
3. Sandeep 32 Math 12/12/96 30000 M
4. Sangeeta 35 History 01/07/99 40000 F
5. Rakesh 42 Math 05/09/97 25000 M
6. Shyam 50 History 27/06/98 30000 M
7. Shiv om 44 Computer 25/02/97 21000 M
8. Shalakha 33 Math’s 31/07/97 20000 F

To show all information about the teacher of the history dept.

Ans: select * from teacher


Where Dept=’history’;

No. Name. Age Dept. Date of Salary Sex


join
2. Sharmila 31 History 24/03/98 20000 F
4. Sangeeta 35 History 01/07/99 40000 F
6. Shyam 50 History 27/06/98 30000 M

(b) To list the names of the female teachers who are in the Hindi Dept.

Ans: select name from teacher


where Dept=’hindi’ and Sex=’f’;

(c) To list all the teachers with their Date of joining in ascending order

Ans: select name from teacher


Order by date of join ASC;

Name.
Sandeep
120
Jugal
Shiv om
Shalakha
Rakesh
Sharmila
Shyam
Sangeeta

(d) To display student’s Name, Fee, Age for Male teachers only.

Ans: select name, salary, age from teacher


Where sex= ‘ m’;

Name. Salary Age


Jugal 12000 34
Sandeep 30000 32
Rakesh 25000 42
Shyam 30000 50
Shiv om 21000 44

(e) To count the number of teachers with Age<23.

Ans: Select count(name) from teacher where age<23;

Q.3

TABLE: MOV
NO TITLE TYPE RATIN STARS QT PRICE
G Y
1 Gone with the wind. Drama G Gable 4 39.95
2 Friday the 13th Horror R Jason 2 69.95
3 Top Gun Drama PG Cruise 7 49.95
4 Splash Comed PG13 Hanks 3 29.95
y
5 Independence Day Drama T Turne 3 19.95
6 Risky Business Comed T Cruise 2 44.95
y
7 Cocoon Scifi PG Ameche 2 31.95
8 Crocodile Dundee Comed PG13 Harris 2 69.95
y
9 101 Dalmatians Comed G 3 59.95
y
121
10 Tootsie Comed PG Hoffman 1 29.95
y

(b) Find the total value of the movie cassettes available in the library.

Ans: select count (Qty)

(c) Display a list of all movies with the price over 20 and sorted by price.

Ans: select * from mov


where price>20.00
order by price;

NO TITLE TYPE RATIN STARS QT PRICE


G Y
4 Splash Comed PG13 Hanks 3 29.95
y
10 Tootsie Comed PG Hoffman 1 29.95
y
7 Cocoon Scifi PG Ameche 2 31.95
6 Risky Business Comed T Cruise 2 44.95
y
3 Top Gun Drama PG Cruise 7 49.95
1 Gone with the wind. Drama G Gable 4 39.95
9 101 Dalmatians Comed G 3 59.95
y
th
2 Friday the 13 Horror R Jason 2 69.95
8 Crocodile Dundee Comed PG13 Harris 2 69.95
y

(d) Display all the movies sorted by QTY in decreasing order.

Ans: select * from mov


Order by QTY DESC;

NO TITLE TYPE RATIN STARS QT PRICE


G Y
10 Tootsie Comed PG Hoffman 1 29.95
y
2 Friday the 13th Horror R Jason 2 69.95
6 Risky Business Comed T Cruise 2 44.95
y
7 Cocoon Scifi PG Ameche 2 31.95
8 Crocodile Dundee Comed PG13 Harris 2 69.95

122
y
4 Splash Comed PG13 Hanks 3 29.95
y
5 Independence Day Drama T Turne 3 19.95
9 101 Dalmatians Comed G 3 59.95
y
1 Gone with the wind. Drama G Gable 4 39.95
3 Top Gun Drama PG Cruise 7 49.95

(e) Display a report listing a movie number, current value and replacement value for
each movie in the given table. Calculate the replacement value for all the movies as
QTY*Price*1.15.

Ans: select no,price,qty*price*1.15 as “Replacement value” from mov;

Q.4

SQL> CREATE TABLE STUDENT1


2 (
3 NO INTEGER NOT NULL PRIMARY KEY,
4 NAME CHAR(20) NOT NULL,
5 STIPEND DECIMAL NOT NULL,
6 STREAM CHAR(10) NOT NULL,
7 AVGMARK DECIMAL NOT NULL,
8 GRADE CHAR(1) NOT NULL,
9 CLASS CHAR(3) NOT NULL
10 );

Table created.

SQL> INSERT INTO STUDENT1 VALUES


2 (&NO, '&NAME', '&STIPEND', '&STREAM', &AVGMARK, '&GRADE',
'&CLASS');
Enter value for no: 1
Enter value for name: KARAN
Enter value for stipend: 400.00
Enter value for stream: MEDICAL
Enter value for avgmark: 78.5
Enter value for grade: B
Enter value for class: 12B
old 2: (&NO, '&NAME', '&STIPEND', '&STREAM', &AVGMARK, '&GRADE',
'&CLASS')

123
new 2: (1, 'KARAN', '400.00', 'MEDICAL', 78.5, 'B', '12B')

1 row created.

SQL> /
Enter value for no: 2
Enter value for name: DIVAKAR
Enter value for stipend: 450.00
Enter value for stream: COMMERCE
Enter value for avgmark: 89.2
Enter value for grade: A
Enter value for class: 11C
old 2: (&NO, '&NAME', '&STIPEND', '&STREAM', &AVGMARK, '&GRADE',
'&CLASS')
new 2: (2, 'DIVAKAR', '450.00', 'COMMERCE', 89.2, 'A', '11C')

1 row created.

SQL> /
Enter value for no: 3
Enter value for name: DIVYA
Enter value for stipend: 300.00
Enter value for stream: COMMERCE
Enter value for avgmark: 68.6
Enter value for grade: C
Enter value for class: 12C
old 2: (&NO, '&NAME', '&STIPEND', '&STREAM', &AVGMARK, '&GRADE',
'&CLASS')
new 2: (3, 'DIVYA', '300.00', 'COMMERCE', 68.6, 'C', '12C')

1 row created.

SQL> /
Enter value for no: 4
Enter value for name: ARUN
Enter value for stipend: 350.00
Enter value for stream: HUMANITIES
Enter value for avgmark: 73.1
Enter value for grade: B
Enter value for class: 12D
old 2: (&NO, '&NAME', '&STIPEND', '&STREAM', &AVGMARK, '&GRADE',
'&CLASS')
new 2: (4, 'ARUN', '350.00', 'HUMANITIES', 73.1, 'B', '12D')

1 row created.

124
SQL> /
Enter value for no: 5
Enter value for name: SABINA
Enter value for stipend: 500.00
Enter value for stream: NMEDICAL
Enter value for avgmark: 90.6
Enter value for grade: A
Enter value for class: 11A
old 2: (&NO, '&NAME', '&STIPEND', '&STREAM', &AVGMARK, '&GRADE',
'&CLASS')
new 2: (5, 'SABINA', '500.00', 'NMEDICAL', 90.6, 'A', '11A')

1 row created.

SQL> /
Enter value for no: 6
Enter value for name: JOHN
Enter value for stipend: 400.00
Enter value for stream: MEDICAL
Enter value for avgmark: 75.4
Enter value for grade: B
Enter value for class: 12B
old 2: (&NO, '&NAME', '&STIPEND', '&STREAM', &AVGMARK, '&GRADE',
'&CLASS')
new 2: (6, 'JOHN', '400.00', 'MEDICAL', 75.4, 'B', '12B')

1 row created.

SQL> /
Enter value for no: 7
Enter value for name: ROBERT
Enter value for stipend: 250.00
Enter value for stream: HUMANITIES
Enter value for avgmark: 64.4
Enter value for grade: C
Enter value for class: 11A
old 2: (&NO, '&NAME', '&STIPEND', '&STREAM', &AVGMARK, '&GRADE',
'&CLASS')
new 2: (7, 'ROBERT', '250.00', 'HUMANITIES', 64.4, 'C', '11A')

1 row created.

SQL> /
Enter value for no: 8
Enter value for name: RUBINA
Enter value for stipend: 450.00

125
Enter value for stream: NMEDICAL
Enter value for avgmark: 88.5
Enter value for grade: A
Enter value for class: 12A
old 2: (&NO, '&NAME', '&STIPEND', '&STREAM', &AVGMARK, '&GRADE',
'&CLASS')
new 2: (8, 'RUBINA', '450.00', 'NMEDICAL', 88.5, 'A', '12A')

1 row created.

SQL> /
Enter value for no: 9
Enter value for name: VIKAS
Enter value for stipend: 500.00
Enter value for stream: NMEDICAL
Enter value for avgmark: 92.0
Enter value for grade: A
Enter value for class: 12A
old 2: (&NO, '&NAME', '&STIPEND', '&STREAM', &AVGMARK, '&GRADE',
'&CLASS')
new 2: (9, 'VIKAS', '500.00', 'NMEDICAL', 92.0, 'A', '12A')

1 row created.

SQL> /
Enter value for no: 10
Enter value for name: MOHAN
Enter value for stipend: 300.00
Enter value for stream: COMMERCE
Enter value for avgmark: 67.5
Enter value for grade: C
Enter value for class: 12C
old 2: (&NO, '&NAME', '&STIPEND', '&STREAM', &AVGMARK, '&GRADE',
'&CLASS')
new 2: (10, 'MOHAN', '300.00', 'COMMERCE', 67.5, 'C', '12C')
(10, 'MOHAN', '300.00', 'COMMERCE', 67.5, 'C', '12C')

1 row created.
SQL> SELECT * FROM STUDENT1 ORDER BY NO;

NO NAME STIPEND STREAM AVGMARK G CLA


--------- -------------------- --------- ---------- --------- - ---
1 KARAN 400 MEDICAL 79 B 12B
2 DIVAKAR 450 COMMERCE 89 A 11C
3 DIVYA 300 COMMERCE 69 C 12C
4 ARUN 350 HUMANITIES 73 B 12D

126
5 SABINA 500 NMEDICAL 90 A 11A
6 JOHN 400 MEDICAL 75 B 12B
7 ROBERT 250 HUMANITIES 64 C 11A
8 RUBINA 450 NMEDICAL 89 A 12A
9 VIKAS 500 NMEDICAL 92 A 12A
10 MOHAN 300 COMMERCE 68 C 12C

10 rows selected.

SQL> SELECT * FROM STUDENT1 WHERE STREAM='NMEDICAL';

NO NAME STIPEND STREAM AVGMARK G CLA


--------- -------------------- --------- ---------- --------- - ---
8 RUBINA 450 NMEDICAL 89 A 12A
5 SABINA 500 NMEDICAL 90 A 11A
9 VIKAS 500 NMEDICAL 92 A 12A
3 rows selected.

SQL> SELECT NAME FROM STUDENT1 WHERE CLASS='12A' OR


CLASS='12B' OR CLASS='12C' ORDER BY STIPEND

NAME
--------------------
DIVYA
MOHAN
KARAN
JOHN
RUBINA
VIKAS

6 rows selected.

SQL> SELECT * FROM STUDENT1 ORDER BY AVGMARK DESC;

NO NAME STIPEND STREAM AVGMARK G CLA


--------- -------------------- --------- ---------- --------- - ---
9 VIKAS 500 NMEDICAL 92 A 12A
5 SABINA 500 NMEDICAL 90 A 11A
2 DIVAKAR 450 COMMERCE 89 A 11C
8 RUBINA 450 NMEDICAL 89 A 12A
1 KARAN 400 MEDICAL 79 B 12B
6 JOHN 400 MEDICAL 75 B 12B
4 ARUN 350 HUMANITIES 73 B 12D
3 DIVYA 300 COMMERCE 69 C 12C
10 MOHAN 300 COMMERCE 68 C 12C
7 ROBERT 250 HUMANITIES 64 C 11A

127
10 rows selected.

SQL> SELECT NAME, STIPEND, STREAM, STIPEND*12 FROM STUDENT1;

NAME STIPEND STREAM STIPEND*12


-------------------- --------- ---------- ----------
KARAN 400 MEDICAL 4800
DIVAKAR 450 COMMERCE 5400
DIVYA 300 COMMERCE 3600
ARUN 350 HUMANITIES 4200
JOHN 400 MEDICAL 4800
ROBERT 250 HUMANITIES 3000
MOHAN 300 COMMERCE 3600
RUBINA 450 NMEDICAL 5400
SABINA 500 NMEDICAL 6000
VIKAS 500 NMEDICAL 6000

10 rows selected.
SQL> SELECT COUNT(GRADE) FROM STUDENT1 WHERE GRADE='A';

COUNT(GRADE)
------------
4

SQL> INSERT INTO STUDENT1 VALUES


2 (11,'HINA',450.00,'NMEDICAL',76,'B','12A');

1 row created.

SQL> SELECT * FROM STUDENT1 ORDER BY NO;

NO NAME STIPEND STREAM AVGMARK G CLA


--------- -------------------- --------- ---------- --------- - ---
1 KARAN 400 MEDICAL 79 B 12B
2 DIVAKAR 450 COMMERCE 89 A 11C
3 DIVYA 300 COMMERCE 69 C 12C
4 ARUN 350 HUMANITIES 73 B 12D
5 SABINA 500 NMEDICAL 90 A 11A
6 JOHN 400 MEDICAL 75 B 12B
7 ROBERT 250 HUMANITIES 64 C 11A
8 RUBINA 450 NMEDICAL 89 A 12A
9 VIKAS 500 NMEDICAL 92 A 12A
10 MOHAN 300 COMMERCE 68 C 12C
11 HINA 450 NMEDICAL 76 B 12A

128
11 rows selected.

SQL> SELECT MIN(AVGMARK) FROM STUDENT1 WHERE AVGMARK<75

MIN(AVGMARK)
------------
64

SQL> SELECT SUM(STIPEND) FROM STUDENT1 WHERE GRADE='B';

SUM(STIPEND)
------------
1600

SQL> SELECT AVG(STIPEND) FROM STUDENT1 WHERE CLASS='12A';

AVG(STIPEND)
------------
466.66667

SQL> SELECT COUNT(DISTINCT NO) FROM STUDENT1

COUNT(DISTINCTNO)
-----------------
11

Q.5

SQL> SELECT * FROM COMPBOOKS;

NO TITLE AUTHOR TYPE PUB QTY


PRICE
--------- -------------------- ------------- -------- ----------
--------- ---------
1 DATA STRUCTURE LIPSCHUTZ DS MCGRAW 4
217
2 COMPUTER STUDIES FRENCH FND GALGOTIA] 2
75
3 ADVANCED PASCAL SCHILDT PROG MCGRAW 4
350
4 DBASE DUMMIES PALMER DBMS PUSTAKM
5 130
5 MASTERING C++ GUREWICH PROG BPB 3
295

129
6 GUIDE NETWORK FREED NET ZPRESS 3
200
7 MASTERING FOXPRO SEIGAL DBMS DPB 2
135
8 DOS GUIDE NORTON OS PHI
3 175
9 BASIC FOR BEGINNERS MORTON PROG BPB 3
40
10 MASTERING WINDOW COWART OS BPB 1
225

10 rows selected.

SQL> SELECT * FROM COMPBOOKS WHERE TYPE='PROG' AND PUB='BPB';

NO TITLE AUTHOR TYPE PUB


QTY PRICE
--------- -------------------- --------------- ------- ---------- -
-------- ---------
5 MASTERING C++ GUREWICH PROG BPB
3 295
9 BASIC FOR BEGINNERS MORTON PROG BPB
3 40

SQL> SELECT * FROM COMPBOOKS WHERE PRICE>130 ORDER BY QTY;

NO TITLE AUTHOR TYPE PUB


QTY PRICE
--------- -------------------- -------------- ------- ----------
--------- ---------
10 MASTERING WINDOW COWART OS BPB
1 225
7 MASTERING FOXPRO SEIGAL DBMS DPB
2 135
5 MASTERING C++ GUREWICH PROG BPB
3 295
6 GUIDE NETWORK FREED NET ZPRESS
3 200
8 DOS GUIDE NORTON OS PHI
3 175
1 DATA STRUCTURE LIPSCHUTZ DS MCGRAW 4
217
3 ADVANCED PASCAL SCHILDT PROG MCGRAW 4
350

7 rows selected.

130
SQL> SELECT TITLE FROM COMPBOOKS ORDER BY PRICE;

TITLE
--------------------
BASIC FOR BEGINNERS
COMPUTER STUDIES
DBASE DUMMIES
MASTERING FOXPRO
DOS GUIDE
GUIDE NETWORK
DATA STRUCTURE
MASTERING WINDOW
MASTERING C++
ADVANCED PASCAL

10 rows selected.

SQL> SELECT NO, QTY*PRICE "CURRENT VALUE" , QTY*PRICE*1.25


"MISPLACEMENT VALUE" FROM COMPBOOKS;

NO CURRENT VALUE MISPLACEMENT VALUE


--------- ---------------------------- -----------------------------------
1 868 1085
2 150 187.5
3 1400 1750
4 650 812.5
5 885 1106.25
6 600 750
7 270 337.5
8 525 656.25
9 120 150
10 225 281.25

10 rows selected.

SQL> SELECT COUNT(*) "BOOKS PUBLISHED BY PHI" FROM COMPBOOKS


WHERE PUB='PHI';

BOOKS PUBLISHED BY PHI


----------------------
1

SQL> INSERT INTO COMPBOOKS VALUES (13,'COMP SC C+


+','AKSHARMA','TEXT','BPB',3,185);

131
1 row created.

SQL> SELECT MIN(PRICE) FROM COMPBOOKS WHERE PRICE<150;

MIN(PRICE)
----------
40

SQL> SELECT AVG(PRICE)FROM COMPBOOKS WHERE QTY<3;

AVG(PRICE)
----------
155
SQL> SELECT COUNT(DISTINCT TYPE) FROM COMPBOOKS;

COUNT(DISTINCT TYPE)
-------------------
7

132
BIBLIOGRAPHY

 COMPUTER SCIENCE C++,


SUMITA ARRORA
 WORKING WITH C++
A.K. SHARMA

 Websites:
www.google.com
www.sourcecode.com

133

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy