NUISANCE
NUISANCE
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.
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:
6
Choose the operations to be done on both matrices:
1. Addition
2. Subtraction
3. Multiplication
Enter your choice(1, 2 or 3): 1
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:
1. Transpose
2. Row sum
3. Column sum
Enter your choice(1, 2 or 3): 1
1. Transpose
2. Row sum
3. Column sum
9
Enter your choice(1, 2 or 3): 2
Q.3
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 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:
13
2
3
Q.5
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:
15
Enter Array elements (in increasing order)
1
2
3
Q.6
16
}
index=Lsearch(AR, N, ITEM);
if(index!=-1)
AR[index]=0;
else
cout<<"Sorry!! No such element in the array.\n";
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:
17
Enter Array elements (in increasing order):
1
2
3
4
The array after shifting All emptied spaces towards right is....
1 2 3
Q.7
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 :
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();
}
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;
OUTPUT:
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
22
12347
Array after iteration - 9 is:
12347
Array after iteration - 10 is:
12347
Q.8
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 list 1 :1
2
3
4
Enter list 2 :1
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
25
if(large<A[i])
large=A[i];
}
cout<<"\nTHE LARGEST NO. IN THE ARRAY IS :- "<<large;
}
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:
MENU
MENU
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;
}
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 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 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
MENU
FUNCTION OVERLOADING
Q.1
#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
OUTPUT:
1
23
33
1
23
345
1
23
345
4567
Q.2
#include<iostream.h>
#include<conio.h> // for clrscr()
#include<math.h> // for sqrt()
#include<process.h> // for exit
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;
35
ar=area(s1,s2);
cout<<"\n The required area of the rectangle is "
<<ar<<" sq.units"<<"\n";
break;
}; // end of switch
getch();
} // main ends
OUTPUT:
Enter 3 sides:2
3
4
Want to continue(y/n)? : Y
36
Enter your choice(1-5):3
Want to continue(y/n)? : Y
Enter your choice(1-5):4
Want to continue(y/n)? : N
Q.3
#include<iostream.h>
#include<conio.h> // for clrscr()
#include<math.h> // for sqrt()
37
float volume(float a)
{ //function sphere
return (4/3)*3.14*a*a*a;
}
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;
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
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
getch();
}
OUTPUT:
Want to continue(y/n)? : Y
Enter your choice(1-3):2
Enter a radius :3
Want to continue(y/n)? : Y
40
Enter your choice(1-3):3
Want to continue(y/n)? : N
LINKED LISTS
Q.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:
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:
MENU
1) Add
2) Delete
3) Display
4) Quit
MENU
1) Add
2) Delete
3) Display
47
4) Quit
1) Add
2) Delete
3) Display
4) Quit
1) Add
2) Delete
3) Display
4) Quit
MENU
1) Add
2) Delete
3) Display
4) Quit
5432
MENU
1) Add
2) Delete
3) Display
4) Quit
48
Q.3
#include<iostream.h>
#include<conio.h> //FOR clrscr(),
getch()
#include<stdio.h>
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
Menu
1. Push
2. Pop
3. Display
4. Quit
Menu
1. Push
2. Pop
3. Display
4. Quit
51
Enter your choice :- 1
Menu
1. Push
2. Pop
3. Display
4. Quit
Menu
1. Push
2. Pop
3. Display
4. Quit
Menu
1. Push
2. Pop
3. Display
4. Quit
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
Menu
1. Push
2. Pop
3. Display
4. Quit
Q.4
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:
Q.5
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
Main Menu
1. Addition of Stack
2. Deletion from Stack
3. Traverse of Stack
4. Exit from Menu
58
Do you want to delete more element<Y/N>?Y
Main Menu
1. Addition of Stack
2. Deletion from Stack
3. Traverse of Stack
4. Exit from Menu
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;
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:
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;
}
}
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:
66
Enter the name..ramneek
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:
70
Enter the name..ram
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:
75
1
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:
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
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:
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
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:
87
4.modify data...
5.display the contents of the file ..
6.exit
1
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:
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
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:
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 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
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
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:
(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
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
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:
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:
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
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 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:
114
singh
INFORMATION OF 1 OVER
is the over maiden?????(y/n)
n
give over details
enter runs given and wicket taken
name
ram singh
total runs 20
total wickets 1
total maidens 110
Q.12
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:
117
SQL
Q1. Write SQL commands for (a) to (f) and Write the outputs for (g)on the basis of
table HOSPITAL.
TABLE: HOSPITAL
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
119
iv) Select SUM (charges) from HOSPITAL where date of adm<{12/08/98}
Ans : SUM(Charges)
3650
Q.2
Relation teacher
(b) To list the names of the female teachers who are in the Hindi Dept.
(c) To list all the teachers with their Date of joining in ascending order
Name.
Sandeep
120
Jugal
Shiv om
Shalakha
Rakesh
Sharmila
Shyam
Sangeeta
(d) To display student’s Name, Fee, Age for Male teachers only.
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.
(c) Display a list of all movies with the price over 20 and sorted by price.
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.
Q.4
Table created.
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;
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.
NAME
--------------------
DIVYA
MOHAN
KARAN
JOHN
RUBINA
VIKAS
6 rows selected.
127
10 rows selected.
10 rows selected.
SQL> SELECT COUNT(GRADE) FROM STUDENT1 WHERE GRADE='A';
COUNT(GRADE)
------------
4
1 row created.
128
11 rows selected.
MIN(AVGMARK)
------------
64
SUM(STIPEND)
------------
1600
AVG(STIPEND)
------------
466.66667
COUNT(DISTINCTNO)
-----------------
11
Q.5
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.
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.
10 rows selected.
131
1 row created.
MIN(PRICE)
----------
40
AVG(PRICE)
----------
155
SQL> SELECT COUNT(DISTINCT TYPE) FROM COMPBOOKS;
COUNT(DISTINCT TYPE)
-------------------
7
132
BIBLIOGRAPHY
Websites:
www.google.com
www.sourcecode.com
133