<p> Vishwa Bharati Public School Practice Questions C++: Review , Classes, Objects , Inheritance </p><p>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 </p><p>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? </p><p>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<strlen(Msg);I++) puts(Msg); } 19. Find the output of the following program ( assume that the required header files are included ) : class student { char name[20]; int I ; public: student() { I=0; strcpy(name," "); } student (char s[20]) { I =strlen(s); strcpy (name,s); } void display( ) { cout<<name<<endl; } void manipulate(student & a, student & b) { I = a.I + b.I; strcpy(name, a.name); strcat(name, b.name); } }; void main( ) { char temp[20]= "MultiMedia"; student name1(temp), name2("Web"), name3("Tech"),S1,S2; S1.manipulate (name1, name2); S2.manipulate (S1, name3); S1.display ( ); S2.display ( ); } 20. Find the output of the following program ( assume that the required header files are included ) : void Convert(char Str[],int Len) { for (int Count =0; Count<Len; Count++ ) { if (isupper (Str [Count] ) ) Str[Count]= tolower(Str[Count]); else if (islower (Str [Count] ) ) Str[Count]= toupper(Str[Count]); else if (isdigit (Str [Count])) Str[Count]= Str[Count] + 1; else Str[Count] = ‘*’; } } void main () { char Text [] = “CBSE Exam 2013”; int Size=strlen(Text); Convert(Text,Size); cout<<Text<<endl; for (int C = 0,R=Size-l;C<=Size/2; C++,R--) { char Temp = Text[C]; Text [C] = Text [R] ; Text [R] = Temp; } cout<<Text<<endl; } 21. The following code is from the game which generates a list of four random numbers . Mayur is playing this game , help him to identify the correct option (s) out of the four choices given below as the possible set of such numbers generated from the program code. Justify your answer.2</p><p> include<iostream.h> include<stdlib.h> const int low=25; void main() { randomize(); int point=5, number; for (int i=1 ; i<=4;i++) { Number=low+random(point); cout<<number<< “:”; Point--; }} (i) 29:26:25:28 (ii) 24:28:25:26 (iii) 29:26:24:28 (iv) 29:26:25:26 22. Will the following program execute successfully ? if not , state the reasons : class ABC { int x=10; float y; ABC ( ) { y=5; } ~ABC( ) { } }; void main ( ) { ABC a1,a2; } Answer the questions (i) and (ii) after going through the following class: class shape { int model; public: shape(int y) {model=y;} //Constructor 1 shape(shape & t); }; //Constructor 2 i. Create an object, such that it invokes Constructor 1. ii. Write complete definition for Constructor 2. iii. Which feature of object oriented programming is implemented in the above functions constructor1 and constructor2. 23. Define a class TEST in C++ with following description: 4 Private Members • TestCode of type integer • Description of type string • NoCandidate of type integer • CenterReqd (number of centers required) of type integer • A member function CALCNTR() to calculate and return the number of centers 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 number of Centres • A function DISPTEST() to allow user to view the content of all the data members 24. Find the output of the following : #include <iostream.h> 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; }</p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages6 Page
-
File Size-