Академический Документы
Профессиональный Документы
Культура Документы
(a) What is a copy constructor? Give a suitable example in C++ to illustrate with
its definition within a class and a declaration of an object with the help of it.
(b) Observe the following C++ code and answer the questions (i) and (ii):
class Passenger
{
long PNR;
char Name[20];
public:
Passenger() //Function 1
{ cout<< ”Ready” << endl; }
~Passenger() //Function 4
{ cout<< ”Booking cancelled!” << endl; }
};
(i) Fill in the blank statements in Line 1 and Line 2 to execute Function 2 and
Function 3 respectively in the following code:
void main()
{
Passenger P;
__________ //Line 1
__________//Line 2
}//Ends here
(ii) Which function will be executed at }//Ends here? What is this function referred as?
(c) Write the definition of a class Photo in C++ with following description:
Private Members
Pno //Data member for Photo Number(an integer)
Category // Data member for Photo Category(a string)
Exhibit // Data member for Exhibition Gallery(a string)
FixExhibit // A member function to assign exhibition Gallery as per Category as
shown in the following table
Public Members-
Register() // A function to allow user to enter values
//Pno, Category and call FixExhibit() function
ViewAll() //A function to display all the data members
(d) Answer the questions (i) to (iv) based on the following:
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?
a. Single Level Inheritance
b. Multi Level Inheritance
c. 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?
[2+1+1+4+4=12]
Answer
(a) Copy constructor copies the value of one object into other object.
Example-
(b)
(ii)
void main()
{
Passenger P;
P.Book(45,”CPP”); //Line 1
P.Print(); //Line 2
}//Ends here
(ii) Function 4 will be executed at }//Ends here. The ~Passenger() is called the
destructor function will is used to de-allocate the memory allocated by the constructor. It
is called automatically at the end of the program.
(c)
(d)
(i) Multi Level inheritance
(ii) float Advance, int WallArea, ColorCode,Type
(iii) void Book(), void View(), void PBook(), void
PView(), void Bill(), void BillPrint()
(iv)
Interior()
Painting()
Billing()
i) Which of the function out of Function 1,2,3,4 or 5 will get executed when the
Statement 1 is executed in the above code?
ii) Write a statement to declare a new object G with reference to already existing
object H using Function 3.
Member Functions
• A constructor function to initialize Type as ‘A’ and CNo as ‘1111’
• A function Charges() to assign PKM as per the following table:
Type PKM
A 25
B 20
C 15
A function Register() to allow administrator to enter the values for CNO and Type.
Also, this function should call Charges() to assign PKM charges.
• A function ShowCab() to allow user to enter the value of Distance and display
CNo, Type, PKM, PKM*Distance(as Amount) on screen.
(d) Consider the following C++ code and answer the questions from (i) to (iv):
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();
void View();
};
(b)
(i) The Function 1 would be called when Statement 1 would be executed.
(ii)
void main()
{
Health H(20);
Health G(H); // Object G
}
(c)
#include < iostream.h >
#include < conio.h >
class CABS
{
int CNo;
char Type;
int PKM;
int Dist;
public:
CABS()
{
CNo=1111;
Type='A';
}
int Charges()
{
if(Type=='A')
return 25;
else if(Type=='B')
return 20;
else if(Type=='C')
return 15;
else
return 0;
}
void Register()
{
cout << "nEnter Cab No:";
cin >>CNo;
cout <<"nEnter City Type(A/B/C): ";
cin >>Type;
PKM=Charges();
}
void ShowCab()
{
cout << "nEnter the value of distance (15/20/25): ";
cin >> Dist;
cout<< "nThe Cab No is: "<< CNo;
cout<< "nThe City type is: "<< Type;
cout<< "nThe charges per kilo meters is: "<< PKM;
cout<< "nThe Total Amount is: "<< PKM*Dist;
}
};
void main()
{
clrscr();
CABS C;
C.Register();
C.ShowCab();
getch();
}
(d)
(i) Multilevel Inheritance
(ii) Member Functions which are directly accessible from the objects of class Applicant
are-
void Enter(), void Show(), void Enroll(), void View()
(iiii) Data members which are directly accessible from the member functions of class
Applicant are-
double Budget, long RegNo, char Name[20]
(iv) No
void main()
{
Race R;
:
}
(i ) Out of the following, which of the options is correct for calling Function2?
(ii) Name the feature of object oriented programming that is illustrated by the
Function 1, Function 2 and Function 3, combined together.
Data members
• Busno - to store Bus No.
• From - to store Place name of origin
• To - to store Place name of destination
• Type - to store the Distance in Kilometres
• Fare - to store the Bus Fare
Member functions
• A constructor function to initialise Type as ‘O’ and Freight as 500
‘O’ 15*Distance
‘E’ 20*Distance
‘L’ 24*Distance
• A function Allocate() to allow the user to enter the values for Busno, From, To,
Type and Distance. Also, this function should call CalcFare() to calculate the
Fare.
• A function Show() to display the content of all the data members on screen.
(d) Consider the following C++ code and answer the questions from (i) to (iv):
class Personal
{
int Class, Rno;
char Section;
protected:
char Name[20];
public:
Personal();
void Pentry();
void Pdisplay();
};
class Marks: private Personal
{
float M[5];
protected:
char Grade[5];
public:
Marks();
void Mentry();
void Mdisplay();
};
(ii) Write the names of those data members, which can be directly accessed from
the objects of class Result.
(iii) Write the names of those member functions, which can be directly accessed
from the objects of class Result.
(iv) Write the names of those data members, which can be directly accessed from
the Mentry() function of class Marks.
[2+2+4+4 = 12]
Marks:12
Answer:
(a) The two similarities between the constructor and destructor
are as follows:
1. . Both have the same name as that of the class name.
2. . Both never return any value.
class Flight
{
:
Flight()
{
cout << ”Constructor.”;
}
~Flight()
{
cout << ”Desctructor.”;
}
};
(b)
(i) Option 1 – Race T(30);
(c)
class Bus
int busno;
char from[20];
char to[20];
char type;
int distance;
int fare;
public:
Bus()
type='E';
int CalcFare();
public:
void Allocate()
fare=CalcFare();
void Show()
};
int Bus::CalcFare()
if((type=='O')||(type=='o'))
return 15*distance;
if((type=='E')||(type=='e'))
return 20*distance;
if((type=='L')||(type=='l'))
return 24*distance;
void main()
clrscr();
Bus B;
B.Allocate();
B.Show();
getch();
}
(d)
(i) Multilevel inheritance
(ii) Data members: FinalGrade, Comments
(iii) Member functions: Rcalculate(), Rdisplay(), Mentry(),
Mdisplay()
(iv) Data members: M, Grade, Name
QUESTION PAPER 2012
) What is the difference between the members in
private visibility mode and the members in protected visibility mode inside a
class? Also, give a suitable C++ code to illustrate both.
b) Answer the questions (i) and (ii) after going through the following class:
class Travel
{
int PlaceCode;
char Place[20];
float Charges;
public:
Travel() //Function 1
{
PlaceCode=1;
strcpy(Place,”DELHI”);
Charges=1000;
}
void TravelPlan(float C) //Function2
{
cout<< PlaceCode<< ”:”<< Place<< ”:”<< Charges << endl;
}
~Travel() //Function3
{
cout<<”Travel Plan Cancelled”<< endl;
}
Travel(int PC, char P[ ],float C) //Function4
{
PlaceCode=PC;
strcpy(Place,P);
Charges=C;
}
};
(i) In Object Oriented Programming, what are Function 1 and Function 4
combined together referred as?
(ii) In Object Oriented Programming, which concept is illustrated by
Function 3? When is this function called /invoked?
c) Define a class RESTRA in C++ with the following description:
Private Members:
FType Sticker
Vegetarian GREEN
Contains Egg YELLOW
Non-Vegetarian RED
Public Members:
A function GetFood() to allow the user to enter values for
FoodCode, Food, FType and call function GetSticker() to
assign Sticker.
A function ShowFood() to allow user to view the content of
all the data members.
Q3
a) Write a function SWAP2BEST (int ARR[ ],int Size) in C++ to modify the
content of the array in such a way that the elements, which are multiples of
10 swap with the values present in the very next position in the array.
For example:
If the content of Array ARR is
90, 56, 45, 20, 34, 54
The content of array ARR should become
56, 90, 45, 34, 20, 54
b) Anarray T[20][10] is stored in the memory along the
column with each of the elements occupying 2 bytes.
Find out the memory location of T[10][5], if the
element[2][9] is stored at the location 7600.
c) Write a function in C++ to perform Insert operation in a static circular
Queue containing Book’s information (represented with the help of an array
of structure BOOK).
struct BOOK
{
long Accno; //Book Accession Number
char Title[20]; //Book Title
};
d) Write a function ALTERNATE (int A[ ][3], int N, int M) in C++ to display all
alternate elements from two-dimensional array A (starting from A[0][0]).
For example:
If the array is containing:
23 54 76
37 19 28
62 13 19
The output will be:
23 76 19 62 19
e) Evaluate the following POSTFIX notation. Show the status of stack after
every step of evaluation (i.e. after each operator):True, False, NOT, AND,
False, True, OR, AND
[3+3+4+2+2 = 14]
Marks:14
Answer:
(a). A C++ function SWAP2BEST(int ARR[], int Size) that
swaps the elements which are multiple of 10, with their very
next positioned element.
void SWAP2BEST (int ARR[], int Size)
{
int temp;
for(int i = 0; i < SIZE; i++)
{
if(ARR[i]%10 == 0)
{ //swap with the next element
temp = ARR[i];
ARR[i] = ARR[i+1];
ARR[i+1] = temp;
i++; //reach next to the number that has been
swapped
}
}
}
(b). B= ?
E=2 Bytes
Lr=Lc=0
S[2][9]=7600
Column Major:
S[I][J]=B+E[(I-Lr)+R(J-Lc)]
S[2][9] = B + 2[(2-0)+20(9-0)]
7600 = B + 2(182)
B = 7600-364
B = 7236
Now Address of S[5][10] is:
S[10][5] = B+ E[(I-Lr)+R(J-Lc)]
= 7236 + 2[(10-0] + 20(5-0)]
= 7236 + 2(110)
= 7236 + 220
= 7456 Ans
(c). // declare a global variables
void insert_in_CQ( )
{
if(front==0 && rear==size-1)||(front==rear+1))
cout<< ”Underflow”;
else if(rear==-1)
front=rear=0;
else
{
rear++;
cout<< ”Enter Accession No:”;
cin>>B[rear].acc;
cout<< ”Enter Title: ”;
cin>>B[rear].Title;
}
}
b) Write the output of the following C++ code. Also write the name of feature of
Object Oriented Programming used in the following program jointly illustrated by
the function [I] to [IV] :
#include< iostream.h >
{
for( int L=1 ; L <= 80; L++) cout << ”-“;
void main()
char K = '#';
Line (K,B);
Line (A,C);
}
c) Define a class Applicant in C++ with following
description:
Private Members
A function ENTER() to allow user to enter values for ANo,Name,Agg &
call function GradeMe() to find the Grade.
A function RESULT() to allow user to view the content of all the data
members.
d) Answer the questions (i)to (iv) based on the following:
class Student
{
int Rollno;
char SName[20];
float Marks1;
protected;
void Result();
public :
Student();
void Enroll();
void Display();
};
class Teacher
{
long TCode;
char TName[20];
protected:
Teacher();
void Enter();
void Show();
};
class Course : public Student, private Teacher
{
long CCode[10]; char CourseName[50];
char StartDate[8], endDate[8];
public :
Course();
void Commence();
void CDetail();
};
(i)Write the names of member functions, which are accessible from objects of
class Course.
(ii) Write the names of all the data members, which is/are accessible from member
function Commence of class Course.
(iii)Write the names of all the members, which are accessible from objects of
class Teacher.
(iv)Which type of Inheritance is illustrated in the above C++ code?
[ 2+2+4+4 = 12 ]
Marks:12
Answer:
(a) Constructor is a member function whose task is to initialize the objects
of its class whereas destructors are used to deallocate memory and do
other clean up tasks for a class object and its class members when the
object is destroyed.
(b) Output is -
####
91827
OOPs feature -
Polymorphism
(c)
long ANo;
char Name[25];
float Agg;
char Grade;
public:
void ENTER()
{
cout << "Enter Admission No :";
cin >> ANo;
}
void RESULT()
{
cout << "The details of the candidate are";
cout << "Admission No: "<< ANo<<"n";
cout << "Name is : "<< Name<<"n";
cout << "Aggregate Marks: "<< Agg<<"n";
cout<<"Grade is: " << Grade;
}
void GradeMe()
{
else
Grade='D';
}
};
void main()
{
Applicant d;
clrscr();
d.ENTER();
d.GradeMe();
d.RESULT();
getch();
}
(d)
(i) The member functions accessible by the object of class Course are:
Enroll(), Display(), Commerce() and CDetail()
A function Buy () to allow user to enter values for ICode, Item, Price,
Qty and call function. Find Disc() to calculate Discount.
A Function ShowAll() to allow user to view the content of all the data
members.
b) i) Polymorphism
or
Function Overloading
or
Constructor Overloading
ii) Destructor, invoked or called when scope of an Object gets
over.
c)
The class is as:
class STOCK
{
int ICode;
char Item [ 20 ] ;
float Price;a) What do you understand by Data Encapsulation and Data Hiding?
Also, give an example in C++ to illustrate
both. (2)
b) Answer the questions (i) and (ii) after going through the following
class: (2)
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;
}
~ Exam()
{ //Module 3
cout << ”Exam Over” << endl;
}
void Show()
{ //Module 4
cout << Rno << ”:” << MaxMarks << ”:” << MinMarks << endl;
cout << ” [ Marks Got ] ” << Marks << endl;
}
};
i) As per Object Oriented Programming, which concept is illustrated by
Module 1 and Module2 together?
ii) What is the module 3 specifically referred as? When do you think module
3 will be invoked/ called?
c) Define a class STOCK in C++ with following
description: (4)
Private Members
A function Buy () to allow user to enter values for ICode, Item, Price,
Qty and call function. Find Disc() to calculate Discount.
A Function ShowAll() to allow user to view the content of all the data
members.
b) i) Polymorphism
or
Function Overloading
or
Constructor Overloading
ii) Destructor, invoked or called when scope of an Object gets
over.
c)
The class is as:
class STOCK
{
int ICode;
char Item [ 20 ] ;
float Price;
int Qty;
float Discount;
void FindDisc();
public:
void Buy()
{
cin >> ICode;
gets(Iyrm);
cin >> Price >> Qty;
GetDisc();
}
void ShowAll()
{
cout << ICode << Item << Price<< Qty << Discount;
}
};
void STOCK::FindDisc()
{
if (Qty < =50)
Discount=0;
else if (Qty < =100)
Discount=5;
else
Discount=10;
}
d)
i. (b) Multi Level Inheritance
ii. None
iii. Enter(), Display()
FID, Address, NOE, Description, Input(), Output(), Assign(),
show(), Allocate()
int Qty;
float Discount;
void FindDisc();
public:
void Buy()
{
cin >> ICode;
gets(Iyrm);
cin >> Price >> Qty;
GetDisc();
}
void ShowAll()
{
cout << ICode << Item << Price<< Qty << Discount;
}
};
void STOCK::FindDisc()
{
if (Qty < =50)
Discount=0;
else if (Qty < =100)
Discount=5;
else
Discount=10;
}
d)
i. (b) Multi Level Inheritance
ii. None
iii. Enter(), Display()
FID, Address, NOE, Description, Input(), Output(), Assign(),
show(), Allocate()
QUESTION PAPER 2009
(a) What is function overloading? Give an example in C++ to illustrate function
overloading.
[2]
(b) Answer the question (i) and (ii) after going through the
following [2]
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)
{
JobId = J.JobId+10;JobType=J.JobType+1;
}
};
i) 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?
ii) Job P; //Line 1
Job Q (P); //Line 2
class Regular
{
char SchoolCode [10];
public:
void InRegular ( );
void OutRegular ( ) ;
};
class Distance
{
char StudyCentreCode[5];
public:
void InDistance ( ) ;
void OutDistance ( ) ;
};
class Course: public Regular, private Distance
{
char Code [5];
float Fees ;
int Duration;
public:
void InCourse ( ) ;
void OutCourse ( ) ;
};
(i) Which type of Inheritance in shown in the above example?
(ii) Write names of all the member functions accessible from OutCourse function
of class Course.
(iii) Write name of all the members accessible through an object of class Course.
(iv)Is the function InRegular() accessible inside the function InDistance()? Justify
your answer.
Marks:12
Answer: (a) A function name having several definitions that are differentiable by the
number or types of their arguments, is known as overloaded function and this process is
known as function overloading.
Example :
# include < iostream.h>
void display ( int i)
{ cout << “ Here integer is” << i << endl; }
void display (double j)
{ cout << “ Here float is” << j << endl; }
void display (char *k)
{ cout << “ Here character* is” << k << endl; }
int main ()
{
display (20);
display (20.1010);
display ( “name”);
}
It will give output as
Here, integer is 10.
Here, float is 20.10 .
Here, character* is name.
(b) (i) Function 1 gets called automatically whenever the scope of an object finishes. It
is called the destructor of a class. Destructors are usually used to deallocate memory
and do other cleanup for a class object and its class members when the object is
destroyed. A destructor is called for a class object when that object passes out of scope
or is explicitly deleted.
(ii) Function 4 that is Job (Job & J) gets invoked when line 2 is executed. It is known as
the copy constructor. There are 3 important places where a copy constructor is called:
When an object is created from another object of the same type.
When an object is passed by value as a parameter to a function.
When an object is returned from a function.
(d) Answer the questions (i) to (iv) based on the following code: [4]
#include< iostream.h >
#include< conio.h >
class Dolls
{
char DCode[5];
protected:
float Price;
void CalcPrice(float);
public:
Dolls();
void DInput();
void DShow();
};
class SoftDolls : public Dolls
{
char SDName[20];
float Weight;
public:
SoftDolls();
void SDInput();
void SDShow();
};
class ElectronicDolls : public Dolls
{
char EDName[20];
char BatterType[10];
int Batteries;
public:
ElectronicDolls();
void EDInput();
void EDShow();
};
Marks:12
Answer:
(a) Private variables are variables that are visible only to the class to which they
belong. The derived classes cannot inherit the private data members and
member functions of the base class.
Public variables are variables that are visible to all classes. The public
members (variables or functions) can even be accessed by the code that is
outside the class.
E.g.,
class Base
{
public : int x ;
private: int y;
};
class Pub: public Base
{
Pub( );
{
x=1; // valid as anybody can access a public member
y=2; // invalid since it is a private member
}
};
(b) (i) Statement 1 will not get executed. The compiler will return an error that
Bazar::Bazar(); is not accessible since by default, the class members are private.
So, main() being outside the code of the class will not be able to access the
private members of Bazar.
(ii) When the following correction will be made, then the output will be:
Electronic_Calculator : 10@225.
(c)
class Garments
{
char GCode[20];
char GType[20];
int GSize;
char GFabric[20];
float GPrice;
void Assign()
{
if(strcmp(GType, “TROUSER”)==0)
GPrice=1300;
else if (strcmp(GType, “SHIRT”)==0)
GPrice=1100;
if(strcmp(GType, “COTTON”)!=0)
Gpice=GPrice- (GPrice * .10);
}
public:
void Garments()
{
GCode= ”NOT ALLOWED”;
GType= ”NOT ALLOWED”;
GFabric=”NOT ALLOWED”;
GSize=0;
GPrice=0;
}
void Input()
{
cout << “n Enter code:”;
cin >> GCode;
cout >> “n Enter type:”;
cin >> GType;
cout<< “n Enter fabric:”;
cin >> GFabric;
cout << “n Enter size:”;
cin >> GSize;
Assign();
}
void Display()
{
cout << “Code:” << GCode;
cout << “n Type:” << GType;
cout << “n Size:” << GSize;
cout << “n Fabric:” << GFabric;
cout << “n Price:”<< GPrice;
}
};
(iii) The data members accessible from member functions of the class
SoftDolls are: Price, SDName and Weight.
(b) Answer the questions (i) and (ii) after going through the following code:
[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?
(c) Define a class Tour in C++ with the description given below : [4]
Private Members :
Tcode of type string
NoofAdults of type integer
NoofKids of type integer
Kilometres of type integer
TotalFare of type float
Public Members:
For each Kid the above Fare will be 50% of the Fare mentioned in
the above table
For example :
If Kilometres is 850, NoofAdults = 2 and NoofKids = 3
Then TotalFare should be calculated as
(d) Answer the questions (i) to (iv) based on the following code : [4]
class Trainer
{
char TNo [5], TName [20], Specialisation [10];
int Days;
protected :
float Remuneration;
void AssignRem (float);
public :
Trainer ( ) ;
void TEntry ( );
void TDisplay ( );
};
class Learner
{
char Regno [10], LName [20], Program [10];
protected :
int Attendance, Grade;
public:
Learner ( );
void LEntry ( );
void LDisplay ( );
};
class Institute: public Learner, public Trainer
{
char ICode[10], IName [20];
public:
Institute ( );
void IEntry ( );
void IDisplay ( );
};
(iii) Write name of all the member(s) accessible from member functions of
class Institute.
(iv) If class Institute was derived privately from class Learner and privately
from class Trainer, then, name the member function(s) that could be
accessed through Objects of class Institute.
Marks:12
Answer: (a) A member function with the same name as its class is called constructor
and is used to initialize the objects of that class type with a legal initial value. A
destructor is used to destroy objects created by constructor. It takes no arguments, and
no return types can be specified for it. It is preceded by tlide(˜)
(b) (i) The specific features shown by member function 1 is: Constructor and by
function 2 is: Destructor.
(ii) Whenever object of the class is created, member function 1 will be called
automatically, since a constructor is called automatically when an object is created.
Whenever the scope of the function is over, the destructor, i.e., member function 2 will
be called.
(c)
Class Tour
{
private:
char Tcode[10];
int NoofAdults;
int NoofKids;
int Kilometres;
float TotalFare;
public:
Tour()
{
strcpy (Tcode, ”NULL”);
NoofAdults=0;
NoofKids=0;
Kilometres=0;
TotalFare=0;
}
void AssignFare()
{
int Fare=0;
if Kilometres(< 500)
Fare=200;
else if ( Kilometres >=500 && < 1000)
Fare=300;
else
Fare=500;
endif ;
endif ;
if (NoofKids > 0)
TotalFare= NoofKids * Fare/2;
TotalFare = TotalFare + NoofAdults *Fare;
}
void EnterTour()
{
cout << “nEnter the details:n”;
cout << “nEnter the Member Code:” ;
cin >> Tcode;
cout << ”nEnter NoofAdults:”;
cin >> NoofAdults;
cout << ”/nEnter NoofKids:”;
cin >> NoofKids;
cout << “/nEnter the total distance:”;
cin >> Kilometres;
AssignFare();
}
void ShowTour()
{
cout << “n Contents of all the data members for a Tour:n “;
cout << “n Members code: “ << Tcode ;
cout << “n Number of Adults:” << NoofAdults;
cout << “n Number of Kids: “ << NoofKids;
cout << “n Total Distance (in Kms ):” << Kilometres;
cout << “n Total Fare: “ << Total Fare;
}
};
(d)
(i) Multiple inheritance
(ii) TEntry(), LDisplay()
(iii) TEntry(), TDisplay(), LEntry(), LDisplay(), IEntry(), IDisplay()
(iv) IEntry(), IDisplay().
QUESTION PAPER 2006
(a) Define multilevel and multiple inheritance in context of object
oriented programming. Give suitable example to illustrate the same. [2]
(b) Answer the question (i) and (ii) after going through the following
class:
class Interview
{ int month;
public:
Interview(int y){month = y;} //Constructor 1
Interview(Interview&t); //Constructor 2
};
(i) Create an object, such that it invokes constructor 1. [1]
(ii) Write complete definition for constructor 2. [1]
(c) Define a class named ADMISSION in C++ with the following
descriptions: [4]
Private members:
AD_NO integer(ranges 10 – 2000)
NAME array of characters(String)
CLASS character
FEES float
Public Members:
Function Read_data() to read an object of ADMISSION type
Function Display() to display the details of an object
Function Draw-Nos() to choose 2 students randomly.
And display the details. Use random function to generate admission
nos. to match with AD_NO
(d) Answer the questions (i) to (iii) based on the following code:
class stationary
{
char Type;
char Manufacturer[10];
public:
stationary();
void Read_sta_details();
void Disp_sta_details();
};
class office : public stationary
{
int no_of_types;
float cost_of_sta;
public:
void Read_off_details();
void Disp_off_details();
};
class printer: private office
{
int no_of_users;
char delivery_date[10];
public:
void Read_pri_details();
void Disp_pri_details();
};
void main()
{ printer MyPrinter; }
(i) Mention the member names which are accessed by myprinter
declared in main() function. [1]
(ii) What is the size of MyPrinter in bytes? [1]
(iii) Mention the names of function accessible from the member
function Read_pri_details() of class printer. [2]
Marks:12
Answer:
(a) Multiple inheritance:
When one class is derived from more than one base class, it is known
as multiple inheritance.
Example:
// first base class
class employee
{
};
//second base class
class customer
{
};
// multiple inheritance
class emp_cust: public employee, public customer
{
Multilevel inheritance:
When a derived class is derived from a class, which is already derived from another
class, then it is known as multilevel inheritance.
Example:
// first base class
class employee
{
};
//derived class of base class
class customer : public employee
{
};
// derived class of derived class
class emp_cust: private customer
{