Sie sind auf Seite 1von 40

# Cscience_1/8 : Write a Program in C++ to

## add two distance type objects into third

one. Structure distance contains following
components1. feet (integer type)
2. inches (integer type)
(Program must have following general
functions1. To input a distance type object.
2. To add two distance type objects
(Pass two distance type arguments and
return a distance type object).
3. To display distance type object.

Solution 1

#include<iostream.h>
#include<conio.h>
struct Distance
{
int feet;
int inches;
};
Distance Input()
{
Distance d;
cout<<"Enter Feet: ";
cin>>d.feet;
cout<<"Enter Inches: ";
cin>>d.inches;
return d;
}
{
Distance temp;
temp.feet=d1.feet + d2.feet +
(d1.inches + d2.inches)/12;
temp.inches=(d1.inches + d2.inches)
%12;
return temp;
}
void Display(Distance d)

{
cout<<d.feet<<" \' <<d.inches<<" \" "<<" ";

}
void main()
{
clrscr();
Distance d1,d2,d3;
cout<<"Input Distance #1\n";
d1=Input();
cout<<"Input Distance #2\n";
d2=Input();
cout<<"The Result Of \n";
Display(d1);
cout<<"+ ";
Display(d2);
cout<<"= ";
Display(d3);
getch();
}
Cscience_2/9: Imagine a ticket selling booth at a fair. People passing by are requested to purchase a
ticket. A ticket is priced Rs. 2.50/- The booth keeps the track of the number of people that have visited
the booth, and of the total amount of money collected.
Model this ticket selling booth with a class ticbooth including following members:
Data Members:
Number of people visited.
Total amount of money collected.
Member Functions:
To increment only people total in case ticket is not sold out.
To increment people total as well as amount total if a ticket is sold out
To display the two totals
To display the number of tickets sold out (a tricky one)

Solution 2
#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<<"\n1. Increment Data";
cout<<"\n2. Display Data";
cout<<"\n3. Exit";
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<<"\n1. Display All";

cout<<"\n2. Display People Paying";
cin>>ch;
if(ch=='1')
obj.DisplayAll();
else obj.DispTickets();
getch();
break;
case 3: cout<<"Exitting";
getch();
break;
}
}while(choice!=3);
getch();
}

## Cscience_3 /10: Define a class to represent batsmen in a cricket team.

Include the following members:
Data members :
First name
Last name
Number of fours
Number of sixes
Member Functions :
To assign the initial values
(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();
<<"\n1. Assign Values" <<"\n2. Update Values"
<<"\n3. Display Info"
<<"\n4. Quit"
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 /11: Write a menu-driven program in C++ to calculate the volume of following
shapesVolume of a cube
Volume of a box
Volume of a sphere.
Quit
Make this program with the help of a class shape with followingMember 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;
case 2: Volume = P1*P2*P3;
break;
case 3: Volume = 3.14*4*P1*P1*P1/3;
break;
Display();

}
}
void Input(int i)
{ switch(i)
{
case 1: cout<<"Enter Side Of Cube: ";
cin>>P1;
break;
case 2: cout<<"Enter Sides Of Box: ";
cin>>P1>>P2>>P3;
break;

## case 3: cout<<"Enter Radius Of Sphere: ";

cin>>P1;
break;
}
Vol(i);
}
void Display()
{
cout<<"Volume Is "<<Volume;
getch();
}
};
void main()
{
clrscr();
Shape S;
cout<<"\t\t\t\tMAIN MENU" <<"\n1. Volume Of Cube" <<"\n2. Volume Of Box"
<<"\n3. Volume Of Sphere"
<<"\n4. Quit" <<"\nEnter Your Choice: ";
int i;
cin>>i;
switch(i)
{
case 1:
case 2:
case 3: S.Input(i); break;
case 4: cout<<"Exitting";
break;
}

getch();
}

Cscience_5/12: 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;
} };
class Book: public Publication
{
private:
int Page_Count;
public:
void Getdata()
{
Publication::Getdata();
cout<<"Enter No. Of Pages: ";
cin>>Page_Count;
}
void Putdata()
{
Publication::Putdata();
cout<<"\nNo. Of Pages: "<<Page_Count;
}
};
class Tape: public Publication
{
private:
float Play_Time;
public:
void Getdata()
{
Publication::Getdata();
cout<<"Enter Playing Time: ";
cin>>Play_Time;
}
void Putdata()
{
Publication::Putdata();
cout<<"\nPlaying Time: "<<Play_Time;
} };
void main( )
{
clrscr( );
Book Bk;
Tape Tp;
Bk.Getdata( );
Tp.Getdata( );

clrscr();
Bk.Putdata( );
Tp.Putdata( );
getch();
}
Question 6/13 Write a program in C++ with the
help of following class employee
Member Data :
Employee name
Employee code
Basic Salary
Da
Hra
Total salary
Member Functions:
1. To input employee detail
(name, code and basic)
2. To calculate following
Code

Da

Hra

50% of basic

30% of basic

40% of basic

25% of basic

Any other

30% of basic

20% of basic

## Total Salary=Basic + Da + Hra

This function must be a private function and
must be called from input detail function
1. A function which returns the address of
that object which has got higher basic salary
(This function compares calling object and passing object)
4. To display the detail of the Employee
In main () function make 5 objects of employee. Input and calculate detail of every employee.
Finally display the detail of that employee who draws the highest salary.

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;
case 2: DA = Basic * 0.4;
HRA = Basic * 0.25;
break;
default: DA = Basic * 0.3;
HRA = Basic * 0.2;
}
Tot_Salary = Basic + DA + HRA;
}
void Employee::Input()
{
cout<<"\nEnter Employee's Code: ";
cin>>Emp_Code;
cout<<"\nEnter Employee's Name: ";
gets(Emp_Name);
cout<<"\nEnter The Basic Salary: ";
cin>>Basic;
this->Calculate();
}
Employee Employee::Compare(Employee Obj)
{
if(Tot_Salary>Obj.Return())
return (*this);
else
return Obj;
}
void Employee::Display()
{
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/14:
Write a program in C++ with the help of class array_search with following membersMember data :
An array ar of integer with 20 elements
No .of elements actually used by user (int n)
Member Functions1. 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 options1.
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::Linear_search(int item)
{
for(int i=0;i<n;i++)
if(arr[i]==item)
{
cout<<"The Item Is At Position: "<<i+1;
return;
}
cout<<"The Item Is Not Present In The List";
}
void Array_Search::Binary_search(int item)
{
int beg=0,end=n-1,mid;
while(beg<=end)
{
mid=(beg+end)/2;
if(arr[mid]==item)
{
cout<<"The Element Is At Position "<<mid+1;
return;
}
else if(arr[mid]>item)
end=mid-1;
else beg=mid+1;
}
cout<<"The Element Is Not In The List";
}
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();
<<"\n1. Array Input"
<<"\n2. Linear Search"
<<"\n3. Binary Search"
<<"\n4. Array Display"
<<"\n5. Exit"
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);
}
Cscience_9/16 : Write a menu-driven program in C++ with following
Options to work with data file1. To add records (Name, Rollno, Marks ) of students
(Add records till the user wants yes)
2. Display all the records
3. Display a particular record on the basis of Roll No.
4. Quit

Solution 8
#include<process.h>
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
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();
<<"\n2. Display All Records"
<<"\n3. Display Single Record"
<<"\n4. Quit"
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 2:

ifstream fin;
fin.open("Stud.dat",ios::in|ios::binary);
fin.seekg(0);
while(!fin.eof())
{
j++;
cout<<"\nRecord #"<<j<<"\n";
Obj.Display();
}
getch();
fin.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())
{
if(Obj.Return()==Roll)
{
Obj.Display();
getch();
flag=1;
break;
}
}

if (flag==0)
cout<<"Record Is Not There in List";
getch();
finn.close();
break;

## case 4: cout<<"Thanks For Visiting";

getch();
exit(0);
}
cout<<\n Do you want to continue (y/n)";
fflush(stdin);
cin>>ch1;
}while(ch1=='y'||ch1=='Y');
file.close();
getch();
}

## Cscience_8/15: Write a program in C++ with the help of class

array_update with following membersMember data :
An array ar of integer with 100 elements
No .of elements actually used by user (int n)
Member Functions1. 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 options1. 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();
<<"\n1. Array Input"
<<"\n2. Insertion"
<<"\n3. Deletion"
<<"\n4. Array Display"
<<"\n5. Quit"
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);
}

## Cscience_10/ 17: Write a menu-driven program in C++ with

following options1. Creation of a text file (say file is mixed.txt, it contains
alphabets, digits or special characters)
2. Make separate files (This option creates three filesalpha.txt (contains alphabets only), digit.txt (contains digits only)
and special.txt (contains special characters only)
taking data from mixed.txt)
3. Display a file (This option displays the contents of a particular
file out of above-mentioned four files, by asking its name, if not
4. Quit
Solution 10
#include<fstream.h>
#include<dos.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int choice;
char ch,filename[15];
ofstream fout,fout1,fout2;
do
{
clrscr();
<<"\n1. Create Text File"
<<"\n2. Make Separate Files"
<<"\n3. Display File"
<<"\n4. Exit"
cin>>choice;
switch(choice)
{
case 1: clrscr();
fout.open("MIXED.TXT");
cout<<"Enter The Text(To End Typing Put A Tild At End): ";
do
6
{
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);
}

## Q11- Q15 sql

Cscience_11/18: Write a program in C++ with the help of class array_sort with following membersMember data :
An array ar of integer with 100 elements
No .of elements actually used by user (int n)
Member Functions1. 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 options1. 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();
<<"\n1. Input Array"
<<"\n2. Selection Sort"
<<"\n3. Bubble Sort"
<<"\n4. Insertion Sort"
<<"\n5. Display Array"
<<"\n6. Quit"
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);
}

## Cscience_17: Write a program in C++ with the

help of class linked_list with following members(Nodes of the linked list are created by self-referential
structure node-struct node
{
int info;
node *next;
};
Member data :
A pointer start which keeps the address of first node.
Member Functions1. A constructor which keeps NULL in start.
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 options1. To create a linked list.
3. To search a particular node
4. Quit.
SOL: - #include<iostream.h>
#include<conio.h>
struct Node
{
int info;
Node *Next;
}*ptr=NULL;
{
private:
Node *Start;
public:
{ Start=NULL; }
void Traversal();
void Search(int);
};
{

## ptr = new Node;

ptr->info = n;
ptr->Next = Start;
Start = ptr;
}
{
cout<<"The Contents Of Linked List Are";
ptr = Start;
while(ptr)
{
cout<<endl<<ptr->info;
ptr = ptr->Next;
}
getch();
}
{
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()
{
int choice;
static int k=0;
do
{
clrscr();

## <<"\n3. Search A Node"

<<"\n4. Quit"
cin>>choice;
switch(choice)
{
case 1: clrscr();
char ch;
int n;
do
{
k++;
cout<<"Enter Data In Node #"<<k<<": ";
cin>>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);
}

## Cscience12/19: Write a program in C++ with the

help of class array stack with following membersMember 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 Functions1. A constructor that initialize 1 in top
2. To push an item in stack.

## 3. To pop an item from stack

4. To display the content of stack without popping
Make a menu in C++ with following options1. A initialize the stack( top must be -1)
2. To push an item in stack.
3. To pop an item from stack
4. To display the content of stack without popping
5. Quit
SOL: - #include<iostream.h>
#include<conio.h>
const int MAX=50;
class Array_Stack
{
private:
int Stack[MAX];
int Top;
public:
Array_Stack()
{ Top=-1;}
void Push(int);
void Pop();
void Display();
};
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();
<<"\n1. Initialize"
<<"\n2. Push"
<<"\n3. Pop"
<<"\n4. Display Stack"
<<"\n5. Quit"
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);
}
Q19 & Q20 LOGIC CIRCUIT

## Cscience13/20: W rite a program in C++ with the help of class

Linked_stack with following members(Nodes of the linked stack are created by self-referential
Structure nodestruct node
{
int info;
node *next;
};
)
Member data :
A pointer top which keeps the address of top-most node.
Member Functions1.A constructor that initialize NULL in top (Makes
2. To push an item on stack.
3. To pop an item from stack
4. To display the content of stack without popping
Make a menu in C++ with following options1. A initialize the stack( top must be NULL)
2. To push an item in stack.
3. To pop an item from stack
4. To display the content of stack without popping

5. Quit
SOL: - #include<iostream.h>
#include<conio.h>
struct Node
{
int info;
Node *Next;
}*ptr;
{
private:
Node *Top;
public:
{
Top=NULL;
}
void Push(int);
void Pop();
void Display();
};
{
ptr=new Node;
ptr->info=n;
ptr->Next=Top;
Top=ptr;
}
{
if(Top==NULL)
cout<<"Underflow";
else
{
cout<<"The Element Being Deleted Is "<<Top->info;
getch();
ptr=Top;
Top=Top->Next;
delete ptr;
}
}
{
cout<<"The Contents Of Stack Are\n";
ptr=Top;
while(ptr)
{
cout<<ptr->info<<endl;
ptr=ptr->Next;
}
}

void main()
{
int choice;
do
{
clrscr();
<<"\n1. Initialize Stack"
<<"\n2. Push"
<<"\n3. Pop"
<<"\n4. Display Stack"
<<"\n5. Exit"
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);
}

Cscience14/21

## Write a program in C++ with the help of class

array_queue with following membersMember 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 Functions1. 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.
Make a menu in C++ with following options1. To initialize the queue (front and rear must be -1)
2. To insert an item in queue
3. To delete an item from queue
4. To display the contents of queue without deletion
5. Quit
SOL: - #include<iostream.h>
#include<conio.h>
const int MAX=50;
class Array_Queue
{
private:
int Queue[MAX];
int Front,Rear;
public:
Array_Queue()
{ Front = Rear = -1; }
void Enqueue(int);
void Dequeue();
void Display();
};

void Array_Queue::Enqueue(int n)
{
if((Rear-Front)==MAX)
cout<<"Overflow";
else
{
if(Rear==-1)
Front=Rear=0;
else
Rear++;
Queue[Rear]=n;
cout<<"The Element "<<n<<" Has Been Added To The Queue";
getch();
}
}
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();
<<"\n1. Initialize Queue"
<<"\n2. Insert"
<<"\n3. Delete"
<<"\n4. Display Queue"
<<"\n5. Exit"
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_15/22

## Write a program in C++ with the help of class

self-referential structure nodestruct node
{
int info;
node *next;
};
)
member Data :
front and rear ( They keep the memory address
of front-most and rear-most linked queue)
Member Functions1. 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.
Make a menu in C++ with following options1. To initialize the queue( front and rear must be NULL)
2. To insert an item in queue
3. To delete an item from queue
4. To display the contents of queue without deletion
5. Quit
SOL: - #include<iostream.h>
#include<conio.h>
struct Node
{
int info;
Node *Next;
}*ptr;
{
private:
Node *Front;
Node *Rear;
public:
{
Front=NULL;
Rear=NULL;

}
void Insert(int);
void Delete();
void Display();
};
{
ptr=new Node;
ptr->info=n;
ptr->Next=NULL;
if(Rear==NULL)
Front=Rear=ptr;
else
{
Rear->Next=ptr;
Rear=ptr;
}
}
{
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;
}
}
{
cout<<"The Contents Of Queue Are\n";
ptr=Front;
while(ptr)

{
cout<<ptr->info<<endl;
ptr=ptr->Next;
}
}
void main()
{
int choice;
do
{
clrscr();
<<"\n1. Initialize Queue"
<<"\n2. Insert"
<<"\n3. Delete"
<<"\n4. Display Queue"
<<"\n5. Exit"
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
Numbers
Name
City
Itemno
SuppliedQty
Rate
S001
Puneet
Delhi
1008
100
40
S002
Bangalore
1009
200
30
S003
Tanmay
Delhi
1008
150
40
S004
Rohini
Bombay
1005
190
20
S005
Tanya
Bombay
1003
20
50
S006
1008
180
40
S007
Kush
Delhi
1009
300
30
Write SQL commands for (a) to (f) and write the outputs of SQL commands given in (h) with the help
of above shown table.
a) Display names of suppliers whose names start with the letter T.
b) Display details of suppliers residing in Delhi.
c) Display supplier name, item numbers, and supplied quantity for quantity > 150.
d) Create a view with one of the columns as rate * 10.
e) List the suppliers name in the descending order of supplied quantity.
f) List the different cities contained in supplier table.
g) Give the output of the following SQL commands on the basis of table supplier.
i.
SELECT MIN(Rate) FROM SUPPLIER
ii.
SELECT COUNT(DISTINCT City) FROM SUPPLIER
iii.
SELECT Name, Itemno FROM SUPPLIER WHERE SuppliedQty>150
iv.
SELECT (Rate*SuppliedQty) FROM SUPPLIER WHERE SuppliedQty>200
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.