You are on page 1of 44

.

INDEX

Q. No. QUESTIONS

1. BUBBLE SORTING

2. SELECTION SORTING

3. LINEAR SEARCH
4. BINARY SEARCH

5. SUM OF MATRICES

6. MARKSHEET

7. MAX,MIN,SUM,AVG
8. PUSH OPERATION

9. POP OPERATION

10. INSERT OPERATION


INDEX

Q. No. QUESTIONS

11. DELETE OPERATION

12. NO. OF ALPHABETS

13. NO. OF LINES


14. NO. OF WORDS

15. NO. OF SPACES

16. TO COPY A BINARY FILE

17. INPUT DATA USING STR.


18. INPUT DATA USING CLASS

19. SUM OF BOTH DIAGONALS

20. REPLACING VALUES UNDER


CONDITION IN ARRAY
QUES. FROM SQL

Q-1) WRITE A PROGRAM TO INPUT AN ARRAY OF INTEGER & ARRANGE THEM IN


THERE DESCENDING ORDER USING BUBBLE SORT

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int a[20],i,n,j,t=0;
cout<<"n=";
cin>>n;
cout<<"Enter the array";
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
{ for(j=0;j<n-1;j++)
{ if(a[j]<a[j+1])
{ t=a[j];
a[j]=a[j+1];
a[j+1]=t; }
}
}cout<<”Sorted Array”;
for(i=0;i<=n-1;i++)
cout<<a[i]<<"\t";
getch();
}
OUTPUT:
N= 5
Enter the Array 2 5 4 3 1
Sorted Array 1 2 3 4 5
Q-2)WRITE A PROGRAM TO INPUT AN ARRAY OF INTEGER AND ARRANGE THEM IN
THERE ASCENDING USING SEL SORT

#include<iostream.h>
#include<conio.h>
void ss(int [],int);
void main()
{clrscr();
int a[50],item,n,p;
cout<<"Enter n ="; cin>>n;
cout<<"Enter the array";
for(int i=0;i<n;i++)
cin>>a[i];
ss(a,n);
cout<<"Sorted array\n";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
getch();}

void ss(int a[],int s)


{ int sl,p,t;
for(int i=0;i<s;i++)
{ sl=a[i]; p=i;
for(int j=i+1;j<s;j++)
{ if(a[j]<sl)
{ sl=a[j]; p=j;}}
t=a[i];
a[i]=a[p];
a[p]=t; }}
OUTPUT: n= 5 Enter the array= 4 9 7 3 1
Sorted Array= 1 3 4 7 9
Q-3) WRITE A PROGRAM TO SEARCH A PARTICULAR ELEMENT IN THE ARRAY USING
LINEAR SEARCH METHOD
#include<iostream.h>
#include<conio.h>
void main()
{int a[10],i,s,p=-1;
clrscr();
cout<<"Enter 10 no."<<endl;
for(i=0;i<10;i++)
cin>>a[i];
cout<<"\n Enter the no. to be searched";
cin>>s;
for(i=0;i<10;i++)
{ if(a[i]==s)
{p=i+1;
break;}
}
if(p==-1)
cout<<"\n Number not found";
else
{cout<<"\n The no. is at location=";
cout<<p; }
getch();
}
OUTPUT :
Enter 10 no.= 1 2 3 4 5 6 7 8 9 10
Enter no. to be searched =5
The no. is at location= 5

Q-4) WRITE A PROGRAM TO SEARCH AN ELEMENT USING BINARY SEARCH


#include<iostream.h>
#include<conio.h>
int bs(int [],int,int);
void main()
{clrscr();
int a[50],item,n,p;
cout<<"Enter n ="; cin>>n;
cout<<"Enter the 'SORTED' array";
for(int i=0;i<n;i++)
cin>>a[i];
cout<<"Element to be searched="; cin>>item;
p=bs(a,n,item);
if(p==-1)
cout<<"No Number found";
else
cout<<"Number found at"<<p+1<<endl;
getch();}
int bs(int a[],int s,int x)
{ int b,l,m;
b=0; l=s-1;
while(b<=l)
{ m=(b+l)/2;
if(x==a[m]) return m;
else if(x>a[m]) b=m+1;
else l=m-1;}
return -1; }
OUTPUT:
Enter n=5 Enter the Sorted Array= 1 2 4 7 9 Element to be
Searched= 4 Number found at 3
Q-5) WRITE A PROGRAM TO INPUT TWO MATRICS AND DETERMINE THEIR SUM.
#include<iostream.h>
#include<conio.h>
void main()
{
int arr1[3][3],arr2[3][3],i,j,add;
clrscr();
cout<<"\nEnter I Array elements =";
for(i=1;i<=3;i++)
{ for(j=1;j<=3;j++)
cin>>arr1[i][j];
}
cout<<"\nPrint the I Array elements ";
for(i=1;i<=3;i++)
{cout<<"\n";
for(j=1;j<=3;j++)
cout<<"\t"<<arr1[i][j];
}
cout<<"\nEnter II Array elements =";
for(i=1;i<=3;i++)
{for(j=1;j<=3;j++)
cin>>arr2[i][j]; }
cout<<"\nPrint the II Array elements ";
for(i=1;i<=3;i++)
{cout<<"\n";
for(j=1;j<=3;j++)
cout<<"\t"<<arr2[i][j]; }
cout<<"\n\nPrint the Addition of Array elements ";
for(i=1;i<=3;i++)
{ cout<<"\n";
for(j=1;j<=3;j++)
cout<<"\t"<<arr1[i][j]+arr2[i][j];
}
getch();
}
OUTPUT:
Enter I array elements= 1 2 4 2
Print I Array= 1 2
4 2
Enter II array elements= 2 0 2 0
Print I Array= 2 0
2 0

Print the Addition array= 3 2


6 2

Q-6) WRITE A PROGRAM TO CREATE & DISPLAY MARKSHEET OF 10 STUDENTS USING


STRUCTURE
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class student
{ private:
int rollno;
char name[20];
float marks[5],total,average,grade;
public:
void input();
void calcgrade();
void dispdata();
};
void student::input()
{ int i;
cout<<"\n\nEnter the roll no., name and marks in 5 subjects respectively=
";
cin>>rollno;
gets(name);
for(i=0;i<5;i++)
cin>>marks[i];}

void student::calcgrade()
{ int i;
total=average=grade=0;
for(i=0;i<5;i++)
total+=marks[i];
average=total/5;
if(average>=75)
grade='A';
else if(average>=60)
grade='B';
else if(average>=40)
grade='C';
else
grade='F';}

void student::dispdata()
{ int i;
cout<<"\n\nThe roll no.="<<rollno<<"\nName= ";
puts(name);
cout<<"Marks in 5 subjects= ";
for(i=0;i<5;i++)
cout<<marks[i]<<" ";
cout<<"\nTotal="<<total<<"\nAverage= "<<average;
cout<<"\nGrade= "<<(char)grade; }

void main()
{ int p;
clrscr();
student s[10];
for(p=0;p<10;p++)
{ s[p].input();
s[p].calcgrade();
s[p].dispdata(); }
getch();
}

OUTPUT :
Enter the roll no., name and marks in 5 subjects respectively= 15
Paramjot
90 90 90 90 90
The roll no.=15
Name= Paramjot
Marks= 90 90 90 90 90
Total= 450
Average= 90
Grade= A

Q-7) WRITE A PROGRAM TO CREATE & DISPLAY MAX, MIN, SUM &AVG. OF ARRAY
FOR 10 OBJECTS OF STUDENTS.
#include<iostream.h>
#include<conio.h>
struct NUMBER
{ float arr[10],max,min,sum,avg;};

void main()
{ clrscr();
int max,min,sum,avg;
NUMBER n[10];
for(int i=0;i<10;i++)
{ cout<<”Enter the ARRAY elements=”
for(int j=0;j<10;j++)
cin>>n[i].arr[j];
for(int x=0;x<10;x++)
{ max=min=avg=sum=0;
max=min=n[i].arr[0];
if(n[i].arr[x]>max)
max=n[i].arr[x];
if(n[i].arr[x]<min)
min=n[i].arr[x];
sum+=n[i].arr[x];
avg=sum/10;
}
cout<<” Maximum, Minimum, Sum & Average is=”;
cout<<max<<” “<<min<<” “<<sum<<” “<<avg;
} getch(); }
OUTPUT: Enter array elements= 2 3 1 5 4 6 7 8 9 10
Maximum, Minimum, Sum & Average is=10 1 55 5.5 (Same 10 times)

Q-8) WRITE A PROGRAM TO PERFORM A PUSH OPERATION ON A LINKED STACK AND


DISPLAY THE STACK ELEMENTS..

#include<iostream.h>
#include<conio.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()
{ int inf;
char ch='y';
top=NULL;
clrscr();
while(ch=='y'||ch=='Y')
{
cout<<"\n enter information for the new node";
cin>>inf;
newptr=create_new_node(inf);
if(newptr==NULL)
{
cout<<"\n can not create new node";
exit(1);
}
push(newptr);
cout<<"\n now the link stack is";
display(top);
cout<<"press Y to enter more nodes,n to exit";
cin>>ch;}}
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<<"!!!\n";
}

OUTPUT:
Enter information for the new node…7
Press Y to enter more nodes, n to exit…y
Enter information for the new node…1
Press Y to enter more nodes, n to exit…n
The stack now is:
1->7->!!!
Q-9) WRITE A PROGRAM TO PERFORM POP OPERATION ON LINKED STACK AND
DISPLAY THE STACK ELEMENT

#include<iostream.h>
#include<conio.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 pop();

void main()
{top=NULL;
int inf;
char ch='y';
while(ch=='y'||ch=='Y')
{cout<<"\n enter information for the new node";
cin>>inf;
newptr=create_new_node(inf);
if(newptr==NULL)
{ cout<<"\n can not create new node";
getch();
exit(1);
}
push(newptr);
cout<<"\n now the link stack is";
cout<<"press Y to enter more nodes,n to exit";
cin>>ch;
}
clrscr();
do
{ cout<<"the stack now is";
display(top);
getch();
cout<<"want to pop an element(y/n)";
cin>>ch;
if(ch=='y'||ch=='Y')
pop();
} while(ch=='y'||ch=='Y');
}

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 pop()
{ if(top==NULL)
cout<<"underflow";
else
{ ptr=top;
top=top->next;
delete ptr; }
}

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

OUTPUT:
Enter information for the new node…1
Press Y to enter more nodes,N to exit…y
Enter information for new nodes…7
Press Y to enter more nodes,N to exit…y
Enter information for new nodes…2
Press Y to enter more nodes,N to exit…n

The stack now is:


2->7->1->!!!
Want to pop an element? (y/n)…y

The stack now is :


7->1->!!!
Want to pop an element? (y/n)…n

Q 10. WRITE A PROGRAM TO PERFORM AN INSERT OPERATION ON LINKED QUEUE


AND DISPLY THE QUEUE ELEMENTS. THE QUEUE CONTAINS DATA OF TYPE STRING.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct queue
{ char str[30];
queue *next;
}*START,*REAR,*newptr,*temp;

void INSERT()
{
newptr=new queue;
cout<<"Enter the string of the node\n";
gets(newptr->str);
newptr->next=NULL;
if(REAR==NULL)
START=REAR=newptr;
else
{
temp=REAR;
REAR=newptr;
newptr->next=temp;
}
}

void DISPLAY()
{ int i=0;
while(newptr!=NULL)
{ i++;
cout<<"\n\nString of node " <<i<<" is: "<<newptr->str;
newptr=newptr->next;
}
getch();
delete newptr;
}

void main()
{
clrscr();
char ch='y';
while(ch=='y'||ch=='Y')
{
INSERT();
cout<<"Do you want to enter more nodes to the queue(y/n)\n";
cin>>ch;
clrscr();
}
cout<<"Do you want to see the queue(y/n)\n";
cin>>ch;
if(ch=='y'||ch=='Y')
DISPLAY();
}
OUTPUT:
Enter information for the new node…17
Now the queue is:
17->!!!
Press Y to enter more nodes,N to exit…y
Enter information for new nodes…12
Now the queue is:
17->12->!!!

Q-11) WRITE A PROGRAM TO PERFORM DELETE OPERATION ON LINKED QUEUE &


DISPLAY THE QUEUE ELEMENTS.

#include<iostream.h>
#include<process.h>
#include<string.h>
struct node
{ char info[25];
node*next;
}*front,*newptr,*save,*ptr,*rear;
node *create_new_node(char n[25]);
void insert(node*);
void display(node*);
void delnode_q();
void main()
{ front=rear=NULL;
char inf[25],ch='y';
while(ch=='y'||ch=='Y')
{ cout<<"\n enter the information for new node";
cin>>inf;
newptr=create_new_node(inf);
if(newptr==NULL)
{cout<<"\n cannot create mew node!!";
exit(1);}
insert(newptr);
cout<<"\n Press Y to enter new node,N to exit\n";
cin>>ch;
}
do
{cout<<"\n The linked queue now is (frontto_rear):\n";
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(char n[25])
{ ptr=new node;
strcpy(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(front==NULL)
cout<<"underflow!!!\n";
else
{ ptr=front;
front=front->next;
delete ptr;} }
void display(node*np)
{ while(np!=NULL)
{ cout<<np->info<<"->";
np=np->next;} }

OUTPUT:
Enter information for the new node…15
Press Y to enter more nodes, N to exit…n
the linked queue now is :
3->4->8->9->15-> !!!
Want to delete first node? (y/n)…y
the linked queue now is :
4->8->9->15-> !!!

Q-12) WRITE A PROGRAM TO READ THE CONTENTS FROM A TEXT FILE “text.txt”,
COUNT & DISPLAY THE NUMBER OF ALPHABETS PRESENT IN IT.

#include<fstream.h>
#include<ctype.h>
#include<conio.h>
void main()
{
char ch; int c=0;
ifstream fin("test.txt");
if(!fin)
{
cout<<"error in opening file";

}
while(fin)
{
fin.get(ch);
if(ch==EOF)
break;
if(isalpha(ch))
c++;
}
cout<<"\n No. of alphabets are"<<c;
fin.close();

OUTPUT:
He is playing Football
No. of alphabets are 19.

Q-13) WRITE A PROGRAM TO READ THE CONTENTS FROM A TEXT FILE “sample.txt”,
COUNT & DISPLAY THE NUMBER OF LINE PRESENT IN IT.
#include<fstream.h>
void main()
{
char str[255];
int l=0;
ifstream fin;
fin.open("sample.txt");
if(!fin)
{
cout<<"error in opening the file";
}
while(fin)
{
fin.getline(str,255);
for(int i=0;i<=255;i++)
{
if(str[i]=='\n')
l++;
}
}
cout<<"The no. of lines r"<<l;
fin.close();
}

OUTPUT:
I am a student of class XII
This is my Practical file

The no. of lines are 2.

Q-14) WRITE A PROGRAM TO READ THE CONTENTS FROM A TEXT FILE “notes.txt”,
COUNT & DISPLAY THE NUMBER OF WORDS PRESENT IN IT.

#include<fstream.h>
void main()
{
char ch; int c=1;
ifstream fin("notes.txt");
if(!fin)
cout<<"error in opening of file";
while(fin)
{
fin.get(ch);
if(ch==EOF)
break;
else if(ch==' ')
c++;
}
cout<<"No.of words are"<<c;
fin.close();
}

OUTPUT: It is a hot sunny day today.

No. of words are 7.

Q-15) WRITE A PROGRAM TO READ THE CONTENTS FROM A TEXT FILE “paper.txt”,
COUNT & DISPLAY THE NUMBER OF BLANK SPACES WORDS PRESENT IN IT.

#include<fstream.h>
void main()
{
char ch; int c=0;
ifstream fin;
fin.open("notes.txt");

if(!fin)
cout<<"error in opening the file";
while(fin)
{
fin.get(ch);
if(ch==EOF)
break;
else if(ch==' ')
c++;
}
cout<<"No. of blank spaces are"<<c-1;
fin.close();
}

OUTPUT: Delhi is capital of India

No. of blank spaces are 4.

Q-16) WRITE A PROGRAM TO COPY THE CONTENTS OF TEXT FILE “book1.txt”, TO


“book2.txt”.
#include<fstream.h>
void main()
{
char ch;
ifstream fin("book1.txt");
ofstream fout("book2.txt");
if(!fin||fout)
{
cout<<"error in opening the file book1.txt";
}
else
{
while(fin)
{
fin.get(ch);
if(ch==EOF)
break;
else
fout.put(ch);
}
}
fin.close();
fout.close();
}

OUTPUT:
book1.txt contains Books on Computer Science
Then book2.txt will have same Books on Computer Science

Q-17) WRITE A PROGRAM TO INPUT THE DETAILS OF 5 EMPLOYEES IN BINARY FILE


USING FOLLOWING STRUCTURE EMPLOYEE, FIELDS – ENAME, ECODE, SALARY,
DESIGNATION.

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
struct Employee
{char ename[20],designation[10];
long int ecode,salary;
};

void INPUT(char file[])


{
ofstream fout;
fout.open(file,ios::out|ios::binary);
if(!fout)
cout<<"unable to open file!!";
else
{
Employee temp;
for(int i=0;i<5;i++)
{
cout<<"Enter name\n";
gets(temp.ename);
cout<<"Enter designation\n";
gets(temp.designation);
cout<<"Enter employee code\n";
cin>>temp.ecode;
cout<<"Enter salary\n";
cin>>temp.salary;
fout.write((char*)&temp,sizeof(temp)); }
fout.close();
}
}
void display(char file[])
{ clrscr();
cout<<"CODE\t\tNAME\t\tDESIGNATION\tSALARY\n";
ifstream fin;
fin.open(file,ios::binary);
if(!fin)
cout<<"Unable to open file";
else
{
Employee temp;
for(int i=0;i<5;i++)
{
fin.read((char*)&temp,sizeof(temp));
cout<<temp.ecode<<"\t\t"<<temp.ename<<"\t\t"<<temp.designation;
cout<<"\t\t"<<temp.salary<<"\n"; }
fin.close();}
}

void main()
{ clrscr();
char file1[20];
cout<<"Enter file name\n";
cin>>file1;
INPUT(file1);
display(file1);
getch(); }
Q-18) WRITE A PROGRAM TO INPUT THE DETAILS OF 5 STUDENTS IN BINARY FILE
USING FOLLOWING CLASS STUDENT WITH INPUT() & DISPLAY() & FIELDS – STUNAME,
ROLLNO, MARKS, GRADE.

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
class student
{ int rollno,marks;
char stuname[20],grade;
public:
void input();
void display();
};

void student::input()
{ cout<<"Enter roll number\n";
cin>>rollno;
cout<<"Enter name\n";
gets(stuname);
cout<<"Enter marks\n";
cin>>marks;
cout<<"Enter grade\n";
cin>>grade; }

void student::display()
{ cout<<rollno<<"\t\t"<<stuname<<"\t\t"<<marks<<"\t\t"<<grade<<"\n"; }

void main()
{ char file[10];
int i;
student temp;
clrscr();
cout<<"enter file name\n";
cin>>file;
ofstream fout;
fout.open(file,ios::binary);
if(!fout)
cout<<"Unable to open file!!";
else
{
for(i=0;i<5;i++)
{
temp.input();
fout.write((char*)&temp,sizeof(temp));
}
fout.close();
}
clrscr();
ifstream fin;
fin.open(file,ios::binary);
if(!fin)
cout<<"Unable to open file!!";
else
{ cout<<"\t\tDetails\n";
cout<<"ROLL\t\tNAME\t\tMARKS\t\tGRADE\n";
for(i=0;i<5;i++)
{
fin.read((char*)&temp,sizeof(temp));
temp.display(); }
}
getch(); }
Q-19) WRITE A PROGRAM TO PRINT THE SUM OF LEFT AND RIGHT DIAGONALS OF A
SQUARE MATRIX SEPERATELY. MATRIX IS PASSED TO THE FUNCTION AS AN
ARGUMENT.

#include<iostream.h>
#include<conio.h>
void DiagSum(int A[][],int N)
{ int SumD1=0,SumD2=0;
for (int I=0;I<N;I++)
{SumD1+=A[I][I];
SumD2+=A[N-I-1][I]; }
cout<<”Sum of Diagonal 1=”<<SumD1<<endl;
cout<<”Sum of Diagonal 2=”<<SumD2<<endl;
}
void main()
{ clrscr();
int a[20][20],i,j,n;
cout<<”Enter the size=”;
cin>>n;
cout<<”Enter the array=”;
for(i=0;i<n;i++)
{ for(j=0;j<10;j++)
{ cin>>a[i][j];} }
DiagSum(a[][],n);
getch();
}

OUTPUT :
Enter the size=2
Enter the array= 4 1 5 3
Sum of Diagonal 1= 7
Sum of Diagonal 2= 6
Q-20) WRITE A PROGRAM USING FUNCTIONS WHICH ACCEPTS AN INTEGER ARRAY &
ITS SIZE AS ARGUMENTS & REPLACES ELEMENTS HAVING ODD VALUES WITH
THRICE ITS VALUE & ELEMENTS HAVING EVEN VALUES WITH TWICE ITS VALUE.

#include<iostream.h>
#include<conio.h>
void replace( int a[],int n)
{ int i;
for(i=0;i<n;i++)
{ if(a[i]%2==0)
a[i]=2*a[i];
if(a[i]%3==0)
a[i]=3*a[i]; }
}
void main()
{ clrscr();
int a[10],i,n;
cout<<”Enter the size=”;
cin>>n;
cout<<”Enter the array=”;
for(i=0;i<n;i++)
cin>>a[i];
replace(a,n);
cout<<”The new array=”;
for(i=0;i<n;i++)
cout<<a[i]<<” “;
getch();
}
OUTPUT:
Enter the size=5
Enter Array= 1 2 5 3 4
The new Array= 3 4 15 9 16
Q.NO.1) Consider the following tables. Write SQL commands for the statements (i) to (iv)
and give outputs for SQL queries (v) to (viii) 6

GARMENT
GCODE DESCRIPTION PRICE MCODE LAUNCHDATE
10023 PENCIL SKIRT 1150 F03 19-DEC-08
10001 FORMAL SHIRT 1250 F01 12-JAN-08
10012 INFORMAL SHIRT 1550 F02 06-JUN-08
10024 BABY TOP 750 F03 07-APR-07
10090 TULIP 850 F02 31-MAR-07
10019 EVENING GOWN 850 F03 06-JUN-08
10009 INFORMAL PANT 1500 F02 20-OCT-08
10007 FORMAL PANT 1350 F01 09-MAR-08
10020 FROCK 850 F04 09-SEP-07
10089 SLACKS 750 F03 31-OCT-08

FABRIC

FCODE TYPE
F04 POLYSTER
F02 COTTON
F03 SILK
F01 TERELENE

1) To display gcode and description of each garment in descending order of gcode


2) To display the details of all the garments which have readydate in between 08-dec-07 and 16-
jun-08(inclusive of both the dates)
3) To display the average PRICE of of all garments which are made up of fabric with fcode as
F03
4) To display fabric wise highest and lowest price of the garments from garment table.
5) SELECT SUM(PRICE) FROM GARMENT WHERE FCODE=’F01’;
6) SELECT DESCRIPTION, TYPE FROM GARMENT, FABRIC WHERE
GARMENT.FCODE=FABRIC.FCODE AND GARMENT.PRICE>=1260;
7) SELECT MAX(FCODE) FROM FABRIC;
8) SELECT COUNT (DISTINCT PRICE) FRON GARMENT;
ANSWERS

1) SELECT DCODE,DESCRIPTION
FROM DRESS
ORDER BY DCODE;
2) SELECT *
FROM DRESS
WHERE LAUNCHDATE
BETWEEN 05-DEC-07 AND 20-JUN-08;
3) SELECT AVG(PRICE)
FROM DRESS
WHERE MCODE=M003;
4) SELECT MAX(PRICE),MIN(PRICE)
FROM DRESS, MATERIAL
WHERE DRESS.DCODE=MATERIAL.MCODE;

5) 1450

6) DESCRIPTION TYPE
PENCIL SKIRT SILK
FORMAL SKIRT TERELINE
INFORMAL COTTON
FORMAL SHIRT TERELENE
FROCK POLYESTER
INFORMAL SHIRT COTTON
EVENING GOWN SILK
TULIP SKIRT COTTON

7) M001,M002

8) 10

Q.NO.2) Consider the following tables. Write SQL commands for the statements (i) to (iv)
and give outputs for SQL queries (v) to (viii) 6
TABLE:PRODUCT

P_ID Product Name Manufacturer Price


TP01 TALCOM POWDER LAK 40
FW05 FACEWASH ABC 45
BS01 BATHSOAP ABC 55
SHO6 SHAMPOO XYZ 120
FW12 FACEWASH XYZ 95
TABLE:CLIENT

C_ID CLINET NAME CITY P_ID


01 COSMETIC SHOP DELHI FW05
06 TOTAL HEALTH MUMBAI BS01
12 LIVELIFE DELHI SH06
15 PRETTY WOMAN DELHI FW12
16 DREAMS BANGALORE TP01

i) To display the details of those clients whose city is Delhi.

ii) To display the details of products whose price is in the range of 50 to 100 (Both values
included)

iii) To display the client name, city from table client, and product name and price from table
product, with their corresponding matching P_ID.

iv) To increase the price of all products by 10

v) SELECT DISTINCT CITY FROM CLIENT;

vi) SELECT MANUFACTURER, MAX (PRICE), MIN (PRICE), COUNT (*)


FROM PRODUCT GROUP BY MANUFACTURER;

vii) SELECT CLIENT NAME, MANUFACTURER NAME FROM PRODUCT,


CLIENT WHERE CLIENT.PROD_ID = PRODUCT. P_ID;

viii) SELECT PRODUCT NAME, PRICE*4 FROM PRODUCT ;

ANSWERS

i. SELECT *
FROM CLIENT
WHERE CITY = “DELHI”;

ii. SELECT*
FROM PRODUCT
WHERE PRICE BETWEEN 50 TO 100 ;

iii. SELECT CLIENT NAME, CITY, PRODUCTNAME, PRICE


FROM CLIENT, PRODUCT
WHERE CLIENT. P_ID=PRODUCT.P_ID

iv. UPDATE PRODUCT


SETPRICE=PRICE+10;

v. DELHI
MUMBAI
BANGALORE

vi. LAK 40 40 1
ABC 55 45 2
XYZ 120 95 2

vii. COSMETICSHOP FACEWASH


TOTALHEALTH BATHSOAP
LIVELIFE SHAMPOO
PRETTYWOMAN FACEWASH
DREAMS TALCOMPOWDER

viii. TALCOMPWDER 160


FACEWASH 180
BATHSOAP 220
SHAMPOO 480
FACEWASH 380

Q.NO.3) Consider the following tables. Write SQL commands for the statements (i) to (iv)
and give outputs for SQL queries (v) to (viii) 6
TABLE:SENDER
TABLE : RECIPIENT

(i) To display the names of all Senders from Mumbai

(ii) To display the RecID), SenderName, SenderAddress, RecName, RecAddress


for every Recipient

(iii) To display Recipient details in ascending order of RecName

(iv) To display number of Recipients from each city

(v) SELECT DISTINCT SenderCity FROM Sender;

(vi) SELECT A. SenderName, B.RecName


FROM Sender A, Recipient B
WHERE A. SenderlD = B.SenderlD AND B.RecCity = ‘Mumbai’;

(vii) SELECT RecName, RecAddress


FROM Recipient
WHERE RecCity NOT IN (‘Mumbai’, ‘Kolkata’);

(viii) SELECT RecID, RecName


FROM Recipient
WHERE SenderID=’MU02' ORSenderID=’ND50';
ANSWERS

(i) SELECT SenderName FROM sender


WHERE SenderCity = “Mumbai”;

(ii) SELECT RecID, SenderName, SenderAddress, RecName, RecAddress


FROM Sender, Recipient WHERE Sender.SenderID = Recipient.SenderID;

(iii) SELECT * FROM Recipient


ORDER BY RecName;

(iv) SELECT RecCity, count(*)


FROM Recipient
Group By RecCity;

(v) New Delhi


Mumbai

(vi) R Jain H Singh


S Jha P K Swamy

(vii) S mahajan 116,A Vihar


S Tripathi 13, B1 D, Mayur Vihar

(viii) ND08 S Mahajan


ND45 S Tripathi

Q.NO.4) Consider the following tables. Write SQL commands for the statements (i) to (iv)
and give outputs for SQL queries (v) to (viii) 6
TABLE : DOCTOR

ID NAME DEPT SEX EXPERIENCE


101 JOHN ENT M 12
104 SMITH ORTHOPAEDIC M 5
107 GEORGE CARDIOLOGY M 10
114 LARA SKIN F 3
109 K GEORGE MEDICINE F 9
105 JOHNSON ORTHOPAEDIC M 10
117 LUCY ENT F 3
111 BILL MEDICINE F 12
130 MORPHY ORTHOPAEDIC M 15

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
105 18900 1690 300
130 21700 2600 300

I) DISPLAY NAME OF ALL DOCTORS WHO ARE IN “MEDICINE” HAVING MORE


THAN 10 YEARS EXPERIENCE FROM THE TABLE DOCTOR.

II) DISPLAY THE AVERAGE SALARY OF ALL DOCTORS WORKING IN “ENT”


DEPARTMENT USING THE TABLES DOCTORS AND SALARY.
SALARY=BASIC+ALLOWANCE.

III) DISPLAY THE MINIMUM ALLOWANCE OF FEMALE DOCTORS.

IV) DISPLAY THE HIGHEST CONSULTATION FEE AMONG ALL MALE DOCTORS.

V) SELECT COUNT (*) FROM DOCTOR WHERE SEX=”F”

VI) SELECT NAME, DEPT,BASIC FROM DOCTOR, SALARY WHERE DEPT =”ENT”
AND DOCTOR.ID=SALARY.ID
ANSWER

i) SELECT NAME FROM DOCTOR


WHERE DEPT=”MEDICINE” AND EXPERIENCE >10 :

ii) SELECT AVG (BASIC+ALLOWANCE) FROM DOCTOR, SALARY


WHERE DOCTOR.ID=SALARY.ID AND DEPARTMENT=”ENT”;

iii) SELECT MIN (ALLOWANCE) FROM DOCTOR, SALARY


WHERE DOCTOR.ID=SALARY
WHERE DOCTOR.ID=SALARY.ID AND SEX = “F” ;

iv) SELECT MAX(CONSULTATION) FROM DOCTOR, SALARY


WHERE DOCTOR.ID=SALARY.ID AND SEX=”M”;

v) 4

vi) NAME DEPT BASIC

JOHN ENT 12000

Q.NO.5) Consider the following tables. Write SQL commands for the statements (i) to (iv)
and give outputs for SQL queries (v) to (viii) 6
EMPLOYEES
EMPID FIRSTNAME LASTNAME ADDRESS CITY
010 GEORGE SMITH 83 FIRST STREET HOWARD
105 MERRY JONES 842 VINE AVE. LOSANTIVILLE
152 SAM TONES 33ELM ST. PARIS
215 SARAH ACKERMAN 440US110 UPTON
244 MANILA SENGUPTA 24FRIENDST. NEW DELHI
300 ROBERT SAMUEL 95TH CROSS WASHINGTON
335 HENRY WILLIAMS 12 MORE ST. BOSTON
400 RACHEL LEE 121HARRISONST. NEW YORK
441 PETER THOMSON 11 RED ROAD PARIS
EMPSALARY

EMPID SALARY BENEFITS DESIGNATION


010 75000 15000 MANGER
105 65000 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
441 28000 7500 SALESMAN

i) TO DISPLAY FIRST NAME, LASTNAME,ADDRESS AND CITY OF ALL


EMPLOYEES IN PARIS FROM THE TABLE EMPLOYEES.
ii) TO DISPLAY THE CONTENT OF EMPLOYEES TABLE IN DECENDING ORDER OF
FIRSTNAME.
iii) TO DISPLAY THE FIRSTNAME, LASTNAME AND TOTAL SALARY OF ALL
MANAGERS FROM THE TABLES EMPLOYEES AND EMP SALARY, WHERE
..TOTAL SALARY IS CALCULATED AS SALARY+BENEFITS.
iv) TO DISPLAY THE MAXIMUM SALARY AMONG MANAGERS AND CLERKS FROM
THE TABLE EMP SALARY.
v) SELECT FIRSTNAME, SALARY FROM EMPLOYEES, EMP SLARY WHERE
DESIGNATION=”SALESMAN” AND EMPLOEES.EMPID=EMP SALARY. EMP ID;

vi) SELECT COUNT (DISTINCT DESIGNATION) FROM EMP SALARY;

vii) SELECT DESIGNATION, SUM (SALARY) FROM EMP SALARY GROUP BY


DESIGNATION HAVING COUNT (*) > 2;

viii) SELECT SUM (BENEFITS) FROM EMPLOYEES WHERE DESIGNATION= ‘CLERK’


ANSWER
i) SELECT FIRSTNAME, LASTNAME, ADDRESS, CITY
FROM EMPLOYEES
WHERE CITY=’Paris’;

ii) SELECT * FROM EMPLOYEES ORDER BY FIRSTNAME DESC;

iii) SELECT FIRSTNAME,LASTNAME, SALARY+ BENEFITS “TOTAL SLARY”


FROM EMPLOYEES E, EMP SALARY ES
WHERE E. EMPID = ES. EMPID
AND DESIGNATION=MANAGER ;

iv) SELECT MIN (SALARY) FROM EMP SALARY GROUP BY DESIGNATION


HAVING DESIGNATION IN (‘MANAGER,CLERK);

v) RACHEL 32000
PETER 28000

vi) 4

vii) MANGER 215000


CLERK 135000

viii) 32000

You might also like