0% found this document useful (0 votes)
144 views14 pages

Questionbank For q2 10marks

Here is the class definition for student with the given private members: class student { private: int admno; char sname[20]; public: // Member function definitions }; 02. Define a constructor in the above class to initialize the private members The constructor to initialize the private members would be: class student { private: int admno; char sname[20]; public: student(int a, char n[]) { admno = a; strcpy(sname, n); } // Other member function definitions }; 03. Define a member function display() to display the values of private members The

Uploaded by

Vinod Srivastava
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views14 pages

Questionbank For q2 10marks

Here is the class definition for student with the given private members: class student { private: int admno; char sname[20]; public: // Member function definitions }; 02. Define a constructor in the above class to initialize the private members The constructor to initialize the private members would be: class student { private: int admno; char sname[20]; public: student(int a, char n[]) { admno = a; strcpy(sname, n); } // Other member function definitions }; 03. Define a member function display() to display the values of private members The

Uploaded by

Vinod Srivastava
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

VKS-LEARNING HUB vinsri76@yahoo.

com

Q2 Based on Class Concept and features Total Marks 10

Q2(A) Theory Based on Class Concept Marks :2

1. Differentiate between members, which are present within the private visibility mode with those
which are present within the public visibility modes.
2. What is copy constructor? Give an example in C++ to illustrate copy constructor.
3. What do you understand by visibility modes in class derivations? What are these modes?
4. Why is a destructor function required in classes? Illustrate with the help of an example.
5. Illustrate the use of "self referential structures‖ with the help of an example
6. 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 name and arguments, which member function
will be called by the object of the derived class if the scope operator is not used ?
7. 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 does it get invoked / called ?
(ii) In Object Oriented Programming, what is Function 2 referred as and when does it get invoked / called ?

8.Define the term Data Hiding in the context of Object Oriented Programming. Give asuitable example
using a C++ code to illustrate the same.
9. Differentiate between Constructor and Destructor function in context of Classes and Objects using C++
10. What do you understand by Polymorphism ? Also, give an example in C++ to illustrate the same.
11. What do you understand by Data Encapsulation and Data Hiding?
12. What do you understand by Data Encapsulation and Data Hiding? Also, give a suitable C++ code to
illustrate both.

C++@12 Question Bank Page 1


VKS-LEARNING HUB [email protected]

13. 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 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?

ii) WORK W; //Statement 1


WORK Y(W); // Statement 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 Statement 2? What is this
function specifically known as out of Destructor or Copy Constructor or Default Constructor?

14. 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 functions [I] to [IV].
#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);
}

C++@12 Question Bank Page 2


VKS-LEARNING HUB [email protected]

15. 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 using Function 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 of class Test.

16 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?

C++@12 Question Bank Page 3


VKS-LEARNING HUB [email protected]

17. 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 1 and Function 2
together?
(ii) What is Function 3 specifically referred as ? When do you think, Function 3 will be invoked/called?

18.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 does it get invoked/called?
ii) In Object Oriented Programming, which concept is illustrated by Function 1 and Function 3 together?
Write an example illustrating the calls for these functions.

C++@12 Question Bank Page 4


VKS-LEARNING HUB [email protected]

QNO 2 (B) Based on Class Creation and defining Member function Marks 4

01. 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

02. 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

03. 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.

C++@12 Question Bank Page 5


VKS-LEARNING HUB [email protected]

04. 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.

05. 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.

06 .Declare a class myfolder with the following specifications :


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 and Usedspace 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

C++@12 Question Bank Page 6


VKS-LEARNING HUB [email protected]

07. Define a class Flight 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
 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

08 Write the definition of a class METROPOLIS in C++ with following description : 4


Private Members –
-MCode //Data member for Code (an integer)
– MName //Data member for Name (a string)
– MPop //Data member for Population (a long int)
– Area //Data member for Area Coverage (a float)
– PopDens //Data member for Population Density ( a float)
– CalDen() //A member function to calculate -------
//Density as PopDens/Area
Public Members
– Enter() //A function to allow user to enter values of //Mcode,MName,MPop,Area and call CalDen()
//function
– ViewALL() //A function to display all the data members //also display a message ―Highly
// Populated Area‖
//if the Density is more than 12000

09 Write the definition of a class PIC in C++ with following description :


Private Members
– Pno //Data member for Picture Number (an integer)
– Category //Data member for Picture Category (a string)
– Location //Data member for Exhibition Location (a string)
– FixLocation //A member function to assign //Exhibition Location as per category //as shown in the
following table
Category Location
Classic Amina
Modern Jim Plaq
Antique Ustad Khan
Public Members
– Enter() //A function to allow user to enter values //Pno, category and call FixLocation() function
– SeeAll() //A function to display all the data members

C++@12 Question Bank Page 7


VKS-LEARNING HUB [email protected]

10. Define a class Candidate in C++ with the following specification : 4


Private Members :
Rno(Registration Number) type long
Cname of type string
Agg_marks (Aggregate Marks) of type float
Grade of type char
setGrade () to find the grade as per the aggregate marks
obtained by the student. Equivalent aggregate marks range and the respective grade as shown
below.
AggregateMarks Grade
>=80 A
Less than 80 and >=65 B
Less than 65 and >=50 C
Less than 50 D
Public members:
A constructor to assign default values to data members: Rno=0,Cname=‖N.A‖,Agg_marks=0.0
A function Getdata() to allow users to enter values for Rno. Cname, Agg_marks and call
function setGrade() to find the grade.
A function dispResult( ) to allow user to view the content of all the data members.

11. Define a class Garments in c++ with following descriptions


private members :
GCode of type string
GType of type string
Gsize of type intiger
Gfabric of type istring
Gprice of type float
A function Assign() which calculate and the value of GPrice as follows.
For the value of GFabric ―COTTON‖ ,
GType GPrice(RS)
TROUSER 1300
SHIRT 1100
For GFabric other than ―COTTON‖, the above mentioned GPrice gets reduced by 10%
public members:
A constructor to assign initial values of GCode,GType and GFabric with the a word
―NOT ALLOTED‖and Gsize and Gprice with 0.
A function Input ()to the values of the data membersGCode, GType,Gsize and GFabric and
invoke the Assign() function.
A function Display () which displays the content of all the data members for a garment.

12. Define a class Play in C++ with the following specifications:


Private members of class Play
*Play code integer
*Playtime 25 character
*Duration float
*Noofscenes integer
Public member function of class Play
*A constructer function to initialize Duration as 45 and Noofscenes as
*Newplay() function to values for Playcode and Playtitle.
*Moreinfor() to assign the values of assign the values of Duration and Noofscenes with the of
corresponding values passed as parameters tothis function.
*Shoplay() function to display all the data members on the screen.

C++@12 Question Bank Page 8


VKS-LEARNING HUB [email protected]

QNO 2 (D) Based on Inheritance Marks 4 Marks

01. Answer the questions (i) to (iv) based on the following code:
class Medicines
{
char Category[lO];
char Date_of_manufacture[lO];
char Company[20];
public:
Medicines();
void entermedicinedetails();
void showmedicinedetails();
};
class Capsules: public Medicines
{
protected:
char capsule_name[30];
char Volume_label[20];
public:
float Price;
Capsules();
void entercapsuledetails();
void showcapsuledetails();
};
class Antibiotics: public Capsule
{
int Dosage_units;
char Side_effects[20];
int Use_within_days;
public:
Antibiotics() ;
void enterdetails();
void showdetails();
};
(i) How many bytes will be required by an object of class Medicines and an object of class Antibiotics
respectively?
(ii) Write names of all the member functions accessible from the object of class Antibiotics.
(iii) Write names of all the members accessible from member functions of class Capsules.
(iv) Write names of all the data members, which are accessible from objects of class Antibiotics.

02.Answer the questions (i) to (iv) based on the following code :


class Trainer
{
char TNo [5], TName [20], Specialisation [10];
int Days;
protected :
float Remuneration;
void AssignRem (float);
public :
Trainer ( ) ;
void TEntry ( );
void TDisplay ( );
};

C++@12 Question Bank Page 9


VKS-LEARNING HUB [email protected]

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 ( );
};
(i) Which type of Inheritance is depicted by the above example?
(ii) Identify the member function(s) that cannot be called directly from the objects of class Institute from the
following TEntry( ) LDisplay() IEntry()
(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.

03. Answer the questions (i) to (iv) based on the following:


class FaceToFace
{
char CenterCode[10];
public:
void Input( );
void Output( );
};
class Online
{
char website[50];
public:
void SiteIn( );
void SiteOut( );
};
class Training: public FaceToFace, private online
{
long Tcode;
float charge;
int period;
public:
void Register( );
void show( );
};
(i) Which type of inheritance is shown in the above example?
(ii) Write names of all the member functions accessible from Show( ) function of class Training.
(iii) Write name of all the member accessible through an object of class Training.
(iv) Is the function Output( ) accessible inside the function SiteOut( )? Justify your answer?

C++@12 Question Bank Page 10


VKS-LEARNING HUB [email protected]

04. Answer the questions (i) to (iv) based on the following :


class Chairperson
{
long CID ; //Chairperson Identification Number
char CName[20] ;
protected :
char Description[40] ;
void Allocate( ) ;
public :
Chairperson( ) ;
void Assign( ) ;
void Show( ) ;
};
class Director
{
int DID ; //Director ID
char Dname[20] ;
protected :
char Profile[30] ;
public :
Director( ) ;
void Input( ) ;
void output( ) ;
};
class Company : private Chairperson, public Director
{
int CID ; //Company ID
char City[20] , Country[20] ;
public :
Company( ) ;
void Enter( ) ;
void Display( ) ;
};

(i) Which type of Inheritance out of the following is specifically is illustrated in the above C++ code ?
(a) Single Level Inheritance
(b) Multi Level Inheritance
(c) Multiple Inheritance

(ii) Write the names of data members, which are accessible by objects of class type Company.
(iii) Write the name of all the member functions, which are accessible by objects of class type Company.
(iv) Write the names of all members, which are accessible from member functions of class Director.

05.Answer the question (i) to (iv) based on the following:


class Student
{
int Rno;
char Name[20];
float Marks;
protected:
void result( );
public:

C++@12 Question Bank Page 11


VKS-LEARNING HUB [email protected]

Student ( );
void Register ( ); void Display( );
};
class Faculty
{
long FCode;
char FName [20];
protected:
float Pay;
public:
Faculty ( );
void Enter( );
void Show( );
};
class Course: public Student, private Faculty
{
long CCode [10]; char CourseName [50];
char StartDate [8], EndDate [8];
public:
Course( );
void Commence ( );
void CDetail ( );
};

(i) Which type of inheritance is illustrated in the above C++ code?


(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 member functions, which are accessible from objects of class Course.
(iv) Write the names of all the members, which are accessible from objects of class faculty.

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


class PUBLISHER
{
char Pub[12];
double Turnover;
protected:
void Register();
public:
PUBLISHER();
void Enter();
void Display();
};
class BRANCH
{
char CITY[20];
protected:
float Employees;
public:
BRANCH();
void Haveit();
void Giveit();
};

C++@12 Question Bank Page 12


VKS-LEARNING HUB [email protected]

class AUTHOR:private BRANCH,public PUBLISHER


{
int Acode;
char Aname[20];
float Amount;
public:
AUTHOR();
void Start();
void Show();
};
(i) Write the names of data members, which are accessible from objects belonging to class AUTHOR.
(ii) Write the names of all the member functions which are accessible from objects belonging to class
BRANCH.
(iii) Write the names of all the members which are accessible from member functions of class AUTHOR.
(iv) How many bytes will be required by an object belonging to class AUTHOR?

7. 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?

C++@12 Question Bank Page 13


VKS-LEARNING HUB [email protected]

8. Answer the questions (i) to (iv) based on the following:


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
– Multi Level 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 ?

C++@12 Question Bank Page 14

You might also like