KENDRIYA VIDYALAYA TIRUMALAGIRI,SECUNDERABAD UNIT TEST II SUB : COMPUTER SCIENCE CLASS : XII TIME : 90 MINS M.M: 40 1.a. Differentiate between default & parameterized constructor with suitable example. -2 b. What is the significance of private, protected and public access specifiers in a class? -2 c. Answer the questions (i) and (ii) after going through the following class. -2 class player int health; int age; player( ) health=6; age=18; } //Function 1 player(int s, int a) health =s; age = a ; } // Function 2 player( player &p); // Function 3 ~player( ) cout<< Memory Deallocate ; } // Function 4 void main( ) player p1(7,24); //Statement1 player p3 = p1; //Statement3 } (i) When p3 object created specify which constructor invoked and why? Write complete definition for Function 3? (ii) Which concept of C++ is demonstrated by Function 1, 2 and 3? Write the calling statement of Function 1. d. Define a class BALANCED_MEAL in C++ with following description: - 4 Private Members: Access_no Integer Name_of_Food String of 25 characters Calories Integer Food_type String Cost Float AssignAccess( ) Generates random numbers between 0 to 99 and return it. Public Members A function INTAKE( ) to allow the user to enter the values of Name_of_Food, Calories, Food_type, cost and call function AssignAccess( ) to assign Access_no. A function OUTPUT( ) to allow user to view the content of all the data members, if the Food_type is Fruit. e. Define a class Employee in C++ with the following specification: - 4 Private Members: ename an array of char of size[50] ( represent employee name) deptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate the total bonus given to an employee according to following conditions Deptname Bonus Accounts 4 % of salary
HR 5% of salary IT 2% of salary Sales 3% of salary Marketing 4% of salary Public Members: Constructor to initialise ename and deptname to NULL and salary and bonus to 0. A function read_info to allow user to enter values for ename, deptname,salary & Call function CalBonus() to calculate the bonus of an employee. A Function disp_info() to allow user to view the content of all the data members. 2. a. Define a class POWER in C++ with following description: -4 Private Members: MNO of type long (Meter Number) Name of type string (Consumer s Name) Units of type long (Power Unit s Consumed) Charges of type float (Charges to be paid by Consumer) A member function CALCCHARGE( ) to calculate Charges according to the following conditions: Units Charges Below 100 Units Rs. 2.00 per Unit Below 200 Units and > = 100 Units Rs. 3.00 per Unit > = 200 Units Rs. 5.00 per Unit For Example: If the Units are 132, Charges should be calculated as Charges = 99 * 2 + (Units 99 ) * 3; If the Units are 392, Charges should be calculated as Charges = 99 * 2 + 100 * 3 + (Units 199) * 5; Public Members A Function Enterdata( ) to allow user to enter values for Mno, Name, Units & call the function CAlCCHARGES( ) to calculate the Charges. A Function ShowBillI( ) to allow user to view the content of all the data members. b. Answer the questions (i) to (iv) based on the following code: -4 class Car char Model[10]; char Date_of_purchase[10]; char Company[20]; public( ); Car( ); void entercardetail( ); void showcardetail( ); class Accessories : public Car protected: char stereo_tape[30]; char sheet_cover[20]; float Price; Accessories( ); void enteraccessoriesdetails( ); void showaccessoriesdetails( );
class Dealer : public Accessories int No_of_dealers; char dealers_name[20]; int No_of_products; Dealer( ); void enterdetails( ); void showdetails( ); (i) How many bytes will be required by an object of class Car and an object of class Dealer. (ii) Write names of all the data members which are accessible from the objects of class Dealer. (iii) Write names of all the members accessible from member functions of class Accessories. (iv) Write names of all the member functions which are accessible from objects of class Dealer. c. Answer the questions (i) to (iv) based on the following code : -4 class Employee int id; char name[20]; char doj[20]; Employee(); ~Employee(); void get(); void show(); class Daily_wager : protected Employee int wphour; int nofhworked; void getd(); void showd(); class Payment : private Daily_wager char date[10]; int amount; Payment(); ~Payment(); void show(); (i) Name the type of Inheritance depicted in the above example. (ii) (iii) Name the member functions accessible through the object of class Payment. From the following, Identify the member function(s) that can be called directly from the object of class Daily_wager class
(iv) show(), getd(),get() Name the base & derived class of Daily_wager class. d. Define a class Book with the following specification: -4 Private members Book_No integer type Book_title 20 character 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: INPUT ( ) function to reed Book_no, Book_title, price. PURCHASE ( ) function to ask the user to input the number of copies to be purchased. It invokes total_cost and prints the total cost to be paid by the user. e. Answer the questions (i) to (iv) based on the following code: -4 class Trainer char TNo [5], TName [20], Specialisation [10]; int Days; float Remuneration; void AssignRem (float); Trainer ( ) ; void TEntry ( ); void TDisplay ( ); class Learner char Regno [10], LName [20], Program [10]; Protected : int Attendance, Grade; Learner ( ); void LEntry ( ); void LDisplay ( ); class Institute : public Learner, public Trainer char ICode[10], IName [20];
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. 3.(a) Differentiate between Constructor and Destructor function in context of Classes and Objects. 2 (b) Answer the questions (i) and (ii) after going through the following class. 2 class Maths char Chapter [20]; int Marks; Maths (int x, char ch[ ]) //Function 1 ---------------- } Math (Math & A1 ) //Member Function 2 ----------------- } (i) Complete the definitions of Member Function 1 and Member Function 2 in the above example. (ii) How would Member Function 1 and Member Function 2 get executed? c. Answer the questions (i) and (ii) after going through the following class : -2 class Computer char C_name[20]; char Config[100]; Computer(Computer &obj); // function1 Computer(); //function 2 Computer(char *n,char *C); // function3
(i) Complete the definition of the function 1. ii)name the specific feature of the OOPs shown in the above example....end...