You are on page 1of 66

C++

PRACTICAL
FILE
NAME : ASHAR FATMI

CLASS : XII-A
BOARD ROLL NUMBER :
SCHOOL : BHATNAGAR
INTERNATIONAL
SCHOOL

INDEX
S.No

1.

2.

3.

4.

5.

6.
7.

8.

9.

10.

TOPIC

A program to calculate the


bill and display the info. Of
all customers using
structures.
A program to represent a
complex no. using
structures and perform
mathematical operations on
it.
A program to accept the
name and total marks of 20
students in an array.
A program to assign
streams on basis
percentage marks using
classes
A program to read
telephone directory and
write it on a file.
A program to input student
data base.
A program to read an
integer type, sort it using
bubble sort, and search it
using Binary Search.
A program to read and
apply uppercase vowels,
lowercase vowels,
uppercase consonants,
lowercase consonants.
A program for hospital
registration of patients
using linked lists.
A program to create a

DATE

SIGNATURE/
REMARKS

11.

12.

13.

14.

15.

16.
17.

18.
19.

20.

linked stack and perform


PUSH and POP operations.
A program to create a
linked Queue and perform
addition and deletion
operations.
A menu driven program to
append and display records
in a file.
A menu driven program to
append and delete record
in a file.
A program to create a
linked queue and perform
addition and deletion in the
queue.
A program to create a
linked and perform PUSH
and POP operations in the
queue.
A program in which inputs a
2D array of integers.
A menu driven program to
perform operations on
entered strings.
A program illustrating
function overloading.
A program to manage
Employee database using
SQL.
A program to manage
Student database using
SQL.

1. Declare a structure having following members Customer no. , no. of


units consumed and bill. The bill is to be calculated according to the
following conditions:
Units consumed
For first 100 units
For next 200 units
For next 300 units
Beyond 100 units

#include<iostream.h>
#include<conio.h>
struct billing{
int customer_no[100];
int no_of_units_consumed[10000];
float bill[100]; };
billing bills;
void main()
{
clrscr();
int x;
cout<<"\n Enter Total No. customers:";
cin>>x;
for(int i=0;i<x;i++)
{
cout<<"\nEnter customer No.:";

Tarif
Rs. 0.40 per unit
Rs. 0.50 per unit
Rs. 1 per unit
Rs. 1.50 per unit

cin>>bills.customer_no[i];
cout<<"\n Enter no. of units consumed:";
cin>>bills.no_of_units_consumed[i];
if(bills.no_of_units_consumed[i]<=100)
{ bills.bill[i]=(bills.no_of_units_consumed[i]*.40); }
else
if(bills.no_of_units_consumed[i]>100&&bills.no_of_units_consumed[i]<=3
00)
{ bills.bill[i]=bills.no_of_units_consumed[i]*(.50); }
else
if(bills.no_of_units_consumed[i]>300&&bills.no_of_units_consumed[i]<=6
00)
{ bills.bill[i]=bills.no_of_units_consumed[i]*(.75); }
else
if(bills.no_of_units_consumed[i]>600&&bills.no_of_units_consumed[i]<=7
00)
{ bills.bill[i]=bills.no_of_units_consumed[i]*(1); }
else
if(bills.no_of_units_consumed[i]>1000)
{ bills.bill[i]
=bills.no_of_units_consumed[i]*(1.5); }
}
cout<<"\n\n Customers Directory:";
for(i=0;i<x;i++)
{ cout<<"\n\n Customer No. :"<<bills.customer_no[i]<<"\n\n Number of
Units consumed :"
<<bills.no_of_units_consumed[i]<<"\n\n the bill is :"<<bills.bill[i]; }
getch();
}

OUTPUT

2. Declare a structure to represent a complex number(a digit having real


part and imaginary part). Write a program to add, subtract, multiply
and divide two complex numbers.

#include<iostream.h>
#include<conio.h>
struct complex

{ float real1;
float imag1;
float real2;
float imag2;
};
complex cno;
void main()
{
clrscr();
cout<<"Enter First complex No.:";
cout<<"\nReal Part :";
cin>>cno.real1;
cout<<"\nImaginary part:"<<"i";
cin>>cno.imag1;
cout<<"\n\nEnter Second Complex no.:"<<"\n real part:";
cin>>cno.real2;
cout<<"\n Imaginary part:"<<"i";
cin>>cno.imag2;
cout<<"\n\n The sum of the entered complex nos. is:\t"
<<(cno.real1+cno.real2)<<"+i"<<(cno.imag1+cno.imag2);
cout<<"\n\n The difference b/w the entered complex nos. is\t"
<<(cno.real1-cno.real2)<<"+i"<<(cno.imag1-cno.imag2);
int x=(cno.real1*cno.real2);
int y=(cno.imag1*cno.imag2);
int p=(cno.real1*cno.imag2);
int q=(cno.real2*cno.imag1);
cout<<"\n\n The product of the entered complex nos. is \t"<<(x-y)<<"+i"
<<(p+q);
int r=cno.real2*cno.real2;
int s=cno.imag2*cno.imag2;
cout<<"\n\n The quotient of the two complex numbers
is:\t"<<(x+y)<<"+i"
<<cno.real1*-(cno.imag2)+(cno.imag1*cno.real2)<<"/"<<r+s;
getch();
}

OUTPUT

3. Write a program to accept the name and total marks of 10 students in


an array. Display the names of the students (including marks) securing
the highest and lowest marks using structures.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
struct student
{
char name[20];
int tmarks;
};
student stu;
void main()
{
clrscr();
int max=0;
int y;

char name1;
char name2;
cout<<"Enter information of the students:";
cout<<"\n Enter Maximum marks:";
cin>>y;
int min = y;
for(int i=0;i<10;i++)
{
cout<<"\n\n Enter name of the student:"<<(i+1)<<":";
gets(stu.name);
cout<<"\t Enter total marks scored by the student:";
cin>>stu.tmarks;
if(stu.tmarks>max)
{
max=stu.tmarks;
strcpy("name1","stu.name");
}
if(stu.tmarks<min)
{
min=stu.tmarks;
strcpy("name2","stu.name");
}
}
cout<<"Students information:";
cout<<"\n\n Highest marks are:"<<max<<","<<"secured by:";
cout<<(name1);
cout<<"lowest marks are:"<<min<<","<<"secured by:";
cout<<(name2);
getch();
}

OUTPUT

4. A class Student has three data members and few member functions:
-Name
-Rollno
-Marks
Write a menu driven program:-To create a file
- To print the stream according to the total marks of the students:
96 or more
Computer Science
91-95
Electronics
86-90
Mechanical
81-85
Electrical
76-80
Chemical
71-75
Civil

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class student
{
char name[20][20];
int rno;
char sub[20];
int m1, m2, m3, m4, m5;
float per;
public:
float calcu()
{
float x=(m1+m2+m3+m4+m5)/5;
return(x);
}
void enter();
void display();
};
void student::enter()
{
cout<<"Enter Roll number:";
cin>>rno;
cout<<"Enter name:";
gets(name[30]);
cout<<"Enter marks for 5 subjects:"<<"\n";
cin>>m1>>m2>>m3>>m4>>m5;
per=calcu();

if(per>=96)
{strcpy(sub,"computer science");}
else
if(per>=91&&per<=95)
{strcpy(sub,"Electronics");}
else
if(per>=86&&per<=90)
{strcpy(sub,"Mechanics");}
else
if(per>=81&&per<=85)
{strcpy(sub,"Electrical");}
else
if(per>=76&&per<=80)
{strcpy(sub,"Chemical");}
else
if(per>=71&&per<=75)
{strcpy(sub,"Civil");}}
void student::display()
{
cout<<"Alotted Subject:"<<sub;
}
void main()
{
clrscr();
student stu;
stu.enter();
stu.display();
getch();
}

OUTPUT

5. Write a program to read a telephone directory with name, phone no.


and write it to a file in the form of hi<<name<<your no. is<<phone
no..
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int i;
int x;
char name[20][20];
char phone[20][20];
cout<<"Enter the number of entries you want to make";
cin>>x;
for(i=1;i<=x;i++)
{
cout<<"enter name"<<i<<":";
gets(name[i]);

cout<<"enter phone number:";


gets(phone[i]);
getch();
}
ofstream enter("DIRECTORY.HTM", ios::out);
for(i=1; i<=x;i++)
{ enter<<"hi"<<name[i]<<", your number is"<<phone[i];
getch();
}
enter.close();
getch();
}

OUTPUT

6. Write a program to store data of students registering in BIS adm no.,


name, address, DOB, class and section. For every new registration
assign a roll no. in sequential order. Read this file and display roll no.,
name, class, and section.

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

struct date
{
int dd,mm, yy;
};
class bis
{
private:
int adno, rno, classs;
char name[20], address[30], sec;
date dob;
public:
void accept(int r)
{
rno=r;
cout<<"\n Enter adno";
cin>>adno;
cout<<"\n Enter name";
gets(name);
cout<<"\n Enter class:";
cin>>classs;
cout<<"\n Enter section";
cin>>sec;
cout<<"\n Enter address";
gets(address);
cout<<"Enter date";
cin>>dob.dd>>dob.mm>>dob.yy;
}
void show()
{

cout<<"\n"<<rno<<"\t"<<name<<"\t"<<classs<<"\t"<<sec<<"\t";
}
void getrno()
{
return rno;
}
};
void addrecord()
{
fstream f;
int r;
bis s;
f.open("bis.dat", ios::binary|ios::in|ios::app);
f.seekg(0, ios::end);
f.seekg(f.tellg()-sizeof(s), ios::beg);
f.read((char*)&s, sizeof(s));
r=s.getrno()+1;
s.accept(r);
f.seekp(0, ios::end);
f.write((char*)&s, sizeof(s));
f.close();
}
void showallrecord()
{
ifstream f;
bis s;
f.open("bis.dat", ios::binary);
cout<<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\n Sno\t\tName\t\tClass\t\tSection";

cout<<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
while(f.read((char*)&s, sizeof(s)))
{
s.show();
}
f.close();
}
void main()
{
clrscr();
int op;
do
{ clrscr();
cout<<"\n 1 add";
cout<<"\n 2 Show all";
cout<<"\n 0 Exit";
cout<<"\n Enter choice";
cin>>op;
switch(op)
{
case 1: addrecord();
break;
case 2: showallrecord();
break;
}
getch();
}
while(op!=0);}

OUTPUT

7. Write a menu driven program to:


- Read an integer array
- Sort it using Bubble sort
- Search an element using Binary Search
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
void bsort(int Arr[],int s)
{

int I,J,Temp;
for(I=0;I<s-1;I++)
{
for(J=0;J<(s-1-I);J++)
if(Arr[J]>Arr[J+1])
{
Temp=Arr[J];
Arr[J]=Arr[J+1];
Arr[J+1]=Temp;
}
}
}
int bsearch(int Arr[],int s)
{
int lb,ub,mid,item;
lb=0;
ub=s-1;
cout<<"\nEnter the value of search:";
cin>>item;
while(lb<=ub)
{
mid=(lb+ub)/2;
if(Arr[mid]==item)
return(mid);
else if(Arr[mid]>item )
ub=mid-1;
else
lb=mid+1;
}
return(-1);
}
int main()
{
int a[20],i,n;
cout<<"\nEnter number of element :";
cin>>n;
cout<<"\nEnter an element of an array:";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\nBefore sorting:";
for(i=0;i<n;i++)
cout<<" "<<a[i];
bsort(a,n);

cout<<"\nAfter sorting";
for(i=0;i<n;i++)
cout<<" "<<a[i];
cout<<"search position:";
cout<<bsearch(a,n);
return 0;
}

OUTPUT

8. Write a menu driven program to:


- Read the file and display uppercase vowels, lowercase vowels,
uppercase consonants, lowercase consonants.

#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
void main()
{
clrscr();

int n,j;
fstream ofile,afile;
char str[100];
char ch,ch1;
do
{
cout<<"\n\t1.Create Text\n\t2.Read from File\n\t3.create another
file";
cout << "\n 4.Exit ";
cin>>ch;
switch(ch)
{
case '1' :
ofile.open("smp.txt",ios::out);
cout<<"\n Enter The Text ";
gets(str);
ofile<<str;
ofile.close();
break;
case '2' :
char tmp1;
afile.open("smp.txt",ios::in);
while(!afile.eof())
{
afile.get(tmp1);
if(isalpha(tmp1))
{
if (islower(tmp1))
{
if (tmp1=='a'||tmp1=='e'||tmp1=='i'||
tmp1=='o'||tmp1=='u')
cout << "\n Lower case vowel "<<tmp1;
else

cout<<"\n Lower case consonants "<<tmp1;


}
if (isupper(tmp1))
{
if (tmp1=='A'||tmp1=='E'||tmp1=='I'||
tmp1=='O'||tmp1=='U')
cout << "\n Upper case vowel "<<tmp1;
else
cout<<"\n Upper case consonants "<<tmp1;
}
}
}
afile.close();
break;
case '3' :

ofile.open("smp.txt",ios::in);

afile.open("smp1.txt",ios::out);
char c;
while(ofile)
{
ofile.get(c);
c = tolower(c);
if (c=='a'||c=='i'||c=='e'||c=='o'||c=='u')
afile.put(c);
}
ofile.close();
afile.close();
case '4' : exit(0);
}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');

getch();
}

OUTPUT

9. Create a linked list of hospital registration of patients:


- Perform addition of new patient at the end of linked list.
- Show update based on registration number.

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

struct node
{
int regno;
char pat[20];
node*next;
} *start, *newptr, *save, *ptr, *rear, pn;
void display(node*);
void insert(node*);
void main()
{
clrscr();
start=rear=NULL;
int reg;
char name[20];
char ch='y';
while(ch=='y'||ch=='Y')
{
cout<<"Enter the information for a new patient:"<<"\n"<<"Enter
Registration no.";
cin>>pn.regno;
cout<<"\n"<<"Enter name:";
gets(pn.pat);
newptr=&pn;
insert(newptr);
cout<<"press Y to enter more node, N to exit";
cin>>ch;
}
cout<<"The list is now"<<"\n";
display(start);
char ans;
int rno;
char nm[20];
cout<<"Wabt to Update list:";
cin>>ans;
if(ans=='y'||ans=='Y')
{
cout<<"Enter reg. no. of patient:";
cin>>regno;
while(newptr!=NULL)
{
if(newptr->regno==rno)
{
cout<<"Enter new name:";

gets(nm);
strcpy(newptr->pat,nm);
newptr=newptr->next;
}
}
cout<<"Now the list is:";
display(start);
}
getch();
}
void insert(node*)
{
if(start==NULL)
{ start=rear=newptr;}
else
{ rear->next=newptr;
rear=newptr;
rear->next=NULL;
}
}
void display(node*np)
{
while(np!=NULL)
{
cout<<"\n"<<np->regno<<". ";
cout.write(np->pat,20);
np=np->next;
}
cout<<"!!!\n";
}

OUTPUT

10.

Create a linked stack and perform push and pop operations.

#include<iostream.h>
#include<stdlib.h>
#include<process.h>
struct node

{
int info;
node*next;
} *top, *newptr, *save, *ptr;
node *create_new_node(int);
void push(node*);
void display(node*);
void main()
{
clrscr();
int inf;
char ch='y';
top=NULL;
while(ch=='y'||ch=='Y')
{
cout<<"Enter the information for the new node";
cin>>inf;
newptr=create_new_node(inf);
if(newptr==NULL)
{
cout<<"cannot create new node....aborting!!";exit(1);
}
push(newptr);
cout<<"now the linked stack is";
display(top);
cout<<"press Y to enter more node, N to exit";
cin>>ch;
}
getch();
}
node*create_new_node(int n)
{
ptr=new node;
ptr->info=n;
ptr->next=NULL;
return ptr;
}
void push(node*np)
{
if(top==NULL)top=np;
else
{
save=top;
top=np;

np->next=save;
}
}
void display(node*np)
{
while(np!=NULL)
{
cout<<np->info<<"->";
np=np->next;
}
cout<<"!!!";
}

OUTPUT

11.
Create a linked queue and perform addition and deletion
operations.
#include<iostream.h>
#include<process.h>
struct node
{ int info;
node*next;
} *front, *newptr, *save, *ptr, *rear;
node*create_new_node(int);
void insert(node*);
void display(node*);

void delnode_q();
void main()
{
front=rear=NULL;
int inf;
char ch='y';
while(ch=='y'||ch=='Y')
{
cout<<"Enter the information for a new node";
cin>>inf;
newptr=create_new_node(inf);
if(newptr==NULL)
{
cout<<"Cannot create new node....aborting!!";exit(1);}
insert(newptr);
cout<<"press Y to enter more node, N to exit";
cin>>ch;
}
}
system("cls")
do
{
cout<<"\n The linked queue is:";
display(front);
cout<<"Want to delete first node?(y/n)";
cin>>ch;
if(ch=='y'||ch=='Y')
delnode_q();
}
while(ch=='y'||ch=='Y');
}
node*create_new_node(int n)
{
ptr=new node;
ptr->info=n;
ptr->next=NULL;
return ptr;
}
void insert(node*np)
{
if(front==NULL)

{front=rear=np;}
else
{
rear->next=np;
rear=np;
}
}
void delnode_q()
{
if(font==NULL)cout<<"Underflow!!!";
else
{
ptr=front;
front=front->next;
delete ptr;
}
}
void display(node*np)
{
while(np!=NULL)
{
cout<<np->info<<"->";
np=np->next;
}
cout<<"!!!";
}

OUTPUT

12.
-

Declare a class containing:


Name
Address
Telephone no.

Write a menu driven program to:


-

Append record in a file.


Display the name and address for the given telephone number

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<iomanip.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
class telephone;
void display();
void append();
int main()
{
int x;
char ch='y';
while(ch=='y')
{
clrscr();
cout<<"....WELCOME TO THE MENU...";
cout<<"\nPress 1 to APPEND record :";
cout<<"\nPress 2 to DISPLAY record :";
cout<<"\nPress any key to EXIT :";
cin>>x;
switch(x)
{
case 1: append();
break;
case 2: display();
break;
default: cout<<"\n....SYSTEM EXITING....";
break;
}
cout<<"\nTo go to MAIN MENU, PRESS Y :";
cout<<"\nTo EXIT, Press any key :";
cin>>ch;
}
return 0;
}
class telephone
{
char name[50];
char address[50];
int tele;
public:

void getdata()
{
cout<<"\nPlease enter your NAME :";
gets(name);
cout<<"\nPlease enter your ADDRESS :";
gets(address);
cout<<"\nPlease enter your TELEPHONE NUMBER :";
cin>>tele;
}
void showdata()
{
cout<<"\nNAME :"<<name<<endl;
cout<<"\nADDRESS :"<<address<<endl;
cout<<"\nTELEPHONE NUMBER :"<<tele<<endl;
}
int gettele()
{
return tele;
}
};
void append()
{
clrscr();
telephone te;
ofstream file;
file.open("tele database", ios::binary|ios::app);
char ch='y';
while(ch=='y')
{
te.getdata();
file.write((char*)&te, sizeof(te));
cout<<"\nPress key Y to enter more data :";
cout<<"\nPress any other key to EXIT :";
cin>>ch;
}
file.close();
}
void display()
{
clrscr();
int x;
cin>>x;
char found='n';
telephone te;
ifstream file;
cout<<"\nPlease enter the TELEPHONE NUMBER :";

cin>>x;
file.open("tele databse", ios::in|ios::binary);
file.seekg(0);
while(!file.eof())
{
file.read((char*)&te, sizeof(te));
if(filee.eof())
{
break;
}
if((te.gettele())==x)
{
te.showdata();
found='y';
}
}
if(found=='n')
cout<<"\nFile not found :";
file.clear();
file.close();
}

OUTPUT

13.
Declare a class students having sno, sname, fees and required
functions. Write a ,menu driven program to:
- Append record in a file
- Delete record for given serial no.
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdlib.h>
#include<stdio.h>
class student;
void append();
void dele();

int main()
{
int x;
char ch='y';
while(ch=='y')
{
cout<<"....WELCOME TO STUDENT DATABASE PROGRAM....";
cout<<"\nPress 1 to APPEND a record :";
cout<<"\nPress 2 to DELETE a record :";
cout<<"\nPress another to EXIT :";
cin>>x;
switch(x)
{
case 1: append();
break;
case 2: dele();
break;
default : cout<<"\n....SYSTEM EXITING....";
break;
}
cout<<"\nPress Y to go to MAIN MENU :";
cout<<"\nPress another key to EXIT :";
cin>>ch;
}
return 0;
}
class student
{
char sname[50];
int sno;
float fee;
public:
void getdata()
{
cout<<"\nPlease enter your ROLL NUMBER :";
cin>>sno;
cout<<"\nPlease enter your NAME :";
gets(sname);
cout<<"\nPlease enter student's FEES :";
cin>>fee;
}
void showdata()
{
cout<<"\nROLL NUMBER :"<<sno<<endl;
cout<<"\nNAME :"<<sname<<endl;
cout<<"\nFEES :"<<fee<<endl;

}
int getsno()
{
return sno;
}
};
void append()
{
student stu;
ofstream file;
file.open("Student database", ios::out|ios::app|ios::binary);
char ch='y';
while(ch=='y')
{
stu.getdata();
file.write((char*)&stu, sizeof(stu));
cin>>ch;
}
file.close();
}
void dele()
{
clrscr();
student stu;
int x;
cout<<"\nEnter the SNO to DELETE record";
cin>>x;
ifstream fin;
ofstream fout;
fin.open("Student database", ios::binary|ios::in);
fin.seekg(0);
fout.open("temp",ios::out|ios::binary);
fout.seekp(0);
char ch;
while(!fin.eof())
{
fin.read((char*)&stu, sizeof(stu));
if(fin.eof())
{
break;
}
if((stu.getsno())==x)
{
cout<<"\nRecord is found";
stu.showdata();
cout<<"\nPress Y to DELETE record :";

cin>>ch;
if(ch!='Y'&&ch!='y')
{
fout.write((char*)&stu, sizeof(stu));
}
found = 'y';
}
if((stu.getsno())!==x)
{
fout.write((char*)&stu, sizeof(stu));
}
}
if(found=='y')
cout<<"\nRecord is FOUND and DELETED";
else
cout<<"\nNO RECORD EXISTS";
fin.close();
fout.close();
remove("Student database");
rename("temp", "Student database");
}

OUTPUT

14.
-

Each node of a queue contains:


Eno
Salary
Pointer field

Front is the first node of the queue and rear is the last node. Write a
menu driven program to:
-

Add elements in the queue


Delete elements from the queue

#include<conio.h>
#include<iostream.h>
#include<process.h>
#include<malloc.h>
struct node
{
int Eno;
float salary;
struct node *next;
};
class queue
{
struct node *frnt,*rear;
public:
queue()
{
frnt=rear=NULL;
}
void insert();
void del();
void show();
};
void queue::insert()
{
int Emno,sal;
struct node *ptr;
cout<<"Enter new employee no: ";
cin>>Emno;
cout<<"Enter new employee salary: ";
cin>>sal;
ptr=new node;
ptr->Eno=Emno;
ptr->salary=sal;
ptr->next=NULL;
if(frnt==NULL)
frnt=ptr;
else
rear->next=ptr;
rear=ptr;
cout<<"\nNew employee no. and salary is inserted to the Queue!!!";
getch();
}

void queue::del()
{
if(frnt==NULL)
{
cout<<"\nQueue is empty!!";
getch();
return;
}
struct node *temp;
temp=frnt;
frnt=frnt->next;
cout<<"\nDeletion Operation........\nDeleted value is "<<temp>Eno<<endl;
delete temp;
getch();
}
void queue::show()
{
struct node *ptr1=frnt;
if(frnt==NULL)
{
cout<<"The Queue is empty!!";
getch();
return;
}
cout<<"\nThe Queue is:\n";
while(ptr1!=NULL)
{
cout<<"\nEmployee No: "<<ptr1->Eno<<endl;
cout<<"Salary: "<<ptr1->salary;
ptr1=ptr1->next;
}
getch();
}
// Main function
int main()
{
queue q;
int choice;
while(1)
{
cout<<"\n-----------------------------------------------------------";
cout<<"\n\t\tQUEUE USING LINKED LIST\n\n";

cout<<"1:INSERTION\n2:DELETION\n3:DISPLAY QUEUE\n4:EXIT";
cout<<"\nEnter your choice(1-4): ";
cin>>choice;
switch(choice)
{
case 1:
q.insert();
break;
case 2:
q.del();
break;
case 3:
q.show();
break;
case 4:
exit(0);
break;
default:
cout<<"Please enter correct choice(1-4)!!";
getch();
break;
}
}
return 0;
}

OUTPUT

15.
-

Each node of a stack contains:


Rollno
Age

Pointer field
Top is the first node of the stack. Write a menu driven program to:
Push an element
Pop an element

#include<iostream.h>
#include<stdlib.h>
#include<malloc.h>
#include<conio.h>
struct node{
int rollno,age;
struct node *next;
};
class stack{
struct node *top;
public:
stack();
void push();
void pop();
void display();
};
stack::stack()
{
top = NULL;
}
void stack::push()
{
int rollnumber,age1;
struct node *p;
if((p=new node)==NULL)
{
cout<<"Memory Exhausted";
exit(0);
}
cout<<"Enter a roll Number to insert:";
cin>>rollnumber;
cout<<"\nEnter the age of the student:";
cin>>age1;
p = new node;
p->rollno = rollnumber;
p->age=age1;
p->next = NULL;
if(top!=NULL){
p->next = top;

}
top = p;
cout<<"\nNew roll number and age are inserted"<<endl;
}
void stack::pop()
{
struct node *temp;
if(top==NULL)
{
cout<<"\nThe stack is Empty"<<endl;
}
else
{
temp = top;
top = top->next;
cout<<"\nThe value popped is: "<<endl;
cout<<"Roll No: "<<temp->rollno<<endl;
cout<<"Age: "<<temp->age<<endl;
delete temp;
}
}
void stack::display()
{
struct node *p = top;
if(top==NULL)
{
cout<<"\nNothing to Display\n";
}
else
{
cout<<"\nThe contents of Stack\n";
while(p!=NULL){
cout<<"Roll No: "<<p->rollno<<endl;
cout<<"Age: "<<p->age<<endl<<endl;
p = p->next;
}
}
}
int main()
{
clrscr();
stack s;
int choice;
do{
cout<<"\nSTACK IMPLEMENTATION";

cout<<"\n1. PUSH\n2. POP\n3. DISPLAY\n4. EXIT\n";


cout<<"\nEnter your choice: ";
cin>>choice;
switch(choice){
case 1:
s.push();
break;
case 2:
s.pop();
break;
case 3:
s.display();
break;
case 4:
exit(0);
break;
default:
cout<<"Invalid Choice please enter valid choice";
break;
}
}while(choice);
getch();
return 0;
}

OUTPUT

16.
Write a program to accept a 2D array of integers and its size as
arguments and displays elements which are exactly two digit numbers.
#include<conio.h>

#include<iostream.h>
#include<process.h>
#include<conio.h>
int main()
{
clrscr();
int row,col,i,j;
int arr[2][2];
cout<<"ARRAY INPUT\n";
cout<< "enter the no. of row: \n ";
cin>>row;
cout<<"enter the no. of coloum: ";
cin>>col;
cout<<"enter the array elemet:\n";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cin>>arr[i][j];
}
}
cout<<"entered array is:\n";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cout<<"\t"<<arr[i][j];
}
cout<<"\n";
}
cout<<"element in array which are exactly 2 digit\n";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(arr[i][j]>9 && arr[i][j]<100)
{
cout<<"\t"<<arr[i][j];
}
}
}
getch();
return 0;
}

OUTPUT

17.
Write a menu driven program to perform the following operations
on a string without using inbuilt functions:
- Find the length
- Compare two strings
- Concatenate two strings

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class string
{
private:
char a[40], b[40], c[80];
public:
void findlength();
void compare();
void concatenate();
};
void string::findlength()
{
cout<<"\n Enter string";
gets(a);
int i=0;
while(a[i]!='\0')
{
i++;
}
cout<<"the length of the given string is"<<i;
}
void string::concatenate()
{
cout<<"Enter first string:";
gets(a);
cout<<"\nEnter second string:";
gets(b);
int j=0;
for(int i=0;a[i]!='\0';++i)
{
c[j++]=a[i];
}
for(i=0;b[i]!='\0';++i)
{
c[j++]=b[i];
}
c[j]='\0';
cout<<"\nThe concatenate string is"<<c;
}

void string::compare()
{
int c, i=0;
cout<<"\n ENTER THE STRING 1:";
cin>>a;
cout<<"\n ENTER THE STRING 2:";
cin>>b;
while(a[i]!='\0'&&b[i]!='\0')
{
if(a[i]==b[i])
{
c=1;
}
else
{
c=0;
break;
}
i++;
}
if(c==1&&a[i]=='\0'&&b[i]=='\0')
{
cout<<"\n\n THE GIVEN TWO STRINGS ARE ONE & SAME";
}
else
{
cout<<"\n NOT SAME";
}
}
void main()
{ int op;
string s;
do
{ clrscr();
cout<<"\n 1 FIND LENGTH";
cout<<"\n 2 COMPARE";
cout<<"\n 3 CONCATENATE";
cout<<"\n 0 EXIT";
cout<<"\n ENTER";
cin>>op;
switch(op)
{
case 1: s.findlength();
break;
case 2: s.compare();

break;
case 3: s.concatenate();
break;
}
getch();
}while(op!=0);
}

OUTPUT

18.

Write a program to illustrate working of function overloading,

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void amount(float princ, int time, float rate)
{
cout<<"\nPrincipal Amount:"<<princ;
cout<<"\tTime:"<<time<<"years";
cout<<"\tRate:"<<rate;
cout<<"\nInterest Amount:"<<(princ*time*rate)<<"\n";
}
void amount(float princ, int time)
{
cout<<"\nPrincipal amount:"<<princ;
cout<<"\tTime:"<<time<<"years";
cout<<"\tRate : 0.08";
cout<<"\nInterest amount:"<<(princ*time*0.08)<<"\n";
}
void amount(float princ, float rate)
{ cout<<"\nPrincipal amount:"<<princ;
cout<<"\tTime : 2 years";
cout<<"\tRate:"<<rate;
cout<<"\nInterest amount:"<<(princ*2*rate)<<"\n";
}
void amount(int time, float rate)
{ cout<<"\nPrincipal amount : 2000";
cout<<"\tTime:"<<time<<"years";
cout<<"\tRate:"<<rate;
cout<<"\nInterest amount:"<<(2000*time*rate)<<"\n";
}
void amount(float princ)
{ cout<<"\nPrincipal amount:"<<princ;
cout<<"\tTime : 2 years";
cout<<"\tRate : 0.08";
cout<<"\nInterest amount:"<<(princ*2*0.08)<<"\n";
}
void main()
{ system("cls");
cout<<"case 1";
amount(2000.0F);
cout<<"case 2";
amount(2500.0F, 3);
cout<<"case 3";
amount(2300.0F, 3, 0.11F);

cout<<"case 4";
amount(2, 0.12F);
cout<<"case 5";
amount(6, 0.07F);
getch();
}

19.
-

OUTPUT

Create a table in SQL with the name employees


Insert two records in the table employees
Fields as Empno, Deptno, Empname, Job and Manager

20.
-

List Empname and Deptname for all the employees sorted by


Empno.
Count the total number of departments in the organization

Create a table in SQL with the name Students:


Fields as Rollno, Name, Age, Gender, Marks

Set Rollno as primary key


Enter two records in the table
Count the number of boys in the class
Display Rollno and Name of all the students whose age is less than
18 years.

THE END