You are on page 1of 30

THE VELAMMAL INTERNATIONAL SCHOOL

COMPUTER SCIENCE LAB MANUAL(1-20)


1.CLASS STUDENT
To find the total and average mark of a student using class
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class student
{
char sname[20];
float m,p,c,cs,e,total,avg;
void calculate()
{
total=m+p+c+cs+e;
avg=total/5;
}
public:
void output()
{
cout<<"Enter your name: ";
gets(sname);
cout<<"\nEnter marks of 5 subjects: ";
cin>>m>>p>>c>>cs>>e;
calculate();
}
void display()
{
cout<<"\n Student name "<<sname;

cout<<"\n Marks are "<<m<<" "<<p<<" "<<c<<" "<<cs<<" "<<e<<" ";


cout<<"\n Total and Average "<<total<<" "<<avg;
}
};
void main()
{
clrscr();
student s1;
s1.output();
s1.display();
getch();
}

2.CLASS EMPLOYEE
AIM:
To calculate the net salary of an employee using constructors.
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class employee
{
int empno;
char ename[20];
float basic,da,hra,ded,netsal;
public:
employee()
{empno=100;
strcpy(ename,"ram");
basic=5000;
da=1000;
}
void input()
{
cout<<"\n Enter employee number: ";
cin>>empno;
cout<<"\n Enter employee name: ";
gets(ename);
cout<<"\n Enter basic,da,hra ";
cin>>basic>>da>>hra;
cout<<"\n Enter deduction: ";
cin>>ded;
}
void calculate()
{
netsal=(basic+da+hra)-ded;
}
void output()
{
cout<<"\n Employee details";
cout<<"\n Employee number: "<<empno;
cout<<"\n Employee name: "<<ename;
cout<<"\n Basic: "<<basic<<"\n Da:"<<da<<"\n Hra:"<<hra<<"\n Ded:"<<ded;
cout<<"\n Net salary:"<<netsal;
}};
void main()
{
clrscr();
employee e1;
e1.input();
e1.calculate();
e1.output();
getch();
}

3.INHERITANCE
AIM:
To implement multiple inheritance.
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class person
{
public:
char name[20];

char address[80];
void input()
{
cout<<"\n Enter name: ";
gets(name);
cout<<"\n Enter address: ";
gets(address);
}
void output()
{
cout<<"\n Name: "<<name;
cout<<"\n Address: "<<address;
}
};
class student
{
public:
int Class;
int total;
void enter()
{
cout<<"\n Enter class:";
cin>>Class;
cout<<"\nEnter the total marks";
cin>>total;
}
void display()
{cout<<"\n Student belongs to"<<Class;
cout<<"\nThe total is"<<total;
}
};
class details:public person,public student
{
char grade;
public:
void assign()
{
if (total>=90)
grade='A';
else if(total>=80 && total<90)
grade='B';
else if(total>=70 && total<80)
grade='C';
else
grade='D';
cout<<"\n The Grade is"<<grade;
}
};
void main()
{
clrscr();
details d;
d.input();
d.enter();
cout<<"\n Student details";
d.output();
d.display();
d.assign();
getch();
}

4.COUNTING YOU and ME IN A TEXT FILE


AIM:
To count numbers of “you ” and “me” in a text file “NOTES.TXT”
SOURCE CODE:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
void main()
{
clrscr();
char ch1[100];
int c1=0,c2=0;
ofstream f1("NOTES.TXT",ios::out);
cout<<"\nEnter Text:";
gets(ch1);
f1<<ch1;
f1.close();
ifstream f2("NOTES.TXT",ios::in);
while(!f2.eof())
{
f2>>ch1;
if(strcmpi(ch1,"you")==0)
c1++;
else if(strcmpi(ch1,"me")==0)
c2++;
}
f2.close();
cout<<"\n No of you ="<<c1;
cout<<"\n No of me ="<<c2;
getch();
}

5. CHANGING THE OCCURRENCES OF '?' TO '&' IN A TEXT FILE


AIM:
To change the occurrences of '?' to '&' in a text file "NOTES.Txt"
Source Code:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
void main()
{
clrscr();
char ch,ch1[100];
ofstream f1("NOTES.TXT",ios::out);
cout<<"\nEnter Text:";
gets(ch1);
f1<<ch1;
f1.close();
ifstream f2("NOTES.txt", ios::in);
ofstream f3("temp.txt",ios::out);
while(!f2.eof())
{
f2.get(ch);
if(ch=='?')
f3.put('&');
else
f3.put(ch);
}
f2.close();
f3.close();
remove("NOTES.TXT");
rename("temp.txt","NOTES.TXT");
ifstream f("NOTES.txt");
cout<<"Replaced string is";
while(!f.eof())
{
f.get(ch);
cout<<ch;
}
getch();
}

6.DISPLAYING RECORDS FROM BINARY FILES


AIM:
To search and display the books above a specific price from a binary file.
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
struct BOOKS
{int bno;
char bname[10];
float price;
};
void main()
{
clrscr();
BOOKS b;
int flag=0;
fstream f;
int i,n;
float x;
f.open("BOOK1.dat",ios::in|ios::app|ios::binary);
cout<<"Enter the number of books to be entered";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"\nEnter the book no,name and price";
cin>>b.bno;
cin>>b.bname;
cin>>b.price;
f.write((char *)&b,sizeof(b));
}
f.seekg(0);
cout<<"Enter the price";
cin>>x;
while(f.read((char*)&b,sizeof(b)))
{
if(b.price>x)
{
flag=1;
cout<<"Found\n";
cout<<"BOOk NO , NAME AND PRICE\n";
cout<<b.bno<<" "<<b.bname<<" "<<b.price<<'\n';
}
}
if(flag==0)
cout<<"Not found";
getch();
}

7.Delete a RECORD FROM BINARY FILES


AIM:
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
struct BOOKS
{int bno;
char bname[10];
float price;
};
void main()
{
clrscr();
BOOKS b;
int bn;
fstream f("BOOK01.dat",ios::in|ios::app|ios::binary);
fstream fout("temp.dat",ios::out|ios::binary);
int i,n;
float x;
cout<<"Enter the number of books to be entered";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"\nEnter the book no,name and price";
cin>>b.bno;
cin>>b.bname;
cin>>b.price;
f.write((char *)&b,sizeof(b));
}
f.seekg(ios::beg);
cout<<"Enter the book number to be deleted";
cin>>bn;
while(f.read((char*)&b,sizeof(b)))
{
if(b.bno!=bn)
fout.write((char*)&b,sizeof(b));
else
cout<<"\nDeleted element is"<<b.bno<<" "<<b.bname<<" "<<b.price;
}
f.close();
fout.close();
remove("BOOK01.DAT");
rename("temp.dat","BOOK01.DAT");
ifstream fin("BOOK01.dat",ios::binary);
cout<<"\nBooks after deletion\n";
while(fin.read((char*)&b,sizeof(b)))
{
cout<<b.bno<<" "<<b.bname<<" "<<b.price<<"\n";
}
fin.close();
getch();

}
8.LINEAR SEARCH
AIM:
To search for a particular element in an array using linear search technique
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a[20],n,ele,i,p,flag=0;
cout<<"\n Enter the size of the array:";
cin>> n;
cout<<"\n Enter the array elements:";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"\n Enter the elements to be searched for:";
cin>>ele;
for(i=0;i<n;i++)
{
if(a[i]==ele)
{
cout<<"\n Element found at “<<i+1;
flag=1;
break;
}
}
if(flag==0)
cout<<"\n Element not found ";
getch();}
9.BINARY SEARCH
AIM:
To search for a particular element in an array using Binary search technique
Source code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a[20],ele,n,i,p,flag=0, beg,mid,end;
cout<<"\n Enter the size of array:";
cin>>n;
cout<<"\n Enter array elements:";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"\n Enter the element to search :";
cin>>ele;
beg=0;
end=n-1;
while(beg<=end)
{
mid=(beg+end)/2;
if(a[mid]==ele)
{
cout<<"Element found"<<mid+1;
flag=1;
break;
}
else if(ele>a[mid])
beg=mid+1;
else
end=mid-1;
}
if(flag==0)
cout<<"\n Element not found";
getch();
}
10.ARRAY INSERTION
AIM:
To add a new element at a specific loctation in a 1-D array
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10],i,m,n,loc,ele,pos;
cout<<"\n Enter the array size:";
cin>>n;
cout<<"\n Enter the array elements";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"\n Enter the location where the element need to be inserted\n";
cin>>loc;
cout<<"\n Enter the element to be added";
cin>>ele;
loc=loc-1;
m=n;
while(loc<m)
{
a[m]=a[m-1];
m--;
}
a[loc]=ele;
n=n+1;
cout<<" \n Array after insertion is ";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
getch();
}

11.ARRAY DELETION
AIM:
To delete an element from specific location in a 1-D array
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10],i,n,loc;
cout<<"\n Enter the array size:";
cin>>n;
cout<<"\n Enter the array elements";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"\n Enter the location of the element need to be deleted";
cin>>loc;
loc=loc-1;
while(loc<n-1)
{
a[loc]=a[loc+1];
loc++;
}
n=n-1;
cout<<" \n Array after deletion is ";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
getch();
}

12.BUBBLE SORT
AIM:
To arrange array element in ascending order using bubble sort.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a[50],i,size,j,temp;
cout<<"\n Enter the array size:";
cin>>size;
cout<<"\n Enter the array elements";
for(i=0;i<size;i++)
cin>>a[i];
for(i=0;i<size;i++)
for(j=0;j<size-1;j++)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
cout<<" The sorted array is ";
for(i=0;i<size;i++)
cout<<a[i]<<" ";
getch();
}
SOURCE CODE:

13.MERGE SORT
AIM:To merge two increasingly arranged arrays into the third array in ascending
order
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int a[10],b[10],c[20];
int m,n,i,j,k;
cout<<"\n Enter the size of 1st array(max10)=";
cin>>m;
cout<<"\n Enter the size of 2nd array(max10) ";
cin>>n;
cout<<"\n Enter the first array elements in ascending order ";
for(i=0;i<m;i++)
cin>>a[i];
cout<<"\n Enter the second array elements in ascending order ";
for(j=0;j<n;j++)
cin>>b[j];
i=j=k=0;
while(i<m&&j<n)
{
if(a[i]<b[j])
{
c[k]=a[i];
i++;
k++;
}
else
{

c[k]=b[j];
k++;
j++;
}
}
while (i<m)
{
c[k]=a[i];
k++;
i++;
}
while(j<n)
{
c[k]=b[j];
k++;
j++;
}
cout<<"\n The merged array is :";
for(i=0;i<m+n;i++)
cout<<c[i]<<" ";
getch();
}

14 .SUM OF ELEMENTS DIVISIBLE BY 7


AIM:
To find and display the sum of elements divisible by 7 in a 2D array
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10][10],i,j,r,c,sum=0;
cout<<"\n Enter the row size (max 10)=";
cin>>r;
cout<<"\n Enter the column size (max 10)=";
cin>>c;
cout<<"\n enter the array elements=";
for(i=0;i<r;i++)
for(j=0;j<c;j++)
cin>>a[i][j];
for(i=0;i<r;i++)
for(j=0;j<c;j++)
if(a[i][j]%7==0)
sum=sum+a[i][j];
cout<<"\n The sum is:"<<sum;
getch();
}
15.PRODUCT OF EACH ROW IN A 2D ARRAY
AIM:
To display the product of each row in a 2D Array
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
int a[10][10],i,j,r,c,prod=1;
clrscr();
cout<<"\n Enter the row and col size";
cin>>r>>c;
cout<<"\n Enter the array elements \n";
for(i=0;i<r;i++)
for(j=0;j<c;j++)
cin>>a[i][j];
cout<<"Entered array is\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
for(i=0;i<r;i++)
{
prod=1;
for(j=0;j<c;j++)
prod=prod*a[i][j];
cout<<"\n Product of rows"<<i+1<<"="<<prod;
}
getch();
}
16 .MATRIX TRANSPOSE
AIM:
To interchange rows and columns in a 2-D array
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10][10],i,j,r,c;
cout<<"\n Enter the row size (max 10)=";
cin>>r;
cout<<"\n Enter the column size (max 10)=";
cin>>c;
cout<<"\n Enter the array elements=";
for(i=0;i<r;i++)
for(j=0;j<c;j++)
cin>>a[i][j];
cout<<"\n Entered array is \n ";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}

cout<<"\n Transpose is \n ";


for(j=0;j<c;j++)
{
for(i=0;i<r;i++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
getch();
}
17.LINEAR STACK
AIM:
To Implement push,pop and display operations in an array stack.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
const int size=25;
void main()
{
clrscr();
int a[size];
int result,ele,n,top=-1;
char ch='y';
do
{
cout<<"\nMENU \n 1.PUSH \n 2.POP \n 3.DISPLAY \n 4.EXIT";
cout<<"\n Enter your choice";
cin>>n;
switch(n)
{
case 1:
if(top==size-1)
cout<<"Stack full";
else
{
cout<<"\n Enter the elements ";
cin>>ele;
top++;
a[top]=ele;
}
break;
case 2:
if(top==-1)
cout<<"\nStack is empty cant delete";
else
{
cout<<"\nDeleted "<<a[top];
top--;
}
break;
case 3:

if(top==-1)
cout<<"\n Stack is empty cant display";
for(int i=top;i>=0;i--)
cout<<a[i]<<"\t";
break;
case 4:
exit(0);
break;
default: cout<<"\n Invalid input";
}
cout<<"\nEnter y/Y to continue";
cin>>ch;
}while(ch=='y'||ch=='Y');
getch();
}

18.LINEAR QUEUE
AIM:
To Implement push,pop and display operations in an array queue.
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
const int size=25;
void main()
{
clrscr();
int a[50];
int front,rear,ele,result;
front=-1;
rear=-1;
char ch='Y';
int choice;
do
{
cout<<"\nMENU\n 1.INSERT \n 2.DELETE \n 3.DISPLAY \n 4.EXIT";
cout<<"\n Enter your choice ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter the element :";
cin>>ele;
if(rear==size-1)
cout<<"\n Queue full.Cannot insert";
else
{
if(rear==-1)
front=rear=0;
else
rear++;
a[rear]=ele;
}
break;
case 2:
if(front==-1)
cout<<"Empty";
else
{
cout<<"\nDeleted Element is " <<a[front];
if(front==rear)
front=rear=-1;
else
front++;
}
break;
case 3:
if(front==-1)
cout<<"Empty";
else
{
cout<<"\n Elements are ";
for(int i=front;i<=rear;i++)
cout<<a[i]<<"\t";
}
break;
case 4:
exit(0);
break;
default:
cout<<"\n Invalid input";
}
cout<<"\n Enter y/Y to continue";
cin>>ch;
}while(ch=='y' || ch=='Y');
getch();
}

19.LINKED STACK
AIM:
To Implement push,pop and display operations in a linked stack.
SOURCE CODE:
#include<iostream.h>
#include<process.h>
#include<stdio.h>
#include<conio.h>
struct node
{
int data;
node *link;
};
node *temp,*top;
void main()
{
clrscr();
int result;
char ch='Y';
int choice;
do
{
cout<<"MENU\n1.PUSH\n2.POP\n3.DISPLAY\n4.EXIT";
cout<<"\nEnter your choice";
cin>>choice;
switch(choice)
{
case 1:
temp=new node;
cout<<"Enter the value";
cin>>temp->data;
temp->link=NULL;
if(top==NULL)
top=temp;
else
{
temp->link=top;
top=temp;
}
break;
case 2:
if(top==NULL)
cout<<"\n Empty";
else
{
temp=top;
cout<<"Deleted value is"<<temp->data;
top=top->link;
delete temp;
}
break;
case 3:
if(top==NULL)
cout<<"\nEmpty";
else
{
temp=top;
cout<<"\n The values are";
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp=temp->link;
}
}
break;
case 4:
exit(0);
break;
default:
cout<<"\nInvalid input";
}
cout<<"\nPress y/Y to continue";
cin>>ch;
}while(ch=='y' || ch=='Y');
getch();
}

20.LINKED QUEUE
AIM:
To Implement push,pop and display operations in a linked queue
SOURCE CODE:
#include<iostream.h>
#include<process.h>
#include<stdio.h>
#include<conio.h>
struct node
{
int data;
node *link;
};
node *temp,*rear,*front;
void main()
{
clrscr();
int result;
char ch='Y';
int choice;
do
{
cout<<"MENU \n1.INSERT\n2.DELETE\n3.DISPLAY\n4.EXIT";
cout<<"\nEnter your choice";
cin>>choice;
switch(choice)
{
case 1:
temp=new node;
cout<<"Enter the value";
cin>>temp->data;
temp->link=NULL;
if(rear==NULL)
front=rear=temp;
else
{
rear->link=temp;
rear=temp;
}
break;
case 2:
if(front==NULL)
cout<<"\nEmpty";
else
{
temp=front;
cout<<"\nDeleted value is "<<temp->data;
front=front->link;
delete temp;
}
break;
case 3:
if(front==NULL)
cout<<"\nEmpty";
else
{
temp=front;
cout<<"\n The values are";
while(temp!=NULL)
{
cout<<temp->data<<" " ;
temp=temp->link;
}
}
break;
case 4:
exit(0);
break;
default:
cout<<"\nInvalid input";
}
cout<<"\nPress y/Y to continue";
cin>>ch;
}while(ch=='y' || ch=='Y');
getch();
}
Ex:No:21

SQL Command - I

(a) To show all information about the students of history department.

(b) To list the names of female student who are in Hindi department.

(c) To list the names of all students with their date of admission in ascending order.

(d) To display students Name, Fee, Age, for male only.

(e) To count the number of student with Age<23.

TABLE : STUDENT

NO NAME AGE DEPARTMENT DATEOFADM FEE SEX


1 Pankaj 24 Computer 10-JAN-97 120 M
2 Shalini 21 History 24-MAR-98 200 F
3 Sanjay 22 Hindi 12-DEC-96 300 M
4 Sudha 25 History 01-JUL-99 400 F
5 Rakesh 22 Hindi 08-JUL-97 250 M
6 Shakeel 30 History 27-JUN-98 300 M
7 Surya 34 Computer 25-FEB-97 200 M
8 Shikha 23 Hindi 31-JUL-97 200 F

Answers:

(a) SELECT*FROM student WHERE Department = 'History';

NO NAME AGE DEPARTMENT DATEOFADM FEE SEX


2 Shalini 21 History 24-MAR-98 200 F
4 Sudha 25 History 01-JUL-99 400 F
6 Shakeel 30 History 27-JUN-98 300 M

(b) SELECT Name FROM student WHERE SEX = ‘F’ AND department = ‘Hindi’;
NAME
Shikha

(c) SELECT Name FROM Student ORDER BY Date of ADM;

NAME
Sanjay
Pankaj
Surya
Rakesh
Shikha
Shalini
Shakeel
Sudha

(d) SELECT Name, FEE, Age from student WHERE SEX = ‘M’;

NAME FEE AGE


Pankaj 120 24
Sanjay 300 22
Rakesh 250 22
Shakeel 300 30
Surya 200 34

(e) SELECT count (*) FROM students WHERE Age < 23;

Count(*)
3

------------

Ex:No:22

SQL Command - II

(a) To display DCODE and DESCRIPTION of each in ascending order of DCODE.

(b) To display the details of all dress which have READYDATE in between 05-Dec-
07 and 20-Jan-08.

(c) To display the average PRICE of all the dress which is made up of material with
MCODE as M003.

(d) To display material wise highest and lowest price of dresses from DRESS table.
(e) To display the DESCRIPTION and TYPE from tables Dress and material.

TABLE : DRESS

DCODE DESCRIPTION PRICE MCODE READYDATE


10001 Formal shirt 250 M001 12-Jan-08
10020 Frock 750 M004 09-Sep-07
10012 Informal shirt 1450 M002 06-Jun-08
10019 Evening gown 850 M002 06-Jun-08
10090 Tulip shirt 850 M003 31-Mar-08
10023 Pencil shirt 1250 M002 17-Dec-08
10089 Slacks 850 M003 20-Oct-08
10007 Formal pant 1450 M001 09-Mar-08
10009 Informal shirt 1400 M002 20-Oct-08
10024 Baby top 650 M003 07-Apr-07

TABLE : MATERIAL

MCODE TYPE
M001 Terelene
M002 Cotton
M003 Silk
M004 Polyesters

Answers :

(a) Select DCODE, DESCRIPTION from dress order by DCODE;

DCODE DESCRIPTION
10001 Formal shirt
10007 Formal pant
10009 Informal shirt
10012 Informa lshirt
10019 Evenin gown
10020 Frock
10023 Pencil shirt
10024 Baby top
10089 Slacks
10090 Tulip shirt

(b) Select * from dress where READYDATE between ‘05-DEC-07’ and ’20-Jun-08’;
DCODE DESCRIPTION PRICE MCODE READYDATE
10001 Formal Shirt 250 M001 12-Jan-08
(c) Select avg(PRICE) from dress where MCODE = ‘M003’;

AVG(Price)
753.33

(d) Select MCODE, Max(PRICE), Min(PRICE) from dress group by MCODE;

MCODE MAX(Price) MIN(Price)


M001 1450 250
M004 750 750
M002 1450 850
M003 850 650

(e) Select DESCRIPTION, TYPE from dress D, material M where d.MCODE =


M.MCODE;

TYPE
DESCRIPTION
Formal shirt Terelene
Frock Polyesters
Informal shirt Cotton
Evening gown Cotton
Tulip shirt Silk
Pencil shirt Cotton
Slacks Silk
Formal pant Terelene
Informal shirt Cotton
Baby top Silk

------
Ex:No:23

SQL Command - III

(a) To display the details of those candidates consumers whose address in Delhi.

(b) To display the details of stationery. Whose price is in the range of 8 to 15.

(c) To display the consumer name, address from table consumer and company and
price from table
stationary with their corresponding matching SID.

(d) To increase the price of all the stationery by 2.

(e) Add a new record in consumer table with the following details (17, ‘Fast Writer’;
‘Mumbai’, ‘GPOI’).
TABLE : STATIONERY

S-ID STATIONERY COMPANY PRICE


NAME
DPO3 Dot pen ABC 10
DL02 Pencil XYZ 6
ER02 Eraser XYZ 7
PL01 Pencil CAM 5
GP02 Gel pen ABC 15
.
TABLE : CONSUMER
C-ID CONSUMER- ADDRESS S-ID
NAME
01 Good Learner Delhi PL01
06 Write wall Mumbai GP02
12 Topper Delhi DP01
15 Write & Draw Delhi PL02
16 Motivation Banglore PL01

Answers :

(a) SELECT * FROM consumer WHERE Address = ‘Delhi’;


C-ID CONSUMER- ADDRESS S-ID
NAME
01 Good Learner Delhi PL01
12 Topper Delhi DP01
15 Write & Draw Delhi PL02

(b) SELECT * FROM stationary WHERE Price between 8 and 15;

S-ID STATIONERY COMPANY PRICE


NAME
DPO3 Dot pen ABC 10
GP02 Gel pen ABC 15

(c) SELECT Consumer Name, Address, Company, Price FROM consumer C,


Stationary S WHERE

C. S_ID = S.S_ID;

CONSUMER- ADDRESS COMPANY PRICE


NAME
Good Learner Delhi CAM 5
Write Wall Mumbai ABC 15
Motivation Bangalore CAM 5
(c) UPDATE Stationary SET price = price +2;
5 rows updated.

(e) INSERT INTO Consumer VALUES (17, ‘fast writer’, ‘mumbai’, GP01);

1 row inserted (Created).

You might also like