Professional Documents
Culture Documents
PROGRAM STATEMENT:
Write a program in C++ to perform the following operations on a two
dimensional array using functions
Minimum and maximum element of mth row.
Minimum and maximum element of nthcolumn.
Diagonal elements
Swapping two rows.
Swapping two columns.
ALGORITHM:
1. Take the array from the user and take max row and max col.
2. Take the values associated with the operations.
3. Perform the operation.
4. For minimum and maximum element parse through the whole column, row and
compare max and min element.
5. For swapping 2 rows/columns, use a temporary variable.
PROGRAM:
#include<iostream.h>
#include<conio.h>
void minmaxr(int a[10][10],int m,int q) //func to calculate min and max of a row
{
int j;
int max=a[m-1][0];
int min=a[m-1][0];
1
for(j=0;j<q;j++)
{
if(a[m-1][j]>max)
max=a[m-1][j];
if(a[m-1][j]<min)
min=a[m-1][j];
}
cout<<"\n\nThe maximum and minimum elements of the "<<m<<" th row
are ";
cout<<max<<" and "<<min;
}
void minmaxc(int a[10][10],int n,int p)//func to calculate min and max of a column
{
int i;
int max=a[0][n-1];
int min=a[0][n-1];
for(i=0;i<p;i++)
{
if(a[i][n-1]>max)
max=a[i][n-1];
if(a[i][n-1]<min)
min=a[i][n-1];
}
cout<<"\n\nThe maximum and minimum elements of the "<<n<<" th
column are ";
cout<<max<<" and "<<min;
}
void dgnl(int a[10][10],int n)
{
2
if(i==j)
cout<<a[i][j]<<endl;
}
cout<<"\n\nRight diagonal elements ";
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
if(i+j==n-1)
cout<<a[i][j]<<endl;
}
}
void swaprow(int a[10][10],int p,int q,int m)//func to swap 2 rows
{
int t;
for(int j=0;j<m;j++)
{
t=a[p-1][j];
a[p-1][j]=a[q-1][j];
a[q-1][j]=t;
}
}
void swapcol(int a[10][10],int p,int q,int n)//func to swap 2 cols
{
int t;
for(int i=0;i<n;i++)
{
t=a[i][p-1];
a[i][p-1]=a[i][q-1];
a[i][q-1]=t;
}
3
}
void display(int a[10][10],int m,int n)//func to display matrix
{
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
cout<<" "<<a[i][j];
cout<<endl;
}
}
int main()
{
int choice,n,m,p,q;
int a[10][10];
do
{
cout<<"\n\nMENU";
cout<<"\n\n1.Minimum and maximum in a row";
cout<<"\n\n2.Minimum and maximum in a column ";
cout<<"\n\n3.Diagonal elements ";
cout<<"\n\n4.Swap two rows";
cout<<"\n\n5.Swap two columns";
cout<<"\n\nEnter your choice ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"\n\nEnter the number of rows and columns of
matrix";
cin>>m>>n;
4
dgnl(a,n);
break;
case 4:
cout<<"\n\nEnter the number of rows and columns of
matrix";
cin>>m>>n;
cout<<"\n\nEnter which 2 rows you want to interchange
";
cin>>p>>q;
cout<<"\n\nEnter the array rowwise ";
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
swaprow(a,p,q,n);
cout<<"\n\nResulting matrix is ";
display(a,m,n);
break;
case 5:
cout<<"\n\nEnter the number of rows and columns of
matrix";
cin>>m>>n;
cout<<"\n\nEnter which 2 columns you want to
interchange ";
cin>>p>>q;
cout<<"\n\nEnter the array rowwise ";
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
swapcol(a,p,q,m);s
cout<<"\n\nResulting matrix is ";
6
display(a,m,n);
break;
case 6:return 0;
default:break;
}
}while(1);
getch();
return 0;
}
OUTPUT:
MENU
1.Minimum and maximum in a row
2.Minimum and maximum in a column
3.Diagonal elements
4.Swap two rows
5.Swap two columns
8
9
The maximum and minimum elements of the 3 th row are 9 and 7
MENU
1.Minimum and maximum in a row
2.Minimum and maximum in a column
3.Diagonal elements
4.Swap two rows
5.Swap two columns
MENU
1.Minimum and maximum in a row
2.Minimum and maximum in a column
8
3.Diagonal elements
4.Swap two rows
5.Swap two columns
3
5
MENU
1.Minimum and maximum in a row
2.Minimum and maximum in a column
3.Diagonal elements
9
MENU
1.Minimum and maximum in a row
2.Minimum and maximum in a column
3.Diagonal elements
4.Swap two rows
10
PROGRAM 2
PROGRAM STATEMENT:
11
ALGORTIHM:
1. Create 2 objects of the structure.
2. Use member functions to take in objects variables.
3. Calladds or subtracts function to display added or subtracted distances.
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<math.h>
struct DISTANCE
{
int m;
int cm;
void getdist()
12
}
void showdist()
{
}
}a,b,c;
DISTANCE add(DISTANCE a,DISTANCE b) //func to add two distances
{
DISTANCE c;
c.m=a.m+b.m;
c.cm=a.cm+b.cm;
if(c.cm>100)
{
c.cm-=100;
c.m++;
}
return c;
}
DISTANCE sub(DISTANCE a,DISTANCE b) // func to subtract 2 distances
{
int subm,subcm;
DISTANCE c;
if(a.m>b.m)
{
subm=a.m-b.m;
subcm=(a.cm-b.cm);
13
}
else
{
subm=b.m-a.m;
subcm=(b.cm-a.cm);
}
if(subcm<0)
{
subm--;
subcm+=100;
}
c.m=subm;
c.cm=subcm;
return c;
}
int main()
{
//main
int choice;
do
{
cout<<"\n\nMENU";
cout<<"\n\n1.Add two distances";
cout<<"\n\n2.Subtract two distances ";
cout<<"\n\n3.Exit";
cout<<"\n\nEnter your choice ";
cin>>choice;
switch(choice)
{
case 1:
a.getdist();
b.getdist();
14
c=add(a,b);
cout<<"\n\nAddition of two distance resulted in
"<<c.m<<" m ";
cout<<"and "<<c.cm<<" cm ";
break;
case 2:
a.getdist();
b.getdist();
c=sub(a,b);
cout<<"\n\nSubtraction of two distance resulted in
"<<c.m<<" m";
cout<<" and "<<c.cm<<" cm ";
break;
case 3:return 0;
default:break;
}
}while(1);
getch();
return 0;
}
OUTPUT:
MENU
1.Add two distances
2.Subtract two distances
3.Exit
MENU
1.Add two distances
2.Subtract two distances
3.Exit
MENU
1.Add two distances
2.Subtract two distances
3.Exit
16
MENU
1.Add two distances
2.Subtract two distances
3.Exit
Enter your choice 3
Process exited with return value 0
Press any key to continue . . .
PROGRAM 3
PROGRAM STATEMENT:
17
ALGORITHM:
Start.
Enter the choice.
If its circle, enter the radius.
Display the area of the circle.
If its rectangle, enter the length and breadth.
Display the area of the rectangle.
If its polygon, 1st enter the no. of sides and then enter the length of
each side(assuming it is a regular polygon).
Display the area of the polygon.
End.
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<math.h>
#define PI 3.14159265359
using namespace std;
void area(float r)
{
float area;
area=PI*r*r;
cout<<"\n\nThe area of the given circle = "<<area<<" Sq units ";
18
}
void area(float l,float b)
{
float area=l*b;
cout<<"\n\nThe area of the given rectangle = "<<area<<" Sq units
";
}
void area(int n,float s)
{
float area;
area=0.25*n*s*s*(1/tan(PI/n));
cout<<"\n\nThe area of the n-sided polygon = "<<area<<" Sq units
";
}
int main()
{
//main
int ch,n;
float r,l,b,s;
while(1)
{
19
cout<<endl;
cout<<"\n\nEnter the breadth = ";
cin>>b;
cout<<endl;
area(l,b);
break;
case 3:cout<<"\n\nNumber of sides = ";
cin>>n;
cout<<"\n\nLength of each side = ";
cin>>s;
area(n,s);
break;
case 4:cout<<"Your choice is to EXIT!!!";
return 0;
break;
}
}
getch();
return 0;
}
OUTPUT:
For case 1:
1. Area of a circle
2. Area of a rectangle
1. Area of a circle
2. Area of a rectangle
2. Area of a rectangle
1. Area of a circle
2. Area of a rectangle
2. Area of a rectangle
22
Number of sides = 9
1. Area of a circle
2. Area of a rectangle
Number of sides = 6
2. Area of a rectangle
4. Exit!!!
PROGRAM 4
PROGRAM STATEMENT:
Write a c++ program to define a class SUPPLY with following description:
Private Members:
Code of type integer
FoodName of type string
Sticker of type string
FoodType of type string
A member function GetType() to assign the following values for
FoodType as per the given Sticker:
24
Sticker
FoodType
GREEN
Vegetarian
YELLOW
Contains Egg
RED
Non-Vegetarian
Public Members:
A function FoodIn ( ) to allow user to enter values for
Code,FoodName,Sticker and call function GetType ( ) to assign respective
FoodType.
A function FoodOut ( ) to allow user to view the content of all the data
members.
ALGORITHM:
1.
2.
3.
4.
5.
6.
Start.
Enter the food code.
Enter the food name.
Enter the colour of the sticker.
Check the type of the food as per the given colour of the sticker.
Display all the required contents for the order.
PROGRAM:
#include<iostream.h>
#include<conio.h>
class SUPPLY
{
private:
int code;
char FoodName[50];
char Sticker[50];
char FoodType[50];
25
public:
void GetType()
colour of the sticker
{
if(!strcmpi(Sticker,"Green"))
strcpy(FoodType,"Vegeterian\n");
else if(!strcmpi(Sticker,"Yellow"))
strcpy(FoodType,"Contains Egg\n");
else
strcpy(FoodType,"Non Vegeterian\n");
}
void FoodIn()
{
cout<<"
"<<"\n\n";
cout<<"
|
***************FOOD*MENU***************|"<<"\n\n";
cout<<"
_-"<<"\n\n";
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
GetType();
}
void FoodOut()
contents
{
cout<<"*******YOUR ORDER:\n\n";
cout<<"CODE:"<<code<<"\n\n";
cout<<"FOOD NAME:"<<FoodName<<"\n\n";
cout<<"STICKER:"<<Sticker<<"\n\n";
cout<<"FOOD TYPE:"<<FoodType<<"\n\n";
}
};
int main()
{
int ch;
while(1)
{
cout<<"1. Food Menu\n";
//Menu
cout<<"2. Exit\n";
cout<<"Enter Your Choice: ";
cin>>ch;
switch(ch)
{
case 1: SUPPLY s;
class
s.GetType();
s.FoodIn();
s.FoodOut();
27
//Object of the
getch();
break;
case 2: cout<<"************Thank You For Coming To Our
Restaurant**********\n;
cout<<"*************************VISIT
AGAIN************************\n";
return 0;
}
}
getch();
return 0;
}
OUTPUT:
For Choice 1For food type(1):
1. Food Menu
2. Exit
Enter Your Choice: 1
WELCOME TO OUR RESTAURANT
|***************FOOD*MENU***************|
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
28
*******YOUR ORDER:
CODE:476
FOOD NAME:FriedRice
STICKER:Green
FOOD TYPE:Vegeterian
1. Food Menu
2. Exit
Enter Your Choice: 1
WELCOME TO OUR RESTAURANT
|***************FOOD*MENU***************|
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
29
*******YOUR ORDER:
CODE:781
FOOD NAME:ShahiPaneer
STICKER:Green
FOOD TYPE:Vegeterian
For choice 2For food type(2):
1. Food Menu
2. Exit
Enter Your Choice: 1
WELCOME TO OUR RESTAURANT
|***************FOOD*MENU***************|
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
*******YOUR ORDER:
CODE:344
FOOD NAME:EggNoodles
STICKER:Yellow
1. Food Menu
2. Exit
Enter Your Choice: 1
WELCOME TO OUR RESTAURANT
|***************FOOD*MENU***************|
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
31
*******YOUR ORDER:
CODE:566
FOOD NAME:EggPuff
STICKER:Yellow
|***************FOOD*MENU***************|
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
*******YOUR ORDER:
CODE:239
FOOD NAME:ChickenBiriyani
STICKER:Red
1. Food Menu
2. Exit
Enter Your Choice: 1
WELCOME TO OUR RESTAURANT
|***************FOOD*MENU***************|
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
*******YOUR ORDER:
CODE:991
FOOD NAME:TandooriChicken
STICKER:Red
34
PROGRAM 5
PROGRAM STATEMENT:
Write a program in C++ Write a class Hotel in c++ with following
description:
Private members:
Rno // Data member to store Room No
Name // Data member to store customer name
Tariff // Data member to store per day charges
Days //Number of days of stay
Calculate( ) // A function to calculate and return the amount
days*tariff. If the product is greater that 5000
then return 1.05*days*tariff
Public members:
Constructor to initialize the tariff and days to 0.
Checkin( ) // A function to enter Rno, Name, Tariff and days
Display( ) // A function to display Rno, Name, Tariff, days and total
amount as per the called Calculate() function
Destructor to display an appropriate message.
Instantiate the class and write the main function as needed.
1. Enter the room no., name of the customer and the no. of days he/she
will be staying.
2. Enter the tarrif per day.
OUTPUT:
1. Display the complete details of the customer and the total amount
he/she will be paying.
2. Also display the tarrif per day, and the no. of days.
ALGORITHM:
1.
2.
3.
4.
5.
6.
7.
8.
Start.
Enter the room no.
Enter the name of the customer.
Enter the no. of days of stay.
Enter the tarrif per day.
Calculate the total amount will be paid by the customer.
Display all the necessary details.
End.
PROGRAM:
#include<iostream.h>
#include<conio.h>
class HOTEL
{
int Rno;
char Name[50];
float Tariff;
int Days;
float Calculate()
// Function to calculate
discount
{
float amount;
amount=Days*Tariff;
cout<<"The Total Amount: "<<amount<<"\n";
if(amount>5000)
36
return 1.05*Days*Tariff;
}
public:
HOTEL()
// Default Constructor
{
Days=0;
Tariff=0;
}
void getCheckIn()
{
cout<<"Enter Room No: ";
cin>>Rno;
cout<<endl;
cout<<"Name: ";
cin>>Name;
cout<<endl;
cout<<"Enter the Tariff: ";
cin>>Tariff;
cout<<endl;
cout<<"Enter the no. of Days: ";
cin>>Days;
cout<<endl;
}
void Display()
{
cout<<"Room No: "<<Rno<<"\n";
cout<<"Name: "<<Name<<"\n";
37
// Destructor
{
cout<<"THE SCOPE OF THE OBJECT GETS
OVER!!!"<<endl;
}
};
int main()
{
HOTEL H;
int ch;
char ch1;
while(1)
{
cout<<"1. Accomodation Details\n\n";
cout<<"2. Exit!\n\n";
cout<<"Enter Your Choice: ";
cin>>ch;
cout<<endl;
switch(ch)
{
case 1: H.getCheckIn();
H.Display();
getch();
38
// Menu
break;
case 2: return 0;
}
}
getch();
return 0;
}
// End of Main
OUTPUT:
For case 1:
1. Accomodation Details
2. Exit!
Name: RaviKumar
1. Accomodation Details
2. Exit!
Name: ManojTiwary
1. Accomodation Details
2. Exit!
40
Name: BarackObama
Room No: 45
Name: BarackObama
Tariff per Day: 5000
No. of Days: 90
The Total Amount: 450000
For case 2:
1. Accomodation Details
2. Exit!
PROGRAM 6
PROGRAM STATEMENT:
Write a program in C++ to implement the following inheritance
class Book
{
char Title[20];
char Author[20];
int noofpages;
public:
void read();
void show();
};
class TextBook: private Book
{ int noofchap, noofassignments;
protected:
int standard;
public:
void readtextbook();
void showtextbook();
};
Implement all the functions.
OUTPUT:
1. Display the book details.
ALGORITHM:
1.
2.
3.
4.
5.
6.
Start.
Enter the title.
Enter the author.
Enter the no. of pages.
Display the book details from the inherited class.
End.
PROGRAM:
#include<iostream.h>
#include<conio.h>
class Book
{
char Title[20];
char Author[20];
int noofpages;
public:
void read()
{
cout<<"Enter the Title: \n\n";
cin>>Title;
cout<<"\n\n";
cout<<"Enter the name of the Author: \n\n ";
cin>>Author;
cout<<"\n\n";
cout<<"Enter the no. of pages: \n\n";
cin>>noofpages;
cout<<"\n\n";
43
}
void show()
{
cout<<"BOOK DETAILS:- \n\n";
cout<<"TITLE- "<<Title<<"\n\n";
cout<<"AUTHOR- "<<Author<<"\n\n";
cout<<"PAGES- "<<noofpages<<"\n\n";
}
};
class TextBook: private Book
{
int noofchap, noofassignments;
protected:
int standard;
public:
void readtextbook()
{
read();
//Function call 1
}
void showtextbook()
{
show();
}
};
int main()
{
int ch;
44
//Function call 2
TextBook b;
while(1)
{
cout<<"1. Book Details "<<endl;
cout<<"2. Exit "<<endl;
cout<<"Enter Your Choice: ";
cin>>ch;
cout<<"\n\n";
switch(ch)
{
case 1:b.readtextbook();
b.showtextbook();
break;
case 2:cout<<"Your Choice Is To Exit!!!";
return 0;
}
}
getch();
return 0;
}
OUTPUT:
For the case 1:
1. Book Details
2. Exit
Enter Your Choice: 1
TheInvisibleMan
H.GWells
255
BOOK DETAILS:-
TITLE- TheInvisibleMan
AUTHOR- H.GWells
PAGES- 255
1. Book Details
2. Exit
Enter Your Choice: 1
TheCantervilleGhost
46
OscarWilde
488
BOOK DETAILS:-
TITLE- TheCantervilleGhost
AUTHOR- OscarWilde
PAGES- 488
For case 2:
1. Book Details
2. Exit
Enter Your Choice: 2
47
PROGRAM 7
PROGRAM STATEMENT:
Write a program in C++ to create a text file and perform the
following operations:
PROGRAM:
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<fstream.h>
#include<ctype.h>
#include<string.h>
void create()
{
ofstream fout;
fout.open("abc.txt",ios::out);
char ch[100]="Time is @ great teacher but unfortunately kills all its
pupils 8 a time;
fout<<ch;
fout.close();
}
void Display()
{
ifstream fin;
char ch[80];
fin.open("abc.txt");
49
while(!fin.eof())
{
fin.getline(ch,80);
cout<<ch;
}
}
void countsp()
{
int count=0;
ifstream fin;
char ch[80];
fin.open("abc.txt");
while(!fin.eof())
{
fin>>ch;
count++;
}
cout<<"\nThe number of spaces are "<<count-1;
}
void countvc()
{
int count=0,sum=0;
ifstream fin;
char ch;
fin.open("abc.txt");
while(!fin.eof())
{
50
fin>>ch;
if(isalpha(ch))
{
ch=tolower(ch);
if((ch=='a')||(ch=='e')||(ch=='i')||(ch=='o')||(ch=='u'))
count++;
else
sum++;
}
}
cout<<"\nThe number of vowels are "<<count;
cout<<"\nThe number of consonants are "<<sum;
}
void countul()
lowercase characters
{
int count=0,sum=0;
ifstream fin;
char ch;
fin.open("abc.txt");
while(!fin.eof())
{
fin>>ch;
if(isupper(ch))
count++;
else
if(islower(ch))
51
sum++;
}
cout<<"\nThe number of upper case characters are "<<count;
cout<<"\nThe number of lower case characters are "<<sum;
}
void countdalp()
characters
{
int count=0,sum=0;
ifstream fin;
char ch;
fin.open("abc.txt");
while(!fin.eof())
{
fin>>ch;
if(isdigit(ch))
count++;
else
if(!isalnum(ch))
sum++;
}
cout<<"\nThe number of digits are "<<count;
cout<<"\nThe number of special characters are "<<sum;
}
int main()
{
ifstream fin;
52
ofstream fout;
char t;
int ch;
while(1)
//Menu
{
cout<<"\n\n1.CREATE A TEXT FILE";
cout<<"\n\n2.DISPLAY THE FILE";
cout<<"\n\n3.COUNT NUMBER OF SPACES";
cout<<"\n\n4.COUNT NUMBER OF VOWELS AND CONSONANTS";
cout<<"\n\n5.COUNT NUMBER OF UPPER CASE AND LOWER
CASE CHARACTERS";
cout<<"\n\n6.COUNT NUMBER OF DIGITS AND SPECIAL
CHARACTERS";
cout<<"\n\n7.GOOD BYE";
cout<<"\n\n\nENTER YOUR CHOICE :-";
cin>>ch;
switch(ch)
{
case 1:create();
//Function call 1
case 2:Display();break;
//Function call 2
case 3:countsp();break;
//Function call 3
case 4:countvc();break;
//Function call 4
case 5:countul();break;
case 6:countdalp();break;
//Function call 5
//Function call 6
else
break;
default:cout<<"\nWRONG CHOICE"<<endl;
}
}
getch();
return 0;
}
OUTPUT:
For case 1: Creating the file and displaying it
7.GOOD BYE
7.GOOD BYE
7.GOOD BYE
7.GOOD BYE
7.GOOD BYE
57
7.GOOD BYE
7.GOOD BYE
58
PROGRAM 8
PROGRAM STATEMENT:
59
{
ifstream fin;
ofstream fout;
fout.open("My Text.txt");
char ch[300]="The Journey Of A Thousand Miles Begins With One
Step!!!";
fout<<ch;
cout<<"\n\nFile Created\n\n";
fout.close();
getch();
60
}
void copy()
{
ifstream fin;
ofstream fout;
char ch;
fin.open("My Text.txt");
fout.open("Duplicate.txt");
while(!fin.eof())
{
fin>>ch;
fout<<ch;
}
fin.close();
fout.close();
getch();
}
void display()
file
{
ifstream fin;
char ch;
fin.open("Duplicate.txt");
cout<<"\n\nThe Copied File Is"<<endl;
while(!fin.eof())
{
fin>>ch;
61
cout<<ch;
}
fin.close();
}
int main()
{
int ch;
char t;
while(1)
{
cout<<"\n\n1. CREATE THE FILE";
cout<<"\n\n2. COPY THE FILE";
cout<<"\n\n3. EXIT";
cout<<"\n\nENTER YOUR CHOICE: ";
cin>>ch;
switch(ch)
{
case 1: create();
//Function call 1
break;
case 2: copy();
display();
//Function call 2
//Function call 3
break;
case 3: cout<<"\n\nAre you sure you want exit?? (Y/N)";
cin>>t;
if(t=='Y')
return 0;
else
62
break;
default:cout<<"\n\nWRONG CHOICE\n\n";
break;
}
}
getch();
return 0;
}
OUTPUT:
For case 1:
3. EXIT
File Created
For case 2:
3. EXIT
63
3. EXIT
3. EXIT
64
File Created
For case 2:
3. EXIT
3. EXIT
65
WRONG CHOICE
For case 3:
3. EXIT
PROGRAM 9
PROGRAM STATEMENT:
Write a program in C++ to create a binary file with the information
of the students and display the report card.
The structure STUDENT must have following information
1. Admission number
2. Name of the student
66
{
cout<<"\n\nEnter the Name: ";
cin>>name;
cout<<"\n\nEnter the admission no :";
cin>>admno;
cout<<"\n\nEnter the class: ";
cin>>Class;
cout<<"\n\nEnter the section: ";
cin>>Section;
cout<<"\n\nEnter the marks in Physics =";
cin>>phy;
cout<<"\n\nEnter the marks in Chemistry =";
cin>>chem;
cout<<"\n\nEnter the marks in Maths =";
cin>>maths;
cout<<"\n\nEnter the marks in English =";
cin>>eng;
cout<<"\n\nEnter the marks in Computer Science =";
cin>>cs;
}
void Student::showdata()
68
{
float Per;
cout<<"\n\n REPORT CARD \n\n\";
cout<<"\n\nNAME: "<<name<<endl;
cout<<"\n\nADMISSION NO: "<<admno<<endl;
cout<<"\n\nCLASS: "<<Class<<endl;
cout<<"\n\nSECTION: "<<Section<<endl;
cout<<"\n\n PHYSICS: "<<phy<<endl;
cout<<"\n\n CHEMISTRY: "<<chem<<endl;
cout<<"\n\n MATHS: "<<maths<<endl;
cout<<"\n\n ENGILSH: "<<eng<<endl;
cout<<"\n\n COMPUTER SCIENCE: "<<cs<<endl;
Per=(phy+chem+maths+eng+cs)/5;
cout<<"\n\nPERCENTAGE ="<<Per<<"%";
if(Per>=33)
cout<<"\n\nPASSED\n\n";
else
cout<<"\n\nDETAINED\n\n";
}
void ip()
{
ofstream fout;
Student S;
fout.open("Stud Record.dat",ios::binary|ios::app);
S.getdata();
fout.write((char*)&S,sizeof(S));
fout.close();
69
getch();
}
void op()
{
ifstream fin;
Student S;
fin.open("Stud Record.dat",ios::binary|ios::app);
while(!fin.eof())
{
fin.read((char*)&S,sizeof(S));
S.showdata();
}
}
int main()
{
int ch;
char t;
while(1)
{
cout<<"\n\n1. Enter the Students Data"<<endl;
cout<<"\n\n2. Show the Students Data"<<endl;
cout<<"\n\n3. Exit"<<endl;
cout<<"\n\n4. ENTER YOUR CHOICE: ";
cin>>ch;
switch(ch)
{
case 1:ip();break;
70
case 2:op();break;
case 3:cout<<"\n\nAre you sure you want to exit?? (Y/N)";
cin>>t;
if(t=='Y')
return 0;
else
break;
default:cout<<"\n\nWRONG CHOICE!!\n\n";
break;
}
}
getch();
return 0;
}
OUTPUT:
For case 1:
1. Enter the Students Data
3. Exit
3. Exit
72
3. Exit
REPORT CARD
NAME: Vaibhav
73
CLASS: XII
SECTION: A
PHYSICS: 87
CHEMISTRY: 94
MATHS: 95
ENGILSH: 92
COMPUTER SCIENCE: 84
PERCENTAGE =90%
PASSED
For same case:
REPORT CARD
NAME: Ajay
CLASS: XII
SECTION: B
74
PHYSICS: 23
CHEMISTRY: 21
MATHS: 9
ENGILSH: 18
COMPUTER SCIENCE: 45
PERCENTAGE =23%
DETAINED
For invalid choice:
1. Enter the Students Data
3. Exit
WRONG CHOICE!!
For case 3:
3. Exit
PROGRAM 10
PROGRAM STATEMENT:
Write a program in C++ to create a binary file containing details of
the book as given
The structure BOOK must have following information
-> Accession number
-> Title of the book
-> Author
-> Price
Perform the following operation on the file
-> Search based on Accession number, title and author
->Insert a new book in a sorted file
-> Delete a book
-> Modify the information about the book
EXPECTED INPUT AND OUTPUT:
Input:
1. Enter the accession number.
2. Enter the title of the book.
3. Enter the author's name.
4. Enter the cost of the book.
76
Output:
1. In searching, enter the required accession no. to search the book and
display it.
2. In modifying, enter the required accession number and change the data
and display it.
ALGORITHM:
1. Start.
2. Enter the accession number.
3. Enter the title.
4. Enter the author's name.
5. Enter the cost.
6. For case 1, enter the required accession no. and search the book and
display it.
7. For case 3, enter the accession no. of which you want to delete the data
and delete the data.
8. For case 4, enter the accession no. and update the data of the book.
9. End.
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
struct BOOK
{
int accno;
char Title[30];
char Author[20];
float Price;
};
77
//Structure of BOOK
void insert()
to the file
{
int flag=0;
ifstream fin;
ofstream fout;
BOOK B1,B2;
fin.open("Book.dat",ios::binary);
fout.open("Temp.dat",ios::binary);
cout<<"\n\nEnter Accession No: ";
cin>>B1.accno;
cout<<"\n\nEnter Title: ";
cin>>B1.Title;
cout<<"\n\nEnter Cost:Rs. ";
cin>>B1.Price;
cout<<"\n\nEnter the Author's Name: ";
cin>>B1.Author;
while(fin.read((char*)&B2,sizeof(B2)))
{
if(B2.accno<B1.accno)
fout.write((char*)&B2,sizeof(B2));
else
{
flag=1;
break;
}
}
78
if(flag==1)
{
fout.write((char*)&B1,sizeof(B1));
fout.write((char*)&B2,sizeof(B2));
while(fin.read((char*)&B2,sizeof(B2)))
fout.write((char*)&B2,sizeof(B2));
}
else
fout.write((char*)&B1,sizeof(B1));
fin.close();
fout.close();
remove("Book.dat");
rename("Temp.dat","Book.dat");
}
void search()
{
int flag=0;
BOOK B;
int n;
cout<<"\n\nEnter the new accession no- ";
cin>>n;
ifstream fin;
fin.open("Book.dat",ios::binary);
while(fin.read((char*)&B,sizeof(B)))
{
if(B.accno==n)
{
79
flag=1;
break;
}
}
if(flag==1)
{
cout<<"\n\nBook Found!!";
cout<<"\n\nBook Details:- ";
cout<<"\n\nAccession No: ";
cout<<B.accno;
cout<<"\n\nTitle: ";
cout<<B.Title;
cout<<"\n\nAuthor: ";
cout<<B.Author;
cout<<"\n\nPrice: ";
cout<<B.Price;
}
else
{
cout<<"\n\nNOT FOUND!!";
}
fin.close();
getch();
}
void del()
BOOK
{
80
int n;
cout<<"\n\nEnter the new accession no- ";
cin>>n;
BOOK B;
ifstream fin;
ofstream fout;
fin.open("Book.dat",ios::binary);
fout.open("Temp.dat",ios::binary|ios::out);
while(fin.read((char*)&B,sizeof(B)))
{
if(B.accno!=n)
fout.write((char*)&B,sizeof(B));
}
fin.close();
fout.close();
remove("Book.dat");
rename("Temp.dat","Book.dat");
}
void modify()
file
{
int n;
cout<<"\n\nEnter the new accession no- ";
cin>>n;
BOOK B;
ifstream fin;
ofstream fout;
81
fin.open("Book.dat",ios::binary);
fout.open("Temp.dat",ios::binary|ios::out);
int pos=fin.tellg();
while(fin.read((char*)&B,sizeof(B)))
{
if(B.accno==n)
fin.seekg(-1*sizeof(B),ios::cur);
cout<<"\n\nEnter Title: ";
cin>>B.Title;
cout<<"\n\nEnter Author: ";
cin>>B.Author;
cout<<"\n\nEnter The Cost:Rs ";
cin>>B.Price;
fout.write((char*)&B,sizeof(B));
break;
}
fin.close();
fout.close();
}
int main()
{
int ch;
char t;
while(1)
//Menu
{
cout<<"\n\nOPERATIONS ON BINARY FILES\n\n";
cout<<"\n\n1. INSERTING";
82
cout<<"\n\n2. SEARCHING";
cout<<"\n\n3. DELETING";
cout<<"\n\n4. MODIFYING";
cout<<"\n\n5. EXIT!!";
cout<<"\n\nENTER YOUR CHOICE: ";
cin>>ch;
switch(ch)
{
case 1: insert();
//Function call 1
break;
case 2: search();
//Function call 2
break;
case 3: del();
//Function call 3
break;
case 4: modify();
//Function call 4
break;
case 5: cout<<"\n\nAre you sure you want exit?? (Y/N)";
cin>>t;
if(t=='Y')
return 0;
else
break;
default:cout<<"\n\nWRONG CHOICE\n\n";
break;
}
}
getch();
83
return 0;
} //end of main
OUTPUT:
For case 1:
1. INSERTING
2. SEARCHING
3. DELETING
4. MODIFYING
5. EXIT!!
1. INSERTING
2. SEARCHING
3. DELETING
4. MODIFYING
5. EXIT!!
For case 2:
OPERATIONS ON BINARY FILES
1. INSERTING
85
2. SEARCHING
3. DELETING
4. MODIFYING
5. EXIT!!
Book Found!!
Book Details:-
Title: TogetherWithPhysics
Author: N.S.Bhandari
Price: 220
For same case:
OPERATIONS ON BINARY FILES
86
1. INSERTING
2. SEARCHING
3. DELETING
4. MODIFYING
5. EXIT!!
Book Found!!
Book Details:-
Title: AllinOneComputerScience
Author: MiniGoyalandHarshitGarg
Price: 294.003
For same case:
87
1. INSERTING
2. SEARCHING
3. DELETING
4. MODIFYING
5. EXIT!!
NOT FOUND!!
For case 4:
OPERATIONS ON BINARY FILES
1. INSERTING
2. SEARCHING
3. DELETING
88
4. MODIFYING
5. EXIT!!
1. INSERTING
2. SEARCHING
3. DELETING
4. MODIFYING
5. EXIT!!
1. INSERTING
2. SEARCHING
3. DELETING
4. MODIFYING
5. EXIT!!
90
PROGRAM 11
PROGRAM STATEMENT:
Write a program in C++ to create a binary file using following class
and copy it to another based on users choice.
The class BOOK must have following information
Private members
1. Accession number
2. Title of the book
3. Author
4. Type
5. Price
Public members
1. Getbook to take the values of data members from the user
2. Showbook to display the values of data members.
Categorize the books into different files based on their price.
EXPECTED INPUT AND OUTPUT:
Input:
1. Enter the details of the required book.
Output:
1. Display the details of the book categorised by their price.
ALGORITHM:
1. Start.
2. Enter the details of the book.
3. Categorise the book based on their price.
4. Display the book categorised by their price.
91
5. End.
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class BOOK
{
long accno;
char title[30];
char author[30];
int price;
char type[30];
public:
void Getbook()
//input function
{
cout<<"\n\nEnter Accession No: ";
cin>>accno;
cout<<"\n\nEnter the title: " ;
cin>>title;
cout<<"\n\nName of the Author: ";
cin>>author;
cout<<"\n\nEnter the Cost: Rs.";
cin>>price;
cout<<"\n\nEnter the type of the book: ";
cin>>type;
check();
92
}
void check()
//categorising function
{
if(price<1000)
book1()
else if(price<300)
book2();
else
book3();
}
void book1()
//display function
{
ofstream fout;
fout.open("BOOK1.dat",ios::binary|ios::out);
BOOK B;
fout.write((char*)&B,sizeof(B));
}
void book2()
{
ofstream fout;
fout.open("BOOK2.dat",ios::binary|ios::out);
BOOK B;
fout.write((char*)&B,sizeof(B));
}
void book3()
{
93
ofstream fout;
fout.open("BOOK3.dat",ios::binary|ios::out);
BOOK B;
fout.write((char*)&B,sizeof(B));
}
void Showbook()
{
cout<<"\n\nACCESSION NO: ";
cout<<accno;
cout<<"\n\nTITLE OF THE BOOK: ";
cout<<title;
cout<<"\n\nNAME OF AUTHOR: ";
cout<<author;
cout<<"\n\nPRICE: Rs.";
cout<<price;
cout<<"\n\nTYPE OF BOOK : ";
cout<<type;
}
};
int main()
//main function
{
BOOK obj;
int ch;
char t;
while(1)
//menu
{
cout<<"\n\n1.CREATE";
94
cout<<"\n\n2.DISPLAY";
cout<<"\n\n3.EXIT";
cout<<"\n\nENTER YOUR CHOICE: ";
cin>>ch;
switch(ch)
{
case 1: obj.Getbook();
//func call 1
break;
case 2: obj.Showbook();
//func call 2
break;
case 3: cout<<"\n\nARE YOU SURE YOU WANT TO EXIT!!!
(Y/N)";
cin>>t;
if(t=='Y')
return 0;
else
break;
default:cout<<"\n\nWRONG CHOICE!!!";
break;
}
}
getch();
return 0;
}
//end of main
OUTPUT:
For choice 1:
95
1.CREATE
2.DISPLAY
3.EXIT
For choice 2:
1.CREATE
2.DISPLAY
3.EXIT
PRICE: Rs.5000
For choice 3:
1.CREATE
2.DISPLAY
3.EXIT
97
PROGRAM 12
PROGRAM STATEMENT:
Write a program in C++ to perform the following searches on a one
dimensional array.
Insertion
Selection
98
int min,t;
for(int i=0;i<size;i++)
{
min=i;
for(int j=i;j<size;j++)
if(a[j]<a[min])
{
t=a[j];
a[j]=a[min];
a[min]=t;
}
a[i]=a[min];
99
}
cout<<"\n\nSorted array is ";
for(int i=0;i<size;i++)
cout<<a[i]<<" ";
}
void isort(int a[],int size)
{
int temp;
int j;
for(int i=1;i<size;i++)
{temp = a[i];
for(j=i;j>0&&a[j-1]>temp;j--)
{
a[j] = a[j-1];
}
a[j] = temp;
}
cout<<"\n\nSorted array is ";
for(int i=0;i<size;i++)
cout<<a[i]<<" ";
}
int main()
{
int ch,n,i,a[100];
char t;
while(1)
{
100
cout<<"\n\nSORTING ARRAYS:";
cout<<"\n\n1. SELECTION SORT";
cout<<"\n\n2. INSERTION SORT";
cout<<"\n\n3. EXIT!!";
cout<<"\n\nENTER YOUR CHOICE: ";
cin>>ch;
switch(ch)
{
case 1: cout<<"\n\nEnter the size of the array: ";
cin>>n;
cout<<"\n\nEnter the array:-";
for(i=0;i<n;i++)
cin>>a[i];
ssort(a,n);
//Function call 1
break;
case 2: cout<<"\n\nEnter the size of the array: ";
cin>>n;
cout<<"\n\nEnter the array:- ";
for(i=0;i<n;i++)
cin>>a[i];
isort(a,n);
//Function call 2
break;
case 3: cout<<"\n\nAre you sure you want to exit??
(Y/N)";
cin>>t;
if(t=='Y')
return 0;
101
else
break;
default:cout<<"\n\nWRONG CHOICE!!";
break;
}
}
getch();
return 0;
} //End of main
OUTPUT:
For case 1:
SORTING ARRAYS:
1. SELECTION SORT
2. INSERTION SORT
3. EXIT!!
234
9763
1. SELECTION SORT
2. INSERTION SORT
3. EXIT!!
1. SELECTION SORT
2. INSERTION SORT
3. EXIT!!
1. SELECTION SORT
2. INSERTION SORT
104
3. EXIT!!
SORTING ARRAYS:
For case 3:
1. SELECTION SORT
2. INSERTION SORT
3. EXIT!!
105
PROGRAM 13
PROGRAM STATEMENT:
Write a program in C++ to perform the linear and binary search on
a one dimensional array.
EXPECTED INPUT AND OUTPUT:
Input:
1. Enter the no. of elements in the array.
2. Enter the array.
3. Enter the element to be searched.
Output:
1. The required element will be shown as FOUND else it will show NOT
FOUND.
106
ALGORITHM:
1. Start.
2. Enter the no. of elements.
3. Enter the array.
4. Enter the element is to be searched.
5. After that it will show element which is to be searched else it will not
show the element.
6. End.
PROGRAM:
#include<iostream.h>
#include<conio.h>
void lsearch(int a[100],int n)
{
int s,i,flag=0;
cout<<"\n\nEnter The Element: ";
cin>>s;
for(i=0;i<n;i++)
{
if(a[i]==s)
{
flag=1;
break;
}
}
if(flag==1)
{
cout<<"\n\nFOUND!!!";
107
{
int beg,mid,end,flag=0,s;
cout<<"\n\nEnter the element to be searched- ";
cin>>s;
beg=0;
end=n-1;
mid=(beg+end)/2;
while(beg<=end)
{
if(s==a[mid])
{
flag=1;
break;
}
if(s<a[mid])
end=mid-1;
else
beg=mid+1;
108
mid=(beg+end)/2;
}
if(flag==0)
cout<<"\n\nNOT FOUND";
else
{
cout<<"\n\nFOUND AND POSITION IS "<<mid<<\n\n;
cout<<"Element is= "<<s;
}
}
int main()
//main
{
int ch,n,a[100],s,i;
char t;
while(1)
//menu
{
cout<<"\n\nSEARCHING IN ARRAYS\n\n";
cout<<"\n\n1. LINEAR SEARCH";
cout<<"\n\n2. BINARY SEARCH";
cout<<"\n\n3. EXIT";
cout<<"\n\nENTER YOUR CHOICE: ";
cin>>ch;
switch(ch)
{
case 1: cout<<"\n\nNo of elements= ";
cin>>n;
cout<<"\n\nEnter the array: ";
109
for(i=0;i<n;i++)
cin>>a[i];
lsearch(a,n);
break;
case 2: cout<<"\n\nNo of elements= ";
cin>>n;
cout<<"\n\nEnter the array: ";
for(i=0;i<n;i++)
cin>>a[i];
bsearch(a,n);
search
break;
case 3: cout<<"\n\nAre you sure you want exit?? (Y/N)";
cin>>t;
if(t=='Y')
return 0;
else
break;
default:cout<<"\n\nWRONG CHOICE\n\n";
break;
}
}
getch();
return 0;
} //end of main
OUTPUT:
For choice 1:
110
SEARCHING IN ARRAYS
1. LINEAR SEARCH
2. BINARY SEARCH
3. EXIT
No of elements= 5
FOUND!!!
SEARCHING IN ARRAYS
111
1. LINEAR SEARCH
2. BINARY SEARCH
3. EXIT
No of elements= 4
NOT FOUND!!!
For choice 2:
SEARCHING IN ARRAYS
1. LINEAR SEARCH
2. BINARY SEARCH
112
3. EXIT
No of elements= 5
SEARCHING IN ARRAYS
1. LINEAR SEARCH
2. BINARY SEARCH
3. EXIT
113
No of elements= 4
NOT FOUND
For choice 3:
SEARCHING IN ARRAYS
1. LINEAR SEARCH
2. BINARY SEARCH
3. EXIT
PROGRAM 14
PROGRAM STATEMENT:
Write a program in C++ to add and subtract two time intervals
using pointers to class.
EXPECTED INPUT AND OUTPUT:
Input:
1. Enter the hours, minutes and seconds of the required time.
Output:
1. The sum and difference of the time and the final time will be shown.
ALGORITHM:
1. Start.
2. Enter your choice.
3. Enter the choice and store it in ch.
4. If choice is 1, go to step 4, if choice is 2, go to step 8, if choice is 3, go to
step 9.
5. Input Time1 and Time 2.
6. Calculate the sum
7. Print sum
115
8. Go to step 2
9. Input Time1 and Time
10. Calculate the difference
11. Print difference
12. Go to step 2
13. End.
PROGRAM:
#include<iostream.h>
#include<conio.h>
class TIME
{
int hr,min,sec;
public:
TIME()
//default constructor
{
hr=0;
min=0;
sec=0;
}
int hour()
{
return hr;
}
void geth()
{
cin>>hr;
}
116
//hour function
int minutes()
//minutes function
{
return min;
}
void getm()
{
cin>>min;
}
void gets()
//seconds function
{
cin>>sec;
}
int seconds()
{
return sec;
}
void assign(int x,int y,int z)
//assigning function
{
hr=x;
min=y;
sec=z;
}
void display()
//displaying function
{
cout << "\n\n\t Hours :\t " << hr;
cout << "\n\t Minutes :\t " << min;
cout << "\n\t Seconds :\t " << sec;
117
}
};
int main()
//main
{
TIME *a,*b,*c;
int ch,p,q,r;
long t1,t2,sum,sub;
char t;
ch=0;
a = new TIME;
b = new TIME;
c = new TIME;
while(1)
//menu
{
cout<<"\n\nMENU ";
cout<<"\n\n1. Add two time intervals ";
cout<<"\n\n2. Subtract two time intervals ";
cout<<"\n\n3. Exit!";
cout<<"\n\n Enter your Choice: ";
cin >> ch;
if((ch==1)||(ch==2))
{
cout << "\n\n Time 1:- ";
cout << "\n\n Hours : " ;
a->geth();
118
sum%=60;
r = sum;
c->assign(p,q,r);
}
else if(ch==2)
{
p = sub/3600;
sub-=p;
q = sub/60 ;
sub%=60;
r = sub;
c->assign(p,q,r);
}
cout << "\n\n\t THE FINAL RESULT IS : " ;
c->display();
}
else if(ch==3)
{
cout<<"\n\nARE YOU SURE YOU WANT TO EXIT!!! (Y/N)";
cin>>t;
if(t=='Y')
return 0;
else
break;
}
}
getch();
120
return 0;
} //end of main
OUTPUT:
For choice 1: (Sum)
MENU
3. Exit!
Time 1:-
Hours : 4
Minutes : 19
Seconds : 359
Time 2 :-
Hours : 12
Minutes : 657
121
Seconds : 2316
Sum is : 100835
Difference is : 69037
Hours :
28
Minutes :
Seconds :
35
3. Exit!
Time 1:-
122
Hours : 4
Minutes : 0
Seconds : 5
Time 2 :-
Hours : 8
Minutes : 10
Seconds : 0
Sum is : 43805
Difference is : 14995
Hours :
Minutes :
249
Seconds :
51
For choice 3:
MENU
123
3. Exit!
124
PROGRAM 15
PROGRAM STATEMENT:
Write a program in C++ to implement stack of structure ITEM
using array.
The structure ITEM should have Itemno of type integer
Itemname of type string
Price of type float
EXPECTED INPUT AND OUTPUT:
Input:
1. Enter the Item no.
2. Enter the Item name.
3. Enter the price.
Output:
1. Display the stack containing Item no, Item name, Price.
ALGORITHM:
1. Start.
2. Enter the Item no.
3. Enter the Item name.
4. Enter the price.
5. Either delete or display the data based on the choice.
6. End.
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<string.h>
125
#define n 5
using namespace std;
struct ITEM
{
int Itemno;
char Itemname[20];
float Price;
}I[100];
ITEM st[n];
int top=-1;
void push()
{ char iname[30];
int ino;
float cost;
cout<<"\n\nEnter Item Name- ";
cin>>iname;
cout<<"\n\nEnter Item No- ";
cin>>ino;
cout<<"\n\nEnter Price- Rs. ";
cin>>cost;
if(top<n-1)
{
top++;
strcpy(st[top].Itemname,iname);
st[top].Itemno=ino;;
st[top].Price=cost;;
126
}
else
cout<<"\n\nSTACK OVERFLOW\n\n";
}
void pop()
{
if(top==-1)
cout<<"\n\nSTACK UNDERFLOW\n\n";
else
{
cout<<"\n\nITEM NAME: ";
cout<<st[top].Itemname;
cout<<"\n\nITEM NO: ";
cout<<st[top].Itemno;
cout<<"\n\nCOST: Rs. ";
cout<<st[top].Price;
top--;
cout<<"\n\nDELETED ";
}
}
void display()
{
int i=0;
if(top==-1)
cout<<"\n\nSTACK UNDERFLOW\n\n";
else
{
127
for(i=0;i<=top;i++)
{
cout<<"\n\nITEM NAME: ";
cout<<st[i].Itemname;
cout<<"\n\nITEM NO: ";
cout<<st[i].Itemno;
cout<<"\n\nCOST: Rs. ";
cout<<st[i].Price;
}
}
}
int main()
//main
{
int ch;
char t;
while(1)
//menu
{
cout<<"\n\nIMPLEMENTATION OF STACK USING ARRAYS\n\n";
cout<<"\n\n1. PUSH";
cout<<"\n\n2. DISPLAY";
cout<<"\n\n3. POP";
cout<<"\n\n4. EXIT";
cout<<"\n\nENTER YOUR CHOICE: ";
cin>>ch;
switch(ch)
{
128
case 1: push();
stack
break;
case 2: display();
data
break;
case 3: pop();
stack
break;
case 4: cout<<"\n\nAre you sure you want exit?? (Y/N)";
cin>>t;
if(t=='Y')
return 0;
else
break;
default:cout<<"\n\nWRONG CHOICE\n\n";
break;
}
}
getch();
return 0;
}// End of main
OUTPUT:
For choice 1:
129
1. PUSH
2. DISPLAY
3. POP
4. EXIT
1. PUSH
2. DISPLAY
3. POP
4. EXIT
130
For choice 2:
1. PUSH
2. DISPLAY
3. POP
4. EXIT
For choice 3:
1. PUSH
2. DISPLAY
3. POP
4. EXIT
DELETED
For same choice:
1. PUSH
2. DISPLAY
3. POP
4. EXIT
DELETED
133
For choice 4:
1. PUSH
2. DISPLAY
3. POP
4. EXIT
PROGRAM 16
PROGRAM STATEMENT:
Write a program in C++ to implement stack of structure ITEM
using linked lists.
The structure ITEM should have134
ITEM *next;
};
ITEM *top=NULL,*temp=NULL;
void push()
stack
{ char Iname[30];
int Ino;
float Pr;
cout<<"\n\nEnter Item Name: ";
cin>>Iname;
cout<<"\n\nEnter Item No: ";
cin>>Ino;
cout<<"\n\nEnter Price: Rs. ";
cin>>Pr;
temp=new ITEM;
temp->next=NULL;
strcpy(temp->Itemname,Iname);
temp->Itemno=Ino;
temp->Price=Pr;
if(top==NULL)
top=temp;
else
{
temp->next=top;
top=temp;
}
cout<<"\n\nINFORMATION ADDED\n\n";
136
cout<<endl;
}
void pop()
stack
{
if(top==NULL)
cout<<"\n\nSTACK UNDERFLOW\n\n";
else
{
temp=top;
top=top->next;
cout<<"\n\nINFORMATION TO BE DELETED\n\n";
cout<<"\n\nITEM NAME: ";
cout<<temp->Itemname<<endl;
cout<<"\n\nITEM NO: ";
cout<<temp->Itemno<<endl;
cout<<"\n\nCOST: Rs. ";
cout<<temp->Price<<endl;
delete temp;
}
cout<<endl;
}
void display()
stack
{
if(top==NULL)
cout<<"\n\nSTACK UNDERFLOW";
else
137
{
temp=top;
cout<<"\n\nDISPLAYING THE INFORMATION\n\n";
while(temp!=NULL)
{
cout<<"\n\nITEM NAME: ";
cout<<temp->Itemname<<endl;
cout<<"\n\nITEM NO: ";
cout<<temp->Itemno<<endl;
cout<<"\n\nCOST: Rs. ";
cout<<temp->Price<<endl;
temp=temp->next;
}
}
cout<<endl;
}
int main()
{
int ch;
char t;
while(1)
//menu
{
cout<<"\n\nIMPLEMENTATION OF STACK USING LINKED
LISTS\n\n";
cout<<"\n\n1. PUSH";
cout<<"\n\n2. DISPLAY";
cout<<"\n\n3. ";
138
cout<<"\n\n4. EXIT";
cout<<"\n\nENTER YOUR CHOICE: ";
cin>>ch;
switch(ch)
{
case 1: push();
break;
case 2: display(); //Function to display the contents of
the stack
break;
case 3: pop();
break;
case 4: cout<<"\n\nAre you sure you want to exit??
(Y/N)";
cin>>t;
if(t=='Y')
return 0;
else
break;
default:cout<<"\n\nWRONG CHOICE!!"<<endl;
break;
}
}
getch();
return 0;
} //End of main
OUTPUT:
For choice 1:
139
1. PUSH
2. DISPLAY
3. POP
4. EXIT
INFORMATION ADDED
1. PUSH
140
2. DISPLAY
3. POP
4. EXIT
INFORMATION ADDED
For choice 2:
1. PUSH
2. DISPLAY
3. POP
4. EXIT
141
For choice 3:
1. PUSH
2. DISPLAY
3. POP
142
4. EXIT
INFORMATION TO BE DELETED
1. PUSH
2. DISPLAY
3. POP
4. EXIT
For choice 3:
1. PUSH
2. DISPLAY
3. POP
4. EXIT
INFORMATION TO BE DELETED
144
1. PUSH
2. DISPLAY
3. POP
4. EXIT
STACK UNDERFLOW
For choice 4:
1. PUSH
145
2. DISPLAY
3. POP
4. EXIT
PROGRAM 17
PROGRAM STATEMENT:
Write a program in C++ to implement queue of structure ITEM
using array.
The structure ITEM should have Itemno of type integer
146
ITEM q[n];
int front=-1,rear=-1;
void addq()
{
char iname[30];
int ino;
float cost;
cout<<"\n\nEnter Item Name- ";
cin>>iname;
cout<<"\n\nEnter Item No- ";
cin>>ino;
cout<<"\n\nEnter Price- Rs. ";
cin>>cost;
if(rear==-1)
{
rear=0;
front=0;
strcpy(q[rear].Itemname,iname);
q[rear].Itemno=ino;
q[rear].Price=cost;
}
else
{
rear++;
strcpy(q[rear].Itemname,iname);
q[rear].Itemno=ino;
q[rear].Price=cost;
148
}
getch();
}
void delq()
{
if(front==-1)
cout<<"\n\nQUEUE EMPTY";
else
{
if(front==rear)
{
cout<<\n\nDATA TO BE DELETED: ;
cout<<"\n\nITEM NAME: ";
cout<<q[front].Itemname;
cout<<"\n\nITEM NO: ";
cout<<q[front].Itemno;
cout<<"\n\nCOST: Rs. ";
cout<<q[front].Price;
front=-1;
rear=-1;
}
else
{
cout<<\n\nDATA TO BE DELETED: ;
cout<<"\n\nITEM NAME: ";
cout<<q[front].Itemname;
cout<<"\n\nITEM NO: ";
149
cout<<q[front].Itemno;
cout<<"\n\nCOST: Rs. ";
cout<<q[front].Price;
front++;
}
}
}
void display()
{
int i;
if(front==-1)
cout<<"\n\nQUEUE IS EMPTY";
i=front;
for(i=front;i<=rear;i++)
{
cout<<"\n\nITEM NAME: ";
cout<<q[i].Itemname;
cout<<"\n\nITEM NO: ";
cout<<q[i].Itemno;
cout<<"\n\nCOST: Rs. ";
cout<<q[i].Price;
}
}
int main()
//main
{
int ch;
char t;
150
while(1)
//menu
{
cout<<"\n\nIMPLEMENTATION OF QUEUE USING ARRAYS\n\n";
cout<<"\n\n1. ADDING QUEUE";
cout<<"\n\n2. DISPLAYING QUEUE";
cout<<"\n\n3. DELETING QUEUE";
cout<<"\n\n4. EXIT";
cout<<"\n\nENTER YOUR CHOICE: ";
cin>>ch;
switch(ch)
{
case 1: addq();
break;
case 2: display();
the queue
break;
case 3: delq();
break;
case 4: cout<<"\n\nAre you sure you want exit?? (Y/N)";
cin>>t;
if(t=='Y')
return 0;
else
break;
default:cout<<"\n\nWRONG CHOICE\n\n";
break;
}
151
}
getch();
return 0;
} //end of main
OUTPUT:
For choice 1:
1. ADDING QUEUE
2. DISPLAYING QUEUE
3. DELETING QUEUE
4. EXIT
1. ADDING QUEUE
2. DISPLAYING QUEUE
3. DELETING QUEUE
4. EXIT
1. ADDING QUEUE
2. DISPLAYING QUEUE
3. DELETING QUEUE
153
4. EXIT
1. ADDING QUEUE
2. DISPLAYING QUEUE
3. DELETING QUEUE
4. EXIT
154
DATA TO BE DELETED:
1. ADDING QUEUE
2. DISPLAYING QUEUE
3. DELETING QUEUE
4. EXIT
155
1. ADDING QUEUE
2. DISPLAYING QUEUE
3. DELETING QUEUE
4. EXIT
156
PROGRAM 18
PROGRAM STATEMENT:
Write a program in C++ to implement queue of structure ITEM
using linked lists.
The structure ITEM should have Itemno of type integer
Itemname of type string
Price of type float.
EXPECTED INPUT AND OUTPUT:
Input:
1. Enter the Item no.
2. Enter the Item name.
3. Enter the price.
Output:
1. Display the queue containing Item no, Item name, Price.
157
ALGORITHM:
1. Start.
2. Enter the Item no.
3. Enter the Item name.
4. Enter the price.
5. Either delete or display the data based on the choice.
6. End.
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<string.h>
struct ITEM
{
char Itemname[30];
int Itemno;
float Price;
ITEM *next;
};
ITEM *front=NULL,*rear=NULL,*temp;
void addq()
{
char Iname[30];
int Ino;
float cost;
cout<<"\n\nEnter the Item Name: ";
cin>>Iname;
cout<<"\n\nEnter the Item No: ";
158
cin>>Ino;
cout<<"\n\nEnter the cost: Rs.";
cin>>cost;
temp=new ITEM;
if(temp==NULL)
{
cout<<"\n\nQUEUE IS FULL";
return;
}
temp->next=NULL;
strcpy(temp->Itemname,Iname);
temp->Itemno=Ino;
temp->Price=cost;
if(rear==NULL)
{
front=temp;
rear=temp;
}
else
{
rear->next=temp;
rear=rear->next;
}
}
void delq()
{
if(front==NULL)
159
cout<<"\n\nQUEUE IS EMPTY";
else
{
if(rear==front)
{
temp=front;
front=NULL;
rear=NULL;
cout<<"\n\nData to be removed: ";
cout<<"\n\nITEM NAME: ";
cout<<temp->Itemname;
cout<<"\n\nITEM NO:";
cout<<temp->Itemno;
cout<<"\n\nCOST: Rs.";
cout<<temp->Price;
delete temp;
}
else
{
temp=front;
front=front->next;
cout<<"\n\nData to be removed: ";
cout<<"\n\nITEM NAME: ";
cout<<temp->Itemname;
cout<<"\n\nITEM NO: ";
cout<<temp->Itemno;
cout<<"\n\nCOST: Rs.";
160
cout<<temp->Price;
delete temp;
}
}
}
void display()
{
temp=front;
while(temp!=NULL)
{
cout<<"\n\nItem no: "<<temp->Itemno;
cout<<"\n\nItem Name: "<<temp->Itemname;
cout<<"\n\nCost: Rs."<<temp->Price;
temp=temp->next;
}
}
int main()
//main
{
int ch;
char t;
while(1)
//menu
{
cout<<"\n\nIMPLEMENTATION OF QUEUE USING LINKED
LISTS\n\n";
cout<<"\n\n1. ADD QUEUE";
cout<<"\n\n2. DISPLAY QUEUE";
cout<<"\n\n3. DELETE QUEUE";
161
cout<<"\n\n4. EXIT";
cout<<"\n\nENTER YOUR CHOICE: ";
cin>>ch;
switch(ch)
{
case 1: addq();
//Func call 1
break;
case 2: display(); //Func call 2
break;
case 3: delq();
//Func call 3
break;
case 4: cout<<"\n\nAre you sure you want to exit??
(Y/N)";
cin>>t;
if(t=='Y')
return 0;
else
break;
default:cout<<"\n\nWRONG CHOICE!!"<<endl;
break;
}
}
getch();
return 0;
} //End of main
OUTPUT:
For choice 1:
162
1. ADD QUEUE
2. DISPLAY QUEUE
3. DELETE QUEUE
4. EXIT
1. ADD QUEUE
2. DISPLAY QUEUE
163
3. DELETE QUEUE
4. EXIT
For choice 2:
1. ADD QUEUE
2. DISPLAY QUEUE
3. DELETE QUEUE
4. EXIT
Cost: Rs.15000
Cost: Rs.25000
For choice 3:
1. ADD QUEUE
2. DISPLAY QUEUE
3. DELETE QUEUE
4. EXIT
Data to be removed:
COST: Rs.15000
DISPLAYING AFTER DELETING THE DATA:
IMPLEMENTATION OF QUEUE USING LINKED LISTS
1. ADD QUEUE
2. DISPLAY QUEUE
3. DELETE QUEUE
4. EXIT
Cost: Rs.25000
For choice 4:
166
1. ADD QUEUE
2. DISPLAY QUEUE
3. DELETE QUEUE
4. EXIT
167
PROGRAM 19
PROGRAM STATEMENT:
Write a program in C++ to implement circular queue of structure
ITEM using arrays.
The structure ITEM should have Itemno of type integer
Itemname of type string
Price of type float.
EXPECTED INPUT AND OUTPUT:
Input:
1. Enter the Item no.
2. Enter the Item name.
3. Enter the price.
Output:
1. Display the queue containing Item no, Item name, Price.
ALGORITHM:
1. Start.
2. Enter the Item no.
3. Enter the Item name.
4. Enter the price.
5. Either delete or display the data based on the choice.
6. End.
PROGRAM:
168
#include<iostream.h>
#include<conio.h>
#include<string.h>
#define n 5
struct ITEM
{
int Itemno;
char Itemname[30];
float Price;
};
ITEM q[n];
int front=-1,rear=-1;
void insert()
{
int ino;
char iname[30];
float cost;
{
if(front==-1)
{
cout<<"\n\nQUEUE IS EMPTY";
return;
}
cout<<"\n\nQUEUE TO BE DELETED\n\n";
170
{
int i;
if(front==-1)
{
cout<<"\n\nQUEUE IS EMPTY";
return;
}
else
{
if(front<rear)
171
{
for(i=front;i<=rear;i++)
{
cout<<"\n\nITEM NAME: ";
cout<<q[i].Itemname;
cout<<"\n\nITEM NO: ";
cout<<q[i].Itemno;
cout<<"\n\nCOST: Rs.";
cout<<q[i].Price;
}
}
else
{
for(i=front;i<n;i++)
{
cout<<"\n\nITEM NAME: ";
cout<<q[i].Itemname;
cout<<"\n\nITEM NO: ";
cout<<q[i].Itemno;
cout<<"\n\nCOST: Rs.";
cout<<q[i].Price;
}
for(i=0;i<=rear;i++)
{
cout<<"\n\nITEM NAME: ";
cout<<q[i].Itemname;
cout<<"\n\nITEM NO: ";
172
cout<<q[i].Itemno;
cout<<"\n\nCOST: Rs.";
cout<<q[i].Price;
}
}
}
}
int main()
//main
{
int ch;
char t;
while(1)
//menu
{
cout<<"\n\nIMPLEMENTATION OF CIRCULAR QUEUE USING
ARRAYS\n\n";
cout<<"\n\n1. INSERTING";
cout<<"\n\n2. DISPLAYING";
cout<<"\n\n3. DELETING";
cout<<"\n\n4. EXIT!!";
cout<<"\n\nENTER YOUR CHOICE: ";
cin>>ch;
switch(ch)
{
case 1: insert();
//func call 1
break;
case 2: display();
break;
173
//func call 2
case 3: delq();
//func call 3
break;
case 4: cout<<"\n\nAre you sure you want to exit??
(Y/N)";
cin>>t;
if(t=='Y')
return 0;
else
break;
default:cout<<"\n\nWRONG CHOICE";
break;
}
}
getch();
return 0;
} //End of main
OUTPUT:
For choice 1:
1. INSERTING
2. DISPLAYING
3. DELETING
174
4. EXIT!!
1. INSERTING
2. DISPLAYING
3. DELETING
4. EXIT!!
COST: Rs.50000
ITEM NAME:
ITEM NO: 0
COST: Rs.0
ITEM NAME:
ITEM NO: 0
COST: Rs.0
ITEM NAME:
ITEM NO: 0
COST: Rs.0
ITEM NAME:
ITEM NO: 0
COST: Rs.0
176
COST: Rs.50000
For choice 3:
1. INSERTING
2. DISPLAYING
3. DELETING
4. EXIT!!
QUEUE TO BE DELETED
177
For choice 4:
1. INSERTING
2. DISPLAYING
3. DELETING
4. EXIT!!
PROGRAM 20
PROGRAM STATEMENT:
SQL:
178
TABLE: FLIGHTS
FNO
SOURCE
DEST
NO OF FL
NO OF STOP
IC301
MUMBAI
BANGALORE
IC799
BANGALORE
KOLKATA
MC101
DELHI
VARANASI
IC302
MUMBAI
KOCHI
AM812
LUCKNOW
DELHI
MU499
DELHI
CHENNAI
Table: FARES
FNO
AIRLINES
FARE
TAX
IC301
Indian Airlines
9425
5%
IC799
Spice Jet
8846
10%
MC101
Deccan Airlines
4210
7%
IC302
Jet Airways
13894
5%
AM812
Indian Airlines
4500
6%
MU499
Sahara
12000
4%
Display flight number & number of flights from LUCKNOW from the
table flights.
To display fno, source, dest, airlines whose fare is less than 10000.
179
| NO_OF_FL |
+-------+--------------------+
184
| AM812 |
+-------+--------------------+
1 row in set (0.00 sec)
FOR QUERY 2:
+------------+----------------+----------------+------------+---------------+
| FNO
| SOURCE | DEST
| NO_OF_FL | NO_OF_STOP |
+------------+----------------+----------------+------------+---------------+
| MC101 | DELHI
| VARANASI |
| IC799
| BANGLORE | KOLKATA
| IC302
| MUMBAI
| MU499 | DELHI
| CHENNAI
| IC301
| BANGLORE |
| MUMBAI
| KOCHI
+-----------+-----------------+----------------+------------+------------+
6 rows in set (0.00 sec)
FOR QUERY 3: (Table after updating)
+-----------+-----------------------+--------+-------+
| FNO
AIRLINES
| FARE | TAX |
+-----------+----------------------+---------+-------+
| IC301
| IC799
| Spice Jet
5 |
| 8846 | 10 |
| Jet Airways
| 13894 |
| 12000 |
5 |
6 |
7 |
+-----------+----------------------+----------+------+
6 rows in set (0.00 sec)
185
| DEST |
+-----------+---------------+----------------+---------------+---------+------+-------------+-------+-------+
| IC301 | MUMBAI | BANGLORE |
Airlines |9425 | 5 |
3 |
| IC301
4 |
| AM812 | Indian
+-----------+----------------+---------------+---------+-------+----------+---------------------+-------+------+
2 rows in set (0.00 sec)
FOR QUERY 5:
+---------+-------------+-----------+-------------------+
| FNO | SOURCE | DEST
| AIRLINES
+---------+-------------+-----------+-------------------+
| IC301
| MUMBAI
| IC799
| BANGLORE | KOLKATA
| MC101 | DELHI
| Indian Airlines |
+-----------+----------------+------------------+--------------------+
4 rows in set (0.39 sec)
FOR QUERY 6:
+-----------------------+
| count(AIRLINES) |
+-----------------------+
186
| Indian
6|
+-----------------------+
1 row in set (0.08 sec)
FOR QUERY 7:
+---------------+---------------+
| min(FARE) | max(FARE) |
+---------------+----------------+
|
8846
8846
+----------------+---------------+
1 row in set (0.05 sec)
FOR QUERY 8:
+--------------+
| avg(FARE) |
+--------------+
| 4355.0000 |
+-----------------+
1 row in set (0.06 sec)
FOR QUERY 9:
+----------------------+
| count(SOURCE) |
+----------------------+
|
+-----------------------+
1 row in set (0.03 sec)
FOR QUERY 10: (Table after deleting)
+-----------+----------------+----------------+---------------+-------------------+
| FNO
187
| SOURCE
DEST
| NO_OF_FL | NO_OF_STOP |
+-----------+----------------+----------------+----------------+------------------+
| AM812 | LUCKNOW | DELHI
| IC301
| MUMBAI
| BANGLORE |
| IC302
| MUMBAI
| KOCHI
| IC799
| BANGLORE | KOLKATA
|
|
| MC101 | DELHI
| VARANASI |
| MU499 | DELHI
| CHENNAI |
FINAL TABLES:
TABLE: FLIGHTS
+-----------+----------------+----------------+---------------+-------------------+
| FNO
| SOURCE
| DEST
| NO_OF_FL | NO_OF_STOP |
+-----------+----------------+----------------+---------------+-------------------+
| AM812 | LUCKNOW | DELHI
| IC301
| MUMBAI
| BANGLORE |
| IC302
| MUMBAI
| KOCHI
| IC799
| BANGLORE | KOLKATA
|
|
| MC101 | DELHI
| VARANASI |
| MU499 | DELHI
| CHENNAI
AIRLINES
| FARE | TAX |
+-----------+----------------------+---------+------+
| IC301
| IC799
| Spice Jet
5 |
| 8846 | 10 |
| Jet Airways
| 13894 |
5 |
6 |
| 12000 |
7 |
+-----------+---------------------+----------+-------+
6 rows in set (0.00 sec)
PROGRAM 21
PROGRAM STATEMENT:
SQL
Table: Emp
EMPID
FNAME
LNAME
ADDRESS
CITY
101
Akash
Singh
M K Nagar
Mumbai
102
Bikash
Kumar
K K Nagar
Chennai
189
103
Mohit
Yadav
D K Nagar
Kolkata
104
Rohit
Singh
T K Nagar
Agra
105
Aman
Sen
G G Nagar
Mumbai
EMPID
SALARY
COMM
DESIGNATIO
N
DATEOFJ
101
12000
120
Manager
12 Dec 2008
102
13500
300
Manager
15 Aug 2006
103
8500
500
Salesman
1 Jan 2006
104
8000
Clerk
8 Sep 2007
105
9000
Salesman
30 Nov 2007
Table: Sal
350
190
mysql> Select *
-> From Emp
-> where CITY="Mumbai";
QUERY 2:
mysql> Select FNAME,LNAME,ADDRESS
-> From Emp,Sal
-> where Emp.EMPID=Sal.EMPID
-> ORDER BY SALARY ASC;
QUERY 3:
mysql> Select SALARY+COMM
-> From Sal;
QUERY 4:
mysql> Select max(SALARY)
-> From Sal
-> where DESIGNATION="Salesman";
QUERY 5:
mysql> Select FNAME,LNAME
-> From Emp,Sal
-> where Emp.EMPID=Sal.EMPID AND DESIGNATION="Manager";
QUERY 6:
mysql> Select count(DESIGNATION)
-> From Sal;
QUERY 7:
mysql> Select count(*)
-> From Emp
-> where CITY="Chennai";
194
QUERY 8:
mysql> Select CITY,ADDRESS
-> From Emp,Sal
-> where Emp.EMPID=Sal.EMPID AND SALARY>10000;
QUERY 9:
mysql> Select EMPID
-> From Sal
-> where COMM IS NULL;
QUERY 10:
mysql> Select EMPID,SALARY,DESIGNATION
-> From Sal
-> ORDER BY DATEOFJ DESC;
QUERY 11:
mysql> Delete from Emp
-> where CITY="Agra";
Query OK, 1 row affected (0.06 sec)
OUTPUT:
FOR QUERY 1:
+----------+-----------+------------+---------------+------------+
| EMPID | FNAME | LNAME | ADDRESS | CITY
+----------+-----------+------------+---------------+-------------+
| 101
| Akash
| Singh
| M K Nagar | Mumbai |
| 105
| Aman
| Sen
| G G Nagar | Mumbai |
+----------+-----------+------------+---------------+-------------+
2 rows in set (0.04 sec)
FOR QUERY 2:
+------------+-----------+---------------+
195
| Singh
| T K Nagar |
| Mohit
| Yadav
| D K Nagar |
| Aman
| Sen
| G G Nagar |
| Akash
| Singh
| M K Nagar |
| Bikash | Kumar
| K K Nagar |
+-----------+-------------+--------------+
5 rows in set (0.08 sec)
FOR QUERY 3:
+----------------------+
| SALARY+COMM |
+-----------------------+
|
12120
13800
9000
NULL
9350
+---------------------+
5 rows in set (0.00 sec)
FOR QUERY 4:
+-------------------+
| max(SALARY) |
+-------------------+
|
9000
+-------------------+
1 row in set (0.22 sec)
196
FOR QUERY 5:
+--------+-------+
| FNAME | LNAME |
+------------+-----------+
| Akash
| Singh
| Bikash | Kumar |
+-----------+------------+
2 rows in set (0.00 sec)
FOR QUERY 6:
+-----------------------------+
| count(DESIGNATION) |
+-----------------------------+
|
+-----------------------------+
1 row in set (0.06 sec)
FOR QUERY 7:
+-------------+
| count(*) |
+-------------+
|
+-------------+
1 row in set (0.00 sec)
FOR QUERY 8:
+--------------+---------------+
| CITY
| ADDRESS |
+--------------+---------------+
| Mumbai | M K Nagar |
197
| Chennai | K K Nagar |
+--------------+---------------+
2 rows in set (0.00 sec)
FOR QUERY 9:
+----------+
| EMPID |
+----------+
| 104
+----------+
1 row in set (0.00 sec)
FOR QUERY 10:
+----------+-----------+--------------------+
| EMPID | SALARY | DESIGNATION |
+----------+-----------+--------------------+
| 101
| 12000 | Manager
+---------+----------+----------------+
5 rows in set (0.00 sec)
FOR QUERY 11: (Table after deleting)
+----------+------------+-----------+---------------+------------+
| EMPID | FNAME | LNAME | ADDRESS | CITY
+----------+------------+-----------+---------------+------------+
| 101
| Akash
| Singh
| 102
| Bikash
198
| M K Nagar | Mumbai|
| 103
| Mohit
| 105
| Aman
| Sen
| G G Nagar | Mumbai|
+----------+------------+-----------+----------------+------------+
4 rows in set (0.00 sec)
FINAL TABLES:
Table: Emp
+----------+------------+-----------+---------------+-------------+
| EMPID | FNAME | LNAME | ADDRESS | CITY
+----------+------------+-----------+---------------+-------------+
| 101
| Akash
| Singh
| M K Nagar | Mumbai |
| 102
| 103
| Mohit
| Yadav
| 105
| Aman
| Sen
| D K Nagar | Kolkata |
| G G Nagar | Mumbai |
+----------+-----------+------------+---------------+-------------+
4 rows in set (0.00 sec)
Table: Sal
+----------+------------+----------+--------------------+---------------+
| EMPID | SALARY | COMM | DESIGNATION | DATEOFJ
+----------+-----------+-----------+--------------------+---------------+
| 101
| 12000 | 120
| Manager
| 2008-12-12 |
| 102
| 13500 | 300
| Manager
| 2006-08-15 |
| 103
| 8500 | 500
| Salesman
| 2006-01-01 |
| 104
| 8000 | NULL
| Clerk
| 2007-09-08 |
| 105
| 9000 | 350
| Salesman
| 2007-11-30 |
+----------+----------+-----------+---------------------+-----------------+
199
*****************************
200