Vishwa Bharati Public School Practice Questions C++: Review , Classes, Objects , Inheritance

1. Differentiate between Protected and Private members of a class in context of Inheritance using C++. 2. Define Multilevel and Multiple inheritances in context of Object Oriented Programming. Give suitable example to illustrate the same. 3. What do you understand by visibility modes in class derivations? What are these modes? Differentiate between private and protected visibility modes in context of Object Oriented Programming using a suitable example illustrating each. 4. What are the benefits of using Inheritance feature. 5. If a base class contains a member function basefunc( ) , and a derived class does not contain a function with this name , can an object of the derived class access basefunc( ) ?Show it with example . 6. How does Inheritance influence the working of constructor & destructor in C++. 7. Write the method of calling base class constructor using derived class object with parameters

8. What is the use of virtual base class ? Why we need to declare the base class as virtual. 9. What is the difference between Global Variable and Local Variable? Also, give a suitable C++ code to illustrate both ? 10. What is inline functions ? which type of functions a should be defined as a inline function . 11. Identify the correct answer from the given choices: (i) What value must a destructor return? A. A pointer to the class. B. An object of the class. C. A status code determining whether the class was destructed correctly D. Destructors do not return a value. (ii) Can two classes contain member functions with the same name? A. No. B. Yes, but only if the two classes have the same name. C. Yes, but only if the main program does not declare both kinds. D. Yes, this is always allowed 12. What is the difference between Object Oriented Programming and Procedural Programming?

13. Define any two features of Object oriented Programming . 14. Answer the questions (i) to (iv) based on the following code : class Employee { int id; protected : char name[20]; char doj[20]; public : Employee(); ~Employee(); void get(); void show(); }; class Daily_wager : protected Employee { int wphour; protected : int nofhworked; public : void getd(); void showd(); }; class Payment : private Daily_wager { char date[10]; protected : int amount; public : Payment(); ~Payment(); void show(); }; Name the type of Inheritance depicted in the above example. 1 (ii) Name the member functions, which are accessible by the objects of class Payment. 1 (iii)From the following, Identify the member function(s) that can be called directly from the object of class Daily_wager 1) show() 2. getd() 3. get() (iv) Find the memory size of object of class Daily_wager. 1 (v) Is the constructors of class Employee will copied in class Payment due to inheritance ? 1 15. Answer the questions (i) to (iv) based on the following: 4 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? 16. Answer the questions (i) to (iv) based on the following code : class Teacher { char TNo[5], TName[20], DeptflO]; int Workload; protected: float Salary; void AssignSal(float); public: Teacher( ) ; void TEntry( ) ; void TDisplay( ); }; class Student { char Admno[10], SName[20], Stream[10]; protected: int Attendance, TotMarks; public: Student( ); void SEntry( ); void SDisplay( ); }; class School : public Student, public Teacher { char SCode[10], SchName[20]; public: School ( ) ; void SchEntry( ); void SchDisplay( ); }; (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 School from the following TEntry( ) , SDisplay( ) , SchEntry( ) (iii) Write name of all the member(s) accessible from member functions of class School. (iv) If class School was derived privately from class Teacher and privately from class Student, then, name the member function(s) that could be accessed through Objects of class School. 17. 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(); }; 1 (i) Write the names of data members which are accessible from objects belonging to class CUSTOMER. 1.1.1.1.1.1.1 (ii) Write the names of all the member functions which are accessible from objects belonging to class SALESMAN. 2 (iii) Write the names of all the members which are accessible from member functions of class SHOP. 3 (iv) How many bytes will be required by an object belonging to class SHOP? 18. Which C++ header file(s) will be essentially required to be included to run the following C++ code: void main() { char Msg[ ]="Sunset Gardens"; for (int I=5;I

include include const int low=25; void main() { randomize(); int point=5, number; for (int i=1 ; i<=4;i++) { Number=low+random(point); cout< class printData { public: void print(int i) { cout << "Printing int: " << i << endl; } void print(double f) { cout << "Printing float: " << f << endl; } void print(char* c) { cout << "Printing character: " << c << endl; } }; int main(void) { printData pd; pd.print(5); pd.print(500.263); pd.print("Hello C++"); return 0; }