You are on page 1of 200

PROGRAM 1

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.

EXPECTED INPUT AND OUTPUT:


INPUT1. User gives which operation he wants to perform.
2. User gives maximum rows and maximum columns and enters array.
OUTPUT1. Perform the operation and display the result.

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

MRINMAY KUMAR DAS

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)

//func to display diagonal ele

{
2

MRINMAY KUMAR DAS

cout<<"\n\nLeft diagonal elements ";


for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{

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

MRINMAY KUMAR DAS

}
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

MRINMAY KUMAR DAS

cout<<"\n\nEnter which row you want the max and min


";
cin>>p;
cout<<"\n\nEnter the array rowwise ";
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
minmaxr(a,p,m);
break;
case 2:
cout<<"\n\nEnter the number of rows and columns of
matrix";
cin>>m>>n;
cout<<"\n\nEnter which column you want the max and
min ";
cin>>p;
cout<<"\n\nEnter the array rowwise ";
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
minmaxc(a,p,n);
break;
case 3:
cout<<"\n\nEnter the number of rows and columns of square
matrix";
cin>>n;
cout<<"\n\nEnter the array rowwise ";
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
5

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

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

Enter your choice 1


Enter the number of rows and columns of matrix3
3
Enter which row you want the max and min 3
Enter the array rowwise
1
2
3
4
5
6
7
7

MRINMAY KUMAR DAS

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

Enter your choice 2


Enter the number of rows and columns of matrix3
3
Enter which column you want the max and min 2
Enter the array rowwise
1
2
3
4
5
6
7
8
9
The maximum and minimum elements of the 2 nd column are 8 and 2

MENU
1.Minimum and maximum in a row
2.Minimum and maximum in a column
8

MRINMAY KUMAR DAS

3.Diagonal elements
4.Swap two rows
5.Swap two columns

Enter your choice 3


Enter the number of rows and columns of square matrix3
Enter the array rowwise
1
2
3
4
5
6
7
8
9
Left diagonal elements 1
5
9

Right diagonal elements

3
5

MENU
1.Minimum and maximum in a row
2.Minimum and maximum in a column
3.Diagonal elements
9

MRINMAY KUMAR DAS

4.Swap two rows


5.Swap two columns

Enter your choice 4


Enter the number of rows and columns of matrix 3
3
Enter which 2 rows you want to interchange
1
2
Enter the array rowwise
1
2
3
4
5
6
7
8
9
Resulting matrix is
456
123
789

MENU
1.Minimum and maximum in a row
2.Minimum and maximum in a column
3.Diagonal elements
4.Swap two rows
10

MRINMAY KUMAR DAS

5.Swap two columns

Enter your choice 5


Enter the number of rows and columns of matrix 3
3
Enter which 2 columns you want to interchange
1
2
Enter the array rowwise
1
2
3
4
5
6
7
8
9
Resulting matrix is
213
546
879

PROGRAM 2
PROGRAM STATEMENT:
11

MRINMAY KUMAR DAS

Write a C++ program to implement the structure DISTANCE having


following members
Data Members
Distance in meter of type integer
Distance in centimeter of type integer
Member Functions

DISTANCE getdist() to get the values of data members


showdist(DISTANCE d) to show the values of the data members.
DISTANCE adddistance(DISTANCE d1,DISTANCE d2) to add the two
distances given as parameters
DISTANCE subdistance(DISTANCE d1,DISTANCE d2) to subtract the
two distances given as parameters

EXPECTED INPUT OR OUTPUT:


INPUT1. User should give the values of two distances.
2. User should select addition or subtraction.
OUTPUT1. Should display the sum or the difference of the two distances.

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

MRINMAY KUMAR DAS

//structure for storing distance

cout<<"\n\nEnter the distance in metres ";


cin>>m;
cout<<"\n\nEnter the distance in centimetre ";
cin>>cm;

}
void showdist()
{

cout<<"\n\nThe value of metres is "<<m;


cout<<"\n\nThe value of the centimetres is "<<cm;

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

MRINMAY KUMAR DAS

}
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

MRINMAY KUMAR DAS

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

Enter your choice 1


15

MRINMAY KUMAR DAS

Enter the distance in metres 3


Enter the distance in centimetre 97

Enter the distance in metres 4


Enter the distance in centimetre 50

Addition of two distance resulted in 8 m and 47 cm

MENU
1.Add two distances
2.Subtract two distances
3.Exit

Enter your choice 2

Enter the distance in metres 3


Enter the distance in centimetre 45

Enter the distance in metres 2


Enter the distance in centimetre 56

Subtraction of two distance resulted in 0 m and 89 cm

MENU
1.Add two distances
2.Subtract two distances
3.Exit
16

MRINMAY KUMAR DAS

Enter your choice 2


Enter the distance in metres 3
Enter the distance in centimetre 45

Enter the distance in metres 4


Enter the distance in centimetre 54

Subtraction of two distance resulted in 1 m and 9 cm

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

MRINMAY KUMAR DAS

Write a C++ program to overload the functions to calculate area of circle,


rectangle and area of polynomial using measure of side and number of
sides.

EXPECTED INPUT AND OUTPUT:


INPUT:
1. For area of circle, enter the value of the radius.
2. For area of rectangle, enter the values of length and breadth.
3. For area of polygon, enter the no. of sides of the polygon and then
length of the sides.
OUTPUT:
1. The area of the circle will be displayed.
2. The area of rectangle will be displayed.
3. The area of the polygon will be displayed.

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)
{

//func to calculate area of circle

float area;
area=PI*r*r;
cout<<"\n\nThe area of the given circle = "<<area<<" Sq units ";
18

MRINMAY KUMAR DAS

}
void area(float l,float b)
{

//func to calculate area of rectangle

float area=l*b;
cout<<"\n\nThe area of the given rectangle = "<<area<<" Sq units

";
}
void area(int n,float s)
{

//funcn to calculate area of n sided polygon

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)
{

cout<<"\n\n1. Area of a circle";


cout<<"\n\n2. Area of a rectangle";
cout<<"\n\n3. Area of a n sided polygon ";
cout<<"\n\nEnter your choice: ";
cin>>ch;
switch (ch)
{

case 1:cout<<"\n\n Radius of the circle = ";


cin>>r;
area(r);
break;
case 2:cout<<"\n\nEnter the length = ";
cin>>l;

19

MRINMAY KUMAR DAS

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

3. Area of a n sided polygon


20

MRINMAY KUMAR DAS

Enter your choice: 1

Radius of the circle= 455.7

The area of the given circle = 652391 Sq units

1. Area of a circle

2. Area of a rectangle

3. Area of a n sided polygon

Enter your choice: 1

Radius of the circle= 77.7

The area of the given circle = 18966.7 Sq units


For case 2:
1. Area of a circle

2. Area of a rectangle

3. Area of a n sided polygon

Enter your choice: 2


21

MRINMAY KUMAR DAS

Enter the length = 566.69

Enter the breadth = 234.66

The area of the given rectangle = 132979 Sq units

1. Area of a circle

2. Area of a rectangle

3. Area of a n sided polygon

Enter your choice: 2

Enter the length = 1234

Enter the breadth = 123

The area of the given rectangle = 151782 Sq units


For case 3:
1. Area of a circle

2. Area of a rectangle

3. Area of a n sided polygon

22

MRINMAY KUMAR DAS

Enter your choice: 3

Number of sides = 9

Length of each side = 56

The area of the n-sided polygon = 19386.2 Sq units

1. Area of a circle

2. Area of a rectangle

3. Ara of a n sided polygon

Enter your choice: 3

Number of sides = 6

Length of each side = 197.8

The area of the n-sided polygon = 101649 Sq units


For case 4:
1. Area of a circle

2. Area of a rectangle

3. Area of a n-sided polygon


23

MRINMAY KUMAR DAS

4. Exit!!!

Enter your choice 4


Your choice is to EXIT!!!
-------------------------------Process exited with return value 0
Press any key to continue . . .

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

MRINMAY KUMAR DAS

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.

EXPECTED INPUT AND OUTPUT:


INPUT:
1. Enter the food code.
2. Then enter the food name.
3. Then enter the colour of the sticker as per the given type of food.
OUTPUT:
1. The food code along the name and colour of the sticker will be
displayed.
2. Also the food type will also be displayed as per the type of food.

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

MRINMAY KUMAR DAS

public:
void GetType()
colour of the sticker

//function for food type and

{
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()

//function for input

{
cout<<"

WELCOME TO OUR RESTAURANT

"<<"\n\n";
cout<<"
|
***************FOOD*MENU***************|"<<"\n\n";
cout<<"
_-"<<"\n\n";

-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

cout<<"PLEASE PLACE YOUR ORDER\n\n";


cout<<"Enter the code: ";
cin>>code;
cout<<endl;
cout<<"Enter the Food Name: ";
cin>>FoodName;
cout<<endl;
cout<<"Enter the sticker: ";
cin>>Sticker;
cout<<endl;
26

MRINMAY KUMAR DAS

GetType();

//calling the function

}
void FoodOut()
contents

//function to display the

{
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

MRINMAY KUMAR DAS

//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***************|

-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

PLEASE PLACE YOUR ORDER

Enter the code: 476

28

MRINMAY KUMAR DAS

Enter the Food Name: FriedRice

Enter the sticker: Green

*******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***************|

-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

PLEASE PLACE YOUR ORDER

Enter the code: 781

29

MRINMAY KUMAR DAS

Enter the Food Name: ShahiPaneer

Enter the sticker: Green

*******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***************|

-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

PLEASE PLACE YOUR ORDER

Enter the code: 344


30

MRINMAY KUMAR DAS

Enter the Food Name: EggNoodles

Enter the sticker: Yellow

*******YOUR ORDER:

CODE:344

FOOD NAME:EggNoodles

STICKER:Yellow

FOOD TYPE:Contains Egg

1. Food Menu
2. Exit
Enter Your Choice: 1
WELCOME TO OUR RESTAURANT

|***************FOOD*MENU***************|

-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

PLEASE PLACE YOUR ORDER

31

MRINMAY KUMAR DAS

Enter the code: 566

Enter the Food Name: EggPuff

Enter the sticker: Yellow

*******YOUR ORDER:

CODE:566

FOOD NAME:EggPuff

STICKER:Yellow

FOOD TYPE:Contains Egg


For choice 3For food type(3):
1. Food Menu
2. Exit
Enter Your Choice: 1
WELCOME TO OUR RESTAURANT

|***************FOOD*MENU***************|

-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

PLEASE PLACE YOUR ORDER


32

MRINMAY KUMAR DAS

Enter the code: 239

Enter the Food Name: ChickenBiriyani

Enter the sticker: Red

*******YOUR ORDER:

CODE:239

FOOD NAME:ChickenBiriyani

STICKER:Red

FOOD TYPE:Non Vegeterian

1. Food Menu
2. Exit
Enter Your Choice: 1
WELCOME TO OUR RESTAURANT

|***************FOOD*MENU***************|

-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

PLEASE PLACE YOUR ORDER


33

MRINMAY KUMAR DAS

Enter the code: 991

Enter the Food Name: TandooriChicken

Enter the sticker: Red

*******YOUR ORDER:

CODE:991

FOOD NAME:TandooriChicken

STICKER:Red

FOOD TYPE:Non Vegeterian


For choice 31. Food Menu
2. Exit
Enter Your Choice: 2
*************Thank You For Coming To Our Restaurant************
*************************VISIT AGAIN***************************

-------------------------------Process exited with return value 0


Press any key to continue . . .

34

MRINMAY KUMAR DAS

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.

EXPECTED INPUT AND OUTPUT:


INPUT:
35

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

return 1.05*Days*Tariff;
}
public:
HOTEL()

// Default Constructor

{
Days=0;
Tariff=0;
}
void getCheckIn()

// Function to input data

{
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()

// Function to display the data

{
cout<<"Room No: "<<Rno<<"\n";
cout<<"Name: "<<Name<<"\n";
37

MRINMAY KUMAR DAS

cout<<"Tariff per Day: "<<Tariff<<"\n";


cout<<"No. of Days: "<<Days<<"\n";
Calculate();
}
~HOTEL()

// Destructor

{
cout<<"THE SCOPE OF THE OBJECT GETS
OVER!!!"<<endl;
}
};
int main()
{
HOTEL H;

// Object of the class

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

MRINMAY KUMAR DAS

// Menu

break;
case 2: return 0;
}
}
getch();
return 0;
}

// End of Main

OUTPUT:
For case 1:
1. Accomodation Details

2. Exit!

Enter Your Choice: 1

Enter Room No: 344

Name: RaviKumar

Enter the Tariff: 200

Enter the no. of Days: 180

Room No: 344


Name: RaviKumar
Tariff per Day: 200
No. of Days: 180
39

MRINMAY KUMAR DAS

The Total Amount: 36000

1. Accomodation Details

2. Exit!

Enter Your Choice: 1

Enter Room No: 657

Name: ManojTiwary

Enter the Tariff: 177

Enter the no. of Days: 90

Room No: 657


Name: ManojTiwary
Tariff per Day: 177
No. of Days: 90
The Total Amount: 15930

1. Accomodation Details

2. Exit!
40

MRINMAY KUMAR DAS

Enter Your Choice: 1

Enter Room No: 45

Name: BarackObama

Enter the Tariff: 5000

Enter the no. of Days: 90

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!

Enter Your Choice: 2

THE SCOPE OF THE OBJECT GETS OVER!!!

-------------------------------Process exited with return value 0


41

MRINMAY KUMAR DAS

Press any key to continue . . .

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.

EXPECTED INPUT AND OUTPUT:


INPUT:
1. Enter the Title, and enter the Author for the book.
2. Then enter the no. of pages of the book.
42

MRINMAY KUMAR DAS

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

//Function to input the book details

{
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

MRINMAY KUMAR DAS

}
void show()

//Function to display the book details

{
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

MRINMAY KUMAR DAS

//Function call 2

TextBook b;

//Creating the object

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

Enter the Title:


45

MRINMAY KUMAR DAS

TheInvisibleMan

Enter the name of the Author:

H.GWells

Enter the no. of pages:

255

BOOK DETAILS:-

TITLE- TheInvisibleMan

AUTHOR- H.GWells

PAGES- 255

1. Book Details
2. Exit
Enter Your Choice: 1

Enter the Title:

TheCantervilleGhost

46

MRINMAY KUMAR DAS

Enter the name of the Author:

OscarWilde

Enter the no. of pages:

488

BOOK DETAILS:-

TITLE- TheCantervilleGhost

AUTHOR- OscarWilde

PAGES- 488
For case 2:
1. Book Details
2. Exit
Enter Your Choice: 2

Your Choice Is To Exit!!!


-------------------------------Process exited with return value 0
Press any key to continue . . .

47

MRINMAY KUMAR DAS

PROGRAM 7
PROGRAM STATEMENT:
Write a program in C++ to create a text file and perform the
following operations:

Display the file.

Count the no. of spaces.

Count the no. of vowel and consonants.

Count the no. of uppercase and lowercase characters.

Count the no. of digits and special characters.

EXPECTED INPUT AND OUTPUT:


Input:
1. Enter the text which is to be given in the text file and display it.
2. Now count the number of spaces in the text file.
3. Now count the number of vowel and consonants together.
4. Now count the number of uppercase and lowercase characters.
5. Now count the number of digits and special characters.
Output:
1. The number of spaces in the text file will be displayed.
2. The number of vowels and consonants are displayed.
3. The number of uppercase and lowercase characters are displayed.
4. The number of digits and special characters are displayed.
ALGORITHM:
1. Start.
48

MRINMAY KUMAR DAS

2. Enter the text.


3. Count the number of spaces and display it.
4. Count the number of vowels and consonants together and display it.
5. Count the number of uppercase and lowercase characters and display it.
6. Count the number of digits and special characters and display it.

PROGRAM:
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<fstream.h>
#include<ctype.h>
#include<string.h>
void create()

//Creating the file

{
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

MRINMAY KUMAR DAS

//Displaying the file

while(!fin.eof())
{
fin.getline(ch,80);
cout<<ch;
}
}
void countsp()

//Counting the spaces

{
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

MRINMAY KUMAR DAS

//Counting the vowels and consonants

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

MRINMAY KUMAR DAS

//Counting the uppercase and

sum++;
}
cout<<"\nThe number of upper case characters are "<<count;
cout<<"\nThe number of lower case characters are "<<sum;
}
void countdalp()
characters

//Counting the digits and special

{
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

MRINMAY KUMAR DAS

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

case 7:cout<<"\n\nAre You Sure You Want To Exit??? (Y/N)";


cin>>t;
if(t=='Y')
return 0;
53

MRINMAY KUMAR DAS

else
break;
default:cout<<"\nWRONG CHOICE"<<endl;
}
}
getch();
return 0;
}
OUTPUT:
For case 1: Creating the file and displaying it

1.CREATE A TEXT FILE

2.DISPLAY THE FILE

3.COUNT NUMBER OF SPACES

4.COUNT NUMBER OF VOWELS AND CONSONANTS

5.COUNT NUMBER OF UPPER CASE AND LOWER CASE CHARACTERS

6.COUNT NUMBER OF DIGITS AND SPECIAL CHARACTERS

7.GOOD BYE

ENTER YOUR CHOICE :-1


Time is @ great teacher but unfortunately kills all its pupils 8 a time.
54

MRINMAY KUMAR DAS

For case 2: Displaying the file


1.CREATE A TEXT FILE

2.DISPLAY THE FILE

3.COUNT NUMBER OF SPACES

4.COUNT NUMBER OF VOWELS AND CONSONANTS

5.COUNT NUMBER OF UPPER CASE AND LOWER CASE CHARACTERS

6.COUNT NUMBER OF DIGITS AND SPECIAL CHARACTERS

7.GOOD BYE

ENTER YOUR CHOICE :-2


Time is @ great teacher but unfortunately kills all its pupils 8 a time.
For case 3: Counting the number of spaces
1.CREATE A TEXT FILE

2.DISPLAY THE FILE

3.COUNT NUMBER OF SPACES

4.COUNT NUMBER OF VOWELS AND CONSONANTS

5.COUNT NUMBER OF UPPER CASE AND LOWER CASE CHARACTERS


55

MRINMAY KUMAR DAS

6.COUNT NUMBER OF DIGITS AND SPECIAL CHARACTERS

7.GOOD BYE

ENTER YOUR CHOICE :-3

The number of spaces are 13


For case 4: Counting the number of vowels and consonants
1.CREATE A TEXT FILE

2.DISPLAY THE FILE

3.COUNT NUMBER OF SPACES

4.COUNT NUMBER OF VOWELS AND CONSONANTS

5.COUNT NUMBER OF UPPER CASE AND LOWER CASE CHARACTERS

6.COUNT NUMBER OF DIGITS AND SPECIAL CHARACTERS

7.GOOD BYE

ENTER YOUR CHOICE :-4

The number of vowels are 22


The number of consonants are 34
56

MRINMAY KUMAR DAS

For case 5: Counting the number of uppercase and lowercase


characters
1.CREATE A TEXT FILE

2.DISPLAY THE FILE

3.COUNT NUMBER OF SPACES

4.COUNT NUMBER OF VOWELS AND CONSONANTS

5.COUNT NUMBER OF UPPER CASE AND LOWER CASE CHARACTERS

6.COUNT NUMBER OF DIGITS AND SPECIAL CHARACTERS

7.GOOD BYE

ENTER YOUR CHOICE :-5

The number of upper case characters are 1


The number of lower case characters are 55
For case 6: Counting the number of digits and special characters
1.CREATE A TEXT FILE

2.DISPLAY THE FILE

3.COUNT NUMBER OF SPACES

57

MRINMAY KUMAR DAS

4.COUNT NUMBER OF VOWELS AND CONSONANTS

5.COUNT NUMBER OF UPPER CASE AND LOWER CASE CHARACTERS

6.COUNT NUMBER OF DIGITS AND SPECIAL CHARACTERS

7.GOOD BYE

ENTER YOUR CHOICE :-6

The number of digits are 1


The number of special characters are 3
For case 7: Exiting
1.CREATE A TEXT FILE

2.DISPLAY THE FILE

3.COUNT NUMBER OF SPACES

4.COUNT NUMBER OF VOWELS AND CONSONANTS

5.COUNT NUMBER OF UPPER CASE AND LOWER CASE CHARACTERS

6.COUNT NUMBER OF DIGITS AND SPECIAL CHARACTERS

7.GOOD BYE

58

MRINMAY KUMAR DAS

ENTER YOUR CHOICE :-7

Are You Sure You Want To Exit??? (Y/N)Y


-------------------------------Process exited after 25.19 seconds with return value 0
Press any key to continue . . .

PROGRAM 8
PROGRAM STATEMENT:
59

MRINMAY KUMAR DAS

Write a program in C++ to copy a text file without copying the


spaces.
EXPECTED INPUT AND OUTPUT:
Input:
1. Enter the text and create the file. (with spaces between each word).
Output:
1. The copied file without spaces will be displayed.
ALGORITHM:
1. Start.
2. Enter the text.
3. Create the file.
4. Copy the file and display it.
5. End.
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void create()

//Function for creating the file

{
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

MRINMAY KUMAR DAS

}
void copy()

//Function to copy the file

{
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

//Function to display the copied

{
ifstream fin;
char ch;
fin.open("Duplicate.txt");
cout<<"\n\nThe Copied File Is"<<endl;
while(!fin.eof())
{
fin>>ch;
61

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

break;
default:cout<<"\n\nWRONG CHOICE\n\n";
break;
}
}
getch();
return 0;
}
OUTPUT:
For case 1:

1. CREATE THE FILE

2. COPY THE FILE

3. EXIT

ENTER YOUR CHOICE: 1

File Created
For case 2:

1. CREATE THE FILE

2. COPY THE FILE

3. EXIT

63

MRINMAY KUMAR DAS

ENTER YOUR CHOICE: 2

The Copied File Is


TheJourneyOfAThousandMilesBeginsWithOneStep!!!!!
For case 3:

1. CREATE THE FILE

2. COPY THE FILE

3. EXIT

ENTER YOUR CHOICE: 3

Are you sure you want exit?? (Y/N)Y

-------------------------------Process exited after 9.695 seconds with return value 0


Press any key to continue . . .
Another Check: (Same cases as above)
For case 1:

1. CREATE THE FILE

2. COPY THE FILE

3. EXIT
64

MRINMAY KUMAR DAS

ENTER YOUR CHOICE: 1

File Created
For case 2:

1. CREATE THE FILE

2. COPY THE FILE

3. EXIT

ENTER YOUR CHOICE: 2

The Copied File Is


TheJourneyOfAThousandMilesBeginsWithOneStep!!!!!
For incorrect choice:

1. CREATE THE FILE

2. COPY THE FILE

3. EXIT

ENTER YOUR CHOICE: 4

65

MRINMAY KUMAR DAS

WRONG CHOICE
For case 3:

1. CREATE THE FILE

2. COPY THE FILE

3. EXIT

ENTER YOUR CHOICE: 3

Are you sure you want exit?? (Y/N)Y


-------------------------------Process exited after 12.94 seconds with return value 0
Press any key to continue . . .

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

MRINMAY KUMAR DAS

3. Class and section


4. Marks of five subjects
EXPECTED INPUT AND OUTPUT:
Input:
1. Enter the admission number of the student.
2. Enter the name of the student.
3. Enter the class and section of the student.
4. Enter the marks for the five subjects of the student out of 100.
Output:
1. The report card of the student will be displayed.
2. Also the result with percentage will be shown of the student.
ALGORITHM:
1. Start.
2. Enter the admission number.
3. Enter the name.
4. Enter the class and section.
5. Enter the marks of the five subjects.
6. Display the report card along with percentage and result.
7. End.
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
struct Student
{
int admno;
char name[20];
67

MRINMAY KUMAR DAS

char Class[5], Section[5];


int phy,chem,maths,eng,cs;
void getdata();
void showdata();
};
void Student::getdata()

//Function to enter data

{
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

MRINMAY KUMAR DAS

//Function to show data

{
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()

//Function to write in the file

{
ofstream fout;
Student S;
fout.open("Stud Record.dat",ios::binary|ios::app);
S.getdata();
fout.write((char*)&S,sizeof(S));
fout.close();
69

MRINMAY KUMAR DAS

getch();
}
void op()

//Function to display the file

{
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

MRINMAY KUMAR DAS

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

2. Show the Students Data

3. Exit

4. ENTER YOUR CHOICE: 1

Enter the Name: Vaibhav

Enter the admission no :9821


71

MRINMAY KUMAR DAS

Enter the class: XII

Enter the section: A

Enter the marks in Physics =87

Enter the marks in Chemistry =94

Enter the marks in Maths =95

Enter the marks in English =92

Enter the marks in Computer Science =84


For same case:
1. Enter the Students Data

2. Show the Students Data

3. Exit

4. ENTER YOUR CHOICE: 1

Enter the Name: Ajay

Enter the admission no :11378

72

MRINMAY KUMAR DAS

Enter the class: XII

Enter the section: B

Enter the marks in Physics =23

Enter the marks in Chemistry =21


Enter the marks in Maths =9

Enter the marks in English =18

Enter the marks in Computer Science =45


For case 2:
1. Enter the Students Data

2. Show the Students Data

3. Exit

4. ENTER YOUR CHOICE: 2

REPORT CARD

NAME: Vaibhav

ADMISSION NO: 9821

73

MRINMAY KUMAR DAS

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

ADMISSION NO: 11378

CLASS: XII

SECTION: B
74

MRINMAY KUMAR DAS

PHYSICS: 23

CHEMISTRY: 21

MATHS: 9

ENGILSH: 18

COMPUTER SCIENCE: 45

PERCENTAGE =23%

DETAINED
For invalid choice:
1. Enter the Students Data

2. Show the Students Data

3. Exit

4. ENTER YOUR CHOICE:5

WRONG CHOICE!!
For case 3:

1. Enter the Students Data


75

MRINMAY KUMAR DAS

2. Show the Students Data

3. Exit

4. ENTER YOUR CHOICE: 3

Are you sure you want to exit?? (Y/N)Y


-------------------------------Process exited after 146.2 seconds with return value 0
Press any key to continue . . .

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

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

//Structure of BOOK

void insert()
to the file

//Function to insert the data of BOOK

{
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

MRINMAY KUMAR DAS

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

//Function to search the BOOK

{
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

MRINMAY KUMAR DAS

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

//Function to delete the data of the

{
80

MRINMAY KUMAR DAS

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

//Function to update the data of the

{
int n;
cout<<"\n\nEnter the new accession no- ";
cin>>n;
BOOK B;
ifstream fin;
ofstream fout;
81

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

return 0;
} //end of main
OUTPUT:
For case 1:

OPERATIONS ON BINARY FILES

1. INSERTING

2. SEARCHING

3. DELETING

4. MODIFYING

5. EXIT!!

ENTER YOUR CHOICE: 1

Enter Accession No: 04740

Enter Title: TogetherWithPhysics

Enter Cost:Rs. 220

Enter the Author's Name: N.S.Bhandari

Inserting another BOOK:


84

MRINMAY KUMAR DAS

OPERATIONS ON BINARY FILES

1. INSERTING

2. SEARCHING

3. DELETING

4. MODIFYING

5. EXIT!!

ENTER YOUR CHOICE: 1


Enter Accession No: 06730

Enter Title: AllinOneComputerScience

Enter Cost:Rs. 295

Enter the Author's Name: MiniGoyalandHarshitGarg

For case 2:
OPERATIONS ON BINARY FILES

1. INSERTING

85

MRINMAY KUMAR DAS

2. SEARCHING

3. DELETING

4. MODIFYING

5. EXIT!!

ENTER YOUR CHOICE: 2

Enter the new accession no- 04740

Book Found!!

Book Details:-

Accession No: 4740

Title: TogetherWithPhysics

Author: N.S.Bhandari

Price: 220
For same case:
OPERATIONS ON BINARY FILES
86

MRINMAY KUMAR DAS

1. INSERTING

2. SEARCHING

3. DELETING

4. MODIFYING

5. EXIT!!

ENTER YOUR CHOICE: 2

Enter the new accession no- 06730

Book Found!!

Book Details:-

Accession No: 6730

Title: AllinOneComputerScience

Author: MiniGoyalandHarshitGarg

Price: 294.003
For same case:
87

MRINMAY KUMAR DAS

OPERATIONS ON BINARY FILE

1. INSERTING

2. SEARCHING

3. DELETING

4. MODIFYING

5. EXIT!!

ENTER YOUR CHOICE: 2

Enter the new accession no- 34567

NOT FOUND!!
For case 4:
OPERATIONS ON BINARY FILES

1. INSERTING

2. SEARCHING

3. DELETING

88

MRINMAY KUMAR DAS

4. MODIFYING

5. EXIT!!

ENTER YOUR CHOICE: 4

Enter the new accession no- 04740

Enter Title: TogetherwithChemistry

Enter Author: R.PManchanda

Enter The Cost:Rs 272


For case 3:
OPERATIONS ON BINARY FILES

1. INSERTING

2. SEARCHING

3. DELETING

4. MODIFYING

5. EXIT!!

ENTER YOUR CHOICE: 3


89

MRINMAY KUMAR DAS

Enter the new accession no- 06730


For case 5:
OPERATIONS ON BINARY FILES

1. INSERTING

2. SEARCHING

3. DELETING

4. MODIFYING

5. EXIT!!

ENTER YOUR CHOICE: 5

Are you sure you want exit?? (Y/N)Y

-------------------------------Process exited after 329.4 seconds with return value 0


Press any key to continue . . .

90

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

}
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

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

1.CREATE

2.DISPLAY

3.EXIT

ENTER YOUR CHOICE: 1

Enter Accession No: 9382

Enter the title: HarryPotter

Name of the Author: J.KRowling

Enter the Cost: Rs.5000

Enter the type of the book: Mystery/Adventure

For choice 2:

1.CREATE

2.DISPLAY

3.EXIT

ENTER YOUR CHOICE: 2


96

MRINMAY KUMAR DAS

ACCESSION NO: 9382

TITLE OF THE BOOK: HarryPotter

NAME OF AUTHOR: J.KRowling

PRICE: Rs.5000

TYPE OF BOOK : Mystery/Adventure

For choice 3:

1.CREATE

2.DISPLAY

3.EXIT

ENTER YOUR CHOICE: 3

ARE YOU SURE YOU WANT TO EXIT!!! (Y/N)Y

-------------------------------Process exited after 37.8 seconds with return value 0


Press any key to continue . . .

97

MRINMAY KUMAR DAS

PROGRAM 12
PROGRAM STATEMENT:
Write a program in C++ to perform the following searches on a one
dimensional array.
Insertion
Selection
98

MRINMAY KUMAR DAS

EXPECTED INPUT AND OUTPUT:


Input:
1. Enter the no of elements
2. Enter the array.
Output:
1. Sort the array in ascending order either using insertion or selection sort
as per the menu.
ALGORITHM:
1. Start.
2. Enter the no. of elements.
3. Enter the array.
4. Sort the array in ascending order.
5. End.
PROGRAM:
#include<iostream.h>
#include<conio.h>
void ssort(int a[],int size)
{

//function to sort using selection sort

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

MRINMAY KUMAR DAS

}
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

MRINMAY KUMAR DAS

//function for insertion sort

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

MRINMAY KUMAR DAS

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!!

ENTER YOUR CHOICE: 1

Enter the size of the array: 5

Enter the array:-3498


2354
356
102

MRINMAY KUMAR DAS

234
9763

Sorted array is 234 356 2354 3498 9763


For same case:
SORTING ARRAYS:

1. SELECTION SORT

2. INSERTION SORT

3. EXIT!!

ENTER YOUR CHOICE: 1

Enter the size of the array: 6

Enter the array:-345


58
346
56
3467
698

Sorted array is 56 58 345 346 698 3467


For case 2:
SORTING ARRAYS:
103

MRINMAY KUMAR DAS

1. SELECTION SORT

2. INSERTION SORT

3. EXIT!!

ENTER YOUR CHOICE: 2

Enter the size of the array: 4

Enter the array:- 45878


3774
5647457
343

Sorted array is 343 3774 45878 5647457


For same case:
SORTING ARRAYS:

1. SELECTION SORT

2. INSERTION SORT

104

MRINMAY KUMAR DAS

3. EXIT!!

ENTER YOUR CHOICE: 2

Enter the size of the array: 5

Enter the array:- 346


45
356
577
346

Sorted array is 45 346 346 356 577

SORTING ARRAYS:
For case 3:
1. SELECTION SORT

2. INSERTION SORT

3. EXIT!!

ENTER YOUR CHOICE: 3

105

MRINMAY KUMAR DAS

Are you sure you want to exit?? (Y/N)Y

-------------------------------Process exited after 329.4 seconds with return value 0


Press any key to continue . . .

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

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

//Function for linear search

cout<<"\n\nElement is= ";


cout<<s;
}
else
{
cout<<"\n\nNOT FOUND!!!";
}
}
int bsearch(int a[100],int n)

//Function for binary search

{
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

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

for(i=0;i<n;i++)
cin>>a[i];
lsearch(a,n);

//Function call for linear search

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

//Function call for binary

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

MRINMAY KUMAR DAS

SEARCHING IN ARRAYS

1. LINEAR SEARCH

2. BINARY SEARCH

3. EXIT

ENTER YOUR CHOICE: 1

No of elements= 5

Enter the array: 398


893
-234
456
23

Enter The Element: -234

FOUND!!!

Element is= -234


Same choice:

SEARCHING IN ARRAYS

111

MRINMAY KUMAR DAS

1. LINEAR SEARCH

2. BINARY SEARCH

3. EXIT

ENTER YOUR CHOICE: 1

No of elements= 4

Enter the array: -453


-234
879
-543

Enter The Element: -544

NOT FOUND!!!
For choice 2:

SEARCHING IN ARRAYS

1. LINEAR SEARCH

2. BINARY SEARCH

112

MRINMAY KUMAR DAS

3. EXIT

ENTER YOUR CHOICE: 2

No of elements= 5

Enter the array: -456


-932
-123
560
-345

Enter the element to be searched- 560

FOUND AND POSITION IS 3

Element is= 560

For same choice:

SEARCHING IN ARRAYS

1. LINEAR SEARCH

2. BINARY SEARCH

3. EXIT
113

MRINMAY KUMAR DAS

ENTER YOUR CHOICE: 2

No of elements= 4

Enter the array: 2345


34
346
-356

Enter the element to be searched- -567

NOT FOUND
For choice 3:

SEARCHING IN ARRAYS

1. LINEAR SEARCH

2. BINARY SEARCH

3. EXIT

ENTER YOUR CHOICE: 3

Are you sure you want exit?? (Y/N)Y


114

MRINMAY KUMAR DAS

-------------------------------Process exited after 182.9 seconds with return value 0


Press any key to continue . . .

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

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

//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

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

cout << "\n\n Minutes : ";


a->getm();
cout << "\n\n Seconds : " ;
a->gets();
cout << "\n\n Time 2 :- ";
cout << "\n\n Hours : " ;
b->geth();
cout << "\n\n Minutes : ";
b->getm();
cout << "\n\n Seconds : " ;
b->gets();
t1= a->hour() * 3600 + a->minutes() * 60 + a->seconds();
t2= b->hour() * 3600 + b->minutes() * 60 + b->seconds();
sum = t1 + t2;
cout << "\n\n Time 1 in sec is : " << t1;
cout << "\n\n Time 2 in sec is : " << t2;
cout << "\n\n\t Sum is : " << sum;
if(t1>t2)
sub=t1-t2;
else
sub=t2-t1;
cout << "\n\t Difference is : " << sub;
if(ch==1)
{
p = sum/3600;
sum%=3600;
q = sum/60 ;
119

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

return 0;
} //end of main
OUTPUT:
For choice 1: (Sum)

MENU

1. Add two time intervals

2. Subtract two time intervals

3. Exit!

Enter your Choice: 1

Time 1:-

Hours : 4

Minutes : 19

Seconds : 359

Time 2 :-

Hours : 12

Minutes : 657
121

MRINMAY KUMAR DAS

Seconds : 2316

Time 1 in sec is : 15899

Time 2 in sec is : 84936

Sum is : 100835
Difference is : 69037

THE FINAL RESULT IS :

Hours :

28

Minutes :

Seconds :

35

For choice 2: (Difference)


MENU

1. Add two time intervals

2. Subtract two time intervals

3. Exit!

Enter your Choice: 2

Time 1:-

122

MRINMAY KUMAR DAS

Hours : 4

Minutes : 0

Seconds : 5

Time 2 :-

Hours : 8

Minutes : 10

Seconds : 0

Time 1 in sec is : 14405

Time 2 in sec is : 29400

Sum is : 43805
Difference is : 14995

THE FINAL RESULT IS :

Hours :

Minutes :

249

Seconds :

51

For choice 3:
MENU
123

MRINMAY KUMAR DAS

1. Add two time intervals

2. Subtract two time intervals

3. Exit!

Enter your Choice: 3

ARE YOU SURE YOU WANT TO EXIT!!! (Y/N)Y

-------------------------------Process exited after 44.58 seconds with return value 0


Press any key to continue . . .

124

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

#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()

//Adding data in the stack

{ 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

MRINMAY KUMAR DAS

}
else
cout<<"\n\nSTACK OVERFLOW\n\n";
}
void pop()

//Deleting data from stack

{
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()

//Displaying contents of the stack

{
int i=0;
if(top==-1)
cout<<"\n\nSTACK UNDERFLOW\n\n";
else
{
127

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

case 1: push();

//Function call for adding data to

stack
break;
case 2: display();

//Function call for displaying

data
break;
case 3: pop();

//Function call for deleting data from

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:

IMPLEMENTATION OF STACK USING ARRAYS

129

MRINMAY KUMAR DAS

1. PUSH

2. DISPLAY

3. POP

4. EXIT

ENTER YOUR CHOICE: 1

Enter Item Name- Food

Enter Item No- 325

Enter Price- Rs. 950.75


For same choice:

IMPLEMENTATION OF STACK USING ARRAYS

1. PUSH

2. DISPLAY

3. POP

4. EXIT
130

MRINMAY KUMAR DAS

ENTER YOUR CHOICE: 1

Enter Item Name- Drinks

Enter Item No- 751

Enter Price- Rs. 550.50

For choice 2:

IMPLEMENTATION OF STACK USING ARRAYS

1. PUSH

2. DISPLAY

3. POP

4. EXIT

ENTER YOUR CHOICE: 3

ITEM NAME: Food

ITEM NO: 325


131

MRINMAY KUMAR DAS

COST: Rs. 950.75

ITEM NAME: Drinks

ITEM NO: 751

COST: Rs. 550.5

For choice 3:

IMPLEMENTATION OF STACK USING ARRAYS

1. PUSH

2. DISPLAY

3. POP

4. EXIT

ENTER YOUR CHOICE: 2

ITEM NAME: Drinks

ITEM NO: 751


132

MRINMAY KUMAR DAS

COST: Rs. 550.5

DELETED
For same choice:

IMPLEMENTATION OF STACK USING ARRAYS

1. PUSH

2. DISPLAY

3. POP

4. EXIT

ENTER YOUR CHOICE: 2

ITEM NAME: Food

ITEM NO: 325

COST: Rs. 950.75

DELETED

133

MRINMAY KUMAR DAS

For choice 4:

IMPLEMENTATION OF STACK USING ARRAYS

1. PUSH

2. DISPLAY

3. POP

4. EXIT

ENTER YOUR CHOICE: 4

Are you sure you want exit?? (Y/N)Y

-------------------------------Process exited after 85.84 seconds with return value 0


Press any key to continue . . .

PROGRAM 16
PROGRAM STATEMENT:
Write a program in C++ to implement stack of structure ITEM
using linked lists.
The structure ITEM should have134

MRINMAY KUMAR DAS

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>
#define n 5
struct ITEM
{
char Itemname[30];
int Itemno;
float Price;
135

MRINMAY KUMAR DAS

ITEM *next;
};
ITEM *top=NULL,*temp=NULL;
void push()
stack

//Function to add information to the

{ 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

MRINMAY KUMAR DAS

cout<<endl;
}
void pop()
stack

//Function to delete data from

{
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

//Function to display the contents of the

{
if(top==NULL)
cout<<"\n\nSTACK UNDERFLOW";
else
137

MRINMAY KUMAR DAS

{
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

MRINMAY KUMAR DAS

cout<<"\n\n4. EXIT";
cout<<"\n\nENTER YOUR CHOICE: ";
cin>>ch;
switch(ch)
{
case 1: push();

//Function call to add data to stack

break;
case 2: display(); //Function to display the contents of
the stack
break;
case 3: pop();

//Function to delete data from stack

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

MRINMAY KUMAR DAS

IMPLEMENTATION OF STACK USING LINKED LISTS

1. PUSH

2. DISPLAY

3. POP

4. EXIT

ENTER YOUR CHOICE: 1

Enter Item Name: Snacks

Enter Item No: 384

Enter Price: Rs. 1099

INFORMATION ADDED

For same choice:

IMPLEMENTATION OF STACK USING LINKED LISTS

1. PUSH

140

MRINMAY KUMAR DAS

2. DISPLAY

3. POP

4. EXIT

ENTER YOUR CHOICE: 1

Enter Item Name: Casuals

Enter Item No: 935

Enter Price: Rs. 5099

INFORMATION ADDED

For choice 2:

IMPLEMENTATION OF STACK USING LINKED LISTS

1. PUSH

2. DISPLAY

3. POP

4. EXIT
141

MRINMAY KUMAR DAS

ENTER YOUR CHOICE: 2

DISPLAYING THE INFORMATION

ITEM NAME: Casuals

ITEM NO: 935

COST: Rs. 5099

ITEM NAME: Snacks

ITEM NO: 384

COST: Rs. 1099

For choice 3:

IMPLEMENTATION OF STACK USING LINKED LISTS

1. PUSH

2. DISPLAY

3. POP
142

MRINMAY KUMAR DAS

4. EXIT

ENTER YOUR CHOICE: 3

INFORMATION TO BE DELETED

ITEM NAME: Casuals

ITEM NO: 935

COST: Rs. 5099

DISPLAYING AFTER DELETING:

IMPLEMENTATION OF STACK USING LINKED LISTS

1. PUSH

2. DISPLAY

3. POP

4. EXIT

ENTER YOUR CHOICE: 2


143

MRINMAY KUMAR DAS

DISPLAYING THE INFORMATION

ITEM NAME: Snacks

ITEM NO: 384

COST: Rs. 1099

For choice 3:

IMPLEMENTATION OF STACK USING LINKED LISTS

1. PUSH

2. DISPLAY

3. POP

4. EXIT

ENTER YOUR CHOICE: 3

INFORMATION TO BE DELETED

144

MRINMAY KUMAR DAS

ITEM NAME: Snacks

ITEM NO: 384

COST: Rs. 1099

For same choice:

IMPLEMENTATION OF STACK USING LINKED LISTS

1. PUSH

2. DISPLAY

3. POP

4. EXIT

ENTER YOUR CHOICE: 3

STACK UNDERFLOW
For choice 4:

IMPLEMENTATION OF STACK USING LINKED LISTS

1. PUSH
145

MRINMAY KUMAR DAS

2. DISPLAY

3. POP

4. EXIT

ENTER YOUR CHOICE: 4

Are you sure you want to exit?? (Y/N)Y

-------------------------------Process exited after 85.92 seconds with return value 0


Press any key to continue . . .

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

MRINMAY KUMAR DAS

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:
#include<iostream.h>
#include<conio.h>
#include<string.h>
#define n 5
struct ITEM
{
char Itemname[30];
int Itemno;
float Price;
};
147

MRINMAY KUMAR DAS

ITEM q[n];
int front=-1,rear=-1;
void addq()

//Function to add queue

{
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

MRINMAY KUMAR DAS

}
getch();
}
void delq()

//Function to delete queue

{
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

MRINMAY KUMAR DAS

cout<<q[front].Itemno;
cout<<"\n\nCOST: Rs. ";
cout<<q[front].Price;
front++;
}
}
}
void display()

//Function to display the contents of the queue

{
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

MRINMAY KUMAR DAS

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

//Func call to add queue

break;
case 2: display();

//Func call to display the contents of

the queue
break;
case 3: delq();

//Func to delete queue

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

MRINMAY KUMAR DAS

}
getch();
return 0;
} //end of main
OUTPUT:
For choice 1:

IMPLEMENTATION OF QUEUE USING ARRAYS

1. ADDING QUEUE

2. DISPLAYING QUEUE

3. DELETING QUEUE

4. EXIT

ENTER YOUR CHOICE: 1

Enter Item Name- Television

Enter Item No- 334

Enter Price- Rs. 18999


For same choice:

IMPLEMENTATION OF QUEUE USING ARRAYS


152

MRINMAY KUMAR DAS

1. ADDING QUEUE

2. DISPLAYING QUEUE

3. DELETING QUEUE

4. EXIT

ENTER YOUR CHOICE: 1

Enter Item Name- iPhone

Enter Item No- 203

Enter Price- Rs. 60000


For choice 2:

IMPLEMENTATION OF QUEUE USING ARRAYS

1. ADDING QUEUE

2. DISPLAYING QUEUE

3. DELETING QUEUE

153

MRINMAY KUMAR DAS

4. EXIT

ENTER YOUR CHOICE: 2

ITEM NAME: Television

ITEM NO: 334

COST: Rs. 18999

ITEM NAME: iPhone

ITEM NO: 203

COST: Rs. 60000


For choice 3:

IMPLEMENTATION OF QUEUE USING ARRAYS

1. ADDING QUEUE

2. DISPLAYING QUEUE

3. DELETING QUEUE

4. EXIT

154

MRINMAY KUMAR DAS

ENTER YOUR CHOICE: 3

DATA TO BE DELETED:

ITEM NAME: Television

ITEM NO: 334

COST: Rs. 18999


DISPLAYING AFTER DELETING DATA FROM QUEUE:

IMPLEMENTATION OF QUEUE USING ARRAYS

1. ADDING QUEUE

2. DISPLAYING QUEUE

3. DELETING QUEUE

4. EXIT

ENTER YOUR CHOICE: 2

ITEM NAME: iPhone

155

MRINMAY KUMAR DAS

ITEM NO: 203

COST: Rs. 60000


For choice 4:

IMPLEMENTATION OF QUEUE USING ARRAYS

1. ADDING QUEUE

2. DISPLAYING QUEUE

3. DELETING QUEUE

4. EXIT

ENTER YOUR CHOICE: 4

Are you sure you want exit?? (Y/N)Y

-------------------------------Process exited after 51.15 seconds with return value 0


Press any key to continue . . .

156

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

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

//Func to add queue

{
char Iname[30];
int Ino;
float cost;
cout<<"\n\nEnter the Item Name: ";
cin>>Iname;
cout<<"\n\nEnter the Item No: ";
158

MRINMAY KUMAR DAS

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

//Func to delete queue

{
if(front==NULL)
159

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

cout<<temp->Price;
delete temp;
}
}
}
void display()

//func to display the contents of the queue

{
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

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

IMPLEMENTATION OF QUEUE USING LINKED LISTS

1. ADD QUEUE

2. DISPLAY QUEUE

3. DELETE QUEUE

4. EXIT

ENTER YOUR CHOICE: 1

Enter the Item Name: Geyser

Enter the Item No: 928

Enter the cost: Rs.15000

For same choice:

IMPLEMENTATION OF QUEUE USING LINKED LISTS

1. ADD QUEUE

2. DISPLAY QUEUE

163

MRINMAY KUMAR DAS

3. DELETE QUEUE

4. EXIT

ENTER YOUR CHOICE: 1

Enter the Item Name: Desktop

Enter the Item No: 943

Enter the cost: Rs.25000

For choice 2:

IMPLEMENTATION OF QUEUE USING LINKED LISTS

1. ADD QUEUE

2. DISPLAY QUEUE

3. DELETE QUEUE

4. EXIT

ENTER YOUR CHOICE: 2

Item no: 928


164

MRINMAY KUMAR DAS

Item Name: Geyser

Cost: Rs.15000

Item no: 943

Item Name: Desktop

Cost: Rs.25000
For choice 3:

IMPLEMENTATION OF QUEUE USING LINKED LISTS

1. ADD QUEUE

2. DISPLAY QUEUE

3. DELETE QUEUE

4. EXIT

ENTER YOUR CHOICE: 3

Data to be removed:

ITEM NAME: Geyser


165

MRINMAY KUMAR DAS

ITEM NO: 928

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

ENTER YOUR CHOICE: 2

Item no: 943

Item Name: Desktop

Cost: Rs.25000
For choice 4:

IMPLEMENTATION OF QUEUE USING LINKED LISTS

166

MRINMAY KUMAR DAS

1. ADD QUEUE

2. DISPLAY QUEUE

3. DELETE QUEUE

4. EXIT

ENTER YOUR CHOICE: 4

Are you sure you want to exit?? (Y/N)Y

-------------------------------Process exited after 34.38 seconds with return value 0


Press any key to continue . . .

167

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

#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()

//func to add queue

{
int ino;
char iname[30];
float cost;

if(((front==0) && (rear==n-1))||(front=rear+1))


{
cout<<"\n\nQUEUE IS FULL";
return;
}
else
{
cout<<"\n\nEnter Item Name: ";
cin>>iname;
169

MRINMAY KUMAR DAS

cout<<"\n\nEnter Item No: ";


cin>>ino;
cout<<"\n\nEnter Cost:Rs.";
cin>>cost;
if(rear==-1)
{
front=0;
rear=0;
}
else if(rear==n-1)
rear=0;
else
rear++;
strcpy(q[rear].Itemname,iname);
q[rear].Itemno=ino;
q[rear].Price=cost;
return;
}
}
void delq()

//func to delete queue

{
if(front==-1)
{
cout<<"\n\nQUEUE IS EMPTY";
return;
}
cout<<"\n\nQUEUE TO BE DELETED\n\n";
170

MRINMAY KUMAR DAS

cout<<"\n\nITEM NAME: ";


cout<<q[front].Itemname;
cout<<"\n\nITEM NO: ";
cout<<q[front].Itemno;
cout<<"\n\nCOST: Rs. ";
cout<<q[front].Price;
if(front==rear)
{
front=-1;
rear=-1;
}
else if(front==n-1)
front=0;
else
front++;
}
void display()

//func to display the contents of the queue

{
int i;
if(front==-1)
{
cout<<"\n\nQUEUE IS EMPTY";
return;
}
else
{
if(front<rear)
171

MRINMAY KUMAR DAS

{
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

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

//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:

IMPLEMENTATION OF CIRCULAR QUEUE USING ARRAYS

1. INSERTING

2. DISPLAYING

3. DELETING
174

MRINMAY KUMAR DAS

4. EXIT!!

ENTER YOUR CHOICE: 1

Enter Item Name: Laptop

Enter Item No: 354

Enter Cost:Rs 50000


For choice 2:
IMPLEMENTATION OF CIRCULAR QUEUE USING ARRAYS

1. INSERTING

2. DISPLAYING

3. DELETING

4. EXIT!!

ENTER YOUR CHOICE: 2

TEM NAME: Laptop

ITEM NO: 354


175

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

ITEM NAME: Laptop

ITEM NO: 354

COST: Rs.50000

For choice 3:

IMPLEMENTATION OF CIRCULAR QUEUE USING ARRAYS

1. INSERTING

2. DISPLAYING

3. DELETING

4. EXIT!!

ENTER YOUR CHOICE: 3

QUEUE TO BE DELETED

ITEM NAME: Laptop

ITEM NO: 354

177

MRINMAY KUMAR DAS

COST: Rs. 50000

For choice 4:

IMPLEMENTATION OF CIRCULAR QUEUE USING ARRAYS

1. INSERTING

2. DISPLAYING

3. DELETING

4. EXIT!!

ENTER YOUR CHOICE: 4

Are you sure you want to exit?? (Y/N)Y

-------------------------------Process exited after 41.58 seconds with return value 0


Press any key to continue . . .

PROGRAM 20
PROGRAM STATEMENT:
SQL:
178

MRINMAY KUMAR DAS

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.

Arrange the contents of the table flights in the descending order of


destination.

Increase the tax by 3% for the flights starting from Delhi.

To display Indian airlines flights starting from Mumbai.

To display fno, source, dest, airlines whose fare is less than 10000.

To display the number of airlines.

179

MRINMAY KUMAR DAS

To display maximum and minimum fare of Spice Jet

To display average fare of nonstop flights.

To display number of cities from where the flights are originating.

To delete the flights having more than 4 stops.

EXPECTED INPUT AND OUTPUT:


Input:
1. Enter the data in the column according to the given table in the
database.
Output:
1. Display the data and update thte data as per the queries.
ALGORITHM:
1. Start.
2. Create the database.
3. Enter the data in the table as given.
4. Write the queries and give the output.
5. End.
PROGRAM:
mysql> create database MKD
-> ;
Query OK, 1 row affected (0.02 sec)

mysql> use MKD


Database changed
CREATING TABLE FLIGHTS:
mysql> Create table Flights
-> (
-> FNO varchar(6) Primary Key,
180

MRINMAY KUMAR DAS

-> SOURCE varchar(15),


-> DEST varchar(15),
-> NO_OF_FL int,
-> NO_OF_STOP int
-> );
Query OK, 0 rows affected (0.12 sec)
CREATING TABLE FARES:
mysql> Create table Fares
-> (
-> FNO varchar(6),
-> AIRLINES varchar(15),
-> FARE int,
-> TAX int
-> );
Query OK, 0 rows affected (0.11 sec)
INSERTING DATA IN THE TABLE FLIGHTS:
mysql> Insert into Flights
-> values("IC301","MUMBAI","BANGLORE",3,2);
Query OK, 1 row affected (0.06 sec)

mysql> Insert into Flights


-> values("IC799","BANGLORE","KOLKATA",8,3);
Query OK, 1 row affected (0.01 sec)

mysql> Insert into Flights


-> values("MC101","DELHI","VARANASI",6,0);
Query OK, 1 row affected (0.06 sec)
181

MRINMAY KUMAR DAS

mysql> Insert into Flights


-> values("IC302","MUMBAI","KOCHI",1,4);
Query OK, 1 row affected (0.13 sec)

mysql> Insert into Flights


-> values("AM812","LUCKNOW","DELHI",4,0);
Query OK, 1 row affected (0.06 sec)

mysql> Insert into Flights


-> values("MU499","DELHI","CHENNAI",3,3);
Query OK, 1 row affected (0.06 sec)
INSERTING DATA IN THE TABLE FARES:
mysql> Insert into Fares
-> values("IC301","Indian Airlines",9425,5);
Query OK, 1 row affected (0.06 sec)

mysql> Insert into Fares


-> values("IC799","Spice Jet",8846,10);
Query OK, 1 row affected (0.06 sec)

mysql> Insert into Fares


-> values("MC101","Deccan Airlines",4210,7);
Query OK, 1 row affected (0.03 sec)

mysql> Insert into Fares


-> values("IC302","Jet Airways",13894,5);
182

MRINMAY KUMAR DAS

Query OK, 1 row affected (0.06 sec)

mysql> Insert into Fares


-> values("AM812","Indian Airlines",4500,6);
Query OK, 1 row affected (0.16 sec)

mysql> Insert into Fares


-> values("MU499","Sahara",12000,4);
Query OK, 1 row affected (0.06 sec)
QUERY 1:
mysql> Select FNO,NO_OF_FL
-> From Flights
-> where SOURCE="LUCKNOW";
QUERY 2:
mysql> Select *
-> From Flights
-> ORDER BY DEST DESC;
QUERY 3:
mysql> Update Flights,Fares
-> set TAX=TAX+3
-> where Flights.FNO=Fares.FNO AND SOURCE="DELHI";
Query OK, 2 rows affected (0.08 sec)
QUERY 4:
mysql> Select *
-> From Flights,Fares
-> where Flights.FNO=Fares.FNO AND AIRLINES="Indian Airlines";
QUERY 5:
183

MRINMAY KUMAR DAS

mysql> select Fares.FNO,SOURCE,DEST,AIRLINES


-> From Flights,Fares
-> where Flights.FNO=Fares.FNO AND FARE<10000;
QUERY 6:
mysql> Select count(AIRLINES)
-> From Fares;
QUERY 7:
mysql> Select min(FARE),max(FARE)
-> From Fares
-> where AIRLINES="Spice Jet";
QUERY 8:
mysql> Select avg(FARE)
-> From Flights,Fares
-> where Flights.FNO=Fares.FNO AND NO_OF_STOP=0;
QUERY 9:
mysql> Select count(SOURCE)
-> From Flights;
QUERY 10:

mysql> Delete FROM Flights


-> where NO_OF_STOP>4;
Query OK, 0 rows affected (0.01 sec)
OUTPUT:
FOR QUERY 1:
+-------+-------------------+
| FNO

| NO_OF_FL |

+-------+--------------------+
184

MRINMAY KUMAR DAS

| 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

| AM812 | LUCKNOW | DELHI

| 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

| Indian Airlines | 9425 |

| IC799

| Spice Jet

5 |

| 8846 | 10 |

| MC101 | Deccan Airlines | 4210 | 10 |


| IC302

| Jet Airways

| 13894 |

| AM812 | Indian Airlines | 4500 |


| MU499 | Sahara

| 12000 |

5 |
6 |
7 |

+-----------+----------------------+----------+------+
6 rows in set (0.00 sec)
185

MRINMAY KUMAR DAS

Rows matched: 2 Changed: 2 Warnings: 0


FOR QUERY 4:
+---------+------------+------------+---------------+-------------------+-------+-------------+------+--------+
| FNO | SOURCE
|FARE | TAX |

| DEST |

NO_OF_FL | NO_OF_STOP | FNO| AIRLINES

+-----------+---------------+----------------+---------------+---------+------+-------------+-------+-------+
| IC301 | MUMBAI | BANGLORE |
Airlines |9425 | 5 |

3 |

| IC301

| AM812 | LUCKNOW | DELHI


Airlines |4500 | 6 |

4 |

| AM812 | Indian

+-----------+----------------+---------------+---------+-------+----------+---------------------+-------+------+
2 rows in set (0.00 sec)
FOR QUERY 5:
+---------+-------------+-----------+-------------------+
| FNO | SOURCE | DEST

| AIRLINES

+---------+-------------+-----------+-------------------+
| IC301

| MUMBAI

| IC799

| BANGLORE | KOLKATA

| MC101 | DELHI

| BANGLORE | Indian Airlines |


| Spice Jet

| VARANASI | Deccan Airlines|

| AM812 | LUCKNOW | DELHI

| Indian Airlines |

+-----------+----------------+------------------+--------------------+
4 rows in set (0.39 sec)
FOR QUERY 6:
+-----------------------+
| count(AIRLINES) |
+-----------------------+
186

MRINMAY KUMAR DAS

| 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

MRINMAY KUMAR DAS

| 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

6 rows in set (0.00 sec)


TABLE: FARES
+-----------+----------------------+---------+-------+
| FNO

AIRLINES

| FARE | TAX |

+-----------+----------------------+---------+------+
| IC301

| Indian Airlines | 9425 |

| IC799

| Spice Jet

5 |

| 8846 | 10 |

| MC101 | Deccan Airlines | 4210 | 10 |


| IC302
188

| Jet Airways

| 13894 |

MRINMAY KUMAR DAS

5 |

| AM812 | Indian Airlines | 4500 |


| MU499 | Sahara

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

MRINMAY KUMAR DAS

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

Display information of employees from Mumbai

Display fname, lname and address in ascending order of salary.

Display total salary of employees where total salary is calculated as


salary+comm.

Display maximum salary of salesman.

Display fname and lname of managers.

Count the number of designations given in the organization.

Display number of employees from Chennai.

Display address and city of employees having salary more than


10000.

Display empid of employees who do not have any commission

Display empid, salary and designation in descending order of date of


joining.

Delete the employees who are from Agra.

190

MRINMAY KUMAR DAS

EXPECTED INPUT AND OUTPUT:


Input:
1. Enter the data in the column according to the given table in the
database.
Output:
1. Display the data and update thte data as per the queries.
ALGORITHM:
1. Start.
2. Create the database.
3. Enter the data in the table as given.
4. Write the queries and give the output.
5. End.
PROGRAM:
mysql> create database mkdsql
-> ;
mysql> use mkdsql
Database changed
CREATING TABLE 'Emp':
mysql> Create table Emp
-> (
-> EMPID int,
-> FNAME varchar(15),
-> LNAME varchar(15),
-> ADDRESS varchar(15),
-> CITY varchar(15)
-> );
Query OK, 0 rows affected (0.19 sec)
191

MRINMAY KUMAR DAS

CREATING TABLE 'Sal':


mysql> Create table Sal
-> (
-> EMPID int,
-> SALARY int,
-> COMM int,
-> DESIGNATION varchar(15),
-> DATEOFJ date
-> );
Query OK, 0 rows affected (0.11 sec)
INSERTING DATA IN THE TABLE 'Emp':
mysql> Insert into Emp
-> values(101,"Akash","Singh","M K Nagar","Mumbai");
Query OK, 1 row affected (0.08 sec)

mysql> Insert into Emp


-> values(102,"Bikash","Kumar","K K Nagar","Chennai");
Query OK, 1 row affected (0.05 sec)

mysql> Insert into Emp


-> values(103,"Mohit","Yadav","D K Nagar","Kolkata");
Query OK, 1 row affected (0.09 sec)

mysql> Insert into Emp


-> values(104,"Rohit","Singh","T K Nagar,"Agra");

mysql> Insert into Emp


192

MRINMAY KUMAR DAS

-> values(104,"Rohit","Singh","T K Nagar","Agra");


Query OK, 1 row affected (0.06 sec)

mysql> Insert into Emp


-> values(105,"Aman","Sen","G G Nagar","Mumbai");
Query OK, 1 row affected (0.06 sec)
INSERTING DATA IN THE TABLE 'Sal':
mysql> Insert into Sal
-> values(101,12000,120,"Manager","08/12/12");
Query OK, 1 row affected (0.06 sec)

mysql> Insert into Sal


-> values(102,13500,300,"Manager","06/08/15");
Query OK, 1 row affected (0.07 sec)

mysql> Insert into Sal


-> values(103,8500,500,"Salesman","06/01/01");
Query OK, 1 row affected (0.08 sec)

mysql> Insert into Sal


-> values(104,8000,null,"Clerk","07/09/08");
Query OK, 1 row affected (0.07 sec)

mysql> Insert into Sal


-> values(105,9000,350,"Salesman","07/11/30");
Query OK, 1 row affected (0.07 sec)
QUERY 1:
193

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

| FNAME | LNAME | ADDRESS |


+------------+-----------+---------------+
| Rohit

| 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

MRINMAY KUMAR DAS

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

MRINMAY KUMAR DAS

| 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

| 105 | 9000 | Salesman

| 104 | 8000 | Clerk

| 102 | 13500 | Manager

| 103 | 8500 | Salesman

+---------+----------+----------------+
5 rows in set (0.00 sec)
FOR QUERY 11: (Table after deleting)
+----------+------------+-----------+---------------+------------+
| EMPID | FNAME | LNAME | ADDRESS | CITY

+----------+------------+-----------+---------------+------------+
| 101

| Akash

| Singh

| 102

| Bikash

| Kumar | K K Nagar | Chennai |

198

| M K Nagar | Mumbai|

MRINMAY KUMAR DAS

| 103

| Mohit

| Yadav | D K Nagar | Kolkata |

| 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

| Bikash | Kumar | K K Nagar | Chennai |

| 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

MRINMAY KUMAR DAS

*****************************

200

MRINMAY KUMAR DAS

You might also like