Thursday, 28 April 2016

practice questions for class & Object

1.     Define a class Travel in C++ with the description given below:
Private members:
plancode of type long place of type characters array
 number_of_travellers of type integer
 number_of_buses of type integer
Public members:
 A constructor to assign initial values of plancode as 1001, place as “Kolkata”, number_of_travellers as 5 and number_of_buses as 1
A function newplan( ) which allows user to enter plancode , place and number_of_travellers and also assign the number_of_buses as per the following conditions:
number_of_travellers        number_of_buses
less than 20                                         2
equal to and more than 20
 and less than 40                                3
equal to and more than 40               4
 A function show( ) to display the contents of all the data members on the screen
2. Answer the questions (i) to (iv) based on the following code :
class Goods {
int id; protected :
char name[20]; long qty;
void Incr(int n);
public :
Goods(); ~Goods();
void get();
};
class Food_products : public Goods {
char exp_dt[10];
protected : int id; int qty;
public :
void getd();
void showd();
};
class Cosmetics : private Goods {
 int qty; char exp_date[10];
protected : int id;
 public :                                                 
~Cosmetics();
Cosmetics();
 void show();
};




(i)                How many bytes will be required by an object of class Food_products.
(ii)               (ii) Name the member functions accessible through the object of class Food_products.
(iii)             From the following, Identify the member function(s) that cannot be called directly from the object of class Cosmetics show(), getd(), get()
(iv)             (iv) If the class cosmetics inherits the properties of food_products class also, then name the type of inheritance
33 .     Describe friend function with example.
44 .     what is static data member and static function
55 .     Explain nested class with suitable  program.
66 .     Write four  features of constructor and destructor
77 .       Write the following law of Boolean algebra and prove with truth table
a)     Absorption law  b) distributive law    c) complementary law   d) involution law
e)  Idempotent  law  f) associative law
8) Write D Morgan’s theorem and prove it algebraically
9) Define the following terms
a) keyword   b)literals   c) identifier d) default parameter e) function prototype   f) type casting   g) explicit data type conversion   h) random()   i) randomize()  j) header files   k


No comments:

Post a Comment