Practical 17-18
Practical 17-18
#include<iostream.h>
#include<conio.h>
class Ticbooth
{
private:
int No_of_People;
float Amount;
public:
Ticbooth()
{
No_of_People=0;
Amount=0.0;
}
void IncrPeople(int n)
{
No_of_People += n;
}
void IncrAmount(int n)
{
Amount += 2.5*n;
}
void DisplayAll()
{
cout<<"\nTotal No of People Visiting: "
<<No_of_People
<<"\nTotal Amount Collected: "
<<Amount;
}
void DispTickets()
{
cout<<"\nNo. of People Who Paid: "<<Amount/2.50;
}
};
void main()
{
Ticbooth obj;
int choice,n;
char ch;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU";
cout<<"\n1. Increment Data";
cout<<"\n2. Display Data";
cout<<"\n3. Exit";
cout<<"\nEnter Your Choice(1-3): ";
cin>>choice;
switch(choice)
{
case 1: cout<<"How Many People: ";
cin>>n;
obj.IncrPeople(n);
cout<<"Did They Pay(Y/N): ";
cin>>ch;
if(ch=='y'||ch=='Y'0029
obj.IncrAmount(n);
break;
case 2: clrscr();
cout<<"\t\t\t\tMenu";
cout<<"\n1. Display All";
cout<<"\n2. Display People Paying";
cout<<"\nEnter your choice(1-2): ";
cin>>ch;
if(ch=='1')
obj.DisplayAll();
else obj.DispTickets();
getch();
break;
case 3: cout<<"Exitting";
getch();
break;
}
}while(choice!=3);
getch();
}
Cscience_3 /8: Define a class to represent batsmen in a cricket team.
Include the following members:
Data members :
First name
Last name
Runs made
Number of fours
Number of sixes
Member Functions :
To assign the initial values
To update runs made
(It should simultaneously update fours and sixes, if required)
To display the batsmans information.
Make 11 objects to represent a team.
Make a menu with following options.
1. Assign the basic values to all of the team members.
2. Update the information of any batsman on the basis of his first
name
3. Display the information of any batsman on the basis of his first
name
4. Quit
Solution 3
#include<iostream.h>
#include<conio.h>
#include<string.h>
class Batsman
{
private:
char Fname[10], Lname[10];
int Runs, Fours, Sixes;
public:
void Initialize()
{
cout<<"\n Enter First Name: ";
cin>>Fname;
cout<<"Enter Last Name: ";
cin>>Lname;
cout<<"Enter Number Of Runs Scored: ";
cin>>Runs;
cout<<"Enter Fours Hit: ";
cin>>Fours;
cout<<"Enter Sixes Hit: ";
cin>>Sixes;
}
void Update()
{
int x;
cout<<"How Many Runs Scored: ";
cin>>x;
Runs = Runs + x;
cout<<"How Many Fours Hit: ";
cin>>x;
Fours = Fours + x;
cout<<"How Many Sixes Hit: ";
cin>>x;
Sixes = Sixes + x;
}
void Display()
{
cout<<"\nName: "<<Fname<<" "<<Lname
<<"\nRuns: "<<Runs
<<"\nFours: "<<Fours
<<"\t Sixes: "<<Sixes;
getch();
}
char* Return()
{ return (Fname); }
};
void main()
{
Batsman Team[11];
int choice;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU"
<<"\n1. Assign Values" <<"\n2. Update Values"
<<"\n3. Display Info"
<<"\n4. Quit"
<<"\nEnter Your Choice(1-4): ";
cin>>choice;
switch(choice)
{
case 1: clrscr();
for(int i=0;i<11;i++)
{
cout<<"Enter Details Of Batsman "<<i+1;
Team[i].Initialize();
}
break;
case 2: clrscr();
char Name[10];
cout<<"Enter First Name Of Batsman Whose Details Are
To
Be Updated: ";
cin>>Name;
for(i=0;i<11;i++)
if(strcmpi(Name,Team[i].Return())==0)
{
Team[i].Update();
break;
}
break;
case 3: clrscr();
cout<<"Enter First Name Of Batsman Whose Details Are
To Be Viewed: ";
cin>>Name;
for(i=0;i<11;i++)
if(strcmpi(Name,Team[i].Return())==0)
{
Team[i].Display();
break;
} break;
case 4: cout<<"Exitting";
getch();
break;
}
}while(choice!=4);
}
Cscience_4 /9 Write a menu-driven program in C++ to calculate the
volume of following shapes-
Volume of a cube
Volume of a box
Volume of a sphere.
Quit
Make this program with the help of a class shape with following-
Member data:
p1 (type float)
p2 (type float)
p3 (type float)
volume (type float)
Member Functions:
To input data members (Input as many as required)
To calculate volume of various shapes (must be overloaded)
To display the volume.
Solution 4
#include<iostream.h>
#include<conio.h>
class Shape
{
private:
float P1, P2, P3;
float Volume;
public:
void Vol(int i)
{
switch(i)
{
case 1: Volume = P1*P1*P1;
break;
int i;
cin>>i;
switch(i)
{
case 1:
case 2:
case 3: S.Input(i); break;
case 4: cout<<"Exitting";
break;
}
getch();
}
Cscience_5/10: Imagine a publishing company that markets both books
and audio cassette versions of its works. Create a class Publication that
stores the title (a string) and price (type float) of a publication. From this
class derive two classes: book, which adds a page count (type int); and
tape, which adds a playing time in minutes (type float). Each of these
three classes should have a get data() function to get its data from the
user at the keyboard, and a put data() function to display its data.
Write a main () program to test the book and tape classes by creating
instances of them asking the user to fill in their data with get data(), and
then displaying the data with putdata().
Solution 5
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Publication
{
private:
char Title[20];
float Price;
public:
void Getdata()
{
cout<<"Enter Title: ";
gets(Title);
cout<<"Enter Price: ";
cin>>Price;
}
void Putdata()
{
cout<<"\nTitle: "<<Title
<<"\nPrice: "<<Price;
} };
Member Functions:
1. To input employee detail
(name, code and basic)
2. To calculate following
Code Da Hra
1 50% of basic 30% of basic
2 40% of basic 25% of basic
Any other 30% of basic 20% of basic
Solution 6
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Employee
{
private:
char Emp_Name[20];
int Emp_Code;
unsigned Basic;
unsigned DA;
unsigned HRA;
unsigned Tot_Salary;
void Calculate();
public:
Employee()
{ Tot_Salary = 0; }
void Input();
Employee Compare(Employee);
void Display();
unsigned Return() { return this->Tot_Salary; }
};
void Employee::Calculate()
{
switch(Emp_Code)
{
case 1: DA = Basic * 0.5;
HRA = Basic * 0.3;
break;
clrscr();
cout<<"\nThe Employee Having Highest Salary Is ";
cout<<"\nEmloyee's Name: "<<Emp_Name
<<"\nEmloyee's Code: "<<Emp_Code
<<"\nBasic: "<<Basic
<<"\nDA: "<<DA
<<"\nHRA: "<<HRA
<<"\nTotal Salary: "<<Tot_Salary;
}
void main()
{
clrscr();
Employee Emp[5], High;
cout<<"\nEnter Details Of 5 Employees: \n";
for(int i=0;i<5;i++)
{
cout<<"Enter Record#"<<i+1;
Emp[i].Input();
clrscr();
}
for(i=0;i<4;i++)
High = Emp[i].Compare(High);
High.Display();
getch();
}
Cscience_7/12:
Write a program in C++ with the help of class array_search with
following members-
Member data :
An array ar of integer with 20 elements
No .of elements actually used by user (int n)
Member Functions-
1. To input n, and n number of elements
2. Linear search
3. Binary search (If array is in ascending order)
4. To display n elements of the array
Make a menu in C++ with following options-
1. Array Input
2. Linear Search
3. Binary Search
4. Array display
6. Quit
Solution 7
#include<iostream.h>
#include<conio.h>
class Array_Search
{
int arr[20];
unsigned int n;
public:
void Input();
void Linear_search(int);
void Binary_search(int);
void Display();
};
void Array_Search::Input()
{
cout<<"Input Number Of Elements(max-20): ";
cin>>n;
if(n>20)
{
cout<<"Error"
<<"\nEnter A Valid Value";
return;
}
else
cout<<"Enter The Elements: ";
for(int i=0;i<n;i++)
cin>>arr[i];
}
void Array_Search::Display()
{
cout<<"The Array Is ";
for(int i=0;i<n;i++)
cout<<arr[i]<<" ";
}
void main()
{
Array_Search obj;
int ch,item;
do
{
clrscr();
cout<<"\t\t\t\tMain Menu"
<<"\n1. Array Input"
<<"\n2. Linear Search"
<<"\n3. Binary Search"
<<"\n4. Array Display"
<<"\n5. Exit"
<<"\nInput Your Choice: ";
cin>>ch;
switch(ch)
{
case 1: obj.Input();
getch();
break;
case 2: obj.Display();
cout<<"Enter item To Be Searched: ";
cin>>item;
obj.Linear_search(item);
getch();
break;
case 3: obj.Display();
cout<<"Enter item To Be Searched: ";
cin>>item;
obj.Binary_search(item);
getch();
break;
case 4: obj.Display();
getch();
break;
case 5: cout<<"Exitting";
getch();
break;
}
}while(ch!=5);
}
class Student
{
char Name[20];
int RollNo;
int Marks;
public:
void Display();
void Input();
int Return()
{
return RollNo;
}
};
void Student::Display()
{
cout<<"\n Roll No: "<<RollNo
<<"\n Name: "<<Name
<<"\nMarks: "<<Marks;
}
void Student::Input()
{
fflush(stdin);
cout<<"Enter Roll No.: ";
cin>>RollNo;
cout<<"Enter Name: ";
gets(Name);
cout<<"Enter Marks: ";
cin>>Marks;
}
void main()
{
int ch,i=0,j=0,flag=0;
char ch2,ch1;
Student Obj;
fstream file("Stud.dat",ios::in|ios::app|ios::binary);
do
{
clrscr();
cout<<"\t\t\t\tMain Menu"
<<"\n1. Add Records
<<"\n2. Display All Records"
<<"\n3. Display Single Record"
<<"\n4. Quit"
<<"\nEnter Your Choice: ";
cin>>ch;
switch (ch)
{
case 1:
ofstream fout;
fout.open("Stud.dat",ios::app|ios::binary);
do
{
i++;
cout<<"Enter Record#"<<i<<"\n";
fflush(stdin);
Obj.Input();
fout.write((char*)&Obj,sizeof(Obj));
cout<<"Enter Another Record(1/2): ";
fflush(stdin);
cin>>ch2;
} while(ch2=='1');
fout.close();
break;
case 3:
ifstream finn;
finn.open("Stud.dat",ios::in|ios::binary);
finn.seekg(0);
int Roll;
cout<<"Enter Roll No. of Record To Be
Viewed: ";
fflush(stdin);
cin>>Roll;
while(!finn.eof())
{
finn.read((char*)&Obj,sizeof(Obj));
if(Obj.Return()==Roll)
{
Obj.Display();
getch();
flag=1;
break;
}
} if (flag==0)
cout<<"Record Is Not There in List";
getch();
finn.close();
break;
Member Functions-
1. To input n, and n number of elements
2. To insert an item in the array if array is in ascending order
1. To delete an item from the array
2. To display n elements of the array
Make a menu in C++ with following options-
1. Array Input
2. Insertion
3. Deletion
4. Array display
6. Quit
#include<iostream.h>
#include<conio.h>
class Array_Update
{
private:
int *Arr, N;
public:
void Input();
void Insertion();
void Deletion();
void Display();
};
void Array_Update::Input()
{
cout<<"Enter Size Of Array: ";
cin>>N;
Arr=new int[N];
cout<<"Enter Array: \n";
for(int i=0;i<N;i++)
cin>>Arr[i];
}
void Array_Update::Insertion()
{
int pos,item;
cout<<"Enter The Element To Be Inserted: ";
cin>>item;
if(Arr[0]>item)
pos=0;
else
for(int i=0;i<N-1;i++)
if(Arr[i]<=item && Arr[i+1]>item)
{
pos=i+1;
break;
}
else
pos=N-1;
for(i=N;i>pos;i--)
Arr[i]=Arr[i-1];
Arr[pos]=item;
N++;
}
void Array_Update::Deletion()
{
int pos=-1,item;
cout<<"Enter The Element To Be Deleted: ";
cin>>item;
for(int i=0;i<N;i++)
if(Arr[i]==item)
pos=i;
if(pos==-1)
{
cout<<"Element Does Not Exist In The List";
getch();
return;
}
else
for(i=pos;i<N-1;i++)
Arr[i]=Arr[i+1];
Arr[N-1]=0;
N--;
}
void Array_Update::Display()
{
cout<<"The Array Is\n";
for(int i=0;i<N;i++)
cout<<Arr[i]<<" ";
getch();
}
void main()
{
Array_Update Obj;
int choice;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU"
<<"\n1. Array Input"
<<"\n2. Insertion"
<<"\n3. Deletion"
<<"\n4. Array Display"
<<"\n5. Quit"
<<"\nEnter Your Choice(1-5): ";
cin>>choice;
switch(choice)
{
case 1: clrscr();
Obj.Input();
break;
case 2: clrscr();
Obj.Insertion();
break;
case 3: clrscr();
Obj.Deletion();
break;
case 4: clrscr();
Obj.Display();
break;
case 5: cout<<"Exitting";
break;
}
}while(choice!=5);
}
void main()
{
int choice;
char ch,filename[15];
ofstream fout,fout1,fout2;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU"
<<"\n1. Create Text File"
<<"\n2. Make Separate Files"
<<"\n3. Display File"
<<"\n4. Exit"
<<"\nEnter Your Choice(1-4): ";
cin>>choice;
switch(choice)
{
case 1: clrscr();
fout.open("MIXED.TXT");
cout<<"Enter The Text(To End Typing Put A Tild At
End): ";
do
{
ch=getc(stdin);
fout<<ch;
}while(ch!='~');
fout.close();
break;
case 2: clrscr();
cout<<"Working";
for(int i=0;i<80;i++)
{
gotoxy(i+1,20);
cout<<"";
delay(100+i*5);
}
fout.open("ALPHA.TXT");
fout1.open("DIGIT.TXT");
fout2.open("SPECIAL.TXT");
ifstream fin("MIXED.TXT");
fin>>ch;
while(ch!='~')
{
if(ch>='0'&&ch<='9')
fout1<<ch;
else if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
fout<<ch;
else
fout2<<ch;
fin>>ch;
}
fout<<"~";
fout1<<"~";
fout2<<"~";
fout.close();
fout1.close();
fout2.close();
fin.close();
break;
case 3: clrscr();
cout<<"The Files Available Are "
<<"\nMIXED.TXT"
<<"\nALPHA.TXT"
<<"\nDIGIT.TXT"
<<"\nSPECIAL.TXT"
<<"\nEnter File to Be Printed: ";
gets(filename);
fflush(stdin);
if(strcmpi("MIXED.TXT",filename)==0)
{
ifstream fin("MIXED.TXT");
fin>>ch;
while(ch!='~')
{
cout<<ch;
fin>>ch;
}
}
else if(strcmpi("ALPHA.TXT",filename)==0)
{
ifstream fin("ALPHA.TXT");
fin>>ch;
while(ch!='~')
{
cout<<ch;
fin>>ch;
}
}
else if(strcmpi("DIGIT.TXT",filename)==0)
{
ifstream fin("DIGIT.TXT");
fin>>ch;
while(ch!='~')
{
cout<<ch;
fin>>ch;
}
}
else if(strcmpi("SPECIAL.TXT",filename)==0)
{
ifstream fin("SPECIAL.TXT");
fin>>ch;
while(ch!='~')
{
cout<<ch;
fin>>ch;
}
}
else {
cout<<"Error";
getch();
break;
}
getch();
fin.close();
break;
case 4: cout<<"Exitting";
break;
}
}while(choice!=4);
}
Cscience_11/16: Write a program in C++ with the help of class
array_sort with following members-
Member data :
An array ar of integer with 100 elements
No .of elements actually used by user (int n)
Member Functions-
1. To input n, and n number of elements
2. Selection sort
3. Bubble sort
4. Insertion sort
5. To display n elements of the array
Make a menu in C++ with following options-
1. Array Input
2. Selection sort
3. Bubble sort
4. Insertion sort
5. Array display
6. Quit
SOL: - #include<iostream.h>
#include<conio.h>
#include<dos.h>
class Array_Sort
{
private:
int Arr[100], N;
public:
void Input();
void Selection();
void Bubble();
void Insertion();
void Display();
};
void Array_Sort::Input()
{
cout<<"Enter Size Of Array: ";
cin>>N;
cout<<"Enter Array: \n";
for(int i=0;i<N;i++)
cin>>Arr[i];
}
void Array_Sort::Selection()
{
int i,j,temp,pos;
for(i=0;i<N;i++)
{
temp=Arr[i];
pos=i;
for(j=i+1;j<N;j++)
{
if (Arr[j]<temp)
{
temp=Arr[j];
pos=j;
}
}
Arr[pos]=Arr[i];
Arr[i]=temp;
}
cout<<"Sorting Is In Progress";
getch();
}
void Array_Sort::Bubble()
{
int temp;
for(int i=0;i<N;i++)
for(int j=0;j<N-1;j++)
if(Arr[j]>Arr[j+1])
{
temp=Arr[j];
Arr[j]=Arr[j+1];
Arr[j+1]=temp;
}
cout<<"Sorting Is In Progress";
getch();
}
void Array_Sort::Insertion()
{
int temp, pos;
for(int i=1;i<N;i++)
{
temp=Arr[i];
pos=i;
while(temp<Arr[pos-1]&&pos>0)
{
Arr[pos-1]=Arr[pos];
pos--;
}
Arr[pos]=temp;
}
cout<<"Sorting Is In Progress";
getch();
}
void Array_Sort::Display()
{
cout<<"The Array Is\n";
for(int i=0;i<N;i++)
cout<<Arr[i]<<" ";
getch();
}
void main()
{
Array_Sort Obj;
int choice;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU"
<<"\n1. Input Array"
<<"\n2. Selection Sort"
<<"\n3. Bubble Sort"
<<"\n4. Insertion Sort"
<<"\n5. Display Array"
<<"\n6. Quit"
<<"\nEnter Your Choice(1-6): ";
cin>>choice;
switch(choice)
{
case 1: clrscr();
Obj.Input();
break;
case 2: clrscr();
Obj.Selection();
break;
case 3: clrscr();
Obj.Bubble();
break;
case 4: clrscr();
Obj.Insertion();
break;
case 5: clrscr();
Obj.Display();
break;
case 6: cout<<"Exitting";
getch();
break;
}
}while(choice!=6);
}
Member data :
A pointer start which keeps the address of first node.
Member Functions-
1. A constructor which keeps NULL in start.
2. To add a node in a linked list
3. For traversal (Display info. of each node)
4. To search a particular node, on the basis of information of
nodes given.
Make a menu in C++ with following options-
1. To create a linked list.
2. For linked list traversal.
3. To search a particular node
4. Quit.
SOL: - #include<iostream.h>
#include<conio.h>
struct Node
{
int info;
Node *Next;
}*ptr=NULL;
class Linked_List
{
private:
Node *Start;
public:
Linked_List()
{ Start=NULL; }
void AddNode(int);
void Traversal();
void Search(int);
};
void Linked_List::AddNode(int n)
{
ptr = new Node;
ptr->info = n;
ptr->Next = Start;
Start = ptr;
}
void Linked_List::Traversal()
{
cout<<"The Contents Of Linked List Are";
ptr = Start;
while(ptr)
{
cout<<endl<<ptr->info;
ptr = ptr->Next;
}
getch();
}
void Linked_List::Search(int n)
{
ptr = Start;
while(ptr)
{
if(ptr->info==n)
{
cout<<"\nThe Data Is There In The List";
getch();
return;
}
ptr = ptr->Next;
}
cout<<"The Data is Not There In The List";
getch();
}
void main()
{
Linked_List obj;
int choice;
static int k=0;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU"
<<"\n1. Create Linked List"
<<"\n2. Linked List"
<<"\n3. Search A Node"
<<"\n4. Quit"
<<"\nEnter Your Choice(1-4): ";
cin>>choice;
switch(choice)
{
case 1: clrscr();
char ch;
int n;
do
{
k++;
cout<<"Enter Data In Node #"<<k<<": ";
cin>>n;
obj.AddNode(n);
cout<<"Do You Want To Add More Nodes(Y/N): ";
cin>>ch;
}while(ch=='Y'||ch=='y');
break;
case 2: clrscr();
obj.Traversal();
break;
case 3: clrscr();
cout<<"Enter The Data To Be Searched: ";
cin>>n;
obj.Search(n);
break;
case 4: cout<<"\nExitting";
getch();
break;
}
}while(choice!=4);
}
Cscience13/18: Write a program in C++ with the
help of class array stack with following members-
Member data :
An array of integer ar[MAX]
(Where MAX is a globally-declared symbolic-constant
(integer) with size According to the requirement of user)
top (It keeps the index of top most array element)
Member Functions-
1. A constructor that initialize 1 in top
(Makes array_stack ready to push)
2. To push an item in stack.
3. To pop an item from stack
4. To display the content of stack without popping
SOL: - #include<iostream.h>
#include<conio.h>
void Array_Stack::Push(int n)
{
if(Top==MAX-1)
cout<<"Overflow";
else
{
cout<<"The Element Has Been To Pushed Into The Stack" ;
Stack[++Top]=n;
getch();
}
}
void Array_Stack::Pop()
{
if(Top==-1)
cout<<"Underflow";
else
{
cout<<"The Element "<<Stack[Top]<<" Has Been Popped";
getch();
Top--;
}
}
void Array_Stack::Display()
{
cout<<"The Elements In the Stack Are";
for(int i=Top;i>=0;i--)
cout<<endl<<Stack[i];
getch();
}
void main()
{
Array_Stack obj;
int choice;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU"
<<"\n1. Initialize"
<<"\n2. Push"
<<"\n3. Pop"
<<"\n4. Display Stack"
<<"\n5. Quit"
<<"\nEnter Your Choice(1-5): ";
cin>>choice;
switch(choice)
{
case 1: break;
case 2: clrscr();
int n;
cout<<"Enter The Element To Be Pushed: ";
cin>>n;
obj.Push(n);
break;
case 3: clrscr();
obj.Pop();
break;
case 4: clrscr();
obj.Display();
break;
case 5: cout<<"Exitting";
getch();
break;
}
} while(choice!=5);
}
Member data :
A pointer top which keeps the address of top-most node.
Member Functions-
1.A constructor that initialize NULL in top (Makes
array_stack ready to push)
2. To push an item on stack.
3. To pop an item from stack
4. To display the content of stack without popping
SOL: - #include<iostream.h>
#include<conio.h>
struct Node
{
int info;
Node *Next;
}*ptr;
class Linked_Stack
{
private:
Node *Top;
public:
Linked_Stack()
{
Top=NULL;
}
void Push(int);
void Pop();
void Display();
};
void Linked_Stack::Push(int n)
{
ptr=new Node;
ptr->info=n;
ptr->Next=Top;
Top=ptr;
}
void Linked_Stack::Pop()
{
if(Top==NULL)
cout<<"Underflow";
else
{
cout<<"The Element Being Deleted Is "<<Top->info;
getch();
ptr=Top;
Top=Top->Next;
delete ptr;
}
}
void Linked_Stack::Display()
{
cout<<"The Contents Of Stack Are\n";
ptr=Top;
while(ptr)
{
cout<<ptr->info<<endl;
ptr=ptr->Next;
}
}
void main()
{
Linked_Stack obj;
int choice;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU"
<<"\n1. Initialize Stack"
<<"\n2. Push"
<<"\n3. Pop"
<<"\n4. Display Stack"
<<"\n5. Exit"
<<"\nEnter Your Choice(1-5): ";
cin>>choice;
switch(choice)
{
case 1: break;
case 2: clrscr();
int n;
cout<<"Enter element To Be Added: ";
cin>>n;
obj.Push(n);
break;
case 3: clrscr();
obj.Pop();
break;
case 4: clrscr();
obj.Display();
getch();
break;
case 5: cout<<"Exitting";
getch();
break;
}
}while(choice!=5);
}
Cscience15/20
Write a program in C++ with the help of class
array_queue with following members-
Member data :
An array of integer ar[MAX]
(Where MAX is a globally-declared
symbolic-constant (integer) with size according
to the requirement of user)
front and rear ( They keep the index of front-most
and rear-most array element)
Member Functions-
1. A constructor that initialize 1 in front
and rear (Makes array_queue ready for insertion)
2. To insert an item in queue.
3. To delete an item from queue
4. To display the content of queue without deletion.
SOL: - #include<iostream.h>
#include<conio.h>
void Array_Queue::Dequeue()
{
if(Front==-1)
cout<<"Underflow";
else if(Front==Rear)
{
cout<<"The Element Being Deleted Is "<<Queue[Front];
getch();
Rear = Front =-1;
}
else
{
cout<<"The Element Being Deleted Is "<<Queue[Front];
getch();
Front++;
}
}
void Array_Queue::Display()
{
cout<<"The contents Of Queue Are";
for(int i=Front;i<=Rear;i++)
cout<<endl<<Queue[i];
getch();
}
void main()
{
Array_Queue obj;
int choice;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU"
<<"\n1. Initialize Queue"
<<"\n2. Insert"
<<"\n3. Delete"
<<"\n4. Display Queue"
<<"\n5. Exit"
<<"\nEnter Your Choice(1-5): ";
cin>>choice;
switch(choice)
{
case 1: break;
case 2: clrscr();
int n;
cout<<"Enter element To Be Added: ";
cin>>n;
obj.Enqueue(n);
break;
case 3: clrscr();
obj.Dequeue();
break;
case 4: clrscr();
obj.Display();
getch();
break;
case 5: cout<<"Exitting";
getch();
break;
}
}while(choice!=5);
}
Cscience_16/21
Write a program in C++ with the help of class
linked_queue with following members-
(Nodes of the linked queue are created by
self-referential structure node-
struct node
{
int info;
node *next;
}; )
member Data :
front and rear ( They keep the memory address
of front-most and rear-most linked queue)
Member Functions-
1. A constructor that initialize NULL
in front and rear
2. To insert an item in queue.
3. To delete an item from queue
4. To display the content of queue without deletion.
struct Node
{
int info;
Node *Next;
}*ptr;
class Linked_Queue
{
private:
Node *Front;
Node *Rear;
public:
Linked_Queue()
{
Front=NULL;
Rear=NULL;
}
void Insert(int);
void Delete();
void Display();
};
void Linked_Queue::Insert(int n)
{
ptr=new Node;
ptr->info=n;
ptr->Next=NULL;
if(Rear==NULL)
Front=Rear=ptr;
else
{
Rear->Next=ptr;
Rear=ptr;
}
}
void Linked_Queue::Delete()
{
if(Front==NULL)
cout<<"Underflow";
else if(Rear==Front)
{
cout<<"The Element Being Deleted Is "<<Front->info;
getch();
ptr=Front;
Front=Rear=NULL;
delete ptr;
}
else
{
cout<<"The Element Being Deleted Is "<<Front->info;
getch();
ptr=Front;
Front=Front->Next;
delete ptr;
}
}
void Linked_Queue::Display()
{
cout<<"The Contents Of Queue Are\n";
ptr=Front;
while(ptr)
{
cout<<ptr->info<<endl;
ptr=ptr->Next;
}
}
void main()
{
Linked_Queue obj;
int choice;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU"
<<"\n1. Initialize Queue"
<<"\n2. Insert"
<<"\n3. Delete"
<<"\n4. Display Queue"
<<"\n5. Exit"
<<"\nEnter Your Choice(1-5): ";
cin>>choice;
switch(choice)
{
case 1: break;
case 2: clrscr();
int n;
cout<<"Enter element To Be Added: ";
cin>>n;
obj.Insert(n);
break;
case 3: clrscr();
obj.Delete();
break;
case 4: clrscr();
obj.Display();
getch();
break;
case 5: cout<<"Exitting";
getch();
break;
}
}while(choice!=5);
}
EXAMPLE OF SQL
Table : SUPPLIER
NOTE :
Similarly four more assignments Cscience_22, Cscience_23,
Cscience_24, and Cscience_25 can be taken up by students on their own
for SQL.