You are on page 1of 71

KENDRIYA

VIDYALAYA

COMPUTER SCIENCE
PRACTICAL NOTEBOOK
AISSCE 2018-19

SUBMITTED BY: abc , XII-A

2018-2019
ACKNOWLEDGEMENT

I am extremely thankful to the Principal for his encouragement


and for all the facilities that he provided for this practical work and our
computer teacher xyz for giving me the opportunity for this practical work.
I am very thankful to them for their advice and guidance during the course
of my practical work.

Signature of Candidate
CERTIFICATE

This is to certify that abc, student of class XII- of


KENDRIYA VIDHYALAYA has completed the Computer
Practical during the academic year 2018-2019 towards partial
fulfillment of credit for the Computer Practical of AISSCE 2019
and submitted the satisfactory report as completed in the following
pages under my supervision and does not involve in plagiarism of
any kind. The reference taken in making this project has been
declared at the end of this report.

___________________
Signature of teacher
(MR. PRAMOD KUMAR)
INDEX
s.no Program or query
1. Function overloading
2. Class and object
3. Constructor and destructor
4. Multiple inheritance
5. Multilevel inheritance
6. Data handling(average word size)
7. Data handling(count number of spaces)
8. Data handling(frequency of each character in file)
9. Swapping using pointer
10. pointer
11. Linear search
12. Binary search
13. Bubble sorting
14. Selection sorting
15. Insertion sorting
16. Addition and multiplication of two matrix
17. Middle row and middle column (2-D array)
18. Binary file using structure
19. Menu based stack
20. Menu based queue
21. Structured query language
1 . Function Overloading

#include<iostream.h>
#include<conio.h>
void amount(float princ,int time,float rate)

{cout<<"\n Principal Amount : "<<princ;


cout<<"\n Time : "<<time<<" years"; cout<<"\n Rate : "<<rate;
cout<<"\n Intrest Amount : "<<(princ*time*rate); }
void amount(float princ,int time)
{ cout<<"\n Principal Amount : "<<princ;
cout<<"\n Time : "<<time<<" years"; cout<<"\n Rate : 0.08";
cout<<"\n Intrest Amount : "<<(princ*time*0.08); }
void amount(float princ,float rate)
{ cout<<"\n Principal Amount : "<<princ;

cout<<"\n Time : 2 years"; cout<<"\n Rate : "<<rate;


cout<<"\n Intrest Amount : "<<(princ*2*rate); }
void amount(int time,float rate)

{ cout<<"\n Principal Amount : 2000 ";


cout<<"\n Time : "<<time<<" years"; cout<<"\n Rate : "<<rate;

cout<<"\n Intrest Amount : "<<(2000*time*rate);}


void amount(float princ)
{cout<<"\n Principal Amount : "<<princ;

cout<<"\n Time : 2 years"; cout<<"\n Rate : 0.08";


cout<<"\n Intrest Amount : "<<(princ*2*0.08);}
void main()
{clrscr();
cout<<"\nCase 1"; amount(2000.0F);
cout<<"\nCase 2"; amount(2500.0F,3);
cout<<"\nCase 3"; amount(2000.0F,3,0.11F);
cout<<"\nCase 4"; amount(2,0.12F);
cout<<"\nCase 5"; amount(6,0.07F);
getch(); }
2 . Class and Objects
#include<iostream.h>

#include<conio.h>
#include<process.h>

class item
{int itemcode[50];float it_price[50];
public:

void initialize(void);
float largest(void);

float sum(void);
void display(void);
};
void item::initialize(void)
{for(int i=0;i<5;i++)
{cout<<"\nItem No.: "<<i+1; cout<<"\nEnter item code : ";

cin>>itemcode[i];
cout<<"\nEnter item Price :";

cin>>it_price[i];
cout<<"\n";
}
}
float item::largest(void)
{
float large=it_price[0];
for(int i=1;i<5;i++)
{
if(large<it_price[i])
large=it_price[i];
}
return large;
}
float item::sum(void)
{float sum=0;
for(int i=0;i<5;i++)

sum+=it_price[i];
return sum;
}
void item::display(void)
{cout<<"\nCode Price\n";
for(int i=0;i<5;i++)
{cout<<"\n"<<itemcode[i];
cout<<" "<<it_price[i];
}
cout<<"\n";
}
void main()
{
item order;
order.initialize();
float total,biggest;
int ch=0;
clrscr();
do
{
cout<<"\nMain Menu.\n";
cout<<"\n1.Display Largest Price.";
cout<<"\n2.Display Sum of Prices.";
cout<<"\n3.Display Item List.";
cout<<"\n4.Exit";
cout<<"\nEnter Your Choice(1-3)";
cin>>ch;
switch(ch)
{
case 1:biggest = order.largest();
cout<<"The Largest Price is "<<biggest<<"\n";
break;
case 2:total=order.sum();
cout<<"The Sum of Price is "<<total<<"\n";

break;
case 3:order.display();
break;
case 4:exit(0);
break;
default:cout<<"\nWrong Choice!!\n";
break;
}
}while(ch!=4);
getch();
}
3 . Constructor and Destructor
#include<iostream.h>
#include<conio.h>
class stu
{ private: char name[20],add[20];
int roll,zip;
public: stu ( );//Constructor
~stu( );//Destructor
void read( ); void disp( ); };

stu :: stu( )
{ cout<<"This is Student Details "<<endl;
}

void stu :: read( )


{ cout<<"Enter the student Name ";
cin>>name;

cout<<"Enter the student roll no ";


cin>>roll;
}

cout<<"Enter the student address ";


cin>>add;

cout<<"Enter the Zipcode "; cin>>zip;

void stu :: disp( )

{ cout<<"Student Name : "<<name<<endl;


cout<<"Roll no is : "<<roll<<endl;

cout<<"Address is : "<<add<<endl;

cout<<"Zipcode is : "<<zip; }
stu :: ~stu( )
{ cout<<"Student Detail is Closed "; }

void main( )
{ stu s;

clrscr( );

s.read ( );

s.disp ( );
getch( );

}
4 . Multiple Inheritance
#include<iostream.h>

#include<conio.h>
class base1

{ protected: int a;
public: base1(int x)
{a=x; cout<<"Constructing
Base 1\n";} ~base1()
{cout<<"Destructing Base
1\n";} }; class base2
{ protected: int b;
public:
base2(int y)
{b=y; cout<<"Constructing Base 2\n";}
~base2()
{cout<<"Destructing Base 2\n";} };

class derived:public base2,public base1


{int c;
public:
derived(int i,int j,int k):base2(i),base1(j)
{c=k;
cout<<"Constructing Derived.\n"; };
~derived()
{ cout<<"Destructing Derived.\n";}
void show()
{cout<<"1. "<<a<<"\t2. "<<b<<"\t3. "<<c<<"\n";} };

void main()
{ clrscr();
derived ob(14,15,16);

ob.show();
getch();
}
5 . Multilevel Inheritance
#include <iostream.h>
#include<conio.h>
class base
{ public: int x;

void getdata()

{ cout << "Enter value of x= "; cin >> x; } };


class derive1 : public base
{ public: int y;
void readdata()
{cout << "\nEnter value of y= "; cin >> y; } };

class derive2 : public derive1


{ private: int z;

public:

void indata()
{ cout << "\nEnter value of z= "; cin
>> z; } void product()
{ cout << "\nProduct= " << x * y * z; } };

void main()
{clrscr();
derive2 a;
a.getdata();
a.readdata();
a.indata();
a.product();
getch();
}
6 . Data file Handeling (calculate average
word size )
#include<fstream.h>
#include<conio.h>
void calculate()
{
fstream tfile;
clrscr();
tfile.open("Report.txt",ios::in);
char arr[20];
char ch;
int i=0,sum=0,n=0;
while(tfile)
{
tfile.get(ch);
arr[i] = ch;
i++;
if (( ch == ' ') || (ch == '.'))
{
i--;
sum = sum + i;
i = 0;
n++;
}
}
cout<<" Average word size is "<<(sum/n);
}
void main()
{
calculate();
getch();}
7 . Data File Handeling (count number of
spaces )
#include<fstream.h>
#include<iostream.h>
#include<ctype.h>
#include<conio.h>
void display()
{
ifstream afile;
afile.open("NOTES.TXT");
char ch;
int c = 0;
while(afile)
{
afile.get(ch);
if (ch == ' ' )
c++;
}
cout<<"The number of blank spaces : "<<c;
}
void main()
{
clrscr();
display();
getch();
}
8 . Data File Handeling ( find the frequency
of characters in file)
# include<fstream.h>
# include<stdio.h>
# include<conio.h>

void main()

{clrscr();

char ch, fname[20];

int num, fre[26], i;

cout<<"\n enter the name of the


file "; gets(fname);
for (i=0;i<26;i++)
fre[i] = 0; num = 0;

ifstream afile(fname); if (!afile)


cout<<"\n File does not exist "<<endl;
else { while (!afile.eof())
{ afile.get(ch); if (ch>= 'a' && ch<= 'z') fre[ch - 'a']++;
if (ch>= 'A' && ch<= 'Z') fre[ch - 'A']++;

if (ch>= '0' && ch<= '9') num++; }

afile.close();
for (i=0;i<26;i++)
{ cout<<"Frequency of "<<char(i+'A')<<" is "<<fre[i]<<"\t"; }

cout<<"\n Frequency of the numeric digits"<<num<<endl; }

getch();
}
9 . Pointers (swapping using pointers in
function )

#include<iostream.h>
#include<conio.h>
void swap(int &, int &);
void main()
{

clrscr();
int a, b;

cout<<"Enter any two numbers: ";


cin>>a>>b;
cout<<"\nOriginal Values:\n";
cout<<"a = "<<a<<"\tand\tb = "<<b<<"\n";
swap(a, b);
cout<<"\nValues after swapping:\n";
cout<<"a = "<<a<<"\tand\tb = "<<b<<"\n";

getch();
}
void swap(int &x, int &y)
{
int temp;
temp = x;
x = y;
y = temp;
}
10 . Pointers
#include<iostream.h>

#include<conio.h>
char*match(char,char*);

void main()
{ clrscr();
char string[80],*cp,ch;

cout<<"\nEnter a string\t";
cin.getline(string,80);
cout<<"\nEnter a character to be searched for\t";

cin>>ch;
cp=NULL;
cp=match(ch,string);
if(*cp)
{cout<<"\n";
for(;(*cp!='\0');cp++)
cout<<*cp;

}
else
cout<<"\nNO MATCH FOUND\n";
cout<<"\n";
getch();
}
char*match(char c,char *s)
{while((c!=*s)&&(*s))
s++;
return(s);
}
11 . Linear search
#include <iostream.h>

#include<conio.h>
#include<stdlib.h>

void linear_search(int[], int,int);


void main()
{clrscr();

int MAX_SIZE;
cout<<"\nEnter the size\t ";

cin>>MAX_SIZE;
int arr_search[60], i, element;
cout << "\nEnter " << MAX_SIZE << " Elements for Searching : " << endl;
for (i = 0; i < MAX_SIZE; i++)
cin >> arr_search[i];
cout << "\nYour Data :";
for (i = 0; i < MAX_SIZE; i++) {
cout << "\t" << arr_search[i];

}
cout << "\nEnter Element to Search : ";
cin>>element;
linear_search(arr_search, element,MAX_SIZE);
getch();
}
void linear_search(int fn_arr[], int element,int
MAX_SIZE) { int i;
for (i = 0; i < MAX_SIZE; i++) {
if (fn_arr[i] == element) {

cout << "\nLinear Search : Element : " << element << " : Found : Position : " <<
i + 1 << ".\n"; break;}}
if(i == MAX_SIZE)
cout << "\nSearch Element : " << element << " : Not Found \n";
}
12 . Binary Search

#include<iostream.h>
#include<conio.h>
int Bsearch(int[],int,int);
void main()
{clrscr();
int AR[50],item,n,index,i;
cout<<"enter desired array size";
cin>>n;
cout<<"enter elements ";
for(i=0;i<n;i++)
cin>>AR[i];
cout<<"enter the elents to be searched for";
cin>>item;
index=Bsearch(AR,n,item);
if (index==-1)
{ cout<<"sorry element not found"; }

else
{ cout<<"element found at "<<index<<" index and "<<index+1<<"
position"; } getch(); }
int Bsearch(int AR[],int size,int item)
{ int beg,last,mid; beg=0;last=size-1;

while (beg<=last)
{ mid=(beg+last)/2;

if (item==AR[mid])

return mid;
else if (item>AR[mid])

beg=mid+1;

else
last=mid-1; }
return -1;}
13 . Bubble Sorting
#include<iostream.h>

#include<conio.h>
void bs(int[],int);

void main()
{clrscr();
int ar[100],it,n,in,i;

cout<<"\n\t PROGRAM FOR BUBBLE


SORTING\n"; cout<<"\n how many elements
you want in array\n"; cin>>n;
cout<<"\nEnter the elements\n";
for(i=0;i<n;i++)
cin>>ar[i];
bs(ar,n);

cout<<"\n\nsorted data is\n";


for(i=0;i<n;i++)
cout<<ar[i]<<" ";

cout<<endl;
getch();}

void bs(int ar[],int n)


{ int i,j;

for(i=0;i<n;i++)

{ for(j=0;j<n-1;j++)

if(ar[j]>ar[j+1])

{ ar[j]=ar[j]+ar[j+1]-(ar[j+1]=ar[j]);
} } }
14 . Selection Sorting
#include<iostream.h>

#include<conio.h>
void ss(int[],int);

void main()
{clrscr();
int ar[100],it,n,in,i;

cout<<"\n\t\n\t PROGRAM FOR SELECTION


SORTING\n"; cout<<"\n how many elements you
want in array\n"; cin>>n;
cout<<"\nEnter the elements\n";
for(i=0;i<n;i++)
cin>>ar[i];
ss(ar,n);

cout<<"\n\nsorted data is\n";


for(i=0;i<n;i++)
cout<<ar[i]<<" ";

cout<<endl;
getch();}

void ss(int ar[],int n)


{ int i,j,po,sm;

for(i=0;i<n-1;i++)

{sm=ar[i];po=i;

{ for(j=i+1;j<n;j++)

if(ar[j]<sm)

{sm=ar[j]; po=j;}
{ ar[i]=ar[i]+ar[po]-(ar[po]=ar[i]); }
}
}}
15. Insertion Sorting
#include<iostream.h>

#include<conio.h>
#include<limits.h>

void is(int[],int);
void main()
{clrscr();

int ar[100],n,i;
cout<<"\n\t\n\t PROGRAM FOR INSERTION
SORTING\n"; cout<<"\n how many elements you
want in array\n"; cin>>n;
cout<<"\nEnter the elements\n";
for(i=1;i<=n;i++)
cin>>ar[i];

is(ar,n);
cout<<"\n\nsorted data is\n";
for(i=1;i<=n;i++)

cout<<ar[i]<<" ";
cout<<endl;

getch();}
void is(int ar[],int n)
{ int i,j,tem;

ar[0]=INT_MIN;

for(i=1;i<=n;i++)

{ tem=ar[i];

j=i-1;
while(tem<ar[j])
{ ar[j+1]=ar[j];

j--; }

ar[j+1]=tem;

} }
16. 2-D Array (Sum of 2 matrix and
Multiplication of 2 matrices)
#include<iostream.h>

#include<conio.h>
#include<process.h>

#include<dos.h>
void main()
{clrscr();

char cv;
do{clrscr();

int ch;
int a[20][20],b[20][20],c[20][20],i,j,m,n,p,q,k;
cout<<"\t\n Main Menu\n";

cout<<"\n1.Sum of 2 matrx\n";
cout<<"\n2.product of 2 matrix\n";

cout<<"\n3.EXIT\n";
cin>>ch;
switch(ch)

{
case 1:
cout<<"\n Input rows & columns of matrix 1\n";
cin>>m>>n;
cout<<"\n Input rows & columns of matrix 2\n";

cin>>p>>q;
if((m==p)&&(n==q))
cout<<"\n Matrix can be added\n";
else{
cout<<"\n Matrix can't be added\n";
sleep(20);
exit(0);
}
cout<<"\n Input matrix -1\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)

cin>>a[i][j];
}
cout<<"\n Input matrix -2\n";
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
cin>>b[i][j];
}
for(i=0;i<m;i++)
{for(j=0;j<n;j++)
c[i][j]=a[i][j]+b[i][j];
}
cout<<"\n The sum of matrix is\n";
for(i=0;i<m;i++)
{cout<<"\n";
for(j=0;j<n;j++)
cout<<" "<<c[i][j];
}
break;
case 2:
cout<<"\n Input rows & columns of matrix 1\n";

cin>>m>>n;
cout<<"\n Input rows & columns of matrix 2\n";

cin>>p>>q;
if(n==p)
{
cout<<"\n Input matrix -1\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cin>>a[i][j];
}
cout<<"\n Input matrix -2\n";

for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
cin>>b[i][j];
}
cout<<"\n Product of two matrices:\n";
for(i=0;i<m;++i)
{cout<<"\n";
for(j=0;j<q;++j)
{c[i][j]=0;
for(k=0;k<n;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
cout<<c[i][j]<<" ";
}}}
else{
cout<<"\n Matrices are not compatible for multiplication\n";

}
break;
case 3:exit(0);
break;

default:cout<<"\n wrong choice \nchoose


more\n"; break;
}
cout<<"\nwant to continue\n";
cin>>cv;

} while(cv=='y'||cv=='Y');

getch();}
17. MIDDLE ROW AND COLUMN OF 2-D ARRAY
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
const M = 10;
const N = 10;
void display_RowCol(int Array[M][N], int r, int c)
{
clrscr();
int row = r / 2;
int col = c / 2; // Finding the middle row
cout << "Middle Row : ";
for(int j=0; j<c; j++)
cout << Array[row][j] << " ";cout << endl;
// Finding the middle column
cout << "Middle Column : ";
for(j=0; j<c; j++)
cout << Array[j][col] << " ";
getch();
}
void main()
{clrscr();
int Array[M][N];
int i, j;
int r, c;
cout << "Enter total no. of rows: ";
cin >> r;
cout << "Enter total no. of columns: ";
cin >> c;

// Array to be a square matrix with odd dimension


if ((r == c) && ((r%2==1) && (c%2==1)))
{cout << "Input steps";
cout << "\n\Enter the element in the array\n";
for(i=0; i<r; i++)
for(j=0; j<c; j++)
{cin >> Array[i][j];
}
}
Else
{
cout << "Input row and column not valid";
getch();
return;
}
display_RowCol(Array, r, c);
}
18. Binary file using Structure
#include<fstream.h>

#include<stdio.h>
#include<process.h>

#include<conio.h>
void create();
void display();

void roll_search();
struct stud

{int rno;
char name[50],adr[50];
long tel;
}s;
void create()
{ ofstream

fout("stud.dat",ios::binary); char rep;

do{
cout<<"\n Enter the Roll No. : ";cin>>s.rno;
cout<<"\n Enter Name : ";gets(s.name);
cout<<"\n Enter Address : ";gets(s.adr);
cout<<"\n Enter Telephone : ";cin>>s.tel;

fout.write((char*)&s,sizeof(s));

cout<<"\n Do You Want to Enter More Records :


"<<endl; cin>>rep;
}while(rep=='y'||rep=='Y');

fout.close(); }

void display()
{ ifstream fin("stud.dat",ios::binary);

while(fin.read((char*)&s,sizeof(s)))

{
cout<<"\n Roll No. : " <<s.rno<<endl;
cout<<"\n Name : "<<s.name;
cout<<"\n Address : "<<s.adr;
cout<<"\n Telephone : "<<s.tel<<endl;

} fin.close(); }
void roll_search()
{ ifstream

fin("stud.dat",ios::binary); int x;

cout<<"\n Enter the Roll No. to be


Searched"<<endl; cin>>x;
while(fin.read((char*)&s,sizeof(s)))
{if(s.rno==x)
{cout<<"\n Record Found \n";

cout<<"\n Roll No. : " <<s.rno<<endl;

cout<<"\n Name : "<<s.name;

cout<<"\n Address : "<<s.adr;

cout<<"\n Telephone : "<<s.tel<<endl;


break;}} fin.close();
}

void main() {char ch; do {clrscr();int x;

cout<<"\n\tMAIN MENU \n";

cout<<"\n1.Create\n2.Display\n3.Search Roll

No.\n4.Exit"; cout<<"\nEnter your Choice\n";

cin>>x;
switch(x)
{
case 1:create();

break;

case 2:display();

getch();

break;

case 3:roll_search();
getch();
break;

case 4:exit(0);
break;
default:cout<<"\n WRONG CHOICE !!!!\n";break;

}
getch();
} while(ch!=4);}
18. Menu Based Stack
#include<iostream.h>

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

#include<stdlib.h>
#define max_size 50
int stack[max_size],top=-1;

void push();
void pop();

void peep();
void display();

void main()
{clrscr();
int choice;
do{
cout<<"\n";
cout<<"\n\n--------STACK OPERATIONS-----------\n";

cout<<"\t1.Push\n";
cout<<"\t2.Pop\n";
cout<<"\t3.Peep\n";
cout<<"\t4.Display\n";
cout<<"\t5.Exit\n";
cout<<"---------------------------------------";
cout<<"\nEnter your choice:\t";
cin>>choice;
switch(choice)
{case 1:push();break;
case 2:pop();break;
case 3:peep();break;
case 4:display();break;
case 5:exit(0);break;
default:cout<<"\nInvalid choice:\n";
break;

}
}while(choice!=5);
getch();
}
void push()
{
int item;
if(top==(max_size-1))
{
cout<<"\nStack Overflow:";
}
else
{cout<<"Enter the element to be inserted:\t";

cin>>item;
top=top+1;
stack[top]=item;
}
}
void pop()
{
int item;
if(top==-1)
{
cout<<"Stack Underflow:";
}
else
{
item=stack[top];
top=top-1;
cout<<"\nThe poped element:\t"<<item;

}
}
void peep()

{
if(top==-1)
{
cout<<"\nStack is empty:";
}
else
{
cout<<"The topmost element of the stack is "<<stack[top];

}
}
void display()
{
int i;
if(top==-1)
{
cout<<"\nStack is Empty:";
}
else
{
cout<<"\nThe stack elements are:\n";
for(i=top;i>=0;i--)
{
cout<<"\n"<<stack[i];
}
}
}
20. Menue Based Queue
#include<stdio.h>

#include<iostream.h>
#include<stdlib.h>

#include<conio.h>
#define max_size 50

int queue[max_size],front=-1,rear=-1;
void insert();

void del();
void display();
int main()
{clrscr();
int choice;
do{
cout<<"\n\n--------QUEUE OPERATIONS-----------\n";

cout<<"1.Insert\n2.Delete\n3.Display\n4.Exit\n";

cout<<"-----------------------"; cout<<"\nEnter your

choice:\t";

cin>>choice;
switch(choice)
{
case 1:insert();
break;
case 2:del();
break;
case 3:display();
break;
case 4:exit(0);

break;
default:cout<<"\nInvalid choice:\n";
break;
}
}while(choice!=4);

return 0;
}
void insert()
{
int item;
if(rear==(max_size-1))
{
cout<<"\nQueue Overflow:";
}
else
{
cout<<"Enter the element to be inserted:\t";

cin>>item;
rear=rear+1;
queue[rear]=item;

if(front==-1)
front=0; } }

void del()
{
int item;

if(front==-1)
{cout<<"\nQueue Underflow:";}

else
{item=queue[front];
cout<<"\nThe deleted element: \t"<<item;

if(front==rear){
front=-1;
rear=-1;
}
else

{
front=front+1; } }
}

void display()
{ int i; if(front==-1)

{cout<<"\nQueue is

Empty:";}

else
{ cout<<"\nThe queue elements
are:\n" ; for(i=front;i<=rear;i++)
{ cout<<"\t"<<queue[i]; }
}
}
STRUCTURED QUERY LANGUAGE
Consider the following tables Product and Client. Write SQL
commands for the statement (i) to (iv) and give outputs for SQL
queries (v) to (viii)

1. mysql> select*from mmaster where MName like 's%' or MName like '%a';

2 . mysql> select M_Company,M_Name,M_Price from mmaster order by M_Mf_Date desc;


3 . mysql> select Msupplier , MQty from mstock where MId<>"MB003";

4. mysql> select count(*) from mstock where MId="MB003";

5. mysql> alter table mmaster change M_Id MId char(50);

6. mysql> select max(M_Price),min(M_Price) from mmaster;


7. mysql> select count(*),MId from mstock group by MId having count(*)>1;

8. mysql> select MId,M_Name from mmaster where M_Price between 3000 and 5000;

9. mysql> select M_Name,Msupplier from mmaster , mstock where mmaster.MId=mstock.MId;

10. mysql> select MId,sum(MQty) from mstock group by MId;


Consider the following tables Product and Client. Write SQL commands
for the statement (i) to (iv) and give outputs for SQL queries (v) to (viii)
Table: PRODUCT

Product
P_ID Manufacturer Price
Name
TP01 TalcomPowder 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 Client Name City P_ID


01 TalcomPowder Delhi FW05
06 Face Wash Mumbai BS01
12 Bath Soap Delhi SH06
15 Shampoo Delhi FW12
16 Face Wash Banglore TP01

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

Ans: Select all from Client where City=”Delhi”

(ii) To display the details of Products whose Price is in the range of 50 to 100(Both values
included).

Ans: Select all from product where Price between 50 and 100

(iii) To display the ClientName, City from table Client, and ProductName and Price from
table Product, with their corresponding matching P_ID.

Ans: Select ClientName,City,ProductName, Price from Product,Client where


Product.P_ID=Client.P_ID.

(iv) To increase the Price of all Products by 10

Ans: Update Product Set Price=Price +10

(v) SELECT DISTINCT Address FROM Client.

Ans: ( The above question may consist DISTINCT City. If it is DISTINCT City, the following
is the answer)
City
-----
Delhi
Mumbai
Bangalore

(vi) SELECT Manufacturer, MAX(Price), Min(Price), Count(*) FROM Product GROUP BY


Manufacturer;

Ans:

Manufacturer Max(Price) Min(Price) Count(*)


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

(vii) SELECT ClientName, ManufacturerName FROM Product, Client WHERE


Client.Prod_Id=Product.P_Id;

Ans:

ClientName ManufacturerName
CosmeticShop ABC
TotalHealth ABC
LiveLife XYZ
PrettyWoman XYZ
Dreams LAK

(viii) SELECT ProductName, Price * 4 FROM Product.

ProductName Price*4
TalcomPoweder 160
FaceWash 180
BathSoap 220
Shampoo 480
Face Wash 380
Consider the following tables Item and Customer. Write SQL commands for
the statement (i) to (iv) and give outputs for SQL queries (v) to (viii)

Table: ITEM

C_ID ItemName Manufacturer Price


Personal
PC01 ABC 35000
Computer
LC05 Laptop ABC 55000
Personal
PC03 XYZ 32000
Computer
Personal
PC06 COMP 37000
Computer
LC03 Laptop PQR 57000

Table: CUSTOMER

C_ID CustomerName City P_ID


01 N.Roy Delhi LC03
06 H.Singh Mumbai PC03
12 R.Pandey Delhi PC06
15 C.Sharma Delhi LC03
16 K.Agarwalh Banglore PC01

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

Ans: Select all from Customer Where City=”Delhi”

(ii) To display the details of Item whose Price is in the range of 35000 to 55000 (Both
values included).

Ans: Select all from Item Where Price>=35000 and Price <=55000

(iii) To display the CustomerName, City from table Customer, and ItemName and Price
from table Item, with their corresponding matching I_ID.

Ans: Select CustomerName,City,ItemName, Price from Item,Customer where


Item.I_ID=Customer.I_ID.

(iv) To increase the Price of all Items by 1000 in the table Item.

Ans: Update Item set Price=Price+1000

(v) SELECT DISTINCT City FROM Customer.

Ans: City
Delhi
Mumbai
Bangalore

(vi) SELECT ItemName, MAX(Price), Count(*) FROM Item GROUP BY ItemName;

Ans:

ItemName Max(Price) Count(*)


PersonalComputer 37000 3
Laptop 57000
2

(vii) SELECT CustomerName, Manufacturer FROM Item, Customer WHERE


Item.Item_Id=Customer.Item_Id;

Ans:

CustomerName ManufacturerName
N.Roy PQR
H.Singh XYZ
R.Pandey COMP
C.Sharma PQR
K.Agarwal
ABC

(viii) SELECT ItemName, Price * 100 FROM Item WHERE Manufacturer = ‘ABC’;

Ans:

ItemName Price*100
PersonalComputer 3500000
Laptop
550000
Consider the following tables Consignor and Consignee. Write SQL command for the
statements(i)to(iv) And give outputs for the SQL quries (v) to ( viii).

TABLE : CONSIGNOR

CnorID CnorName CnorAddress City


New
ND01 R singhal 24,ABC Enclave
Delhi
123,Palm New
ND02 AmitKumar
Avenue Delhi
MU15 R Kohil 5/A,South,Street Mumbai
MU50 S Kaur 7-K,Westend Mumbai

TABLE : CONSIGNEE

CneeID CnorID CneeName CneeAddress CneeCity


MU05 ND01 RahulKishore 5,Park Avenue Mumbai
16/j,Moore New
ND08 ND02 P Dhingr a
Enclave Delhi
2A,Central/
KO19 MU15 A P Roy Kolkata
avenue
P 245, AB
MU32 ND0 2 S mittal Mumbai
Colony
13,Block New
ND48 MU5 0 B P jain
d,a,viha Delhi

(i) To display the names of all consignors from Mumbai.

Ans: Select CnorName from Consignor where city=”Mumbai”;

(ii) To display the cneeID, cnorName, cnorAddress, CneeName, CneeAddress for every
Consignee.

Ans: Select CneeId, CnorName, CnorAddress, CneeName, CneeAddress from


Consignor,Consignee where Consignor.CnorId=Consignee.CnorId;

(iii) To display the consignee details in ascending order of CneeName.

Ans: Select * from Consignee Orderby CneeName Asc;

(iv) To display number of consignors from each city.

Ans: Select city, count(*) from Consignors group by city;

(v) SELECT DISTINCT City FROM CONSIGNEE;

Ans:
CneeCity
Mumbai
New Delhi
Kolkata

(vi) SELECT A.CnorName A, B.CneeName B FROM Consignor A, Consignee B WHERE


A.CnorID=B.CnorID AND B.CneeCity=’Mumbai’;

(vii) SELECT CneeName,CneeAddress FROM Consignee WHERE CneeCity Not IN


(‘Mumbai’, ‘Kolkata’);

Ans:

(viii) SELECT CneeID, CneeName FROM Consignee WHERE CnorID = ‘MU15’ OR


CnorID = ‘ND01’;

senderCity
New Delhi
Mumbai

Ans: CneeID
CneeName
MU05 Rahul
Kishore
KO19
A P Roy
Consider the following tables. Write SQL command for the
statements (i)to(iv)and give outputs for the SQL quries (v) to (viii).
TABLE : SENDER

Sender Sender
SenderID SenderName
Address City
2,ABC New
ND01 R jain
Appts Delhi
12,
MU02 H sinha Mumbai
Newton
27/
New
MU1 5 S haj A,Park
Delhi
Street
122-
ND5 0 T Prasad Mumbai
K,SDA

TABLE :RECIPIENT

RecID SenderID ReCName RecAddress ReCCity


5,Central
KO05 ND01 RBajpayee Kolkata
Avenue
ND08 MU0 2 S Mahajan 116, A Vihar NewDelhi
2A,Andheri
MU19 ND01 H sing Mumbai
East
B5, CS
MU32 MU1 5 PK Swamy Mumbai
erminus
13, B1
ND48 ND50 S Tripathi D,Mayur NewDelhi
Vihar

(i) To display the names of all senders from Mumbai.

Ans: Select * from Sender where SenderCity =’Mumbai’;

(ii) To display the recID, senderName, senderAddress, RecName,


RecAddress for every recipt.

Ans: Select recID, SenderName, SenderAddress, RecName, RecAddress


from Sender, Recipient where Sender.Senderid=Recipient.RenderId;

(iii) To display the sender details in ascending order of SenderName.


Ans: Select * from Sender order by SenderName;

(iv) To display number of Recipients from each city.

Ans: Select RecCity,Count(*) from Recipient group by RecCity;

CnorName
R singhal
Amit Kumar

CneeName
Rahul Kishore
S mittal

CneeName CneeAddress
16/j,Moore
P Dhingra
Enclave
13,Block
B P jain
d,a,viha

(v) SELECT DISTINCT SenderCity FROM Sender;

Ans:-------

vi) SELECT A.SenderName A, B.RecName FROM Sender A, Recipient B


WHERE A.SenderID=B. SenderID AND B.RecCity=’Mumbai’;

Ans: SenderName RecName


R.Jain H.Singh
S.Jha
P.K.Swamy

(vii) SELECT RecName,RecAddress FROMRecipient WHERE RecCity Not IN


(‘Mumbai’,Kolkata’);

Ans: RecName RecAddressS


Mahajan 116,AVihar
S
Tripati 13, B1
D, Mayur Vihar

(viii) SELECT RecID, RecName FROM Recipient WHERE SenderID = ‘MU02’


OR SenderID = ‘ND50’;

Ans: RecID RecName


ND08 S.Mahajan
ND48 S. Tripathi

You might also like