Practical 16 17
Practical 16 17
Solution 1
#include<iostream.h>
#include<conio.h>
struct Distance
{
int feet;
int inches;
};
Distance Input()
{
Distance d;
cout<<"Enter Feet: ";
cin>>d.feet;
cout<<"Enter Inches: ";
cin>>d.inches;
return d;
}
Distance Addit(Distance d1, Distance d2)
{
Distance temp;
temp.feet=d1.feet + d2.feet +
(d1.inches + d2.inches)/12;
temp.inches=(d1.inches + d2.inches)
%12;
return temp;
}
void Display(Distance d)
{
cout<<d.feet<<" \' <<d.inches<<" \" "<<" ";
}
void main()
{
clrscr();
Distance d1,d2,d3;
cout<<"Input Distance #1\n";
d1=Input();
cout<<"Input Distance #2\n";
d2=Input();
d3=Addit(d1,d2);
cout<<"The Result Of \n";
Display(d1);
cout<<"+ ";
Display(d2);
cout<<"= ";
Display(d3);
getch();
}
Cscience_2/9: Imagine a ticket selling booth at a fair. People passing by are requested to purchase a
ticket. A ticket is priced Rs. 2.50/- The booth keeps the track of the number of people that have visited
the booth, and of the total amount of money collected.
Model this ticket selling booth with a class ticbooth including following members:
Data Members:
Number of people visited.
Total amount of money collected.
Member Functions:
To assign initial values (assign 0 to both data members)
To increment only people total in case ticket is not sold out.
To increment people total as well as amount total if a ticket is sold out
To display the two totals
To display the number of tickets sold out (a tricky one)
Solution 2
#include<iostream.h>
#include<conio.h>
class Ticbooth
{
private:
int No_of_People;
float Amount;
public:
Ticbooth()
{
No_of_People=0;
Amount=0.0;
}
void IncrPeople(int n)
{
No_of_People += n;
}
void IncrAmount(int n)
{
Amount += 2.5*n;
}
void DisplayAll()
{
cout<<"\nTotal No of People Visiting: "
<<No_of_People
<<"\nTotal Amount Collected: "
<<Amount;
}
void DispTickets()
{
cout<<"\nNo. of People Who Paid: "<<Amount/2.50;
}
};
void main()
{
Ticbooth obj;
int choice,n;
char ch;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU";
cout<<"\n1. Increment Data";
cout<<"\n2. Display Data";
cout<<"\n3. Exit";
cout<<"\nEnter Your Choice(1-3): ";
cin>>choice;
switch(choice)
{
case 1: cout<<"How Many People: ";
cin>>n;
obj.IncrPeople(n);
cout<<"Did They Pay(Y/N): ";
cin>>ch;
if(ch=='y'||ch=='Y'0029
obj.IncrAmount(n);
break;
case 2: clrscr();
cout<<"\t\t\t\tMenu";
getch();
}
char* Return()
{ return (Fname); }
};
void main()
{
Batsman Team[11];
int choice;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU"
<<"\n1. Assign Values" <<"\n2. Update Values"
<<"\n3. Display Info"
<<"\n4. Quit"
<<"\nEnter Your Choice(1-4): ";
cin>>choice;
switch(choice)
{
case 1: clrscr();
for(int i=0;i<11;i++)
{
cout<<"Enter Details Of Batsman "<<i+1;
Team[i].Initialize();
}
break;
case 2: clrscr();
char Name[10];
cout<<"Enter First Name Of Batsman Whose Details Are To
Be Updated: ";
cin>>Name;
for(i=0;i<11;i++)
if(strcmpi(Name,Team[i].Return())==0)
{
Team[i].Update();
break;
}
break;
case 3: clrscr();
cout<<"Enter First Name Of Batsman Whose Details Are To Be Viewed: ";
cin>>Name;
for(i=0;i<11;i++)
if(strcmpi(Name,Team[i].Return())==0)
{
Team[i].Display();
break;
} break;
case 4: cout<<"Exitting";
getch();
break;
}
}while(choice!=4);
}
Cscience_4 /11: Write a menu-driven program in C++ to calculate the volume of following
shapesVolume of a cube
Volume of a box
Volume of a sphere.
Quit
Make this program with the help of a class shape with followingMember data:
p1 (type float)
p2 (type float)
p3 (type float)
volume (type float)
Member Functions :
To input data members (Input as many as required)
To calculate volume of various shapes (must be overloaded)
To display the volume.
Solution 4
#include<iostream.h>
#include<conio.h>
class Shape
{
private:
float P1, P2, P3;
float Volume;
public:
void Vol(int i)
{
switch(i)
{
case 1: Volume = P1*P1*P1;
break;
case 2: Volume = P1*P2*P3;
break;
case 3: Volume = 3.14*4*P1*P1*P1/3;
break;
Display();
}
}
void Input(int i)
{ switch(i)
{
case 1: cout<<"Enter Side Of Cube: ";
cin>>P1;
break;
case 2: cout<<"Enter Sides Of Box: ";
cin>>P1>>P2>>P3;
break;
getch();
}
Cscience_5/12: Imagine a publishing company that markets both books and audio cassette versions of
its works. Create a class Publication that stores the title (a string) and price (type float) of a
publication. From this class derive two classes: book, which adds a page count (type int); and tape,
which adds a playing time in minutes (type float). Each of these three classes should have a get data()
function to get its data from the user at the keyboard, and a put data() function to display its data.
Write a main () program to test the book and tape classes by creating instances of them asking the user
to fill in their data with get data(), and then displaying the data with putdata().
Solution 5
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Publication
{
private:
char Title[20];
float Price;
public:
void Getdata()
{
cout<<"Enter Title: ";
gets(Title);
cout<<"Enter Price: ";
cin>>Price;
}
void Putdata()
{
cout<<"\nTitle: "<<Title
<<"\nPrice: "<<Price;
} };
class Book: public Publication
{
private:
int Page_Count;
public:
void Getdata()
{
Publication::Getdata();
cout<<"Enter No. Of Pages: ";
cin>>Page_Count;
}
void Putdata()
{
Publication::Putdata();
cout<<"\nNo. Of Pages: "<<Page_Count;
}
};
class Tape: public Publication
{
private:
float Play_Time;
public:
void Getdata()
{
Publication::Getdata();
cout<<"Enter Playing Time: ";
cin>>Play_Time;
}
void Putdata()
{
Publication::Putdata();
cout<<"\nPlaying Time: "<<Play_Time;
} };
void main( )
{
clrscr( );
Book Bk;
Tape Tp;
Bk.Getdata( );
Tp.Getdata( );
clrscr();
Bk.Putdata( );
Tp.Putdata( );
getch();
}
Question 6/13 Write a program in C++ with the
help of following class employee
Member Data :
Employee name
Employee code
Basic Salary
Da
Hra
Total salary
Member Functions:
1. To input employee detail
(name, code and basic)
2. To calculate following
Code
Da
Hra
50% of basic
30% of basic
40% of basic
25% of basic
Any other
30% of basic
20% of basic
Solution 6
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Employee
{
private:
char Emp_Name[20];
int Emp_Code;
unsigned Basic;
unsigned DA;
unsigned HRA;
unsigned Tot_Salary;
void Calculate();
public:
Employee()
{ Tot_Salary = 0; }
void Input();
Employee Compare(Employee);
void Display();
unsigned Return() { return this->Tot_Salary; }
};
void Employee::Calculate()
{
switch(Emp_Code)
{
case 1: DA = Basic * 0.5;
HRA = Basic * 0.3;
break;
case 2: DA = Basic * 0.4;
HRA = Basic * 0.25;
break;
default: DA = Basic * 0.3;
HRA = Basic * 0.2;
}
Tot_Salary = Basic + DA + HRA;
}
void Employee::Input()
{
cout<<"\nEnter Employee's Code: ";
cin>>Emp_Code;
cout<<"\nEnter Employee's Name: ";
gets(Emp_Name);
cout<<"\nEnter The Basic Salary: ";
cin>>Basic;
this->Calculate();
}
Employee Employee::Compare(Employee Obj)
{
if(Tot_Salary>Obj.Return())
return (*this);
else
return Obj;
}
void Employee::Display()
{
clrscr();
cout<<"\nThe Employee Having Highest Salary Is ";
cout<<"\nEmloyee's Name: "<<Emp_Name
<<"\nEmloyee's Code: "<<Emp_Code
<<"\nBasic: "<<Basic
<<"\nDA: "<<DA
<<"\nHRA: "<<HRA
<<"\nTotal Salary: "<<Tot_Salary;
}
void main()
{
clrscr();
Employee Emp[5], High;
cout<<"\nEnter Details Of 5 Employees: \n";
for(int i=0;i<5;i++)
{
cout<<"Enter Record#"<<i+1;
Emp[i].Input();
clrscr();
}
for(i=0;i<4;i++)
High = Emp[i].Compare(High);
High.Display();
getch();
}
Cscience_7/14:
Write a program in C++ with the help of class array_search with following membersMember data :
An array ar of integer with 20 elements
No .of elements actually used by user (int n)
Member Functions1. To input n, and n number of elements
2. Linear search
3. Binary search (If array is in ascending order)
4. To display n elements of the array
Make a menu in C++ with following options1.
Array Input
2.
Linear Search
3.
Binary Search
4.
Array display
6.
Quit
Solution 7
#include<iostream.h>
#include<conio.h>
class Array_Search
{
int arr[20];
unsigned int n;
public:
void Input();
void Linear_search(int);
void Binary_search(int);
void Display();
};
void Array_Search::Input()
{
cout<<"Input Number Of Elements(max-20): ";
cin>>n;
if(n>20)
{
cout<<"Error"
<<"\nEnter A Valid Value";
return;
}
else
cout<<"Enter The Elements: ";
for(int i=0;i<n;i++)
cin>>arr[i];
}
void Array_Search::Linear_search(int item)
{
for(int i=0;i<n;i++)
if(arr[i]==item)
{
cout<<"The Item Is At Position: "<<i+1;
return;
}
cout<<"The Item Is Not Present In The List";
}
void Array_Search::Binary_search(int item)
{
int beg=0,end=n-1,mid;
while(beg<=end)
{
mid=(beg+end)/2;
if(arr[mid]==item)
{
cout<<"The Element Is At Position "<<mid+1;
return;
}
else if(arr[mid]>item)
end=mid-1;
else beg=mid+1;
}
cout<<"The Element Is Not In The List";
}
void Array_Search::Display()
{
cout<<"The Array Is ";
for(int i=0;i<n;i++)
cout<<arr[i]<<" ";
}
void main()
{
Array_Search obj;
int ch,item;
do
{
clrscr();
cout<<"\t\t\t\tMain Menu"
<<"\n1. Array Input"
<<"\n2. Linear Search"
<<"\n3. Binary Search"
<<"\n4. Array Display"
<<"\n5. Exit"
<<"\nInput Your Choice: ";
cin>>ch;
switch(ch)
{
case 1: obj.Input();
getch();
break;
case 2: obj.Display();
cout<<"Enter item To Be Searched: ";
cin>>item;
obj.Linear_search(item);
getch();
break;
case 3: obj.Display();
cout<<"Enter item To Be Searched: ";
cin>>item;
obj.Binary_search(item);
getch();
break;
case 4: obj.Display();
getch();
break;
case 5: cout<<"Exitting";
getch();
break;
}
}while(ch!=5);
}
Cscience_9/16 : Write a menu-driven program in C++ with following
Options to work with data file1. To add records (Name, Rollno, Marks ) of students
(Add records till the user wants yes)
2. Display all the records
3. Display a particular record on the basis of Roll No.
4. Quit
Solution 8
#include<process.h>
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
class Student
{
char Name[20];
int RollNo;
int Marks;
public:
void Display();
void Input();
int Return()
{
return RollNo;
}
};
void Student::Display()
{
cout<<"\n Roll No: "<<RollNo
<<"\n Name: "<<Name
<<"\nMarks: "<<Marks;
}
void Student::Input()
{
fflush(stdin);
cout<<"Enter Roll No.: ";
cin>>RollNo;
cout<<"Enter Name: ";
gets(Name);
cout<<"Enter Marks: ";
cin>>Marks;
}
void main()
{
int ch,i=0,j=0,flag=0;
char ch2,ch1;
Student Obj;
fstream file("Stud.dat",ios::in|ios::app|ios::binary);
do
{
clrscr();
cout<<"\t\t\t\tMain Menu"
<<"\n1. Add Records
<<"\n2. Display All Records"
<<"\n3. Display Single Record"
<<"\n4. Quit"
<<"\nEnter Your Choice: ";
cin>>ch;
switch (ch)
{
case 1:
ofstream fout;
fout.open("Stud.dat",ios::app|ios::binary);
do
{
i++;
cout<<"Enter Record#"<<i<<"\n";
fflush(stdin);
Obj.Input();
fout.write((char*)&Obj,sizeof(Obj));
cout<<"Enter Another Record(1/2): ";
fflush(stdin);
cin>>ch2;
} while(ch2=='1');
fout.close();
break;
case 2:
ifstream fin;
fin.open("Stud.dat",ios::in|ios::binary);
fin.seekg(0);
while(!fin.eof())
{
j++;
fin.read((char*)&Obj,sizeof(Obj));
cout<<"\nRecord #"<<j<<"\n";
Obj.Display();
}
getch();
fin.close();
break;
case 3:
ifstream finn;
finn.open("Stud.dat",ios::in|ios::binary);
finn.seekg(0);
int Roll;
cout<<"Enter Roll No. of Record To Be Viewed: ";
fflush(stdin);
cin>>Roll;
while(!finn.eof())
{
finn.read((char*)&Obj,sizeof(Obj));
if(Obj.Return()==Roll)
{
Obj.Display();
getch();
flag=1;
break;
}
}
if (flag==0)
cout<<"Record Is Not There in List";
getch();
finn.close();
break;
void Array_Update::Deletion()
{
int pos=-1,item;
cout<<"Enter The Element To Be Deleted: ";
cin>>item;
for(int i=0;i<N;i++)
if(Arr[i]==item)
pos=i;
if(pos==-1)
{
cout<<"Element Does Not Exist In The List";
getch();
return;
}
else
for(i=pos;i<N-1;i++)
Arr[i]=Arr[i+1];
Arr[N-1]=0;
N--;
}
void Array_Update::Display()
{
cout<<"The Array Is\n";
for(int i=0;i<N;i++)
cout<<Arr[i]<<" ";
getch();
}
void main()
{
Array_Update Obj;
int choice;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU"
<<"\n1. Array Input"
<<"\n2. Insertion"
<<"\n3. Deletion"
<<"\n4. Array Display"
<<"\n5. Quit"
<<"\nEnter Your Choice(1-5): ";
cin>>choice;
switch(choice)
{
case 1: clrscr();
Obj.Input();
break;
case 2: clrscr();
Obj.Insertion();
break;
case 3: clrscr();
Obj.Deletion();
break;
case 4: clrscr();
Obj.Display();
break;
case 5: cout<<"Exitting";
break;
}
}while(choice!=5);
}
fout1.open("DIGIT.TXT");
fout2.open("SPECIAL.TXT");
ifstream fin("MIXED.TXT");
fin>>ch;
while(ch!='~')
{
if(ch>='0'&&ch<='9')
fout1<<ch;
else if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
fout<<ch;
else
fout2<<ch;
fin>>ch;
}
fout<<"~";
fout1<<"~";
fout2<<"~";
fout.close();
fout1.close();
fout2.close();
fin.close();
break;
case 3: clrscr();
cout<<"The Files Available Are "
<<"\nMIXED.TXT"
<<"\nALPHA.TXT"
<<"\nDIGIT.TXT"
<<"\nSPECIAL.TXT"
<<"\nEnter File to Be Printed: ";
gets(filename);
fflush(stdin);
if(strcmpi("MIXED.TXT",filename)==0)
{
ifstream fin("MIXED.TXT");
fin>>ch;
while(ch!='~')
{
cout<<ch;
fin>>ch;
}
}
else if(strcmpi("ALPHA.TXT",filename)==0)
{
ifstream fin("ALPHA.TXT");
fin>>ch;
while(ch!='~')
{
cout<<ch;
fin>>ch;
}
}
else if(strcmpi("DIGIT.TXT",filename)==0)
{
ifstream fin("DIGIT.TXT");
fin>>ch;
while(ch!='~')
{
cout<<ch;
fin>>ch;
}
}
else if(strcmpi("SPECIAL.TXT",filename)==0)
{
ifstream fin("SPECIAL.TXT");
fin>>ch;
while(ch!='~')
{
cout<<ch;
fin>>ch;
}
}
else {
cout<<"Error";
getch();
break;
}
getch();
fin.close();
break;
case 4: cout<<"Exitting";
break;
}
}while(choice!=4);
}
};
void Array_Sort::Input()
{
cout<<"Enter Size Of Array: ";
cin>>N;
cout<<"Enter Array: \n";
for(int i=0;i<N;i++)
cin>>Arr[i];
}
void Array_Sort::Selection()
{
int i,j,temp,pos;
for(i=0;i<N;i++)
{
temp=Arr[i];
pos=i;
for(j=i+1;j<N;j++)
{
if (Arr[j]<temp)
{
temp=Arr[j];
pos=j;
}
}
Arr[pos]=Arr[i];
Arr[i]=temp;
}
cout<<"Sorting Is In Progress";
getch();
}
void Array_Sort::Bubble()
{
int temp;
for(int i=0;i<N;i++)
for(int j=0;j<N-1;j++)
if(Arr[j]>Arr[j+1])
{
temp=Arr[j];
Arr[j]=Arr[j+1];
Arr[j+1]=temp;
}
cout<<"Sorting Is In Progress";
getch();
}
void Array_Sort::Insertion()
{
int temp, pos;
for(int i=1;i<N;i++)
{
temp=Arr[i];
pos=i;
while(temp<Arr[pos-1]&&pos>0)
{
Arr[pos-1]=Arr[pos];
pos--;
}
Arr[pos]=temp;
}
cout<<"Sorting Is In Progress";
getch();
}
void Array_Sort::Display()
{
cout<<"The Array Is\n";
for(int i=0;i<N;i++)
cout<<Arr[i]<<" ";
getch();
}
void main()
{
Array_Sort Obj;
int choice;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU"
<<"\n1. Input Array"
<<"\n2. Selection Sort"
<<"\n3. Bubble Sort"
<<"\n4. Insertion Sort"
<<"\n5. Display Array"
<<"\n6. Quit"
<<"\nEnter Your Choice(1-6): ";
cin>>choice;
switch(choice)
{
case 1: clrscr();
Obj.Input();
break;
case 2: clrscr();
Obj.Selection();
break;
case 3: clrscr();
Obj.Bubble();
break;
case 4: clrscr();
Obj.Insertion();
break;
case 5: clrscr();
Obj.Display();
break;
case 6: cout<<"Exitting";
getch();
break;
}
}while(choice!=6);
}
{
clrscr();
cout<<"\t\t\t\tMAIN MENU"
<<"\n1. Initialize"
<<"\n2. Push"
<<"\n3. Pop"
<<"\n4. Display Stack"
<<"\n5. Quit"
<<"\nEnter Your Choice(1-5): ";
cin>>choice;
switch(choice)
{
case 1: break;
case 2: clrscr();
int n;
cout<<"Enter The Element To Be Pushed: ";
cin>>n;
obj.Push(n);
break;
case 3: clrscr();
obj.Pop();
break;
case 4: clrscr();
obj.Display();
break;
case 5: cout<<"Exitting";
getch();
break;
}
} while(choice!=5);
}
Q19 & Q20 LOGIC CIRCUIT
5. Quit
SOL: - #include<iostream.h>
#include<conio.h>
struct Node
{
int info;
Node *Next;
}*ptr;
class Linked_Stack
{
private:
Node *Top;
public:
Linked_Stack()
{
Top=NULL;
}
void Push(int);
void Pop();
void Display();
};
void Linked_Stack::Push(int n)
{
ptr=new Node;
ptr->info=n;
ptr->Next=Top;
Top=ptr;
}
void Linked_Stack::Pop()
{
if(Top==NULL)
cout<<"Underflow";
else
{
cout<<"The Element Being Deleted Is "<<Top->info;
getch();
ptr=Top;
Top=Top->Next;
delete ptr;
}
}
void Linked_Stack::Display()
{
cout<<"The Contents Of Stack Are\n";
ptr=Top;
while(ptr)
{
cout<<ptr->info<<endl;
ptr=ptr->Next;
}
}
void main()
{
Linked_Stack obj;
int choice;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU"
<<"\n1. Initialize Stack"
<<"\n2. Push"
<<"\n3. Pop"
<<"\n4. Display Stack"
<<"\n5. Exit"
<<"\nEnter Your Choice(1-5): ";
cin>>choice;
switch(choice)
{
case 1: break;
case 2: clrscr();
int n;
cout<<"Enter element To Be Added: ";
cin>>n;
obj.Push(n);
break;
case 3: clrscr();
obj.Pop();
break;
case 4: clrscr();
obj.Display();
getch();
break;
case 5: cout<<"Exitting";
getch();
break;
}
}while(choice!=5);
}
Cscience14/21
void Array_Queue::Enqueue(int n)
{
if((Rear-Front)==MAX)
cout<<"Overflow";
else
{
if(Rear==-1)
Front=Rear=0;
else
Rear++;
Queue[Rear]=n;
cout<<"The Element "<<n<<" Has Been Added To The Queue";
getch();
}
}
void Array_Queue::Dequeue()
{
if(Front==-1)
cout<<"Underflow";
else if(Front==Rear)
{
cout<<"The Element Being Deleted Is "<<Queue[Front];
getch();
Rear = Front =-1;
}
else
{
cout<<"The Element Being Deleted Is "<<Queue[Front];
getch();
Front++;
}
}
void Array_Queue::Display()
{
cout<<"The contents Of Queue Are";
for(int i=Front;i<=Rear;i++)
cout<<endl<<Queue[i];
getch();
}
void main()
{
Array_Queue obj;
int choice;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU"
<<"\n1. Initialize Queue"
<<"\n2. Insert"
<<"\n3. Delete"
<<"\n4. Display Queue"
<<"\n5. Exit"
<<"\nEnter Your Choice(1-5): ";
cin>>choice;
switch(choice)
{
case 1: break;
case 2: clrscr();
int n;
cout<<"Enter element To Be Added: ";
cin>>n;
obj.Enqueue(n);
break;
case 3: clrscr();
obj.Dequeue();
break;
case 4: clrscr();
obj.Display();
getch();
break;
case 5: cout<<"Exitting";
getch();
break;
}
}while(choice!=5);
}
Cscience_15/22
}
void Insert(int);
void Delete();
void Display();
};
void Linked_Queue::Insert(int n)
{
ptr=new Node;
ptr->info=n;
ptr->Next=NULL;
if(Rear==NULL)
Front=Rear=ptr;
else
{
Rear->Next=ptr;
Rear=ptr;
}
}
void Linked_Queue::Delete()
{
if(Front==NULL)
cout<<"Underflow";
else if(Rear==Front)
{
cout<<"The Element Being Deleted Is "<<Front->info;
getch();
ptr=Front;
Front=Rear=NULL;
delete ptr;
}
else
{
cout<<"The Element Being Deleted Is "<<Front->info;
getch();
ptr=Front;
Front=Front->Next;
delete ptr;
}
}
void Linked_Queue::Display()
{
cout<<"The Contents Of Queue Are\n";
ptr=Front;
while(ptr)
{
cout<<ptr->info<<endl;
ptr=ptr->Next;
}
}
void main()
{
Linked_Queue obj;
int choice;
do
{
clrscr();
cout<<"\t\t\t\tMAIN MENU"
<<"\n1. Initialize Queue"
<<"\n2. Insert"
<<"\n3. Delete"
<<"\n4. Display Queue"
<<"\n5. Exit"
<<"\nEnter Your Choice(1-5): ";
cin>>choice;
switch(choice)
{
case 1: break;
case 2: clrscr();
int n;
cout<<"Enter element To Be Added: ";
cin>>n;
obj.Insert(n);
break;
case 3: clrscr();
obj.Delete();
break;
case 4: clrscr();
obj.Display();
getch();
break;
case 5: cout<<"Exitting";
getch();
break;
}
}while(choice!=5);
}
EXAMPLE OF SQL
Table : SUPPLIER
Numbers
Name
City
Itemno
SuppliedQty
Rate
S001
Puneet
Delhi
1008
100
40
S002
Pradeep
Bangalore
1009
200
30
S003
Tanmay
Delhi
1008
150
40
S004
Rohini
Bombay
1005
190
20
S005
Tanya
Bombay
1003
20
50
S006
Aditi
Madras
1008
180
40
S007
Kush
Delhi
1009
300
30
Write SQL commands for (a) to (f) and write the outputs of SQL commands given in (h) with the help
of above shown table.
a) Display names of suppliers whose names start with the letter T.
b) Display details of suppliers residing in Delhi.
c) Display supplier name, item numbers, and supplied quantity for quantity > 150.
d) Create a view with one of the columns as rate * 10.
e) List the suppliers name in the descending order of supplied quantity.
f) List the different cities contained in supplier table.
g) Give the output of the following SQL commands on the basis of table supplier.
i.
SELECT MIN(Rate) FROM SUPPLIER
ii.
SELECT COUNT(DISTINCT City) FROM SUPPLIER
iii.
SELECT Name, Itemno FROM SUPPLIER WHERE SuppliedQty>150
iv.
SELECT (Rate*SuppliedQty) FROM SUPPLIER WHERE SuppliedQty>200
NOTE :
Similarly four more assignments Cscience_22, Cscience_23, Cscience_24, and Cscience_25 can be
taken up by students on their own for SQL.