CBSE PREVIOUS YEAR QUESTION BANK
QNO 2 (A)
01.
(a) Differentiate between members, which are present within the private visibilitymode with those which are present within the public visibility modes.2011
02.
(a) What is copy constructor? Give an example in C++ to illustrate copyconstructor.
2009
03.
(a) What is a copy constructor? What do you understand by constructoroverloading? 1998
04.
(a) What do you understand by visibility modes in class derivations? What are these modes? 1999
05.
(a) Why is a destructor function required in classes? Illustrate with the help of an example. 2000
06.
(a) Illustrate the use of "self referential structures” with the help of an example
2001
07.
(a) What do you understand about a base class and a derived class? If a base class and a derived class each include a member function with the same nameand arguments, which member function will be called by the object of the derivedclass if the scope operator is not used ? 2002
08.
(a) Given the following C++ code, answer the questions (i) & (ii). 2
class TestMeOut
{
public:
~TestMeOut() //Function 1
{
cout<“Leaving the examination hall”<endl;
}
TestMeOut() //Function 2
{
cout<“Appearing for examination”<endl;
}
void MyWork() //Function 3
{
cout<“Attempting Questions//<endl; } };
(i) In Object Oriented Programming, what is Function 1 referred as and when doesit get invoked / called ?
(ii) In Object Oriented Programming, what is Function 2 referred as and when doesit get invoked / called ? 2004
09.
(a) Define the term Data Hiding in the context of Object OrientedProgramming. Give asuitable example using a C++ code to illustrate the same. 2005
10.
(a) Differentiate between Constructor and Destructor function in context of Classesand Objects using C++ 2
2007
11.
(a) What do you understand by Polymorphism ? Also, give an example in C++ toillustrate the same. 2 2010
12.
(a) What do you understand by Polymorphism? Give a suitable example of the same. (s.p)
13.
(a) What do you understand by Data Encapsulation and Data Hiding?
2(SP)
14.
(a) What do you understand by Data Encapsulation and Data Hiding? Also, givea suitable C++ code to illustrate both. 2(SP)
QNO 2(B)
01.
(b) Answer the question (i) and (ii) after going through the following class :
class WORK
{
int WorkId; char WorkType;
public:
WORK( ) //Function 1
{
cout<“Un-Allocated”<endl;
}
void Status( ) // Function 2
{
cout<WorkId<“:”<WorkType<endl;
}
WORK( ) // Function 3
{
WorkId=10; WorkType=‟T‟;
}
WORK (WORK &W) // Function 4
{
WorkId = W.WorkId+12; WorkType=W.WorkType+1;
} };
(i) Which member function out of Function 1, Function 2, Function 3 and Function 4shown in the above definition of class Work is called automatically, when thescope of an object gets over? Is it known as Constructor OR Destructor OROverloaded Function OR Copy Constructor?
ii) WORK W; //Statement 1
WORK Y(W); // Statement 2
Which member function out of Function 1, Function 2, Function 3 and Function 4shown in the above definition of class Work will be called on execution ofstatement written as Statement 2? What is this function specifically known as outof Destructor or Copy Constructor or Default Constructor? 2009
02.
(b) Write the output of the following C++ code. Also, write the name of feature ofObject Oriented Programming used in the following program jointlyillustrated bythe functions [I] to [IV]. 2 2011
#include<iostream.h>
void Print ( ) // Function [I]
{
for (int K=1;K<=60; K++) cout< “-”;
cout<endl;
}
void Print (int N) //Function[II]
{
for (int K=1;K<=N; L++) cout<“*”;
cout<endl;
}
void Print(int A, int B) //Function[III]
{
for(int K=1;K<=B;K++) cout<A*k;
cout<endl;
}
void Print(char T, int N) // Function[IV]
{
for (int K=1;k<=N;K++) cout<T;
cout<endl;
}
void main( )
{
int U=9,V=4,W=3;
char C =‟@‟;
Print(C,V);
Print(U,W);
}
03.
(b) Define a class student with the following specification
Private members of class student
- admno integer
- sname 20 character
- eng. math, science float
- total float
- ctotal() a function to calculate eng + math + science with
- float return type.
Public member function of class student
- Takedata() Function to accept values for admno, sname, eng, math,
science and invoke ctotal() to calculate total.
- Showdata() Function to display all the data members on the screen 1998
04.
(b) Define a class Teacher with the following specifications :
Private members :
- name 20 characters
- subject 10 characters
- basic, DA, HRA float
- salary float
- calculate A function that computes the salary and returns it. Salary is sum of basic, DA and HRA.
Public members :
- Readdata() A function that accepts data values and invokes the Calculate function.
- Displaydata() A function that prints the data on the screen 1999
05.
b) Define a class WORKER with the following specification :
Private members of class WORKER:
- wno integer
- wname 25 characters
- hrwrk, wgrate float (hours worked and wage rate per hour)
- totwage float (hrwrk * wgrate)
- calcwg () A function to find hrwrk * wgrate with float return type.
Public members of class WORKER
- in_data () a function to accept values for wno, wname, hrwrk, wgrate and invoke calcwg() function to calculate totpay.
- out_data () a function to display all the data members on the screen. You should give definitions of functions. 2000
06.
b) Define a class BOOK with the following specifications :
Private members of the class BOOK are
- BOOK NO integer type
- BOOKTITLE 20 characters
- PRICE float (price per copy)
- TOTAL_COST() A function to calculate the total cost for N number of copies where N is passed to the function as argument.
Public members of the class BOOK are
- INPUT() function to read BOOK_NO. BOOK TITLE, PRICE
- PURCHASE() function to ask the user to input the number of copies to be
- purchased. It invokes TOTAL COST 0 and prints the total cost to be paid by the user. Note :
Note : You are also required to give detailed function definitions.
2001
07.
(b) Considering the following specifications :
Structure name Data Type Size
- Name first array of character 40
- mid array of character 40
- last array of character 60
- Phone area array of character 4
- exch array of character 4
- numb array of character 6
Class name Data Type
- P_rec name Name
- Phone Phone
- With member functions constructor and display_rec.
- Declare a class of P_rec.
- Define the constructor (outside the class P_rec) that gathers information from the user for the above two structures Name and Phone.
- Define the display_rec (outside the class P_rec) that shows the current values.
2002
08.
(b) Declare a class myfolder with the following specifications : 4
Private members of the class
- Filenames — an array of strings of size [10] [25]
(to represent all the names of files inside myfolder)
- Availspace — long
(to represent total number of bytes available in myfolder)
- Usedspace — long
(to represent total number of bytes used in myfolder)
Public members of the class
- Newfileentry( ) - A function to accept values of Filenames, Availspace andUsedspace from user
- Retavailspace( ) - a function that returns the value of total Kilobytes
available(1 Kilobyte = 1024 bytes)
- Showfiles( ) - a function that displays the names of all the files in
Myfolder 2004
09.
(b) Answer the questions (i) and (ii) after going through the following class: 2
class Test
{
char Paper[20];
int Marks;
public:
Test () // Function 1
{
strcpy (Paper, “Computer”)
Marks = 0;
}
Test (char P [] ) // Function 2
{
strcpy(Paper,P);
Marks = 0;
}
Test (int M) // Function 3
{
strcpy(Paper,”Computer”);
Marks = M;
}
Test (char P[], int M) // Function 4
{
strcpy (Paper, P);
Marks = M;
}
};
(i) Which feature of Object Oriented Programming is demonstrated usingFunction 1, Function 2, Function 3 and Function 4 in the above class Test?
(ii) Write statements in C++ that would execute Function 2 and Function 4 ofclass Test. 2005
10.
(b) Answer the questions (i) and (ii) after going through the following class 2
class Maths
{
char Chapter [20];
int Marks;
public:
Maths ( ) //Member Function 1
{
strcpy (Chapter, “Geometry”);
Marks = 10;
cout<“Chapter Initialised”;
{
~Math ( ) //Member Function 2
}
cout<”Chapter Over”;
}
};
(i) Name the specific features of class shown by Member Function 1 and
Member Function 2 in the above example.
(ii) How would Member Function 1 and Member Function 2 get executed?
2007
11.
(b) Answer the questions (i) and (ii) after going through the following class :
class TEST
{
int Regno, Max, Min, Score ;
public :
TEST( ) //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;
}
} ;
(i) As per Object Oriented Programming, which concept is illustrated by Function 1and Function 2 together ?
(ii) What is Function 3 specifically referred as ? When do you think, Function 3 willbe invoked/called? 2010
12.
(b) Define a classFlight in C++ with following description:
Private Members
- A data member Flight number of type integer
- A data member Destination of type string
- A data member Distance of type float
- A data member Fuel of type float
- A member function CALFUEL() to calculate the value of Fuel as per the following criteria
Distance Fuel <=1000 500 more than 1000 and <=2000 1100 more than 2000 2200 Public Members
Public Members
- A function FEEDINFO() to allow user to enter values for Flight Number, Destination, Distance & call function CALFUEL() to calculate the quantity of Fuel
- A function SHOWINFO() to allow user to view the content of all the data members
(S.P)
13.
(b) Answer the questions (i) and (ii) after going through the following class:
class Seminar
{
int Time;
public:
Seminar() //Function 1
{
Time=30;cout<”Seminar starts now”<end1;
}
void Lecture() //Function 2
{
cout<”Lectures in the seminar on”<end1;
}
Seminar(int Duration) //Function 3
{
Time=Duration;cout<”Seminar starts now”<end1;
}
~Seminar() //Function 4
{
cout<”Vote of thanks”<end1;
}
};
i) In Object Oriented Programming, what is Function 4 referred as and when doesit get invoked/called?
ii) In Object Oriented Programming, which concept is illustrated by Function 1 andFunction 3 together? Write an example illustrating the calls for these functions. (S.P)
14.
(b) Answer the questions (i) and (ii) after going through the following program:
class Match
{ int Time;
public: Match() //Function 1
{ Time=0;
cout<”Match commences”<end1;
}
void Details() //Function 2
{
cout<”Inter Section Basketball Match”<end1;
}
Match(int Duration) //Function 3
{
Time=Duration;
cout<”Another Match begins now”<end1;
}
Match(Match &M) //Function 4
{
Time=M.Duration;
cout<”Like Previous Match “ <endl;
}
};
i) Which category of constructor - Function 4 belongs to and what is the purpose of using it?
ii) Write statements that would call the member Functions 1 and 3. S.P.
QNO 2 (C)
01.
(c) Consider the following declaration and answer the questions given below :
class PPP
{
int H:
protected :
int S;
public :
void INPUT (int);
void OUT();
};
class QQQ : private PPP
{
int T;
protected :
int U;
public :
void INDATA(int, int);
void OUTDATA();
};
class RRR : public QQQ
{
int M;
public :
void DISP( void );
};
(i)Name the base class and derived class of the class QQQ.
(ii) Name the data member(s) that can be accessed from function DISP().
(iii) Name the member function(s), which can be accessed from the objects of class RRR. (iv)Is the member function OUT() accessible by the object of the class QQQ?
02.
(c) Consider the following declarations and answer the question given below :
class vehicle
{
private:
int wheels;
protected :
int passenger:
public :
void inputdata (int, int);
void outputdata();
};
class heavyvehicle : protected vehicle
{
int diesel_petrol;
protected :
int load;
public:
void readdata(int, int);
void writedata();
};
class bus : private heavyvehicle
{
char make[20];
public:
void fetchdata(char);
void displaydata();
};
(i) Name the base class and derived class of the class heavy_vehicle.
(ii) Name the data member(s) that can be accessed from function displaydataO.
(iii) Name the data member's that can be accessed by an object of bus class.
(iv) Is the member fraction outputdata() accessible to the objects of heavy_vehicle
class. Delhi Board 1999
03.
c) Consider the following and answer the questions given below :
class School
{
int A;
protected :
int B,C;
public:
void INPUT (int);
void OUTPUT();
};
class Dept
protected : School
{
int X Y;
protected :
void IN (int, int);
public:
void OUT();
};
class Teacher : public Dept
{
int P;
void DISPLAY (void);
public :
void ENTERO;
};
i. Name the base class and derived class of the class Dept.
ii. Name the data member (s) that can be accessed from function OUT ().
iii. Name the private member function(s) of class Teacher.
iv. Is the member function OUT() accessible by the objects of Dept?
Delhi Board 2000
04.
c) Give the output of the following program :
# include <iostream.h>
# include <string.h>
class per
{
char name [20];
float age;
public:
per (char*s, float a)
{
Strcpy(name, s);
age = a;
}
per &GR (per &x)
{
if (x.age >= age)
return x;
else
return *this;
}
void display()
{
cout <”Name :” < name < '\n';
cout< “Age :” < age < '\n';
}
};
void main ()
{
per P1 ("RAMU", 27.5), P2 ("RAJU", 53), P3("KALU", 40);
per P ('\0', 0);
P = Pl.GR (P3);
P.display();
P = P2.GR (P3);
P.display();
} Delhi Board 2001
05.
c) consider the following class declaration and answer the question below :
class SmallObj
{
private :
int some;
more;
void err_1() {cout<”error”;}
public:
void Xdata(int d) {some=d; more=d++;}
void Ydata() {cout<some<” “<more;}
};
(i) Write the name that specifies the above class.
(ii) Write the data of the class with their access scope.
(iii) Write all member function of the class along with the access scope.
(iv) Indicate the member function of the SmallObj that sets data.
Delhi Board 2002
06.
(c) Given the following class definitions answer the questions that follow :
class livingbeing
{
char specification[20];
int averageage;
public:
void read();
void show();
};
class ape : private livingbeing
{
int no_of_organs, no_of_bones;
protected:
int iq_level;
public:
void readape();
void showape();
};
class human : public ape
{
char race[20];
char habitation[30];
public:
void readhuman();
void showhuman();
};
(i) Name the members, which can be accessed from the member functions of classhuman.
(ii) Name the members, which can be accessed by an object of class ape.
(iii) Name the members, which can be accessed by an object of class human.
(iv) What will be the size of an object (in bytes) of class human ? 2004
07.
(c) Define a class TravelPlan in C++ with the following descriptions :
Private Members:
- PlanCode of type long
- Place of type character array (string)
- Number_of_travellers of type integer
- Number_of_buses of type integer
Public Members:
- A constructor to assign initial values of Plan Code as 1001, Place as “Agra”,
- Number_of_travellers as 5, Number_of_buses as 1
- A function NewPlan( ) which allows user to enter PlanCode, Place and
- Number_of_travellers. Also, assign the value of Number_of_buses as per thefollowing conditions :
- Number_of_travellers Number_of_busesLess than 20 1
- Equal to or more than 20 and less than 40 2
- Equal to 40 or more than 40 3
- A function ShowPlan( ) to display the content of all the data members on screen. 2005
08.
(c) Define a class Tour in C++ with the description given below :
Private Members :
TCode of type string
NoofAdults of type integer
NoofKids of type integer
Kilometres of type integer
TotalFare of type float
Public Members :
• A constructor to assign initial values as follows :
TCode with the word “NULL”
NoofAdults as 0
NoofKids as 0
Kilometres as 0
TotalFare as 0
• A function AssignFare ( ) which calculates and assigns the value of
the data member TotalFare as follows
For each Adult
Fare(Rs) For Kilometres
500 >=1000
300 <1000 >=500
200 <500
For each Kid the above Fare will be 50% of the Fare mentioned inthe above table
For example :
If Kilometres is 850, NoofAdults = 2 and NoofKids = 3Then TotalFare should be calculated as
NumofAdults * 300 + NoofKids * 150
i.e. 2*300 + 3*150=1050
• A function EnterTour( ) to input the values of the data membersTCode, NoofAdults, NoofKids and Kilometres; and invoke theAssign Fare( ) function.
• A function ShowTour( ) which displays the content of all the data
members for a Tour. 2007
09.
c) Define a class ITEM in C++ with the following description :
Private Members
- Code of type integer (Item Code)
- Iname of type string (Item Name)
- Price of type float (Price of each item)
- Qty of type integer (Quantity of item in stock)
- Offer of type float (Offer percentage on the item)
- A member function GetOffer( ) to calculate Offer percentage as per the
following rule :
If Qty <= 50 Offer is 0
If 50 < Qty <= 100 Offer is 5
If Qty >100 Offer is 10
Public Members
- A function GetStock( ) to allow user to enter values for Code, Iname,
- Price, Qty and call function GetOffer( ) to calculate the offer.
- A function ShowItem( ) to allow user to view the content of all the data
members. 2010
10.
(c) Define a class RESORT in C++ with following description:
Private Members:
- Rno // Data member to store Room No
- Name // Data member to store customer name
- Charges // Data member to store per day charges
- Days // Data member to store number of days of stay
- COMPUTE( ) // A function to calculate and return Amount as
- Days* Charges and if the value of Days * Charges
- is more than 11000 then as 1.02 * Days * Charges
Public Members :
- Getinfo( ) // A function to enter the content Rno, Name, Charges and Days
- Dispinfo( ) // A function to display Rno, Name, Charges, Days and Amount
- (Amount to be displayed by calling function COMPUTE( ) ) 2009
11.
(c) Define a class candidate in C++ with following Description:4
Private Members
- A data member RNo (Registration Number) of type long
- A data member Name of type string
- A data member Score of type float
- A data member Remark of type string
- A member function AssignRem( ) to assign Remarks as per the Score
obtained by a candidate. Score range and the respective Remarks are
shown as follows:
Score Remarks
>=50 Selected
less than 50 Not selected
Public members
- A function ENTER( ) to allow user to enter values for RNo, Name, Score& call function AssignRem() to assign the remarks.
- A function DISPLAY( ) to allow user to view the content of all the data
members. 2011
12.
(c) Answer the questions (i) to (iv) based on the following:
class CUSTOMER
{
int Cust_no;
char Cust_Name[20];
protected: void Register();
public: CUSTOMER();
void Status();
};
class SALESMAN
{
int Salesman_no;
char Salesman_Name[20];
protected: float Salary;
public: SALESMAN();
void Enter();
void Show();
};
class SHOP
private : CUSTOMER ;
public : SALESMAN ;
{
char Voucher_No[10];
char Sales_Date[8];
public: SHOP();
void Sales_Entry();
void Sales_Detail();
};
(i) Write the names of data members which are accessible from objects belonging to class CUSTOMER.
(ii) Write the names of all the member functions which are accessible from objects belonging to class SALESMAN.
(iii) Write the names of all the members which are accessible from member functions of class SHOP.
(iv) How many bytes will be required by an object belonging to class SHOP?
Sample paper 1
13.
(c) Define a class TEST in C++ with following description: 4
Private Members
a. TestCode of type integer
b. Description of type string
c. NoCandidate of type integer
d. CenterReqd (number of centers required) of type integer
e. A member function CALCNTR() to calculate and return the number ofcenters as (NoCandidates/100+1)
Public Members
- A function SCHEDULE() to allow user to enter values for TestCode,
Description, NoCandidate & call function CALCNTR() to calculate the