You are on page 1of 28

LIST OF PRACTICAL QUESTIONS FOR CLASS XII

1. Define a class named Cricket in C++ with the following descriptions :


private members
Target_scope int

Overs_bowled int
Extra_time int
Penalty int
cal_penalty() a member function to calculate penalty as follows :
if Extra_time <=10 , penalty =1
if Extra_time >10 but <=20, penalty =2
otherwise, penalty =5
public members
a function extradata() to allow user to enter values for
target_score,overs_bowled,extra_time and call cal_penalty().
a function dispdata() to follow user to view the contents of all data members.

2. Define a class named Directory in C++ with the following descriptions :


private members
docunames string (documents name in directory)
freespace long (total number of bytes available in directory )
occupied long (total number of bytes available in directory)
public members
newdocuentry() a function to accept values of docunames,freespace & occupied from user
retfreespace() a function that return the value of total kilobytes available. (1 KB=1024 b)
showfiles() a function that displays the names of all the documents in directory.

3. Define a class named Publisher in C++ with the following descriptions :


private members
Id long
title 40 char
author 40 char
price , stockqty double
stockvalue double
valcal() A function to find price*stockqty with double as return type
Public members
 a constructor function to initialize price , stockqty and stockvalue as 0
 Enter() function to input the idnumber , title and author
 Takestock() function to increment stockqty by N(where N is passed as argument to this
function) and call the function valcal() to update the stockvalue().
 sale() function to decrease the stockqty by N (where N is sale quantity passed to this
function as argument) and also call the function valcal() to update the stockvalue
 outdata() function to display all the data members on the screen.
4. Define a class named Serial in C++ with the following descriptions :
private members
serialcode int
title 20 char
duration float
noofepisodes integer
Public members
 a constructor function to initialize duration as 30 and noofepisodes as 10.
 Newserial() function to accept values for serialcode and title.
 otherentries() function to assign the values of duration and noofepisodes with the
help of corresponding values passed as parameters to this function.
 dispdata() function to display all the data members on the screen.

5. Define a class Competition in C++ with the following descriptions:


Data Members
Event_no integer
Description char(30)
Score integer
qualified char
Member functions
A constructor to assign initial values Event_No number as 101,Description as “State level” Score is
50 , qualified ‘N’.
Input() To take the input for event_no,description and score.
Award(int) To award qualified as ‘Y’, if score is more than the cutoffscore passed as
argument to the function else ‘N’.
Show() To display all the details.

Q6 Write UDF in C++ which accepts an integer array and its size as arguments/ parameters and assign
the elements into a 2 D array of integers in the following format :
if the array is 1,2,3,4,5
The resultant 2D array is given below
10000
12000
12300
12340
12345

Q7 Write UDF in C++ to print the row sum and column sum of a matrix A[2][5]
.
Q8 Write UDF in C++ to find a name from a list of names using binary search method.

Q9. Write UDF in C++ to insert an element in a one-dimensional sorted array in such a way that after
insertion the array remains sorted.

Q10. Write UDF in C++ to sort an array in ascending order using bubble sort.
Q11. Write UDF in C++ to sort an array (storing names) in ascending order using insertion sort.

Q12.Write UDF in C++ to sort an array of structures on the basis of admno, in ascending order using
Selection sort.
struct student
{ int admno;
char name[20];
};

Q13. Suppose A, B, C are the array of integers having size m, n, m+n respectively .The elements of array
A appear in ascending order, the elements of array B appear in descending order. Write a UDF in C++
to produce third array C after merging arrays A and B in ascending order. Take the arrays A, B and C as
argument to the function.

Q14.Write a function findsort(),to find whether the given integer Array arr[10] is sorted in ascending
order or descending order or is not in order. The function should return “A” for ascending , “D” for
descending and “N” for no order.

Q15.Write a function in C++ which accepts an integer array and its size as arguments/parameters and
exchanges the values of first half side elements with the second half side elements of the array.
example : if the array is 8,10,1,3,17,90,13,60 then rearrange the array as 17,90,13,60,8,10,1,3

Q16.Write a function in C++ which accepts an integer array and its size as arguments/parameters and
exchanges the values at alternate locations .
example : if the array is 8,10,1,3,17,90,13,60 then rearrange the array as 10,8,3,1,90,17,60,13

Q17. Write a function in C++ which accepts an integer array and its size as arguments/parameters and
reverse the contents of the array without using any second array.

Q18.Write a function in C++ which accepts an integer and a double value as arguments/parameters. The
function should return a value of type double and it should perform sum of the following series :
x-x2/3! + x3/5! – x4/7! + x5/9! …… upto n terms

Q19. Assume an array E containing elements of structure employee is required to be arranged in


descending order of salary. Write a C++ function to arrange the same with the help of bubble sort , the
array and its size is required to be passed as parameters to the function. Definition of structure Employee
is as follows : struct employee
{
int Eno;
char name[25];
float salary;
};
Q20.Given two arrays of integers X and Y of sizes m and n respectively . Write a function named
MERGE() which will produce a third array Z , such that the following sequence is followed .
(a) All odd numbers of X from left to right are copied into Z from left to right.
(ii) All even numbers of X from left to right are copied into Z from right to left.
(iii) All odd numbers of Y from left to right are copied into Z from left to right.
(ii) All even numbers of Y from left to right are copied into Z from right to left.
Q21. class stack
{ int data[10];
int top;
public:
Stack( ) { top=-1;}
void push ( ); // to push an element into the stack
void pop ( ) ; // to pop an element into the stack
void display( );// to display all the elements from the stack
};
complete the class with all function definition.

Q22. Write a function in C++ to perform a DELETE, insert & Display operation in a dynamically
allocated queue considering the following description:
struct Node
{ float U,V;
Node *Link;
};
class QUEUE
{ Node *Rear, *Front;
public:
QUEUE( ) { Rear =NULL; Front= NULL;}
Void INSERT ( );
Void DELETE ( );
~QUEUE ( );
}

Q23. Write a function in C++ to perform a PUSH , pop & Display operation in a dynamically allocated
stack considering the following :
Struct Node
{ int X,Y;
Node *Link;
};
class STACK
{ Node * Top;
public:
STACK( ) { TOP=NULL;}
void PUSH( );
void Pop( );
~STACK( );
};

Q24. Define function stackpush( ) to insert and stackpop( ) to delete and display, for a static circular
queue of array a[10].

Q25.Write a function in C++ to read the content from a text file STORY.TXT, count and display the
number of alphabets present in it and display the count of lines starting with alphabet A.
Q26. Write a function in C++ to read the content from a text file NOTES. TXT, count and display the
number of blank spaces present in it and also count and display the word “the” appearing in the text.

Q27.Assuming the class EMPLOYEE given below, write functions in C++ to perform the following:-
(i) Write the objects of EMPLOYEE to binary file.
(ii) Reads the objects of EMPLOYEE from binary file and display them on screen.
class EMPLOYEE
{
int ENC;
char ENAME[0];
public:
Void GETIT(){ cin>> ENO;gets(ENAME);}
Void SHOWIT() { cout>> ENO<<ENAME;<<endl; }
};

Q28. Asuming a binary file FUN.DAT is containing objects belonging to a class


LAUGHTER( as defined below). Write a user defined function in C++ to add more objects
belonging to class LAUGHTER at the bottom of it.
Class LAUGHTER
{
int idno;
char Type[5];
char Desc[255];
PUBLIC:
void Newentry(){ cin>> Idno; gets(Type); gets(Desc);}
void Showonscreen() { cout<<Idno<<” “<<Type<<endll<<Desc<<endl;}
};

Q29. Assuming that a text file named TEXT1.TEXT already contains some text written into it, write a
function named vowelwords(), that reads the file TEXT1.TEXT and creates a new file named
TEXT2.TEXT,which shall contain only those words from the file TEXT1.TEXT which does
not start with a vowel(i.e, with ‘A’,’E’,’I’,’O’,’U’). FOR example, if the file TEXT1.TXT
contains.
Carry umbrella and Overcoat when it Rains
then the file TEXT2.TXT shall contain
Carry when it Rains.
Q32. Given a binary file SPORTS.DAT, containing records of the following structure type:
struct sport
{ char Event[20];
Char Participant[10][30];
};
Write a function in C++ that would read the contents from the file SPORTS.dat and create a file
named Atheletic.dat copying only those records from sports.dat where the event name is “Atheletics”.

Q33 class Queue


{ int data[10];
int front, rear;
public:
Queue(){front=rear=0;}
void insert();
void delet();
void display();
};
Complete the class with all function definitions:

Q34 WAF sum() in c++ with two arguments, double X and int n. The function should return a value of
type double and it should find the sum of the following series:

1+ X / 2! + X3 / 4! + X5 / 6!+ X7 / 8!+ X9 / 10! +…………+ X 2n-1 / (2n)!

Q35 WAF check() to check if the passed array of 10 integers is sorted or not. The function should return
1 if arranged in ascending order, -1 if arranged in descending order, 0 if it is not sorted.

Q36 Given the following class:


char *info={ “over flow”,”under flow”};
class stack
{
int top;
stk[5];
void err_rep(int errornum){cout<<info[errornum];} //report error message
public:
void init(){top=0;}
void push(int);
void pop();
void display();
};
Complete the class with all function definitions:

Q37. Following is the structure of each record in a data file named “Laugh.dat”
struct LAUGHTER
{
int idno;
` char Type[5];
char Desc[255];
};

Write a function to update the file with a new value of LaughterType. The value of laughter number and
laughter type are read during the execution of the program.

38) Write a function in C++ which accepts an integer array and its size as arguments / parameters and
then from 1-d array assign the values in 2 –d array such that the odd numbers are copied in the first row
and even numbers in the second row of a two dimensional array. The unused cells of two dimensional
array must be filled with 0.
If the array is 1, 2, 3, 4, 5, 6
The resultant 2-D array is given below
135000
000642

39) Write a function to count the number of house number that are starting with ‘13’ from a text file that
contains house numbers of all students in a school. The file house.txt contains only house numbers as
record.
Example : If the file house.txt contains the following records,
10101
10113
13101
13103
The function should display the output as 2.

40) Write a function in c++ to read and display the records of computers that cost more than Rs.
20000 from the binary file “COMP.DAT”, assuming that the binary file is containing the objects
of the following class :
class COMPUTER
{ int srno;
char model[25];
float price;
public:
float Retpr( ) { return price; }
void Enter( ){ cin>>srno>>price; gets(model); }
void Display( ){ cout<<rno<<Name<<price<<endl;}
};

41)Observe the program segment carefully and answer the question that follows:
class student
{
int student_no;
char student_name[20];
int mark;
public:
void enterDetails( )
{
cin>> student_no >> mark ; gets(student_name);
}
void showDetail( );
int get_mark( ){ return mark;}
};
Assuming a binary file “RESULT.DAT” contains records belonging to student class, write a
user defined function to separate the records having mark
(i) Greater than 79 into “EXCELLENT.DAT” file
(ii) Greater than 59 but less than 80 into “AVERAGE.DAT” file.
(iii)Remaining records should be in “RESULT.DAT” file.

42) Define a class NUTRITION in C++ with following description:


Private Members:
Access number Integer
Name of Food String of 25 characters
Calories Integer
Food type String
Cost Float
AssignAccess( )
Generates random numbers between 0 to 99 and return it.
Public Members
 A function INTAKE( ) to allow the user to enter the values of Name of Food, Calories, Food type
cost and call function AssignAccess() to assign Access number.
 A function OUTPUT( ) to allow user to view the content of all the data members, if the Food type
is fruit.

43) Assume an array A containing elements of structure Teacher is required to be arranged in


Descending order of salary. Write a C++ program to arrange the same with the help of selection sort. The
array and its size is required to be passed as parameters to the functions. Definition of structure Teacher
is as under:
struct Teacher
{
int ID;
char Teacher_name[25];
float Salary;
};

44) Define a class Departmental with the following specification :


private data members
Prod_name string (45 charactes) Listprice long
Dis_Price long [ Discount Price] Net long [Net Price ]
Dis_type char(F or N) [ Discount type]
Cal_price() – The store gives a 10% discount on every product it sells. However at the time of
festival season the store gives 7% festival discount after 10% regular discount. The discount type can
be checked by tracking the discount type. Where ‘F’ means festival and ‘N’ means Non- festival .The
Cal_price() will calculate the Discount Price and Net Price on the basis of the following table.

Product Name List Price(Rs.)


Washing Machine 12000
Colour Television 17000
Refrigerator 18000
OTG 8000
CD Player 4500
public members
 Constructor to initialize the string elements with “NULL”, numeric elements with 0 and character
elements with ‘N’
 Accept() - Ask the store manager to enter Product name, list Price and discount type . The function
will invoke Cal_price() to calculate Discount Price and Net Price .
 ShowBill() - To generate the bill to the customer with all the details of his/her purchase along with
the bill amount including discount price and net price.

45)Write a function in c++ to count the number of capital vowels present in a text file FILE.TXT.
46)Define a class PhoneBill in C++ with the following descriptions.
Private members:
CustomerName of type character array
PhoneNumber of type long
No_of_units of type int
Rent of type int
Amount of type float.
calculate( ) This member function should calculate the value of amount as Rent+ cost for the
units.Where cost for the units can be calculated according to the following conditions.
No_of_units Cost
First 50 calls Free
Next 100 calls 0.80 @ unit
Next 200 calls 1.00 @ unit
Remaining calls 1.20 @ unit
Public members:
* A constructor to assign initial values of CustomerName as “Raju”, PhoneNumber as
259461, No_of_units as 50, Rent as 100, Amount as 100.
* A function accept ( ) which allows user to enter CustomerName, PhoneNumber, No_of_units
And Rent and should call function calculate ( ).
* A function Display ( ) to display the values of all the data members on the screen.

47) Write a function in C++ which accepts an integer array and its size as arguments/parameters and
assign the elements into a two dimensional array of integers in the following format (size must be odd) If
the array is 1 2 3 4 5 or If the array is 10 15 20
The output must be the output must be
10005 10 0 20
02040 0 15 0
00300 10 0 20
02040
10005

48) Write a function RevText() to read a text file “ Input.txt “ and Print only word in reverse order .

Example:
If value in text file is: INDIA IS MY COUNTRY
Output will be: AIDNI SI MY COUNTRY

49) Given the binary file ITEM.DAT, containing the records of the following structure:

class item
{
int item_no;

char item_name[20];
int stock;

public:
int itmreturn()
{
return item_no;
}
};
Implement the function DelStock(), which delete a record of matching item_no entered through the
keyboard.

50) Write a function in C++ to count and display the no of lines starting with the vowel ‘A’ having single
character in the file “Vowel.TXT”.
Example:
If the Line contains:
A boy is playing there.
I love to eat pizza.
A plane is in the sky.
Then the output should be: 2

(51) Write a function in c++ to read and display the records of computers that cost more than Rs.
20000 from the binary file “COMP.DAT”, assuming that the binary file is containing the objects of the
following class :
class COMPUTER
{ int srno;
char model[25];
float price;
public:
float Retpr( ) { return price; }
void Enter( ){ cin>>srno>>price; gets(model); }
void Display( ){ cout<<rno<<Name<<price<<endl;} };

52)Consider the following portion of a program, which implements passengers Queue for a train.
Complete all the definition, to insert a new node, delete and display in the queue with required
information:
struct NODE
{
long TicketNo;
char PName[20]; // Passenger Name
NODE *NEXT;
}
class TrainQueue
{
NODE *rear, *front;
public:
TrainQueue( ) { rear = NULL, front = NULL ;}
void Q_Insert( );
void Q_Delete ( );
void Q_Display ( );
~TrainQueue( );
};

53) Write a function in C++ which accepts a 2D array of integers and its size as arguments and displays
the elements of middle row and the elements of the middle column.

54)Write function definition for Non_Diagonal() in C++ to display all the elements other than the 3
diagonal(left and right) of a two dimensional integer array Q of size 4 x 4 passed as a parameter to
the function.
Example: If the two dimensional array contains

The function call should display

55)Define a class named PRODUCT in C++ with following description: 4


Private Members:
 P_NO // Product number
 P_Type // Product Type
 P_Name // Product Name
 P_Price // Product Price
 A function Get_Prod ( ) to set the price of the product according to the following:
For the value of P_Type “Mobile”
P_Name P_Price
SONY 15000
SAMSUNG 13000
For P_Type other than “Mobile”
P_Price gets included 14% Extra charge for installation.

Public Members:
 A constructor to assign initial values of P_NO, P_Type and P_Name as “NOT ASSIGNED” and
P_Price as 0.
 A function Get_Info( ) to input the values of P_NO, P_Name and P_Type and also invoke
Get_Prod( ) function.
 A function Disp_Info( ) to display the value of all the data members.

56) Define a class Society with the following specifications.


Private Members :
society_name char (30)
house_no integer
no_of_members integer
flat char(10)
income float
Public members:
A constructer to assign initial values of society_name as “Mahavir Nagar”, flat as “A Type”, house_no
as 56, no_of_members as 6, income as 50000.
input( ) – to read data members.
alloc_flat( ) – To allocate flat according to income
income >=50000 - Flat “ A Type”
income >=25000 and income <50000 - Flat “ B Type”
income <25000 - Flat “ C Type”
show( ) – to display all details.

(57) Write function definition for Total( ) in C++ to display the total number of word “school” present in
a text file “FUNCTION.TXT”.
Example:
If the content of the file “FUNCTION.TXT” is as follows:
The school function is taking place in December. Our school has participated in many inter- school
events. The school life is the best.
The function Total() should display the following:
Total number of word “school”:4

58) Define a class Movie in C++ with following description:


Private Members
Mcode //Data member for Movie code
Type //Data member for the type of Movie
Rating //Data member for Movie critic rating
Collections //Data member for movie collections per day
Assign() //A function to assign Rating a value based on Collections as follows:
Collections Rating
<=1000000 2**
>1000000 && <=5500000 3***
>5500000 4****

Public Members

Read() //A function to enter value of Mcode,Type and Collections . It will invoke Assign() function.
Display() //A function to display Mcode,Type,Rating and Collections
Ret_Rating() //A function to return value of Rating

(59)Write function definition for Sales( ) in C++ to read and display the details of the regions having a
sale of 20000 or more from a binary file “COMPANY.DAT” which contains objects of the following
class.
class Company
{
int Id; //Region id
char C_Name[20]; //Company Name
char Region[30]; //Region(South,North,East, West)
float Sales; //total sales
public:
void Accept_Val(); //Function to enter the details
void Show_Val(); //Function to display the details
float RSales(){return Sales;}
};

60) WAF which is passed a character pointer and that function should reverse the string.

(1) Study the following tables STAFF and SALARY and write SQL commands for the question
(i) to (iv) and give output for SQL queries (v) to (vi)
Relation : STAFF
NAME DOJ DEPT SEX QUALF
ID
101 Siddharth 12/01/02 Sales M MBA
104 Raghav 8/05/88 Finance M CA
107 Naman 14/05/88 Research M MTECH
114 Nupur 1/02/03 Sales F MBA
109 Janvi 18/7/04 Finance F ICWA
105 Rama 14/4/07 Research M BTECH
117 Jace 27/6/87 Sales F MTECH
111 Binoy 12/1/90 Finance M CA
130 Samuel 7/3/99 Sales M MBA
187 Ragini 12/12/02 Research F BTECH
relation : SALARY
ID BASIC ALLOWANCE COMM_PERC
101 15240 5400 3
104 23000 1452 4
107 14870 2451 3
114 21000 3451 14
109 24500 1452 10
105 17000 1250 2
117 12450 1400 3
111 13541 3652 9
130 25000 4785 15
187 14823 5862 2

i) Display the name of all CA’s who are working for more than 5 years
ii) Display the number of staff joined year-wise
iii) Hike the Allowance of all female staff working in finance sector and joined the company
before 2000
iv) Display the average salary given to the employee in each department
v) SELECT DEPT, COUNT(*)
FROM STAFF
WHERE SEX=’m’
GROUP BY DEPT
HAVING COUNT(*) >2;
vi) SELECT AVG(BASIC+ ALLOWANCE), QUALF
FROM SALARY S1, STAFF S2
WHERE S1.ID=S2.ID
GROUP(QUALF) ;
vii) SELECT DISTINCT QUALF FROM STAFF;
viii) SELECT NAME, BASIC+ALLOWANCE
FROM STAFF S, SALARY SA

2) Consider the following tables SCHOOL and ADMIN. Write SQL commands for the statements
(i) to (iv) and give outputs for SQL queries (v) to (viii).

SCHOOL
CODE TEACHERNAME SUBJECT DOJ PERIOD EXPERIENC
S E
1001 RAVI SHANKAR ENGLISH 12/03/2000 24 10
1009 PRIYA RAI PHYSICS 03/09/1998 26 12
1203 LISA ANAND ENGLISH 09/04/2000 27 5
1045 YASHRAJ MATHS 24/08/2000 24 15
1123 GANAN PHYSICS 16/07/1999 28 3
1167 HARISH B CHEMISTRY 19/10/1999 27 5
1215 UMESH PHYSICS 11/05/1998 22 16

ADMIN
CODE GENDER DESIGNATION
1001 MALE VICE PRINCIPAL
1009 FEMALE COORDINATOR
1203 FEMALE COORDINATOR
1045 MALE HOD
1123 MALE SENIOR TEACHER
1167 MALE SENIOR TEACHER
1215 MALE HOD

i) To display TEACHERNAME, PERIODS of all teachers whose periods less than 25.

ii) To display TEACHERNAME, CODE and DESIGNATION from tables SCHOOL and ADMIN whose
gender is male.

iii) To display the TEACHERNAME subject wise.

iv) To display CODE, TEACHERNAME and SUBJECT of all teachers who have joined the school after
01/01/1999.

v) SELECT MAX (EXPERIENCE), SUBJECT FROM SCHOOL GROUP BY SUBJECT;

vi) SELECT TEACHERNAME, GENDER FROM SCHOOL, ADMIN WHERE DESIGNATION =


COORDINATOR’ AND SCHOOL.CODE=ADMIN.CODE;

vii) SELECT DESIGNATION, COUNT (*) FROM ADMIN GROUP BY DESIGNATION HAVING
COUNT (*) <3;

viii) SELECT COUNT (DISTINCT SUBJECT) FROM SCHOOL;

(3)Consider the following table FLIGHT and FARES. Write the SQL commands for the
statements (i) to (iv) and output from (v) to (viii).

Table: FLIGHT
FL_NO DEPARTURE ARRIVAL NO_FLIGHTS NOOFSTOPS
IC301 MUMBAI DELHI 8 0
IC799 BANGALORE DELHI 2 1
MC101 INDORE MUMBAI 3 0
IC302 DELHI MUMBAI 8 0
AM812 KANPUR BANGALORE 3 1
IC899 MUMBAI KOCHI 1 4
AM501 DELHI TRIVANDRUM 1 5
MU499 MUMBAI MADRAS 3 3
IC701 DELHI AHMEDABAD 4 0

Table: FARE
FL_NO AIRLINES FARE TAX%
1C701 Indian Airlines 6500 10
MU499 Sahara 9400 5
AM501 Jet Airways 13450 8
IC899 Indian Airlines 8300 4
1C302 Indian Airlines 4300 9
1C799 Indian Airlines 10500 10
MC101 Deccan Airlines 3500 4

(i) Display Flight No, No of Flights arriving to the DELHI


(ii) Display all the airlines that have maximum no of flights.
(iii) Display total fare of all the airlines.
(iv) To display departure and arrival points of flight no 1C302 and MU499.
Give the Output:
(v) SELECT COUNT(DISTINCT FL_NO) FROM FLIGHT;
(vi) SELECT MIN(NOOFSTOPS) FROM FLIGHT
WHERE FL_NO = ‘IC899’;
(vii) SELECT AVG(FARE) FROM FARE
WHRE AIRLINES = ‘Indian Airlines’;
(viii) SELECT FL_NO, NO_FLIGHTS FORM FLIGHT
WHERE DEPARTURE=’MUMBAI’;

4) Consider the following tables CUSTOMER and MOBILE. Write SQL commands for the
statements (i) to (iv) and give outputs for SQL queries (v) to (viii)
(i) To display the records of those customer who take the connection of Bsnl and Airtel
in ascending order of Activation date.
(ii) To decrease the amount of all customers of Reliance connection by 500.
(iii) Count the no. of companies giving connection from CUSTOMER table whose name starts with ‘P’.
(iv) To display the ID and Cname from table Customer and Make from table Mobile,
with their corresponding matching ID.
(v) select Cname , Make form Customer, Mobile where Customer.ID = Mobile.ID;
(vi) select Connection , sum(Amount) from Customer group by Connection ;
(vii) SELECT COUNT(DISTINCT Make) FROM Mobile; .
(viii) SELECT AVG(Amount) FROM Customer where Validity >= 180;

5) Consider the following tables ARTIST and GALLERY. Write SQL commands for the statements (C1)
6 to (C4) and give outputs for SQL queries (D1) to (D4)
1. To display A_NAME(Artist Name) and TITLE of all Modern type paintings from table ARTIST

2. To display the details of all the Artists in descending order of TITLE within TYPE from table

3. To display the A_NAME, G_NAME and Date of Display (D_OF_DISPLAY) for all the Artists
who are having a display at the gallery from the tables ARTIST and GALLERY.

4. To display the highest price of paintings in each type from table ARTIST

5. SELECT A_NAME, TITLE, PRICE FROM ARTIST WHERE PRICE BETWEEN 120000 AND
300000;

6. SELECT DISTINCT TYPE FROM ARTIST ;

7. SELECT MAX(FEES),MIN(D_OF_DISPLAY) FROM GALLERY;

8. SELECT COUNT(*)FROM ARTIST WHERE PRICE<300000;

6)
TABLE : GRADUATE
S.NO NAME STIPEND SUBJECT AVERAGE DIV.
1 KARAN 400 PHYSICS 68 I
2 DIWAKAR 450 COMP. Sc. 68 I
3 DIVYA 300 CHEMISTRY 62 I
4 REKHA 350 PHYSICS 63 I
5 ARJUN 500 MATHS 70 I
6 SABINA 400 CEHMISTRY 55 II
7 JOHN 250 PHYSICS 64 I
8 ROBERT 450 MATHS 68 I
9 RUBINA 500 COMP. Sc. 62 I
10 VIKAS 400 MATHS 57 II

(a) List the names of those students who have obtained DIV 1 sorted by NAME.
(b) Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend received in a year
assuming that the STIPEND is paid every month.
(c) To count the number of students who are either PHYSICS or COMPUTER SC graduates.
(d) To insert a new row in the GRADUATE table:
11,”KAJOL”, 300, “computer sc”, 75, 1
(e) Give the output of following sql statement based on table GRADUATE:
(i) Select MIN(AVERAGE) from GRADUATE where SUBJECT=”PHYSICS”;
(ii) Select SUM(STIPEND) from GRADUATE WHERE div=2;
(iii) Select AVG(STIPEND) from GRADUATE where AVERAGE>=65;
(iv) Select COUNT(distinct SUBDJECT) from GRADUATE;
(f) Assume that there is one more table GUIDE in the database as shown below:
Table: GUIDE

MAINAREA ADVISOR
PHYSICS VINOD
COMPUTER SC ALOK
CHEMISTRY RAJAN
MATHEMATICS MAHESH

g) What will be the output of the following query:


SELECT NAME, ADVISOR FROM GRADUATE,GUIDE WHERE SUBJECT=
MAINAREA;

Q7.
Employees
Empid Firstname Lastname Address City
010 Ravi Kumar Raj nagar GZB
105 Harry Waltor Gandhi nagar GZB
152 Sam Tones 33 Elm St. Paris
215 Sarah Ackerman 440 U.S. 110 Upton
244 Manila Sengupta 24 Friends New Delhi
street
300 Robert Samuel 9 Fifth Cross Washington
335 Ritu Tondon Shastri Nagar GZB
400 Rachel Lee 121 Harrison New York
St.
441 Peter Thompson 11 Red Road Paris
EmpSalary

Empid Salary Benefits Designation


010 75000 15000 Manager
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

Write the SQL commands for the following :


(i) To show firstname,lastname,address and city of all employees living in paris

(ii) To display the content of Employees table in descending order of Firstname.

(iii) To display the firstname,lastname and total salary of all managers from the tables Employee
and empsalary , where total salary is calculated as salary+benefits.

(iv) To display the maximum salary among managers and clerks from the table Empsalary.
Give the Output of following SQL commands:
(i) Select firstname,salary from employees ,empsalary where designation = ‘Salesman’ and
Employees.empid=Empsalary.empid;
(ii) Select count(distinct designation) from empsalary;
(iii) Select designation, sum(salary) from empsalary group by designation having count(*) >2;
(iv) Select sum(benefits) from empsalary where designation =’Clerk’;

Q8 . Write the SQL commands for the following on the basis of tables INTERIORS and NEWONES
Table: INTERORS
SNO ITEMNAME TYPE DATEOFSTOCK PRIC DISCOUNT
E
1 Red Rose Double Bed 23/02/02 32000 15
2 Soft Touch Baby Cot 20/1//02 9000 10
3 Jerry’s Home Baby Cot 19/02/02 8500 10
4 Rough Wood Office Table 01/01/02 20000 20
5 Comfort Zone Double Bed 12/01/02 15000 20
6 Jerry Look Baby Cot 24/02/02 7000 19
7 Lion King Office Table 20/02/02 16000 20
8 Royal Tiger Sofa 22/02/02 30000 25
9 Park Sitting Sofa 13/12/01 9000 15
10 Dine Paradise Dining Table 19/02/02 11000 15
Table: NEWONES
SN ITEMNAME TYPE DATEOFSTO PRIC DISCOUN
O CK E T
11 White Wood Double Bed 23/02/02 20000 20
12 James 007 Sofa 20/02/03 15000 15
13 Tom Look Baby Cot 21/02/03 7000 10

(i) To list the ITEMNAME which are priced at more than 1000 from the INTERIORS table

(ii) To list ITEMNAME and TYPE of those items, in which DATEOFSTOCK is before 22/01/02
from the INTERIORS table in descending order of ITEMNAME

(iii) To show all information about the sofas from the INTERIORS table

(iv) To display ITEMNAME and DATEOF STOCK of those items in which the discount
percentage is more than 15 from INTERIORS table

(v) To count the number of items, whose type is “Double Bed” from INTERIORS table

(vi) To insert a new row in the NEWONES table with the following data
14,”True Indian”, “Office Table”, 28/03/03,15000,20

(vii) Get the Output (Use the above table without inserting the record)
a) Select COUNT(distinct TYPE) from INTERIORS

b) Select AVE(DISCOUNT) from INTERIORS where TYPE=”Baby Cot”

c) Select SUM(Price) from INTERIORS where DATEOF STOCK<{12/02/02}

d) Select MAX(Price) from INTERIORS , NEWONES;

9.Consider the following tables BOOKS and ISSUED. Write SQL commands for the statements (i) to
(iv) and give outputs for SQL queries (v) to (viii)
BOOKS
Book_Id Book_Name Author_Name Publishers Price Type Quantity
C01 Fast Cook Lata Kapoor EPB 355 Cooker 5
y
F01 The Tears William First 650 Fiction 20
Hopkins
T01 My C++ Brain & Brooke FPB 350 Text 10
T02 C++ Brain A.W.Rossaine TDH 350 Text 15
F02 Thuderbolts Anna Roberts First 750 Fiction 50
ISSUED
Book_Id Quantity_Issued
T01 4
C01 5
F01 2
C01 6
T02 3

1. To list the names from books of Text type.

2. To display the names and price from books in ascending order of their price.

3. To increase the price of all books of EPB publishers by 50.

4. To display the Book Name, Quantity_Issued and Price for all books of EPB publishers.

5. Select max(price) from books;

6. Select count(DISTINCT Publishers) from books where Price >=400;

7. Select Book_Name, Author_Name from books where Publishers = ‘First’;

8. Select min(Price) from books where type = ‘Text’;

10. Consider the following tables FACULTY and COURSES. Write SQL commands for the statements
(i)
to (iv) and give outputs for SQL queries (v) to (viii)
(i) To display details of those Faculties whose date of joining is before 31-12-2001.

(ii) To display the details of courses whose fees is in the range of 15000 to 50000 (both values included).

(iii) To increase the fees of Dreamweaver course by 500.

(iv) To display F_ID, Fname, Cname of those faculties who charged more than15000 as fees.

(v) Select COUNT(DISTINCT F_ID) from COURSES;

(vi) Select MIN(Salary) from FACULTY,COURSES where COURSES.F_ID = FACULTY.F_ID;

(vii) Select SUM(Fees) from courses Group By F_ID having count(*) > 1;

(viii) Select Fname, Lname from FACULTY Where Lname like “M%”;

11.
(i) To display the name of all Games with their Gcodes
(ii) To display details of those games which are having PrizeMoney more than 7000.
(iii) To display the content of the GAMES table in ascending order of ScheduleDate.
(iv) To display sum of PrizeMoney for each of the Number of participation groupings (as shown in
column Number 2 or 4)
(v) SELECT COUNT(DISTINCT Number) FROM GAMES;
(vi) SELECT MAX(ScheduleDate),MIN(ScheduleDate) FROM GAMES;
(vii) SELECT SUM(PrizeMoney) FROM GAMES;
(viii) SELECT DISTINCT Gcode FROM PLAYER;

Q12.
(i) Display FirstName and City of Employee having salary between 50,000 and 90,000
(ii) Display details of Employees who are from “PARIS” city.
(iii) Increase the benefits of employee having W_ID = 210 by 500.
(iv) Count number of employees whose name starts from character ‘S’.
(v) Select MAX(salary) from desig
(vi) Select FirstName from employee, desig
where designation = ‘MANAGER’ AND employee.W_ID = desig.W_ID;
(vii) Select COUNT (DISTINCT designation) from desig;
(viii) Select designation, SUM(salary) from desig
Group by designation Having count (*) > 2;

Q13
Write the SQL commands:-
(i) To display Firstname, Lastname, Address and City of all employees living
in ND from the table EMPLOYEES.
(ii) To display the contents of EMPLYEES table in descending order of
firstname.
(iii) To display the firstname, lastname, and Total Salary of all mangers from
the table EMPLOYEES and EMPSALARY. Where total salary is
calculate as Salary + Benefits.
(iv) To display the maximum salary among Managers and Clerks from
EMPSALARY.
(v) Write the output of the following:-
(a) Select COUNT (DISTINCT DESIGNATION) FROM
EMPSALARY.
(b) Select firstname, salary from EMPLOYEES, EMPSALARY
WHERE Designation = ‘Salesman’
AND EMPLOYEES. Emid = EMPSALARY. Emid.
(c) Select designation. Sum (salary) from EMPSALARY Group ByDesignation Having Count (*)>2;
(d) Select SUM (Benefits) from EMPLOYEES where designation =‘clerk’;
Consider the following tables Product and Clint. Write SQL commands for the statement (i) to (iv) and give outputs for
SQL queries (v) to (viii)
Table: PRODUCT ProductName Manufac Price
P_ ID turer
TP01 Talcum Powder LAK 40
FW05 Face Wash ABC 45
BS01 Bath Soap ABC 55
SH06 Shampoo XYZ 120
FW12 Face Wash XYZ 95

Table:CLIN
T C_ID ClientName City P_ID
01 Cosmetic Shop Delhi FW05
06 Total Health Mumbai BS01
12 Live Life Delhi SH06
15 Pretty Woman Delhi FW12
16 Dreams Banglore 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 ClientName, City from table Client, and ProductName 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 ClientName, ManufacturerName FROM Product, Client WHERE Client.Prod-ID=Product.P_ID;

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

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 ItemName Manufa Price
I_ID cture
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 l_ID
01 MRS REKHA Delhi LC03
06 MANSH Mumbai PC03
12 RAJEEV Delhi PC06
15 YAJNESH Delhi LC03
16 VIJAY Banglore PC01

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

(ii) To display the details of item whose price is in the range of 35000 to 55000 ( both values included)

(iii) To display the customer name, city from table Customer, and itemname and price from table Item, with their
corresponding matching I_ID.

(iv) To increase the price of all items by 1000 in the table Item.

(v) SELECT DISTINCT City FROM Customer;

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

(vii) SELECT CustomerName, Manufacturer FROM Item, Customer WHERE Item.Item_Id=Customer.Item_Id

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

You might also like