Showing posts with label Sample Paper. Show all posts
Showing posts with label Sample Paper. Show all posts

Wednesday

Sample Paper Computer Science of Class XII for Session 2020-21










Thursday

Important Questions for Class 12 Computer Science (C++) – Inheritance (Extending Classes)

 

Previous Years Examination & Important Questions
2 Marks Questions

Question 1:
Differentiate between protected and private members of a class in context of Object Oriented Programming. Also give a suitable example illustrating accessibility/non-accessibility of each using a class and an object in C++. All India 2017

or

What is the difference between protected and private members of a class? Give a suitable example in C++ to illustrate with its definition within a class. All India 2015C

Answer:
Private visibility A member declared as private can be accessed only in class. It means that it cannot be accessed outside the class.
Protected visibility A member declared as protected can be accessed inside the class as well as inside its sub class only.

e.g.
class Super 
{
private: 
int x; 
protected: 
int y;
};
class Sub : protected Super 
{
private: 
int z;
public:
void disp()
{
cout<<x<<y<<z;
/*Here y and z can be accessed but x cannot be accessed because it is a private member of Super class*/
}
}:

Question 2:
Differentiate between members, which are present within the private visibility mode with those which are present within the public visibility modes. Delhi 2011
Answer:
Private visibility A member declared as private can be accessed only in class. It means that it cannot be accessed outside class.
Public visibility A member declared as public can be access inside the class as well as outside the class with object of that class.

e.g. class Super 
{
private 
int x; 
public: 
int y;
}:
class sub : private super 
{
private: 
int z; 
public:
void show()
{cout<<x<<y<<z;
/*Here y and z can be accessed because it a private member of super class*/
}
};

Question 3:
Differentiate between public and protected visibilities in context of object oriented programming giving suitable examples for both. Delhi 2008C
Answer:
Public visibility A member declared as public can be access inside the class as well as outside the class with object of that class.
Protected visibility A member declared as protected can be accessed inside the class as well as inside its sub class only. It cannot be accessed outside the class through the object of that class in which it is declared,

e.g. class Super 
{
public: 
int y; 
protected: 
int x; 
protected:
void input()
{
cin>>x>>y;
}
}:
class Sub: public Super
{
public: int z;
void Show()
{
x = 10;
cout<<x<<y<<z;
}
}:
void main()
{
Super SI: 
cin>>Sl.x;
SI.input();/*It cannot be accessed here because it is protected member*/
Sub S2;
cin>>S2.y>>S2.z;/*y and z can be accessed here because these are public members*/
S2.Show( );/*Show( ) can be accessed here because it is public member of Sub class*/
}

4 Marks Questions

Question 4:
Answer the questions (i) to (iv) based on the following:

class First 
{
int X1; 
protected: 
float X2;
public:
First(); 
void Enter1(); void Display1();
};
class Second : private First 
{
int Y1; 
protected:
float Y2; 
public:
Second(); 
void Enter2(); 
void Display();
};
class Third : public Second 
{
int Z1; 
public:
Third(); 
void Enter3();
void Display(); 
}:
void main()
{
Third T; //Statement 1
: _______ //Statement 2
}

(i) Which type of Inheritance out of the following is illustrated in the above example?
Single Level Inheritance, Multilevel Inheritance, Multiple Inheritance
(ii) Write the names of all the member functions, which are directly accessible by the object T of class Third as declared in main() function.
(iii) Write Statement 2 to call function Display!) of class Second from the object T of class Third.
(iv) What will be the order of execution of the constructors, when the object T of class Third is declared inside main()?

Answer:

(i) Multiple Inheritance
(ii) Enter3(), Display!) of class Third, Enter2(),
(iii) Statement2 T.Second::Display():
(iv) First( )→Second( )→Third()

Question 5:
Answer the questions (i) to (iv) based on the following : Delhi 2016

class PRODUCT 
{
int Code: 
char Item[20];
protected: 
float Qty; 
public:
PRODUCT ( );
void GetIn( ); void Show( ):
};
class WHOLESALER
{
int WCode; 
protected:
char Manager[20]; 
public:
WHOLESALER(); 
void Enter(); 
void Display ();
};
class SHOWROOM : public PRODUCT, 
private WHOLESALER
{
char Name[20],City[20];
public:
SHOWROOM();
void Input ();
void View ( );
};

(i) Which type of Inheritance out of the following is illustrated in the above example?
• Single Level Inheritance
• Multilevel Inheritance
• Multiple Inheritance
(ii) Write the names of all the data members, which are directly accessible from the member functions of class SHOWROOM.
(iii) Write the names of all the member functions, which are directly accessible by an object of class SHOWROOM.
(iv) What will be the order of execution of the constructors, when an object of class SHOWROOM is declared?

Answer:

(i) Multiple Inheritance
(ii) Name[20], City[20], Manager[20], Qty
(iii) Input(), View( ), Getln( ), Show( )
(iv) PRODUCT()→ WHOLESALER()
→ SHOWROOM()

Question 6:
Answer the questions (i) to (iv) based on the following: All India 2016

class ITEM
{
int Id;
char IName [20]; 
protected: 
float Qty; 
public:
ITEM();
void Enter(); void View();
};
class TRADER
{
int DCode; 
protected:
char Manager[20]; 
public:
TRADER(); 
void Enter(); 
void View();
};
class SALEPOINT : public ITEM,
private TRADER
{
char Name[20],
Location[20]; 
public:
SALEPOINT(); 
void EnterAll(); 
void ViewAll();
};

(i) Which type of Inheritance out of the following is illustrated in the above example?
• Single Level Inheritance
• Multilevel Inheritance
• Multiple Inheritance
(ii) Write the names of all the data members, which are directly accessible from the member functions of class SALEPOINT.
(iii) Write the names of all the member functions, which are directly accessible by an object of class SALEPOINT.
(iv) What will be the order of execution of the constructors, when an object of class SALEPOINT is declared?

Answer:

(i) Multiple Inheritance
(ii) Name[20], Location[20], Qty, Manager[20]
(iii) EnterAll( ), ViewAll( ), Enter ( ) and View( ) of class ITEM
(iv) ITEM( ) → TRADER() → SALEPOINT( )

Question 7:
Answer the questions (i) to (iv) based on the following: Delhi 2015

class Exterior
{
int OrderId; 
char Address[20]; 
protected:
float Advance;
public:
Exterior(); 
void Book();
void View();
};
class Paint : public Exterior
{
intWallArea, ColorCode; 
protected: 
char Type; 
public:
Paint(); 
void PBook(); 
void PView();
};
class Bill : public Paint
{
float Charges; 
void Calculate(); 
public:
Bill();
void Bi11ing(); 
void Print();
};

(i) Which type of inheritance out of the following is illustrated in the above example?
• Single Level Inheritance
• Multilevel Inheritance
• Multiple Inheritance
(ii) Write the names of all the data members, which are directly accessible from the member functions of class Paint.
(iii) Write the names of all the member functions, which are directly accessible from an object of class Bill.
(iv) What will be the order of execution of the constructors, when an object of class Bill is declared?

Answer:

(i) Multilevel Inheritance
(ii) WallArea, ColorCode, Type, Advance
(iii) Billing! b Print! b PBook( ), PView( ), Book( b View( )
(iv) Exterior() → Paint! ) → Bill( )

Question 8:
Answer the questions (i) to (iv) based on the following: All India 2015

class Interior 
{
int orderId; 
char Address[20]; 
protected:
float Advance; 
public;
Interior(); 
void Book(); 
void View();
}:
class Painting : public Interior
{
int WallArea, ColorCode; 
protected: char Type; 
public:
Painting(); 
void PBook(); 
void PView();
};
class Billing : public Painting 
{
float Charges; 
void Calculate(); 
public:
Billing(); 
void Bill(); 
void BillPrint();
};

(i) Which type of Inheritance out of the following is illustrated in the above example?
• Single Level Inheritance
• Multilevel Inheritance
• Multiple Inheritance
(ii) Write the names of all the data members, which are directly accessible from the member functions of class Painting.
(iii) Write the names of all the member functions, which are directly accessible from an object of class Billing.
(iv) What will be the order of execution of the constructors, when an object of class Billing is declared?

Answer:

(i) Multilevel Inheritance
(ii) WallArea, ColorCode, Type, Advance
(iii) Bill( b BillPrint( ), PBook( ), PView( ), Book( b View! )
(iv) Interior! ) → Painting! ) → Billing! )

Question 9:
Consider the following C++ code and answer the questions from (i) to (iv). Delhi 2014

class Campus
{
long Id;
char City[20];
protected:
char Country[20]; 
public:
Campus(); 
void Register(); 
void Display();
};
class Dept : private Campus
{
long DCode[10]; 
char HOD[20]; 
protected:
double Budget; 
public:
Dept();. 
void Enter(); 
void Show();
};
class Applicant : public Dept
{
long RegNo;
char Name[20]; 
public:
Applicant();
void Enroll (C); 
void View();
};

(i) Which type of inheritance is shown in the above example?
(ii) Write the names of those member functions, which are directly accessed from the objects of class Applicant.
(iii) Write the names of those data members, which can be directly accessed from the member functions of class Applicant.
(iv) Is it possible to directly call function Display( ) of class University from an object of class Dept? (Answer as Yes or No).

Answer:

(i) Multilevel Inheritance
(ii) Enroll! b View ( ), Enter ( ), Show( ).
(iii) RegNo, Name[20], Budget.
(iv) No, because in the given program there is no class named University.

Question 10:
Consider the following C++ code and answer the questions from (i) to (iv). All India 2014

class University 
{
long Id;
char City[20];
protected:
char Country[20]; 
public:
University();
void Register(); 
void Display(); 
};
class Department : private University 
{
long DCode[10]; 
char HOD[20]; 
protected:
double Budget; 
public:
Department(); 
void Enter(); 
void Show();
};
class Student : public Department 
{
long Roll No; 
public:
Student();
void Enroll();
void View();
};

(i) Which type of inheritance is shown in the above example?
(ii) Write the names of those member functions, which are directly accessed from the objects of class Student.
(iii) Write the names of those data members, which can be directly accessible from the member functions of class Student.
(iv) Is it possible to directly call function Display! ) °f class University from an object of class Department?
(Answer as Yes or No).

Answer:

(i) Multilevel inheritance
(ii) Enroll() View( ), Enter( ), Show( ).
(iii) RollNo, Budget.
(iv) No, it is not possible because class Department is inheriting from class University privately. So, all the public and protected members of the class University will become private in class Department and objects cannot access private members of a class.

Wednesday

Important Questions for Class 12 Computer Science (C++) – Constructor and Destructor (Part 3)

 Question 26:

Answer the questions (i) and (ii) after going through the following class: Delhi 2013

class Motor
{
int MotorNo, Track; 
public:
Motor();          //Function 1
Motor(int MN);    //Function 2
Motor(Motor &M);  //Function 3
void Allocate()   //Function 4
void Move();
};
void main() 
{
Motor M;
  :
  :
}
  1. Out of the following, which of the option is correct for calling Function 2?
    Option 1 – Motor N(M);
    Option 2 – Motor P(10) ;
  2. Name the feature of object oriented programming, which is illustrated by Function 1, Function 2 and Function 3 combined together.

Аnswer:

  1. Option 2-Motor P( 10) is correct.
  2. Constructor overloading.

Question 27:
Answer the questions (i) and (ii) after going through the following class: Delhi 2012

class Tour 
{
int LocationCode;
char Location[20]; 
float charges;
public:
Tour()    //Function 1
{
LocationCode = 1; 
strcpy(Location,"PURI"); 
charges = 1200;
}
void TourPlan(float C) //Function 2
{
cout<<LocationCode<<":"<< Location<<":”<<charges<<endl; 
charges += 100;
}
Tour(int LC, char L[], float C)  //Function 3
{
LocationCode=LC; 
strcpy(Location,L); 
charges = C;
}
~Tour()    //Function 4
{
cout<<"TourPlan Cancelled"<<endl;
}
};
  1. In object oriented programming, what are Function 1 and Function 3 combined together as?
  2. In object oriented programming, which concept is illustrated by Function 4? When is this function called/invoked?

Аnswer:

  1. Function 1 and Function 3 combined together referred as constructor overloading, i.e. polymorphism.
  2. Function 4 indicates destructor. This function is called/invoked whenever an object goes out of scope.

Question 28:
Answer the questions (i) and (ii) after going through the following class: All India 2012

class Travel 
{
int PlaceCode; 
char Place[20]; 
float Charges; 
public:
Travel()    //Function 1
{
PlaceCode = 1; 
strcpy(Place, "DELHI");
Charges = 1000;
}
void TravelPlan(float C) //Function 2 
{
cout<<PlaceCode<<":"<<Place<<":"<<Charges<<endl;
}
∼Travel()    //Function 3
{
cout<<"TravelPlan Cancelled"<<endl;
}
Travel(int PC, char P[], float C)    //Function 4 
{
PlaceCode = PC; 
strcpy(Place, P):
Charges = C;
}
};
  1. In object oriented programming, what are Function 1 and Function 4 combined together as ?
  2. In object oriented programming, which concept is illustrated by Function 3? When is this function called/invoked?

Аnswer:

  1. Function 1 and Function 4 combined together referred as constructor overloading, i.e. polymorphism.
  2. Function 3 indicates destructor/ This function is called/invoked whenever an object goes out of scope.

Question 29:
Find the output of the following program: Delhi 2012

#include<iostream.h> 
class Train 
{ 
int TNo.TripNo.PersonCount;
public:
Train(int TN = 1)
{
TNo = TN:
TripNo=0;
PersonCount=0;
}
void Trip(int TC=100)
{
TripNo++;
PersonCount+=TC;
}
void Show()
{
cout<<TNo<<":"<<TripNo<<":"<<PersonCount<<endl;
}
};
void main()
{
Train T(10),N;
N.Trip();
T.Show();
N.Trip(70);
N.Trip(40);
N.Show();
T.Show();
}

Аnswer:
Output of the given program would be:
10:0:0
1:3:210
10:0:0

Question 30:
Find the output of the following program: All India 2012

#include<iostream.h> 
class METRO 
{
int Mno,TripNo,PassengerCount; 
public:
METR0(int Tmno=1)
{
Mno=Tmno:
TripNo=0;
PassengerCount=0;
}
void Trip(int PC=20)
{
TripNo++;
PassengerCount+=PC;
}
void StatusShow()
{
cout<<Mno<<":"<<TripNo<<":"<<PassengerCount<<endl;
};
void main()
{
METRO M(5),T;
M.Trip();
T.Trip(50);
M.StatusShow();
M.Trip(30);
T.StatusShow(); 
M.StatusShow();
}

Аnswer:
Output of the given program would be:
5:1:20
1:1:50
5:2:50

Question 31:
Rewrite the following program after removing the syntactical errors (if any). Underline each correction. Delhi 2011c

#inc1ude<iostream.h> 
#include<stdio.h> 
class AUTO 
{
char Model[20]; 
float Price;
AUTO()
{
Price = 0;
strcpy(Model,"NULL");
}
public:
void GetInfo()
{
cin>>Price; 
gets(Model);
}
void PutInfo()
{
cout<<setw(10)<<Price<<setw(10)<<Model<,<endl;
}
}
void main()
{
AUTO Car; 
Car.GetInfo(); 
Car.PutInfo();
}

Аnswer:

#include<iostream.h>
#include<stdio.h> 
#include<string.h>
#inc1ude<iomanip.h> 
class AUTO
{
char Model[20]; 
float Price; 
public:
AUTO()
{
Price = 0;
strcpy(Model, "NULL”);
}
void Getlnfo()
{
cin>>Price; 
gets(Model);
}
void Putlnfo()
{
cout<<setw(10)<<Price<<setw(10)<<Model<<endl;
}
};
void main()
{
AUTO Car;
Car.Getlnfo();
Car.Putlnfo();
}

Question 32:
Answer the questions (i) and (ii) after going through the following class; All India 2010

class Exam 
{
int Rno, MaxMarks, MinMarks, Marks; 
public:
Exam()    //Module 1
{
Rno - 101; MaxMarks = 100; 
MinMarks = 40; Marks = 75;
}
Exam(int Prno.int Pmarks) //Module 2
{
Rno = Prno; MaxMarks = 100; 
MinMarks = 40; Marks = Pmarks;
}
∼ExamO    //Module 3
{
cout<<"Exam over"<<endl;
}
void show()    //Module 4
{
cout<<Rno<<":"<<MaxMarks<<":"<<MinMarks<<endl; 
cout<<"[MarksGot]"<<Marks<<endl;
}
};
  1. As per object oriented programming, which concept is illustrated by Module 1 and Module 2 together?
  2. What is Module 3 specifically referred as, when do you think Module 3 will be invoked/called?

Аnswer:

  1. Constructor overloading or polymorphism.
  2. Function 3 is referred to as destructor. It is invoked or called, when scope of an object gets over.

Question 33:
Answer the questions (i) and (ii) after going through the following class: Delhi 2016

class TEST
{
int Regno, Max, Min, Score; 
public:
TESTO    //function 1
{
Regno = 101; Max = 100;
Min = 40; Score = 75;
}
TEST(int Pregno.int Pscore) //Function 2
{
Regno = Pregno; Max = 100; 
Min = 40; Score = Pscore;
}
~TEST()    //Function 3
{
cout<<"TEST over"<<endl;
}
void Display()   //Function 4
{
cout<<Regno<<":"<<Max<<":"<<Min<<endl; 
cout<<"[Score]"<<Score<<endl;
}
};
  1. As per object oriented programming, which concept is illustrated by Function 1 and Function 2 together?
  2. What is Function 3 specifically referred as, when do you think Function 3 will be invoked/called?

Аnswer:

  1. Constructor overloading or polymorphism.
  2. Function 3 is referred to as destructor. It is invoked or called, when scope of an object gets over.

Question 34:
Answer the questions (i) and (ii) after going through the following class: HOTS; Delhi 2009

class WORK
{ 
int Workld; char WorkType; 
public:
∼WORK()    //Function 1
{
cout<<"Un-allocated"<<endl;
}
void status()    //Function 2
{
cout<<WorkId<<":"<<WorkType<<endl;
}
WORK()    //Function    3
{
Workld = 10; WorkType = 'T';
}
WoRK(WORK &W)    //Function 4
{
WorkId = W.WorkId+12;
WorkType = W.WorkType+1;
}
};
  1. Which member function, out of Function 1, Function 2, Function 3 and Function 4 shown in the above definition of class WORK is called automatically, when the scope of an object gets over? Is it known as constructor or destructor or overloaded function or copy constructor?
  2. WORK W; //Line 1
    WORK Y(W); //Line 2
    Which member function, out of Function 1, Function 2, Function 3 and Function 4 shown in the above definition of class WORK will be called on execution of statement written as Line 2? What is this function specifically known as out of destructor or copy constructor or default constructor?

Аnswer:

  1. Function 1 is called, when the scope of an object gets over. It is called destructor.
  2. Function 4 will be called and this function is referred to as copy constructor.

Question 35:
Answer the questions (i) and (ii) after going through the following class: Delhi 2009C

class Factory
{
char Name[20]; 
int Workers; 
public:
Factory()    //Function 1
{
strcpy(Name, "Default”); 
Workers = 0;
}
void Details() //Function 2
{
cout<<Name<<endl<<Workers<<endl;
}
Factory(char*act_Name,int No);  //Function 3 
Factory(Factory & F);   //Function 4
};
  1. In object oriented programming, what is function 4 referred as? Also, write a statement which will invoke this function.
  2. In object oriented programming, which concept is illustrated by Function 1, Function 3 and Function 4 together?

Аnswer:

  1. Function 4 is referred to as copy constructor.
    The statement to invoke it as follows:
    Factory F2(“ABC”, 101);
    Factory F3(F2); //Invoking Function 4
  2. Function 1, Function 3 and Function 4 illustrate the concept of constructor overloading; i.e. polymorphism

Question 36:
Answer the questions (i) and (ii) after going through the following class: All India 2009

class Job 
{
int JobId; 
char JobType; 
public:
∼Job()    //Function 1
{
cout<<"Resigned"<<endl;
}
Job()    //Function 2
{
JobId = 10; JobType = 'T';
}
void TellMe()   //Function 3
{
cout<<JobId<<":"<<JobType<<endl;
}
Job(Job &J)    //Function 4
{
JobId = J.JobId+10;
JobType = J.JobType+1;
}
};
  1. Which member function out of Function 1, Function 2, Function 3 and Function 4 shown in the above definition of class Job is called automatically, when the scope of an object gets over? Is it known as constructor or destructor or overloaded function or copy constructor?
  2. Job P; // Line 1
    Job Q(P1 ; // Line 2
    Which member function out of Function 1, Function 2, Function 3 and Function 4 shown in the above definition of class Job will be called on execution of statement written as Line 2? What is this function specifically known as out of destructor or copy constructor or default constructor?

Аnswer:

  1. Function 1 is called, when the scope of an object getsover. It is called destructor.
  2. Function 4 is called, when Line 2 is executed. It is called copy constructor.

Question 37:
Rewrite the following C++ program code after removing the syntax error(s) (if any). Underline each correction. Delhi 2009

#inClude<iostream.h> 
#include<stdio.h> 
class Employee 
{
int EmpId=901; 
char EName[20]; 
public
Employee(){} 
void Joining()
{
cin>>EmpId; 
gets(EName);
}
void List()
{
cout<<EmpId<<":"<<EName<<endl;
}
};
void main()
{
Employee E;
Joining.E();
E.List();
}

Аnswer:

#include<iostream.h> 
#include<stdio.h>
class Employee 
{
int Empld:   //cannot initialise data member here
char EName[20]; 
public:    //: symbol is required after public 
Employee(){EmpId = 901;} 
void Joining()
{ 
cin>>EmpId; 
gets(EName);
}
void List() 
{
cout<<EmpId<<":"<<EName<<endl;
}
};
void main()
{
Employee E;
E.Joining(); //object name is used before members 
E.List();
}

Question 38:
Rewrite the following program after removing the syntactical error(s) (if any). Underline each correction. All India 2009

#include<iostream.h> 
#include<stdio.h> 
class MyStudent 
{
int StudentId=1001; 
char Name[20]; 
public
MyStudent(){}
void Register() 
{
cin>>StudentId;
gets(Name);
}
void Display()
{
cout<<StudentId<<":"<<Name<<endl;
}
};
void Main()
{
Mystudent MS;
Register.MSC();
MS.Display();
}

Аnswer:

#include<iostream.h>
#1nclude<stdio.h> 
class MyStudent
{
int Studentld; 
char Name[20]; 
public:
MyStudent(){Studentld=1001;}
void Register()
{
cin>>StudentId; 
gets(Name);
}
void Display!)
{
cout<<StudentId<<":"<<Name<<endl;
}
};
void main()
{
MyStudent MS;
MS.Reaister();
MS.Display();
}

4 Marks Questions

Question 39:
Define a class CABS in C++ with the following specification: Delhi 2014
Data members

  • CNo – to store Cab No
  • Type – to store a character ‘A’, ‘B’ or ‘C as City Type
  • PKM – to store per Kilometre charges
  • Dist – to store Distance travelled (in KM)

Member functions

  • A constructor function to initialise Type as ‘A’ and CNo as ‘1111’
  • A function Charges( ) to assign PKM as per the following table:
  • A function Register( ) to allow administrator to enter the values for CNo and Type. Also, this function should call Charges( )to adding PKM charges.
  • A function ShowCab( ) to allow user to enter the value of Dist and display CNo, Type, PKM, PKM Dist (as Amount) on screen.
TypePKM
‘A’25
‘B’20
‘C15

Аnswer:

class CABS 
{
int CNo; 
char Type; 
float PKM; 
float Dist; 
public;
CABS()
{
 Type = 'A';
 CNo = 1111;
}
void Charges!)
{
if(Type == 'A')
PKM = 25;
else if(Type == 'B')
PKM = 20;
else if(Type == 'C')
PKM = 15;
}
void Register()
{
cout<<"Enter value for CNo:"; 
cin>>CNo;
cout<<"Enter value for Type:"; 
cin>>Type;
Charges();
}
void ShowCab()
{
cout<<"Enter the value of Distance:”; cin>>Dist; 
cout<<"\nCab Number: "<<CNo; 
cout<<"\nType:"<<Type; 
cout<<"\nPer Kilometre Charges:"<<PKM; 
cout<<"\nAmount:"<<PKM*Dist;
}
};

Question 40:
Define a class Tourist in C++ with the following specification: All India 2014
Data members

  • CNo – to store Cab No
  • CType – to store a character A B or C as City Type
  • PerKM – to store per Kilometre charges
  • Distance – to store Distance travelled (in KM)

Member functions

  • A constructor function to initialise CType as A and CNo as ‘0000’
  • A function CityChargesO to assign PerKM as per the following table:
  • A function RegisterCab( ) to allow administrator to enter the values for CNo and CType. Also, this function should call CityChargesO to assign PerKM Charges.
  • A function Display( ) to allow user to enter the value of Distance and display CNo, CType, PerKM, PerKM*Distance (as Amount) on screen.
CTypePerKM
A20
B18
C15

Аnswer:

class Tourist 
{
int CNo; 
char CType; 
float PerKM; 
float Distance; 
public:
Tourist()
{
CType = 'A';
CNo = 0000; 
}
void CityCharges()
{
if(CType == 'A')
PerKM = 20;
else if(CType == 'B')
PerKM = 18;
else if(CType == 'C')
PerKM = 15;
}
void RegisterCab()
{
cout<<"Enter the Cab Number:"; 
cin>>CNo;
cout<<"Enter the Cab Type:"; 
Cin>>CType;
CityCharges();
}
void Display()
{
cout<<"Enter the Distance:";
cin>>Distance;
cout<<"Registered details are\n"; 
cout<<"Cab Number:"<<CNo<<endl; 
cout<<"Cab Type:"<<CType<<endl; 
cout<<"Charges per km :"<<PerKM<<endl;
cout<<"Amount:"<<PerKM*Distance<<endl;
}
};

Question 41:
Define a class CONTEST in C + + with the following description: All India 2014C
Private Data Members
Eventno – integer
Description – char (30)
Score – integer
qualified –  char
Public Member functions

  • A constructor to assign initial values Eventno as 11, Description as “School level”, Score as 100, qualified as ‘N’.
  • Input( )-To take the input for Eventno, description and score.
  • Award (int cutoffscore)- To assign qualified as ‘Y’, if score is more than the cutoffscore that is passed as argument to the function, else assign qualified as ‘N’.
  • Displaydata( )-to display all data members.

Аnswer:

class CONTEST
{
private:
int Eventno; 
char Description[30]; 
int Score; 
char qualified; 
public:
CONTEST()
{
Eventno=11;
Description-"School level";
Score-100;
qua1ified='N';
}
void input()
{
cout<<”Enter the event no, description and score"; 
cin>>Eventno>>Description; 
cin>>Score;
}
void Award(int cutoffscore) 
{
if(score>cutoffscore) 
qualified='Y'; 
else
qualified='N';
}
void Displaydata()
{
cout<<"Eventno:"<<Eventno; 
cout<<endl; 
cout<<"Description:";<<Description<<endl; 
cout<<"Score:"<<Score<<endl; 
cout<<"Qualified:"cout<<qualified<<endl;
}
};

Question 42:
Define a class Bus in C++ with the following specifications: HOTS; All India 2013
Data members

  • Busno – to store Bus Number
  • From – to store Place name of origin
  • To – to store Place name of destination
  • Type – to store Bus Type such as ‘O’ for ordinary
  • Distance – to store the Distance in Kilometre
  • Fare – to store the Bus Fare

Member functions

  • A constructor function to initialise Type as ‘O’ and Freight as 500.
  • A function CalcFare( ) to calculate Fare as per the following criteria:
  • A function Allocate! ) to allow user to enter values for Busno, From, To, Type and Distance. Also, this function should call CalcFare( ) to calculate Fare.
  • A function Show( ) to display the content of all the data members on screen.
TypePKM
‘O’15* Distance
‘E’20* Distance
‘L’24* Distance

Аnswer:

class Bus 
{
int Busno; 
char From[25]; 
char To[25]; 
char Type; 
float Distance; 
float Fare; 
public:
Bust()
{
Type = ' '; Fare = 500;
}
void CalcFare()
{
if(Type == ' ')
{
Fare = 15*Distance;
}
else if(Type == 'E')
{
Fare = 20*Distance;
} 
else if(Type == 'L')
{ 
Fare = 24*Distance;
}
}
void Allocated()
{
cout<<"Enter the values for Busno, From, To, Type and Distance";
cin>>Busno; 
cin>>From; 
cin>>To; 
cin>>Type; 
cin>>Distance;
Call C Fared();
}
void Show()
{
cout<<"\nBus No:"<<Busno; 
cout<<"\nFrom:"<<From; 
cout<<"\nTo:"<<To; 
cout<<"\nType:"<<Type; 
cout<<"\nDistance:"<<Distance;
cout<<"\nFare:"<<Fare;
}
};

Question 43:
Define a class Tourist in C++ with the following specification: Delhi 2013
Data members

  • Carno-to store Bus No
  • Origin-to store Place name
  • Destination-to store Place name
  • Type-to store Car Type such as ‘E’ for Economy
  • Distance-to store the Distance in Kilometere
  • Charge-to store the Car Fare

Member functions

  • A constructor function to initialise Type as ‘E’ and Freight as 250
  • A function CalcChargef) to calculate Fare as per the following criteria:
  • A function Enter( ) to allow user to enter values for Carno, Origin, Destination, Type and Distance. Also, this function should call CalcCharge( ) to calculate Fare.
  • A function Show( ) to display the content of all the data members on screen.
TypeCharge
‘E’16* Distance
‘A’22* Distance
‘L’30* Distance

Аnswer:

class Tourist 
{
int Carno;
char Origin[20];
char Destination[20];
char Type;
float Distance;
float Charge;
public:
Tourist()
{
Type='E';
Charge=250;
}
void CalcCharge()
{
if(Type=='E')
Charge=16*Distance; 
else if(Type=='A') 
Charge=22*Distance; 
else if(Type='L') 
Charge=30*Distance;
}
void Enter() 
{
cout<<"Enter Carno, Origin, Type, Destination and Distance"; 
cin>>Carno; 
gets(Origin); 
gets(Destination); 
cin>>Type>>Distance; 
CalcCharge();
}
void Show()
{
cout<<"Car No:"<<Carno; 
cout<<"0rigin;"<<0rigin; 
cout<<"Destination:"<<Destination; 
cout<<"Type:"<<Type; 
cout<<" Distance:"<<Distance; 
cout<<"Charge:"<<Charge;
}
};

Thursday

Important Questions for Class 12 Computer Science (C++) – Structured Query Language

 

Previous Years Examination Questions
2 Marks Questions

Question 1:
Explain the concept UNION between two tables, with the help of appropriate example. Delhi 2014
Answer:
The UNION operator is used to combine the result-set of two or more tables, without returning any duplicate rows,
e.g.
Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A1

6 Marks Questions

Question 2:
Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on the tables.All India 2017
Important Questions for Class 12 Computer Science (C++) - Structured Query Language-1
(i) To display all details from the table MEMBER in descending order of ISSUEDATE.
(ii) To display the DCODE and DTITLE of all Folk Type DVDs from the table DVD.
(iii) To display the DTYPE and number of DVDs in each DTYPE from the table DVD.
(iv) To display all NAME and ISSUEDATE of those members from the table MEMBER who have DVDs issued
(i.e., ISSUEDATE) in the year 2017.

(v) SELECT MIN (ISSUEDATE) FROM MEMBER;
(vi) SELECT DISTINCT DTYPE FROM DVD;
(vii) SELECT D.DCODE, NAME, DTITLE '
FROM DVD D, MEMBER M WHERE D.DC0DE=M.DCODE;
(viii) SELECT DTITLE FROM DVD
WHERE DTYPE NOT IN ("Folk”, "Classical”);

Answer:

(i) SELECT * FROM MEMBER ORDER BY ISSUEDATE DESC;
(ii) SELECT DCODE, DTITLE FROM DVD WHERE DTYPE = "Folk";
(iii) SELECT DTYPE, COUNT (*) FROM DVD GROUP BY DTYPE;
(iv) SELECT NAME, ISSUEDATE FROM MEMBER WHERE ISSUEDATE LIKE ‘2017%’;

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A2 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A3

Question 3:
Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii),
which are based on the tables. All India 2016 

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-2

NOTE

• KM is Kilometres travelled
• NOP is number of passengers travelled in vehicle.

(i) To display CNO, CNAME, TRAVELDATE from the table TRAVEL in descending order of CNO.
(ii) To display the CNAME of all the customers from the table TRAVEL who are traveling by vehicle with code V01 or V02.
(iii) To display the CNO and CNAME of those customers from the table TRAVEL who travelled between ‘2015-12-31’ and ‘2015-05-01’.
(iv) To display all the details from table TRAVEL for the customers, who have travel distance more than 120 KM in ascending order of NOP.

(v) SELECT COUNT(*), VCODE FROM TRAVEL 
GROUP BY VCODE HAVING C0UNT(*)>1;
(vi) SELECT DISTINCT VCODE FROM TRAVEL;
(vii) SELECT VCODE,CNAME,VEHICLETYPE 
FROM TRAVEL A, VEHICLE B
WHERE A.VC0DE=B.VCODE AND KM<90;
(viii) SELECT CNAME, KM*PERKM
FROM TRAVEL A, VEHICLE B
WHERE A.VC0DE=B.VCODE AND A.VC0DE='V05';

Answer:

(i) SELECT CNO, CNAME, TRAVELDATE FROM TRAVEL ORDER BY CNO DESC;
(ii) SELECT CNAME FROM TRAVEL WHERE VCODE = "VO1" OR VC0DE="VO2";
(iii) SELECT CNO, CNAME FROM TRAVEL WHERE TRAVELDATE BETWEEN '2015-12-31' AND ‘2015-05-01 ‘;
(iv) SELECT * FROM TRAVEL WHERE KM>120  ORDER BY NOP

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A4 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A5

Question 4:
Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on the tables. Delhi 2016 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-3
NOTE
• PERKM is Freight Charges per kilometre • VTYPE is Vehicle Type Important Questions for Class 12 Computer Science (C++) - Structured Query Language-4

NOTE
• NO is Traveller Number
• KM is Kilometre travelled
• NOP is number of travellers travelled in vehicle
• TDATE is Travel Date

(i) To display NO, NAME, TDATE from the table TRAVEL in descending order of NO.
(ii) To display the NAME of all the travellers from the table TRAVEL who are travelling by vehicle with code 101 or 102. ‘
(iii) To display the NO and NAME of those travellers from the table TRAVEL who travelled between ’2015-12-31’ and ‘2015-04-01’.
(iv) To display all the details from table TRAVEL for the travellers, who have travelled distance more than 100 KM in ascending order of NOP.

(v) SELECT COUNT(*), CODE FROM TRAVEL 
GROUP BY CODE HAVING C0UNT(*) >1;
(vi) SELECT DISTINCT CODE FROM TRAVEL;
(vii) SELECT CODE,NAME,VTYPE 
FROM TRAVEL A, VEHICLE B 
WHERE A.C0DE=B.C0DE AND KM<90;
(viii) SELECT NAME,KM*PERKM
FROM TRAVEL A, VEHICLE B
WHERE A.C0DE=B.C0DE AND A.C0DE='105' ;

Answer:

(i) SELECT NO, NAME, TDATE FROM TRAVEL ORDER BY NO DESC;
(ii) SELECT NAME FROM TRAVEL WHERE CODE = 101 OR CODE = 102;
(iii) SELECT NO. NAME FROM TRAVEL WHERE TDATE BETWEEN '2015-12-31' AND '2015-04-01' ;
(iv) SELECT * FROM TRAVEL WHERE KM > 100 ORDER BY NOP;

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A6

Question 5:
Consider the following DEPT and WORKER tables.
Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii): Delhi 2015 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-5

NOTE
DOJ refers to Date of Joining and DOB refers to Date of Birth of workers.
(i) To display WNO, NAME,, GENDER from the table WORKER in descending order of WNO.
(ii) To display the NAME of all the FEMALE workers from the table WORKER.
(iii) To display the WNO and NAME of those workers from the table WORKER, who are born between ‘1987-01-01’ and ‘1991-12-01’.
(iv) To count and display MALE workers who have joined after ‘1986-01-01’.

(v) SELECT COUNT(*), DCODE FROM WORKER 
GROUP BY DCODE HAVING C0UNT(*)>1;
(vi) SELECT DISTINCT DEPARTMENT FROM DEPT;
(vii) SELECT NAME, DEPARTMENT, CITY FROM WORKER W, DEPT D 
WHERE W.DC0DE=D.DCODE AND WNO<1003;
(viii) SELECT MAX (DOJ), MIN(DOB) FROM WORKER;

Answer:

(i) SELECT WNO, NAME, GENDER FROM WORKER ORDER BY WNO DESC; 
(ii) SELECT NAME FROM WORKER WHERE GENDER = "FEMALE"; 
(iii) SELECT WNO, NAME FROM WORKER WHERE DOB BETWEEN '1987-01-01' AND '1991-12-01'; 
(iv) SELECT COUNT(*) FROM WORKER WHERE GENDER = "MALE" AND DOJ > '1986-01-01';

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A7 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A8

Question 6: Consider the following DEPT and EMPLOYEE tables.
Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii). All India 2015 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-6 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-7

NOTE DOJ refers to Date of Joining and DOB refers to Date of Birth of employees.
(i) To display ENO, NAME, GENDER from the table EMPLOYEE in ascending order of ENO.
(ii) To display the NAME of all the MALE employees from the table EMPLOYEE.
(iii) To display the ENO and NAME of those employees from the table EMPLOYEE who are born between ‘1987-01-01’ and ‘1991-12-01’.
(iv) To count and display FEMALE employees who have joined after ‘1986-01-01’.

(v) SELECT COUNT (*), DC0DE FROM EMPLOYEE 
GROUP BY DCODE HAVING C0UNT(*)>1;
(vi) SELECT DISTINCT DEPARTMENT FROM DEPT;
(vii) SELECT NAME, DEPARTMENT FROM EMPLOYEE E.DEPT D 
WHERE E.DCODE = D.DCODE AND ENO<1003;
(viii) SELECT MAX(DOJ),MIN(DOB)FROM EMPLOYEE;

Answer:

(i) SELECT ENO, NAME, GENDER FROM EMPLOYEE ORDER BY ENO; 
(ii) SELECT NAME FROM EMPLOYEE WHERE GENDER = 'MALE'; 
(iii) SELECT ENO, NAME FROM EMPLOYEE WHERE DOB BETWEEN '1987-01-01' AND '1991-12-01';
(iv) SELECT COUNT!*) FROM EMPLOYEE WHERE GENDER = 'FEMALE' AND DOJ >'1986-01-01' ;

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A9

Question 7:
Consider the following tables SCHOOL and ADMIN  and answer (a) and (b) parts of this question : All India 2014 c Important Questions for Class 12 Computer Science (C++) - Structured Query Language-8

(a) Write SQL statements for the following:
(i) To display TEACHERNAME, PERIODS of all teachers whose periods are more than 25.
(ii) To display all the information from the table SCHOOL in descending order of experience.
(iii) To display DESIGNATION without duplicate entries from the table ADMIN.
(iv) To display TEACHERNAME, CODE and corresponding DESIGNATION from tables SCHOOL and ADMIN of Male teachers.
(b) Give the output of the following SQL queries :

(i) SELECT DESIGNATION, COUNT (*) FROM ADMIN GROUP BY DESIGNATION HAVING COUNT (*)<2;
(ii) SELECT MAX (EXPERIENCE) FROM SCHOOL;
(iii) SELECT TEACHERNAME FROM SCHOOL WHERE EXPERIENCE > 12 ORDER BY TEACHERNAME;
(iv) SELECT COUNT (*), GENDER FROM ADMIN GROUP BY GENDER;

Answer:

(a) (i) SELECT TEACHERNAME, PERIODS 
FROM SCHOOL WHERE PERI0DS>25; 
(ii) SELECT *FROM SCHOOL ORDER BY EXPERIENCE DESC; 
(iii) SELECT DISTINCT DESIGNATION FROM ADMIN; 
(iv) SELECT TEACHERNAME, CODE, DESIGNATION FROM SCHOOL S, 
ADMIN A WHERE S.CODE = A.CODE AND  GENDER = "MALE"; 

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A10

Question 8:
Answer the questions (a) and (b) on the basis of the following tables STORE and ITEMDelhi 2014

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-9

(a) Write the SQL queries
(i) to (iv): (i) To display IName and Price of all the Items in ascending order of their Price.
(ii) To display SNo and SName of all Store located in CP.
(iii) To display Minimum and Maximum Price of each IName from the table ITEM.
(iv) To display IName, Price of all items and their respective SName where they are available.
(b) Write the output of the following SQL commands (i) to (iv):

(i) SELECT DISTINCT IName FROM ITEM
WHERE Price >=5000;
(ii) SELECT Area, COUNT(*)
FROM STORE GROUP BY Area;
(iii) SELECT COUNT(DISTINCT Area) FROM STORE;
(iv) SELECT IName, Price * 0.05 DISCOUNT FROM ITEM 
WHERE SNo IN (S02, S03);

Answer:

(a)(i) SELECT IName, Price FROM ITEM ORDER BY Price; 
(ii) SELECT SNo, SName FROM STORE WHERE Area = 'CP’; 
(iii) SELECT IName, MIN(Price)"Minimum Price", MAX(Price)"Maximum Price" FROM ITEM GROUP BY IName; 
(iv) SELECT IName, Price, SName FROM ITEM I, STORE S WHERE I.SNo = S.SNo;

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A11 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A12

Question 9:
Answer the questions (a) and (b) on the basis of the following tables
SHOPPE and ACCESSORIESAll India 2014

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-10
(a) Write the SQL queries:
(i) To display Name and Price of all the accessories in ascending order of their Price.
(ii) To display Id and SName of all Shoppe located in Nehru Place.
(iii) To display Minimum and Maximum Price of each Name of accessories.
(iv) To display Name, Price of all accessories and their respective SName where they are available.
(b) Write the output of the following SQL commands:

(i) SELECT DISTINCT Name FROM ACCESSORIES WHERE Price>=5000;
(ii) SELECT Area, C0UNT(*) FROM SHOPPE GROUP BY Area;
(iii) SELECT C0UNT(DISTINCT Area) FROM SHOPPE:
(iv) SELECT Name, Price*0.05 DISCOUNT FROM ACCESSORIES WHERE SNo IN (S02.S03);

Answer:

(a)(i) SELECT Name, Price FROM ACCESSORIES ORDER BY Price ASC;
(ii) SELECT ID, SName FROM SHOPPE WHERE Area = ‘Nehru Place’;
(iii) SELECT MIN(Price)”Minimum Price”, MAX(Price)”Maximum Price”, Name FROM ACCESSORIES GROUP BY Name;
(iv) The query for this statement cannot be done because relation column, i.e. foreign key is not present. Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A13

Question 10:
Write SQL queries for (a) to (f) and write the outputs for the SQL queries
mentioned shown in (i) to (iv) parts on the basis of tables PRODUCTS and SUPPLIERSAll India 2013 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-11 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-12
(a) To display the details of all the products in ascending order of product names (i.e. PNAME).
(b) To display product name and price of all those products, whose price is in the range of 10000 and 15000 (both values inclusive).
(c) To display the number of products which are supplied by each supplier, i.e. the expected output should be

501 2
502 2
503 1

(d) To display the price, product name (i.e. PNAME) and quantity (i.e. QTY) of those products which have quantity more than 100.
(e) To display the names of those suppliers, who are either from DELHI or from CHENNAI.
(f) To display the name of the companies and the name of the products in descending order of company names.
(g) Obtain the outputs of the following SQL queries based on the data given in tables PRODUCTS and SUPPLIERS:

(i) SELECT DISTINCT SUPCODE FROM PRODUCTS:
(ii) SELECT MAX(PRICE), MIN(PRICE) FROM PRODUCTS;
(iii) SELECT PRICE * QTY AMOUNT FROM PRODUCTS WHERE PID = 104;
(iv) SELECT PNAME, SNAME FROM PRODUCTS P, SUPPLIERS S 
WHERE P.SUPCODE - S.SUPCODE AND QTY>100;

Answer:

(a) SELECT * FROM PRODUCTS ORDER BY PNAME; 
(b) SELECT PNAME, PRICE FROM PRODUCTS WHERE PRICE BETWEEN 10000 AND 15000; 
(c) SELECT SUPCODE, COUNT(*) FROM PRODUCTS GROUP BY SUPCODE; 
(d) SELECT PRICE, PNAME, QTY FROM PRODUCTS WHERE QTY > 100; 
(e) SELECT SNAME FROM SUPPLIERS WHERE CITY = 'DELHI' OR CITY = 'CHENNAI' ; 
(f) SELECT COMPANY, PNAME  FROM PRODUCTS ORDER BY COMPANY DESC;

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A14
Question 11:
Write SQL queries for (a) to (f) and write the outputs for the SQL queries
mentioned shown in (i) to (iv) parts on the basis of tables ITEMS and TRADERS. Delhi 2013 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-13
(a) To display the details of all the items in ascending order of item names (i.e. INAME).
(b) To display item name and price of all those items, whose price is in the range of 10000 and 22000 (both values inclusive). (c) To display the number of items, which are traded by each trader. The expected output of this query should be

T01 2
T02 2
T03 1

(d) To display the price, item name (i.e. INAME) and quantity (i.e. QTY) of those items which have quantity more than 150.
(e) To display the names of those traders, who are either from DELHI or from MUMBAI.
(f) To display the name of the companies and the name of the items in descending order of company names.
(g) Obtain the outputs of the following SQL queries based on the data given in tables ITEMS and TRADERS:

(i) SELECT MAX (PRICE), MIN( PRICE) FROM ITEMS;
(ii) SELECT PRICE * QTY AMOUNT FROM ITEMS WHERE CODE = 1004;
(iii) SELECT DISTINCT TCODE FROM ITEMS;
(iv) SELECT INAME, TNAME FROM ITEMS I, TRADERS T 
WHERE I.TCODE = T.TCODE AND QTY<100;

Answer:

(a) SELECT * FROM ITEMS ORDER BY INAME;
(b) SELECT INAME, PRICE FROM ITEMS WHERE PRICE BETWEEN 10000 AND 22000;
(c) SELECT TCODE, COUNT(*) FROM ITEMS GROUP BY TCODE;
(d) SELECT PRICE, INAME, QTY FROM ITEMS WHERE QTY >150;
(e) SELECT TNAME FROM TRADERS WHERE CITY
= ‘MUMBAI’ OR CITY= 'DELHI' ; (f) SELECT COMPANY, INAME

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A15 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A16

Question 12:
Write SQL queries for (a) to (f) and write the outputs for the SQL queries mentioned shown in (i) to (iv) parts on the basis of tables APPLICANTS and COURSESDelhi (C) 2013 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-14
(a) To display name, fee, gender, joinyear about the applicants, who have joined before 2010.
(b) To display the names of applicants, who are paying fee more than 30000.
(c) To display names of all applicants in ascending order of their joinyear.
(d) To display the year and the total number of applicants joined in each YEARfrom the table APPLICANTS.
(e) To display the CJD (i.e. Course ID) and the number of applicants registered in the course from the APPLICANTS table.
(f) To display the applicant’s name with their respective course’s name from the tables APPLICANTS and COURSES.
(g) Give the output of following SQL statements:

(i) SELECT NAME, JO I NY EAR FROM APPLICANTS WHERE GENDER-'F’ and C_ID=’A02';
(ii) SELECT MINIJOINYEAR) FROM APPLICANTS WHERE Gender='M';
(iii) SELECT AVG (FEE) FROM APPLICANTS WHERE C_ID='A01’ OR C_ID='A05’;
(iv) SELECT SUM(FEE), C_ID FROM APPLICATIONS GROUP BY C_ID HAVING C0UNT(*)=2;

Answer:

(a) SELECT NAME, FEE, GENDER, JOINYEAR FROM APPLICANTS WHERE J0INYEAR<2010; 
(b) SELECT NAME FROM APPLICANTS WHERE FEE >30000; 
(c) SELECT NAME FROM APPLICANTS ORDER BY JOINYEAR; 
(d) SELECT JOINYEAR, COUNT(*) FROM APPLICANTS GROUP BY JOINYEAR; 
(e) SELECT C_ID, COUNT(*) FROM APPLICANTS ORDER BY C_ID; 
(f) SELECT NAME, COURSE FROM APPLICANTS, COURSES WHERE APPLICANTS.C_ID=COURSES.C_ID;

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A17

Question 13:
Consider the following tables CABHUB and CUSTOMER and answer (a) and (b) parts of this question: Delhi 2012

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-15
(a) Write SQL commands for the following statements:
(i) To display the names of all the white colored vehicles.
(ii) To display name of vehicle, make and capacity of vehicles in ascending order of their  setting Capacity.
(iii) To display the highest charges at which a vehicle can be hired from CABHUB.
(iv) To display the customer names and the corresponding name of the vehicle hired by them.
(b) Give the output of the following SQL queries :

(i) SELECT COUNT (DISTINCT Make) FROM CABHUB;
(ii) SELECT MAX(Charges), MIN (Charges) FROM CABHUB;
(iii) SELECT COUNT(*), Make FROM CABHUB;
(iv) SELECT VehicleName FROM CABHUB WHERE Capacity = 4;

Answer:

(a) (i) SELECT VehicleName 
FROM CABHUB 
WHERE Color = 'WHITE';
(ii) SELECT VehicleName, Make, 
Capacity FROM CABHUB 
ORDER BY Capacity;
(iii) SELECT MAX(Charges)
FROM CABHUB;
(iv) SELECT CName, VehicleName 
FROM CABHUB C1, CUSTOMER 
C2 WHERE C1.Vcode = C2.Vcode;

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A18
(iii) This query will execute but COUNT (*) will give result one row and Make will give more than one row so both are not compatible together. But on removing Make from select clause it will give following result.
Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A19

Question 14:
Consider the following tables CUSTOMER and ONLINESHOP.
Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii). Delhi (C) 2012
Important Questions for Class 12 Computer Science (C++) - Structured Query Language-16
(i) To display cname, area of fill female customers from CUSTOMER table.
(ii) To display the details of all the customers in ascending order of CNAME within SID.
(iii) To display the total number of customers for each area from CUSTOMER table.
(iv) To display cname and corresponding shop from CUSTOMER table and ONLINESHOP table.

(v) SELECT COUNT(DATE), GENDER FROM CUSTOMER GROUP BY GENDER;
(vi) SELECT C0UNT(*) FROM ONLINESHOP;
(vii) SELECT CNAME FROM CUSTOMER WHERE CNAME LIKE "L%";
(viii) SELECT DISTINCT AREA FROM CUSTOMER;

Answer:

(i) SELECT CNAME, AREA FROM CUSTOMER WHERE GENDER = 'FEMALE';
(ii) SELECT * FROM CUSTOMER ORDER BY SID, CNAME;
(iii) SELECT COUNT(*) FROM CUSTOMER GROUP BY AREA;
(iv) SELECT CNAME, SHOP FROM CUSTOMER C, ONLINESHOP O WHERE C.SID = O.SID;

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A20

Question 15:
Consider the following tables CARDEN and CUSTOMER and answer (a) and (b) parts of this question: All India 2012 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-17
(a) Write SQL commands for the following statements:
(i) To display the name of all the SILVER colored cars.
(ii) To display name of car, make and capacity of cars in descending order of their sitting capacity.
(iii) To display the highest Charges at which a vehicle can be hired from CARDEN.
(iv) To display the customer names and the corresponding name of the cars hired by them,
(b) Give the output of the following SQL queries:

(i) SELECT COUNT (DISTINCT Make) FROM CARDEN:
(ii) SELECT MAX(Charges), MIN (Charges) FROM CARDEN;
(iii) SELECT C0UNT(*), Make FROM CARDEN;
(iv) SELECT CarName FROM CARDEN WHERE Capacity = 4;

Answer:

(a) (i) SELECT CarName FROM CARDEN WHERE Color = ’SILVER’;
(ii) SELECT CarName, Make, Capacity FROM CARDEN ORDER BY Capacity DESC;
(iii) SELECT MAX(Charges) FROM CARDEN;
(iv) SELECT Cname, CarName FROM CARDEN C1, CUSTOMER C2 WHERE C1.Ccode = C2.Ccode:

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A21
Question 16:
Consider the following tables EMPLOYEE and SALGRADE and answer (a) and (b) parts of this question: All India 2011 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-18
(a) Write SQL commands for the following statements:
(i) To display the details of all the EMPLOYEE in descending order of DOJ.
(ii) To display name and desig of those EMPLOYEE, whose sgrade is either S02 or S03.
(iii) To display the content of all the EMPLOYEE table, whose DOJ is in between ‘09-FEB-2006’ and ‘08-AUG-2009’.
(iv) To add a new row in the EMPLOYEE table with the following data: 109, ‘Harish Roy’, ‘HEAD-IT, ‘S02’, ‘09-SEP-2007’, ‘21-APR-1983’.
(b) Give the output of the following SQL queries:

(i) SELECT C0UNT(SGRADE), SGRADE FROM EMPLOYEE GROUP BY SGRADE;
(ii) SELECT MIN (DOB), MAX (DOJ) FROM EMPLOYEE;
(iii) SELECT NAME, SALARY FROM EMPLOYEE E, SALGRADE S 
WHERE E.SGRADE = S.SGRADE AND E.EC0DE<103;
(iv) SELECT SGRADE, SALARY+HRA FROM SALGRADE WHERE SGRADE = ‘S02';

Answer:

(a) (i) SELECT * FROM EMPLOYEE ORDER BY DOJ DESC;
(ii) SELECT. NAME, DESIG FROM EMPLOYEE WHERE SGRADE='SO2' OR SGRADE ='SO3’;
(iii) SELECT * FROM EMPLOYEE WHERE DOJ BETWEEN '09-FEB-2006’ AND '08-AUG-2009';
(iv) INSERT INTO EMPLOYEE VALUES 
(109, 'HarishRoy', 'HEAD-IT', ’ SO2', '09-SEP-2007', '21-APR-1983');

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A22 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A23

Question 17:
Consider the following tables WORKER and PAYLEVEL and answer (a) and (b) parts of this question: Delhi 2011 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-19 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-20
(a) Write SQL commands for the following statements:
(i) To display the details of all WORKER in descending order of DOB.
(ii) To display name and desig of those WORKER, whose plevel is either P001 or P002.
(iii) To display the content of all the WORKER table, whose DOB is in between ‘19-JAN-1984’ and T8-JAN-1987’.
(iv) To add a new row with the following: 19, ‘Daya Kishore’, ‘Operator’, ‘P003’, ‘19-JUN-2008’, ‘11-JUL-1984’.
(b) Give the output of the following SQL queries:

(i) SELECT COUNTCPLEVEL(). PLEVEL FROM WORKER GROUP BY PLEVEL:
(ii) SELECT MAX (DOB), MIN(DOJ) FROM WORKER;
(iii) SELECT NAME, PAY FROM WORKER W, PAYLEVEL P 
WHERE W.PLEVEL= P.PLEVEL AND W.EC0DE<13;
(iv) SELECT PLEVEL, PAY+ALLOWANCE FROM PAYLEVEL WHERE PLEVEL = ‘POO3’:

Answer:

(a) (i) SELECT *
FROM WORKER
ORDER BY DOB DESC;
(ii) SELECT NAME, DESIG 
FROM WORKER 
WHERE PLEVEL = 'Poo1'
OR PLEVEL = *Poo2';
(iii) SELECT *
FROM WORKER
WHERE DOB BETWEEN ’ 19-JAN-1984' 
AND '18-JAN-1987';
(iv) INSERT INTO WORKER VALUES (19, FR0M ST0CK GR0UP BY Dcode:
'Daya Ki shore', 'Operator', 'P003' 
(b) (i) COUNT (DISTINCT Dcode) '19:JUN-2008', '11-JUL-1984');

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A24

Question 18:
Consider the following tables STORE and SUPPLIERS and answer  (a) and (b) parts of this question: Delhi 2010
Important Questions for Class 12 Computer Science (C++) - Structured Query Language-21
(a) Write SQL commands for the following statements:
(i) To display details of sill the items in the STORE table in ascending order of LastBuy.
(ii) To display ItemNo and Item of those items from STORE table whose Rate is more than Rs. 15.
(iii) To display the details of those items whose supplier code (Scode) is 22 or quantity in store (Qty) is more than 110 from the table STORE.
(iv) To display minimum Rate of items for each supplier individually as per Scode from the table STORE.
(b) Give the output of the following SQL queries:

(i) SELECT COUNT(DISTINCT Scode) FROM STORE;
(ii) SELECT Rate * Qty FROM STORE WHERE ItemNo = 2004;
(iii) SELECT Item, Sname FROM STORE S, SUPPLIERS P 
WHERE S.Scode = P.Scode AND ItemNo = 2006;
(iv) SELECT MAX(LastBuy) FROM STORE;

Answer:

(a) (i) SELECT *
FROM STORE ORDER BY LastBuy;
(ii) SELECT ItemNo, Item 
FROM STORE WHERE Rate>15;
(iii) SELECT * FROM STORE
WHERE Scode = 22 OR Qty>110;
(iv) SELECT MIN (Rate) FROM STORE GROUP BY Scode;

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A25
Question 19:
Consider the following tables STOCK and DEALERS and  answer (a) and (b) parts of this question: All India 2010

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-22
(a) Write SQL commands for the following statements:
(i) To display details of all the items in the STOCK table in ascending order of StockDate.
(ii) To display ItemNo and ItemName of those items from STOCK table whose UnitPrice is more than Rs. 10.
(iii) To display the details of those items whose dealer code (Dcode) is 102 or quantity in stock (Qty) is more than 100 from the table STOCK.
(iv) To display maximum UnitPrice of items for each dealer individually as per Dcode from the table STOCK.
(b) Give the output of the following SQL queries:

(i) SELECT COUNT(DISTINCT Dcode) FROM STOCK;
(ii) SELECT Qty * UnitPrice FROM STOCK WHERE ItemNo = 5006;
(iii) SELECT ItemName. Dname FROM STOCK S, DEALERS D 
WHERE S.Dcode = D.Dcode AND ItemNo = 5004;
(iv) SELECT MIN(StockDate) FROM STOCK;

Answer:

(a)(i) SELECT *
FROM STOCK ORDER BY StockDate; 
(ii) SELECT ItemNo, ItemName
FROM STOCK WHERE UnitPrice>10; 
(iii) SELECT * FROM STOCK
Where Dcode = 102 OR Qty>100
(iv) SELECT MAX (UNITEPRICE) FROM ST0CK GROUP BY Dcode

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A26

Question 20:
Consider the following tables GARMENT and FABRIC.
Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii). Delhi 2009
Important Questions for Class 12 Computer Science (C++) - Structured Query Language-23 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-24
(i) To display GCODE and DESCRIPTION of each GARMENT in descending order of GCODE.
(ii) To display the details of all the GARMENT, which have READYDATE in between 08-DEC-07 and 16-JUN-08 (inclusive of both the dates).
(iii) To display the average PRICE of all the GARMENT, which are made up of fabric with FCODE as F03.
(iv) To display fabric wise highest and lowest price of GARMENT from GARMENT table. (Display FCODE of each GARMENT alongwith highest and lowest Price).

(v) SELECT SUM(PRICE) FROM GARMENT WHERE FCODE = 'FO1'; . .
(vi) SELECT DESCRIPTION, TYPE FROM GARMENT, FABRIC
WHERE GARMENT.FCODE = FABRIC.FCODE AND GARMENT.PRICE >=1260;
(vii) SELECT MAX(FCODE) FROM FABRIC;
(viii) SELECT COUNT(DISTINCT PRICE) FROM GARMENT;

Answer:

(i) SELECT GCODE, DESCRIPTION FROM GARMENT ORDER BY GCODE DESC; 
(ii) SELECT * FROM GARMENT WHERE READYDATE BETWEEN '08-DEC-07' AND '16-JUN-08' ; ' 
(iii) SELECT AVG(PRICE) FROM GARMENT WHERE FCODE = ’F03’; 
(iv) SELECT FCODE, MAX(PRICE), MIN(PRICE) FROM GARMENT GROUP BY FCODE;

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A27 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A28

Question 21:
Consider the following tables DRESS and MATERIAL.
Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii). All India 2009
Important Questions for Class 12 Computer Science (C++) - Structured Query Language-25
(i) To display DCODE and DESCRIPTION of each dress in ascending order of DCODE.
(ii) To display the details of all the dresses which have LAUNCHDATE in between 05-DEC-07 and 20- JUN-08 (inclusive of both the dates).
(iii) To display the average PRICE of all the dresses which are made up of material with MCODE as M003.
(iv) To display materialwise highest and lowest price of dresses from DRESS table, (display MCODE of each dress alongwith highest and lowest price).

(v) SELECT SUM(PRICE) FROM DRESS WHERE MCODE = *M001';
(vi) SELECT DESCRIPTION, TYPE FROM DRESS, MATERIAL
WHERE DRESS.DCODE = MATERIAL.MCODE AND DRESS.PRICE >= 1250;
(vii) SELECT MAX (MCODE) FROM MATERIAL;
(viii) SELECT COUNT(DISTINCT PRICE) FROM DRESS;

Answer:

(i) SELECT DCODE, DESCRIPTION FROM DRESS ORDER BY DCODE;
(ii) SELECT * FROM DRESS WHERE LAUNCHDATE BETWEEN '05 - DEC - 07' AND ’20-JUN-08’;
(iii) SELECT AVG(PRICE) FROM DRESS WHERE MCODE ='M003’;
(iv) SELECT MCODE. MAX(PRICE), MIN(PRICE) FROM DRESS GROUP BY MCODE;

Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A29 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-A30

Question 22: Consider the following tables STUDENT and STREAM.
Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii). Delhi (C) 2009 Important Questions for Class 12 Computer Science (C++) - Structured Query Language-26
(i) To display the name of streams in alphabetical order from table STREAM.
(ii) To display the number of students whose POINTS are more than 5.
(iii) To update GRADE to ‘A’ for all those students who are getting more than 8 as POINTS.
(iv) ARTS+MATHS stream is no more available. Make necessary change in table fjTREAM.

(v) SELECT SUM(POINTS) FROM STUDENT WHERE AGE >14; .
(vi) SELECT STRCDE, MAX(POINTS) FROM STUDENT
GROUP BY STRCDE HAVING SCODE BETWEEN 105 AND 130;
(vii) SELECT AVG(AGE) FROM STUDENT WHERE SCODE IN (102,105, 110, 120);
(viii) SELECT COUNT(STRNAME) FROM STREAM WHERE STRNAME LIKE "SCI%";

Answer:

(i) SELECT STRNAME
FROM STEAM
ORDER BY STRNAME;
(ii) SELECT COUNT(*)
FROM STUDENT
WHERE P0INTS>5;
(iii) UPDATE STUDENT
SET GRADE = 'A'
WHERE P0INTS>8;
(iv) DELETE FROM STREAM WHERE STRNAME = "ARTS + MATHS";