Vous êtes sur la page 1sur 7

Q1 Assume that the cell users are two kinds those with a post paid option and those

e with a prepaid option. Post paid gives a fixed free talk time and the rest is computed at the rate of Rs.1.90 per pulse. Prepaid cards have a fixed talk time. Define a class Cell_user as a base class and derive the hierarchy of classes. Define member functions and override them wherever necessary to (i) retrieve the talk time left for each user. (ii) print the bill in a proper format containing all the information for the post paid user.

Q2 Write a C++ program to prepare the mark sheet of an university examination with the following items from the keyboard : Name of the student Roll no. Subject name Subject code Internal marks External marks Design a base class consisting of data members Name of the student and Roll no. The derived class consists of the data members Subject name, Subject code, Internal marks and External marks.

Q3 Write a program to overload the unary minus operator using friend function.

Q4 Create a class Patient that stores the patient name (a string) and the disease (a string) of the patient. From this class derive two classes : In_patient which has a data member roomrent (type float) and Out_patient which has a data member OPD_charges (float). Each of these three classes should have a nondefault constructor and a putdata() function to display its data. Write a main() program to test In_ patient and Out_patient classes by creating instances of them and then displaying the data with putdata().

Q5 An electricity board charges the following rates to domestic users to discourage large consumption of energy : For the first 100 units Beyond 300 units 50 P per unit 60 P per unit

If the total cost is more than Rs.250.00 then an additional surcharge of 15% is added on the difference. Define a class Electricity in which the function Bill computes the cost. Define a derived class More_Electricity and override Bill to add the surcharge. Q6 Answer the questions (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( ) { cout<<WorkID<<;<<WorkType<<endl; } WORK( ) { WorkID=10; WorkType=T; } WORK(WORK &W) { WorkID=W.WorkID+12; WorkType=W.WorkType+1; } }; // Function 4 // Function 3 // Function 2

(i)

(ii)

Which member function out of function1, function2, function3 and function4 shown in the above example 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? WORK W; //Statement 1 WORK Y (W); //Statement 2

Which member function out of Function1, Function2, Function3 and Function4 shown in 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 Parameterized Constructor?

Q7 Define a class Travel in C++ with the description given below : Private Members : T_Code No_of_Adults No_of_Children Distance TotalFare Public Members : A Constructor to assign initial values as follows : T_Code with the word NULL No_of_Adults as 0 No_of_Children as 0 Distance as 0 TotalFare as 0 A function AssignFare( ) which calculates and assigns the value of the data member TotalFare as follows : of type char[15] of type integer of type integer of type integer of type float

For each Adult: Fare (Rs) For Distance (Km) 200 300 500 <500 <1000 & >=500 >=1000

For each Child the above Fare will be 50% of the Fare mentioned in the above table. For example : If Distance is 750, No_of_Adults = 3 and No_of_Children = 2 Then the fair for the Adults is 300. Then Total Fare should be calculated as No_of_Adults*300 + No_of_Children *150

i.e. 3 * 300 + 2 * 150 = 1200 A function EnterTravel() to input the values of the data members T_Code, No_of_Adults, No_of_Children and Distance; and invoke the AssignFare( ). A function ShowTravel(), which displays the content of all the data members. Q9 ) Find the output of the following program: #include<iostream.h> int a=10; void main() { void demo(int &,int,int*); int a=20,b=5; demo(::a,a,&b); cout<<::a<<a<<b<<endl; } void demo(int &x,int y,int *z) { a+=x; y*=a; *z=a+y; cout<<x<<y<<*z<<endl; } Q10 Consider the following and answer the questions given below: class CEO { double Turnover; 2

protected:

int Noofcomp; public: CEO(); void INPUT(int); void OUTPUT(); }; class Director : public CEO { int Noofemp; public: Director (); void Indata(); void Outdata(); protected: float Funds; }; class Manager : public Director { float Expenses; public: void Display(); Manager(); } 1) a) Which constructor will be called first at the time of declaration of an object of class Manager? b) How many bytes will an object belonging to class Manager require? 2) Name the member function(s), which are directly accessible from the object of class Manager. 3) Is the data member Funds accessible by the object of the class Manager and why? 4) If the class Manager is derived in protected mode in place of public then, give the names of inherited members in the protected section only?

Vous aimerez peut-être aussi