Sei sulla pagina 1di 49

CBSE Practical Record

Table of Content
Sr. No. Topic
1 Defined a Class for the working of a Restaurant
2 Defined a Class Book
3 Defined a Class to demonstrate the Working of Constructor
4 Defined a Class to demonstrate the Working of Destructor
5 Defined a Class to demonstrate the Working of Inheritance
6 Program to Perform Writing and Reading of names in a Text File
7 Program to Perform Writing and Reading of 10 places in a Text File
8 Program to Perform Searching of a Movie in a Text File
9 Program to Count Upper Case and Lower Case Characters in a Text File
10 Program to Perform Writing, Reading and Searching of the objects of Class Stu
11 Program to Perform Writing, Reading and Searching of the objects of Class
Emp
12 Program to Perform Searching of the objects of Class Stu in a binary file
13 Program to Perform Searching of the objects of Class Emp in a binary file
14 Binary search in Linear Array
15 Bubble sort in Linear Array
16 Selection Sort in Linear Array
17 Insertion Sort in Linear Array
18 Insertion in Sorted Linear Array
19 Deletion from Linear Array
20 Deletion of Even Element from an Linear Array
21 Merging of Two Sorted Linear Arrays
22 Program of 2D Array for even and odd elements
23 Program of 2D Array to display upper right triangle
24 Program of 2D Array to display upper left triangle
25 Program of 2D Array to display both the diagonals
26 Program of 2D Array to display boundary elements
27 To perform insertion and deletion in static stack
28 To perform insertion and deletion in dynamic linked stack
29 To perform insertion and deletion in static queue
30 To perform insertion and deletion in dynamic linked queue
31 To perform insertion and deletion in static circular queue
32 Questions of SQL
PROGRAM 1

(CLASS)

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class rest
{
int foodcode;
char food[30],ftype[15];
char sticker[15];
void getsticker()
{
if(strcmp(ftype,"vegetarian")==0)
strcpy(sticker,"green");
else if(strcmp(ftype,"contains egg")==0)
strcpy(sticker,"yellow");
else if(strcmp(ftype,"non-vegetarian")==0)
strcpy(sticker,"red");
}
public:
void getfood()
{
cout<<"enter foodcode";
cin>>foodcode;
cout<<"\nenter food";
gets(food);
cout<<"enter food type";
gets(ftype);
getsticker();
}
void showfood()
{
cout<<"\nfood code:"<<foodcode<<endl;
cout<<"food: "<<food<<endl;
cout<<"foodtype "<<ftype<<endl;
cout<<"sticker: "<<sticker<<endl;
} };
void main()
{
rest ob;
clrscr();
ob.getfood();
cout<<endl;
ob.showfood();
cout<<endl;
getch();
}
OUTPUT : PROGRAM 1
PROGRAM 2

(CLASS)

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class book
{
int book_no;
char book_title[20];
float price,total_cost(int n)
{
float tc;
tc=n*price;
return tc;
}
public:
void input()
{
cout<<"bookno."<<endl;
cin>>book_no;
cout<<"book title"<<endl;
gets(book_title);
cout<<"price per book";
cin>>price;
}
void purchase()
{
int n;float t;
cout<<"enter no of books";
cin>>n;
t=total_cost(n);
cout<<"\n total amount "<<t;
}
};
void main()
{
clrscr();
book ob;
ob.input();
ob.purchase();
getch();
}
OUTPUT : PROGRAM 2
PROGRAM 3

(CLASS WITH CONSTRUCTOR AND DESTRUCTOR)

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class conference
{
int dur,time;
public:
conference()
{
dur=8;
cout<<"Inaugration"<<endl;
}
~conference()
{
cout<<"Concluding ceremony"<<endl;
}
void session(int s=1)
{
cout<<"Session"<<s<<"is on"<<endl;
}
conference(int dur)
{
time=dur;
cout<<"Inaugration"<<endl;
}
};
void main()
{
clrscr();
conference ob;
ob.session(5);
getch();
}

OUTPUT : PROGRAM 3

PROGRAM 4
PROGRAM 4

(CLASS WITH CONSTRUCTOR AND DESTRUCTOR)

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class abc
{
int rno;
char name[100];
public:
abc()
{
rno=1;
strcpy(name,"Pankhi");
}
void show()
{
cout<<rno<<','<<name<<endl;
}
~abc()
{
cout<<"GaME OVER.......";
}
};
void main()
{
abc ob;
ob.show();
getch();
}

OUTPUT : PROGRAM 4
PROGRAM 5

(INHERITANCE)

#include<iostream.h>
#include<conio.h>
class abc
{
public:
int a;
};
class b1:virtual public abc
{
public:
int b;
};
class b2:virtual public abc
{
public:
int c;
};
class xyz:public b1,public b2
{
public:
int d;
};
void main()
{
clrscr();
xyz ob;
ob.a=1;
cout<<ob.a;
cout<<endl<<ob.b;
cout<<endl<<ob.c;
cout<<endl<<ob.d;
getch();
}

OUTPUT : PROGRAM 5
PROGRAM 6

(TEXTFILE)

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<fstream.h>
void fn()
{
ofstream ob("twitter.txt");
char n[100];
int i;
for(i=0;i<5;i++)
{
cout<<"enter names";
cin>>n;
ob<<n<<endl;
}
ob.close();
};
void be()
{
ifstream ob("twitter.txt",ios::app);
char n[100];
int i;
for(i=0;i<5;i++)
{
cout<<"enter names";
cin>>n;
ob>>n;
}
ob.close();
};
void main()
{
clrscr();
fn();
}

OUTPUT : PROGRAM 6
getch();
}
OUTPUT : PROGRAM 6
PROGRAM 7

(TEXTFILE)

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void fn()
{
ofstream ob("places.txt",ios::app);
char n[100];
int i;
cout<<"Enter the name of ten places...\n";
for(i=0;i<10;i++)
{
cin>>n;
ob<<n;
}
cout<<"\n Entered successfully..";
ob.close();
}
void main()
{
clrscr();
fn();
getch();
}

OUTPUT : PROGRAM 7
PROGRAM 8

(TEXTFILE)

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
void fn()
{
ofstream ob("movies.txt");
char n[100];
int i;
cout<<"Enter the names of five movies..\t";
for(i=0;i<5;i++)
{
cin>>n;
ob<<n;
}
cout<<"\nEntered..";
ob.close();
}
void main()
{
clrscr();
fn();
getch(); }

OUTPUT : PROGRAM 8
PROGRAM 9

(TEXTFILE)

#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<fstream.h>
#include<stdio.h>
void fn()
{ char ch[200];
ofstream ob("text.txt");
cout<<"Enter the line(s)";
gets(ch);
ob<<ch;
ob.close();
}
void f2()
{
ifstream ob("text.txt");
char ch;
int lc=0,uc=0;
while(!ob.eof())
{
ob.get(ch);
if(islower(ch))
lc++;
else if(isupper(ch))
uc++;
}
cout<<"\n upper case\t"<<uc;
cout<<"\nlower case\t"<<lc;
ob.close();
}
void main()
{
fn();
f2();
getch();
}

OUTPUT : PROGRAM 9
PROGRAM 10
(BINARY FILE)
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class stu
{char n[100];
int m;
public:
void in()
{cout<<"Enter name\n";
gets(n);
cout<<"\nEnter marks\n";
cin>>m;
}
void out()
{cout<<"\n The Details Are::\n";
puts(n);
cout<<m;
cout<<endl;
}
char * getn()
{return n;}
};
void fin()
{ofstream ob("spr.txt",ios::binary);
stu s; char ch,p[100];
do
{cout<<"Wanna Enter Records....\n\t";
s.in();
ob.write((char *)&s,sizeof(s));
cout<<"\npress y to continue\n ";
cin>>ch;}
while(ch=='y'||ch=='Y');
ob.close();
}
void fout()
{ifstream ob("spr.txt",ios::binary);
stu s;
char p[100];
cout<<"\nenter the name to be searched\n";
gets(p);
ob.read((char *)&s,sizeof(s));
while(!ob.eof())
{if(strcmpi(s.getn(),p)==0)
{s.out();}
ob.read((char *)&s,sizeof(s));}
ob.close();
}
void main()
{clrscr();
fin();
cout<<"\nThe records to b searched are::: ";
fout();
getch();
}

OUTPUT : PROGRAM 10
PROGRAM 11

(BINARY FILE)

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class emp
{char n[20],s;
long sal,ph;
public:
void gi()
{cout<<"Enter name \t";
gets(n);
cout<<"\nSex:\t";
cin>>s;
cout<<"\nEnter phone no.:\t";
cin>>ph;
cout<<"\nEnter salary:\t";
cin>>sal;
}
void disp()
{cout<<"\n The Details are:\n\t";
puts(n);
cout<<"\nSex \t"<<s<<"\nPhone no\t"<<ph<<"\nSalary\t"<<sal;
}
char rets()
{return s;}
};
void in()
{ofstream ob("Employee.txt",ios::binary);
emp x;char ch;
do
{cout<<"\nEnter details:\n";
x.gi();
ob.write((char*)&x,sizeof(x));
cout<<"\nWanna continue.......Press y\t";
cin>>ch;
}
while(ch=='y'||ch=='Y');
ob.close();
}
void out()
{ifstream ob("Employee.txt",ios::binary);
emp x;
ob.read((char*)&x,sizeof(x));
while(!ob.eof())
{if(x.rets()=='f'||x.rets()=='F')
{x.disp();}
ob.read((char*)&x,sizeof(x));
}
ob.close();
}
void main()
{clrscr();
in();
out();
getch();
}

OUTPUT : PROGRAM 11
PROGRAM 12
(BINARY FILE)
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
struct stu
{
char name[100];
int marks;
};
void fn()
{
ofstream ob("abc.dat",ios::binary);
stu x;
char ch;
do
{
cout<<"\nEnter name and marks\t";
cin>>x.name>>x.marks;
ob.write((char *)&x,sizeof(x));
cout<<"\nPress y to continue\n";
cin>>ch;
}
while(ch=='y'||ch=='Y');
ob.close();
}
void main()
{
fn();
getch();
}

OUTPUT : PROGRAM 12
PROGRAM 13
(BINARY FILE)
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
struct stu
{
char name[100];
int marks;
};
void fn()
{
ifstream ob("abc.dat",ios::binary);
stu x;
ob.read((char *)&x,sizeof(x));
while(!ob.eof())
{
if(x.marks>50)
{
cout<<x.name<<"\t"<<x.marks;
}
ob.read((char *)&x,sizeof(x));
}
ob.close();
}
void main()
{
fn();
getch();
}

OUTPUT : PROGRAM 13
PROGRAM 14
(BINARY SEARCH)

#include<iostream.h>
#include<conio.h>
void main()
{
int a[100],l,s,e,b,m,i,p;
cout<<"Enter the size\t";
cin>>s;
cout<<"\nEnter the elements\t";
for(i=0;i<s;i++)
{cin>>a[i];}
p=-1;
cout<<"\nEnter the element to be searched\t";
cin>>e;
b=0;l=s-1;
while(b<=l)
{m=(b+l)/2;
if(e==a[m])
{p=m;break;}
else if(e>a[m])
{b=m+1;}
else if(e<m)
{l=m-1;}
}
if(p==-1) cout<<"\nNot Found";
else cout<<"\nFound at"<<p+1;
getch();
}

OUTPUT : PROGRAM 14
PROGRAM 15
(SORTING)
#include<iostream.h>
#include<conio.h>
void main()
{
int s,i,j,t,a[100];
cout<<"\nEnter size\t";
cin>>s;
cout<<"\nEnter elements\t";
for(i=0;i<s;i++)
{
cin>>a[i];
} j=s-1;
while(j>=0)
{
if(a[j]<a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
j--;
}
cout<<"\nSorted array....\n";
for(i=0;i<s;i++)
{
cout<<a[i];
}
getch();
}

OUTPUT : PROGRAM 15
PROGRAM 16
(SORTING)
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,s,p,t,a[100],min;
cout<<"Enter size\t";
cin>>s;
cout<<"\nEnter elements\t";
for(i=0;i<s;i++)
{
cin>>a[i];
}
for(i=0;i<s;i++)
{
min=a[i];
p=i;
for(j=1+i;j<s;j++)
{if(a[j]<min)
{min=a[j];
p=j;
} }
t=a[i];
a[i]=a[p];
a[p]=t;
}
cout<<"\nSorted array is...\n";
for(i=0;i<s;i++)
{cout<<a[i];}
getch();
}

OUTPUT : PROGRAM 16
PROGRAM 17
(SORTING)
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,a[100],t,s;
cout<<"Size\t";
cin>>s;
cout<<"\nEnter elements....\t";
for(i=0;i<s;i++)
{
cin>>a[i];
}
for(i=0;i<s;i++)
{
t=a[i];
for(j=i-1;a[j]>t&&j>=0;j--)
{
a[j+1]=a[j];
}
a[j+1]=t;
}
cout<<"\nSorted array is...\n";
for(i=0;i<s;i++)
{
cout<<a[i];
}
getch();
}

OUTPUT : PROGRAM 17
PROGRAM 18
(INSERTION IN ARRAY)
#include<iostream.h>
#include<conio.h>
void fn(int a[],int ele,int s);
void main()
{ clrscr();
int s,a[100],ele,i;
cout<<"Enter size\t";
cin>>s;
cout<<"\nElements\t";
for(i=0;i<s;i++)
{
cin>>a[i];
}
cout<<"Enter element..\t";
cin>>ele;
fn(a,ele,s);
getch();
}
void fn(int a[],int ele,int s)
{
int i,p;
for(i=s;i>3;i--)
{
a[i]=a[i-1];
}
a[3]=ele;
s++;
for(i=0;i<s;i++)
{
cout<<a[i];
}
}

OUTPUT : PROGRAM 18
PROGRAM 19
(DELETION IN ARRAY)
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int ele,s,i,p,a[100];
cout<<"Size\t";
cin>>s;
cout<<"\nElements\t";
for(i=0;i<s;i++)
{ cin>>a[i]; }
cout<<"\nEnter element to be deleted\t";
cin>>ele;
for(i=0;i<s;i++)
{ if(ele==a[i])
{ p=i;
break;
}
}
for(i=p;i<s;i++)
{ a[i]=a[i+1];
}
s--;
for(i=0;i<s;i++)
{ cout<<a[i]; }
getch();
}

OUTPUT : PROGRAM 19
PROGRAM 20
(DELETION IN ARRAY)
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int ele,s,i,p,j,a[100];
cout<<"Size\t";
cin>>s;
cout<<"\nElements\t";
for(i=0;i<s;i++)
{ cin>>a[i];
}
cout<<"\nEnter element to be deleted\t";
cin>>ele;
for(i=0;i<s;i++)
{ if(ele==a[i])
{ p=i;
for(j=p;j<s;j++)
{ a[j]=a[j+1];
}
s--;
i--;
} }
for(i=0;i<s;i++)
{ cout<<a[i];
}
getch();
}

OUTPUT : PROGRAM 20
PROGRAM 21
(2D ARRAY)
#include<iostream.h>
#include<conio.h>
void fn(int a[][10],int r,int c)
{int i,j;
for(i=0;i<r;i++)
{for(j=0;j<c;j++)
{if(a[i][j]%2==0)
{a[i][j]=a[i][j]/2;
}
else
{a[i][j]=a[i][j]*3;}
}
}
for(i=0;i<r;i++)
{for(j=0;j<c;j++)
{cout<<a[i][j];
}
cout<<endl;}
}
void main()
{clrscr();
int a[10][10],r,c,i,j;
cout<<"Enter rows n columns\t";
cin>>r>>c;
cout<<"\nEnter elements\t";
for(i=0;i<r;i++)
{for(j=0;j<c;j++)
{cin>>a[i][j];}
}
fn(a,r,c);
getch();
}

OUTPUT : PROGRAM 21
PROGRAM 22
(2D ARRAY)
#include<iostream.h>
#include<conio.h>
void fn(int a[][10],int s)
{int i,j;
for(i=0;i<s;i++)
{for(j=0;j<s;j++)
{if(i<=j)
cout<<a[i][j];
elsecout<<' ';}
cout<<endl;
}}
void main()
{clrscr();
int a[10][10],s,i,j;
cout<<"Enter size\t";
cin>>s;
cout<<"\nEnter elements\t";
for(i=0;i<s;i++)
{for(j=0;j<s;j++)
{cin>>a[i][j];}
}
fn(a,s);
getch();
}

OUTPUT : PROGRAM 22
PROGRAM 23
(2D ARRAY)
#include<iostream.h>
#include<conio.h>
void fn(int a[][10],int s)
{int i,j;
for(i=0;i<s;i++)
{for(j=0;j<s;j++)
{if(i+j>=s-1)
cout<<a[i][j];
else
cout<<' ';
}
cout<<endl;
}
}
void main()
{clrscr();
int a[10][10],s,i,j;
cout<<"Enter size\t";
cin>>s;
cout<<"\nEnter elements\t";
for(i=0;i<s;i++)
{for(j=0;j<s;j++)
{cin>>a[i][j];
}
}
fn(a,s);
getch();
}

OUTPUT : PROGRAM 23
PROGRAM 24
(2D ARRAY)
#include<iostream.h>
#include<conio.h>
void fn(int a[][10],int s)
{int i,j;
for(i=0;i<s;i++)
{for(j=0;j<s;j++)
{if(i==j||i+j==s-1)
{cout<<a[i][j];}
else
{cout<<' ';}
}
cout<<endl;
}
}
void main()
{clrscr();
int a[10][10],s,i,j;
cout<<"Enter size\t";
cin>>s;
cout<<"\nEnter elements\t";
for(i=0;i<s;i++)
{for(j=0;j<s;j++)
{cin>>a[i][j];}
}
fn(a,s);
getch();
}

OUTPUT : PROGRAM 24
PROGRAM 25
(2D ARRAY)
#include<iostream.h>
#include<conio.h>
void fn(int a[][10],int s)
{int i,j;
for(i=0;i<s;i++)
{for(j=0;j<s;j++)
{if(i==0||j==0||j==s-1||i==s-1)
cout<<a[i][j];
else
cout<<' ';
}
cout<<endl;
}
}
void main()
{clrscr();
int a[10][10],s,i,j;
cout<<"Enter size\t";
cin>>s;
cout<<"\nEnter elements\t";
for(i=0;i<s;i++)
{for(j=0;j<s;j++)
{cin>>a[i][j];
}
}
fn(a,s);
getch();
}

OUTPUT : PROGRAM 25
PROGRAM 26
(ARRAY AS STACK)
#include<iostream.h>
#include<conio.h>
#include<stddef.h>
#include<process.h>
struct node
{
int a;
node *next;
};
int ar[100],front=-1,rear=-1;
void insertion(int ele)
{
if((front==0&&rear==9)||(rear==front-1))
{cout<<"overflow";
return;
}
else if(front==-1)
{front=rear=0;
}
else if(rear==9)
{rear=0;
}
else
{rear++;
}
ar[rear]=ele;
}
void deletion()
{
if(front=-1)
{cout<<"underflow";
return;
}
else if(front==rear)
{front=rear=-1;
}
else if(front==9)
{front=0;
}
else
{front++;
}
}
void display()
{ int i;
if(front<=rear)
{for(i=0;i<front;i++)
{cout<<"space ";
}
for(i=front;i<=rear;i++)
{cout<<ar[i];
}
for(i=rear+1;i<=9;i++)
{cout<<"space ";
}
}
else
{for(i=front;i<=9;i++)
{cout<<ar[i];
}
for(i=0;i<=rear;i++)
{cout<<ar[i];
}
for(i=rear+1;i<front;i++)
{cout<<"space ";
}
}}
void main()
{clrscr();
int ch,ele;
do
{
cout<<"\nPress 1 toinsert in list \n";
cout<<"Press 2 to delete an element from list \n";
cout<<"Press 3 to display the list \n";
cout<<"Press 4 to exit \n";
cout<<"Enter Choice :";
cin>>ch;
switch(ch)
{case 1:cout<<"enter element ";
cin>>ele;
insertion(ele);break;
case 2:deletion();break;
case 3:display();break;
case 4:exit(1);break;
default:cout<<"\n WRONG CHOICE \n";

}
}
while(ch!=4);
getch();
}
OUTPUT : PROGRAM 26
PROGRAM 27
(ARRAY AS LINKLIST)
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<stddef.h>
struct node
{int a; node *next; };
node *ob,*top=NULL,*save;
void beg()
{ob=new node;
cout<<"Enter info";
cin>>ob->a;
ob->next=NULL;
if(top==NULL) {top=ob; }
else
{save=top;
top=ob;
ob->next=save; }
}
void deletion()
{if(top==NULL) {cout<<"Underflow";}
else
{ob=top;
top=top->next;
delete ob; }
}
void display()
{ob=top;
if(ob==NULL) {cout<<"Underflow"; }
else
{while(ob!=NULL)
{cout<<ob->a;
ob=ob->next; } }
}
void main()
{ clrscr(); int ch;
do
{cout<<"Press 1 to insert\n"<<"press 2 to delete an element from list \n"<<"press 3 to display the
list\n"<<"press 4 to exit\n"<<"enter choice:\n" ;
cin>>ch;
switch(ch)
{case 1:beg();break;
case 2:deletion();break;
case 3:display();break;
case 4:exit(1);break;
default:cout<<" WRONG CHOICE ";
}}
while(ch!=4);
getch(); }
OUTPUT : PROGRAM 27
PROGRAM 28
(ARRAY AS QUEUE)
#include<iostream.h>
#include<conio.h>
#include<process.h>
int ar[10],front=-1,rear=-1;
void insertion(int ele)
{if(rear==9)
{cout<<"overflow";}
else
{if(front==-1)
front=rear=0;
else
rear++;
ar[rear]=ele;
}
}
void deletion()
{if(front==-1){cout<<"underflow";}
else
{if(front==rear)
front=rear=-1;
else
front++; }
}
void display()
{if(front==-1){cout<<"underflow";}
else
{for(int i=front;i<=rear;i++)
{cout<<ar[i];} }
}
void main()
{clrscr(); int ch,ele;
do
{cout<<"\nPress 1 toinsert in list \n";
cout<<"Press 2 to delete an element from list \n";
cout<<"Press 3 to display the list \n";
cout<<"Press 4 to exit \n";
cout<<"Enter Choice :";
cin>>ch;
switch(ch)
{case 1:cout<<"enter element "; cin>>ele; insertion(ele);break;
case 2:deletion();break;
case 3:display();break;
case 4:exit(1);break;
default:cout<<"\n WRONG CHOICE \n";
}
}
while(ch!=4);
getch(); }

OUTPUT : PROGRAM 28
PROGRAM 29
(QUEUE AS LINKLIST)
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<stddef.h>
struct node
{int a; node *next; };
node *ob,*front=NULL,*save;
void beg()
{ob=new node;
cout<<"Enter info";
cin>>ob->a; ob->next=NULL;
if(front==NULL)
{front=ob;}
else
{save=front;
front=ob;
ob->next=save; }
}
void deletion()
{if(front==NULL){cout<<"Underflow";}
else
{ob=front;
front=front->next;
delete ob; }
}
void display()
{ob=front;
if(ob==NULL){ cout<<"Underflow";}
else
{while(ob!=NULL)
{cout<<ob->a; ob=ob->next; } }
}
void main()
{ clrscr(); int ch;
do
{cout<<"Press 1 to insert\n"<<"press 2 to delete an element from list \n"<<"press 3 to display the
list\n"<<"press 4 to exit\n"<<"enter choice:\n" ;
cin>>ch;
switch(ch)
{case 1:beg();break;
case 2:deletion();break;
case 3:display();break;
case 4:exit(1);break;
default:cout<<" WRONG CHOICE ";
}}
while(ch!=4);
getch();
}
OUTPUT : PROGRAM 29
PROGRAM 30
(CIRCULAR QUEUE)
#include<iostream.h>
#include<conio.h>
#include<stddef.h>
#include<process.h>
int a[10],front=-1,rear=-1;
void insertion(int ele)
{
if((front==0&&rear==9)||(rear==front-1))
{cout<<"overflow";
return;
}
else if(front==-1)
{front=rear=0;
}
else if(rear==9)
{rear=0;
}
else
{rear++;
}
a[rear]=ele;
}
void deletion()
{if(front==-1)
{
cout<<"underflow";
return;
}
else if(front==rear)
{front=rear=-1;
}
else if(front==9)
{front=0;
}
else
{front++;
}
}
void display()
{ int i;
if(front<=rear)
{for(int i=0;i<front;i++)
{cout<<"space";
}
for(i=front;i<=rear;i++)
{cout<<a[i];
}
for(i=rear+1;i<=9;i++)
{cout<<"space";
}}
else
{
for(i=front;i<=9;i++)
{cout<<a[i];
}
for(i=0;i<=rear;i++)
{cout<<a[i];
}
for(i=rear+1;i<front;i++)
{cout<<"space";
}
}
}
void main()
{
int ch; int ele;
do
{
cout<<"Press 1 to insert in list\nPress 2 to delete in list\nPress 3 to display the list\nPress 4 to exit\nEnter
choice:";
cin>>ch;
switch(ch)
{
case 1:cout<<"\nEnter element\t";
cin>>ele;
insertion(ele);
break;
case 2:deletion();
break;
case 3:display();
break;
case 4:exit(-1);
break;
default:cout<<"\nWRONG CHOICE\n";
}
}
while(ch!=4);
getch();
}
OUTPUT : PROGRAM 30
Consider the following tables and write SQL commands for the given statements
1) Table : PRODUCT
P_ID ProductName Manufacturer Price
TP01 Talcom Powder LAK 40
FW05 Face Wash ABC 45
BS01 Bath Soap ABC 55
SH06 Shampoo XYZ 120
FW12 Face Wash XYZ 95

Table : CLIENT
C_ID ClientName City P_ID
01 Cosmetic Shop Delhi FW05
06 Total Health Mumbai BS01
12 Live Life Delhi SH06
12 Pretty Woman Delhi FW12
16 Dreams Banglore TP01

1) To display the details of those Clients whose City is Delhi.


2) To display the details of products whose Price is in the range of 50 to 100 ( Both values included ).
3) To display the ClientName, City from table CLIENT and ProductName and Price from table PRODUCT, with their
corresponding matching P_ID.
4) To increase the price of all Products by 10 which are having Manufacturer ABC.
5) Give outputs:
a. select Count ( distinct City ) from Client;
b. select Manufacturer, MAX (Price) from Product Group By Manufacturer;
c. select ClientName, Manufacturer from Client, Product where Client . P_ID = Product . P_ID;
d. select ProductName, Price * 4 from Product;

Answers
1) Select * from CLIENT where City = ‘Delhi’;
2) Select * from PRODUCT where Price between 50 and 100;
3) Select ClientName, City, ProductName, Price from CLIENT A , PRODUCT B where A . P_ID = B . P_ID;
4) Update PRODUCT set Price = Price + 10 where Manufacturer = ‘ABC’ ;
a. Count ( Distinct City)
3
b. Manufacturer Max ( Price )
LAK 40
ABC 55
XYZ 120
c. ClientName Manufacturer
Cosmatic Shop ABC
Total Health ABC
Live Life XYZ
Pretty Woman XYZ
Dreams LAK

d. ProductName Price * 4
Talcom Powder 160
Face Wash 180
Bath Soap 220
Shampoo 480
Face Wash 380
2) Table : Emp
Empid Firstname Lastname Address City
010 Ravi Kumar Raj nagar GZB
152 Sam Tones 33 Elm St. Paris
215 Sarah Ackerman 440 U.S. 110 Upton
244 Manila Sengupta 24 Friends street New Delhi
300 Robert Samuel 9 Fifth Cross Washington
335 Ritu Tondon Shastri Nagar GZB
400 Rachel Lee 121 Harrison St. New York

Sal
Empid Salary Benefits Designation
010 75000 15000 Manager
152 80000 25000 Director
215 75000 12500 Manager
244 50000 12000 Clerk
300 45000 10000 Clerk
335 40000 10000 Clerk
400 32000 7500 Salesman

(i) To show firstname, address and city of all employees living in Paris
(ii) To display the content of Employees table having empid > 200 in descending order of Firstname.
(iii) To display the firstname and total salary of all managers from the tables Emp and sal , where total salary is calculated as
salary+benefits.
(iv) To display the maximum salary among managers and clerks from the table sal.
(v) Give the Output of following SQL commands:
(i) Select count(distinct designation) from sal;
(ii) Select designation, Count(*) from sal group by designation having count(*) >2;
(iii) Select sum(benefits) from sal where designation =’Clerk’;
(iv) Select distinct City from Emp;

Answers
a) Select Firstname, Address from Emp where City = ‘Paris’;
b) Select * from Emp where Empid > 200 Order By Firstname Desc;
c) Select Firstname, Salary + Benefits “Total Salary” from Emp A, Sal B Where A . Empid = B . Empid and Designation
= ‘Manager’;
d) Select Max ( Salary ) from Sal where Designation In (‘Manager’ , ‘Clerk’);

I. Count(distinct designation)
4

II. Designation Count(*)


Clerk 3

III. Sum ( Benefits )


32000

IV. Distinct city


GZB
Paris
Upton
New Delhi
Washington
New York
3) Table : ITEM
I_ID ItemName Manufacturer Price
PC01 Personal Computer ABC 35000
LC05 Laptop ABC 55000
PC03 Personal Computer XYZ 32000
PC06 Personal Computer COMP 37000
LC03 Laptop PQR 57000

Table : CUSTOMER
C_ID CustomerName City I_ID
01 N Roy Delhi LC03
06 H Singh Mumbai PC03
12 R Pandey Delhi PC06
15 C Sharma Delhi LC03
16 K Agarwal Banglore PC01
a) To display the details of those customers whose city is Delhi.
b) To display the details of Item whose Price is in the range of 35000 to 55000 (Both values included).
c) To display CustomerName, City, ItemName and Price of those items whose price is more than 50000.
d) To increase the Price of all items by 1000 in the table Item.
e) Give output of the following commands:
i) Select Count(Distinct City) From Customer;
ii) Select ItemName, Max(Price)) From Item Group By ItemName;
iii) Select CustomerName, Manufacturer From Item, Customer
Where Item . I_ID = Customer . I_I_D;
iv) Select ItemName, Price * 100 From Item Where Manufacturer = ‘ABC’;

Answers
1) Select * from CUSTOMER where City = ‘Delhi’;

2) Select * from ITEM where Price between 35000 and 55000;

3) Select CustomerName, City, ItemName, Price from CUSTOMER A , ITEM B where A . I_ID = B . I_ID;

4) Update ITEM set Price = Price + 10 ;

e. Count ( Distinct City)


3
f. ItemName Max ( Price )
ABC 55000
XYZ 32000
COMP 37000
PQR 57000
g. CustomerName Manufacturer
N Roy PQR
H Singh XYZ
R Pandey COMP
C Sharma PQR
K Agarwal ABC

h. ItemName Price * 10
Personal Computer 350000
Laptop 550000

4) Table : Doctor
ID Name Dept Sex Experience
101 John ENT M 12
104 Smith ORTHOPEDIC M 5
107 George CARDIOLOGY M 10
114 Lara SKIN F 3
109 K George MEDICINE F 9
117 Lucy ENT F 3

Table : Salary
ID Basic Allowance Consultation
101 12000 1000 300
104 23000 2300 500
107 32000 4000 500
114 12000 5200 100
109 42000 1700 200

a) Display Name of all doctors who are in ‘MEDICINE’ having more than 10 years experience.
b) Display the Salary of all doctors working in ‘ENT’ department, where Salary = Basic + Allowance.
c) Display the minimum Allowance of female doctors.
d) Increase the Basic Salary of the doctors by 10% whose consultation fees is greater than 200.
e) Give output :
i) Select Count(*) from Doctor where sex = ‘F’;
ii) Select Name, Basic From Doctor, Sal Where Dept = ‘ENT’ And Doctor.ID = Salary.ID;
iii) Select Distinct Dept from Doctor where Sex = ‘M’;
iv) Select Sum(Consultation) from Doctor, Sal where Doctor.ID = Salary.ID and Experience >= 10;

Answers
a) Select Name from Doctor where Dept = ‘MEDICINE’ and Experience > 10;

b) Select Basic + Allowance “ Salary “ from Doctor A , Sal B where A . ID = B . ID and Dept = ‘ENT’;

c) Select Min ( Allowance ) from Doctor A, Sal B Where A . ID = B . ID and Sex = ‘F’;

c) Update Sal set Basic = Basic + 0.1 * Basic where Consultation > 200 ;

i. Count( * )
3

ii. Designation Basic


John 12000

iii. Min ( Allowance )


1700

iv. Sum ( Consultation )


800

5) Table : Voter

VoterID Name Area City Sex Age


101 Ravi Sanjay Nagar Bareilly M 45
102 Seema Ram Nagar Delhi F 35
103 Alex Central Point Delhi M 25
104 Nitin Pawan Bihar Bareilly M 42
105 Sudha Avadh Avas Mumbai F 55
106 Pushpa Civil Lines Delhi F 33
107 Ali Old City Bareilly M 40

a) To display the information of Voters who live in Delhi and having age in between 30 and 50.
b) Create a view “VIP” having information of male Voters who belong to Area “Civil Lines”.
c) Display Name and Age of male Voters whose name starts with ‘A’ in the descending order of there Age and alphabetical order
of their Name.
d) Display average Age of the male Voters of each city.
e) Assign the value of age as 18 to those Voters whose age is NULL.
f) Insert a new row in the table Voter with following values ( 108 , ‘Neha’ , ‘Old City’ , ‘Bareilly’ , ‘F’ , 36).

Answers

a) Select * from Voter where City = ‘Delhi’ and Age Between 30 and 50;

b) Create View VIP as Select * from Voter where Area = ‘Civil Lines’ and Sex = ‘M’;

c) Select Name , Age from Voter where Sex = ‘F’ and Name Like ‘A%’ Order By Age Desc, Name ;

d) Select Avg ( Age ) from Voter Group By City Having Sex = ‘M’ ;

e) Update Voter Set Age = 18 Where Age Is Null;

f) Insert Into Voter Values ( 108 , ‘Neha’ , ‘Old City’ , ‘Bareilly’ , ‘F’ , 36);

Potrebbero piacerti anche