Sunteți pe pagina 1din 11

(i) Which type of inheritance is shown in the above

class FacetoFace
example?
{
char CenterCode[10]; Multiple
public:
void Input( ); (ii) Write names of all member functions accessible
void Output( );
}; from Show( ) function of class Training.
class Online
{ void FacetoFace::Input( );
char Website[50]; void FacetoFace::Output( );
public: void Online::Input( );
void Input( );
void Output( );
void Online::Output( );
}; void Register( );
class Training : public FacetoFace, private Online
{ (iii) Write names of all the members accessible through
long Tcode;
float Charge; an object of class Training.
int Period;
public: void FacetoFace::Input( );
void Register( ); void FacetoFace::Output( );
void Show ( ); void Register( );
};
void Show ( );
(iv) Is the function Output( ) accessible inside the
function SiteOut() no not a member
class PUBLISHER class BRANCH
{ { class AUTHOR : private BRANCH , public PUBLISHER
char Pub[12]; char CITY[20]; {
double Turnover; protected: int Acode;
protected: float Employees; char Aname[20];
void Register(); public: float Amount;
public: BRANCH(); public:
PUBLISHER(); void Haveit(); AUTHOR();
void Enter(); void Giveit(); void Start();
void Display(); }; void Show();
}; };

Write the names of data members, which are accessible from objects belonging
to class AUTHOR.
Nil

(ii) Write the names of all the member functions which are accessible from objects
belonging to class BRANCH.
void Haveit();
void Giveit();

(iii) Write the names of all the members which are accessible from member functions
of class AUTHOR.
void Enter(); void Display(); void Register(); float Employees;
void Haveit(); void Giveit();
int Acode;char Aname[20];float Amount;
void Start(); void Show();

(iv) How many bytes will be required by an object belonging to class AUTHOR? 70
class WORLD class COUNTRY : private WORLD class STATE : public COUNTRY
{ { {
int H; int T; int M;
protected : protected : public :
int S; int U; void DISPLAY (void);};
public : public :
void INPUT(int); void INDATA( int, int)
void OUTPUT(); void OUTDATA();
}; };
i) Name the base class and derived class of the class COUNTRY.
base class WORLD
and derived class STATE
(ii) Name the data member(s) that can be accessed from function DISPLAY().
int U; int M;

(iii) Name the member function(s), which can be accessed from the objects of class STATE.
void DISPLAY (void);
void INDATA( int, int)
void OUTDATA();
(iv) Is the member function OUTPUT() accessible by the objects of the class COUNTRY ?
No.
class Medicines class Capsules: public Medicines class Antibiotics: public Capsule
{ { {
char Category[lO]; protected: int Dosage_units;
char Date_of_manufacture[lO]; char capsule_name[30]; char Side_effects[20];
char Company[20]; char Volume_label[20]; int Use_within_days;
public: public: public:
Medicines(); float Price; Antibiotics() ;
void entermedicinedetails(); Capsules(); void enterdetails();
void showmedicinedetails(); void entercapsuledetails(); void showdetails();
}; void showcapsuledetails(); };
};
(i) How many bytes will be required by an object of class Medicines and an object of class Antibiotics
respectively?
class Medicines : 40 class Antibiotics : 118
(ii) Write names of all the member functions accessible from the object of class Antibiotics.
entermedicinedetails ( ) showmedicinedetaiDs ( ) entercapsuledetails ( ) showcapsuledetails ( )
enterdetails ( ) showdetails ( )
(iii) Write names of all the members accessible from member functions of class Capsules.
entermedicinedetails() showmedicinedetails() entercapsuledetails() showcapsuledetails () capsule_name,
Volume_label, Price
(iv) Write names of all the data members, which are accessible from objects of class Antibiotics. Price
class Inter
{ int m;
public:
Inter( int y) { m = y; } // Function 1
Inter ( Inter & t ); // Function 2
~Inter( ) { } // Function 3
};
(i) Create an object, such that it invokes Function 1. Inter i(6);
(ii)What is Function 3? Destructor
(iii)Write complete definition for Function 2.
Inter ( Inter & t ){m=t.m;}
class Seminar
{
int Time; i) In Object Oriented Programming, what is Function 4 referred as and
public: when does it get invoked/called?
Seminar() //Function 1 Destructor
{
Time=30;cout<<"Seminar starts now"<<end1; ii) In Object Oriented Programming, which concept is illustrated by Function 1
and Function 3 together? Write an example illustrating the calls for these
}
functions.
void Lecture() //Function 2 Function Overloading implementing Polymorphism
{ Seminar x[10]; - Function 1
cout<<"Lectures in the seminar on"<<end1; Seminar S(5);
}
Seminar(int Duration) //Function 3
{
Time=Duration;cout<<"Seminar starts now"<<end1;
}
~Seminar()
//Function 4
{
cout<<"Vote of thanks"<<end1;
}
};
class Test Test(int M) // Function 3
{ {
char Paper[20]; strcpy(Paper,Computer);
int Marks; Marks = M;
public: }
Test() // Function 1 Test(char P[], int M) // Function 4
{ {
strcpy(Paper, Computer) strcpy(Paper, P);
Marks = 0; Marks = M;
} }
Test(char P[] ) // Function 2 };
{
strcpy(Paper,P);
Marks = 0;
} (i) Which feature of Object Oriented Programming is demonstrated using
Function 1, Function 2, Function 3 and Function 4 in the above class Test?
Function Overloading implementing Polymorphism

(ii) Write statements in C++ that would execute Function 2 and Function 4 of class Test
Funtion 4: Test T(UNIT1, 60);
Funtion 2: Test T(UNIT1);
1. Consider the following declaration :

class welcome which of the following are valid statements justify


welcome obj (33, a9); - not a single character
{public: welcome obj1(50, 9);

welcome (int x, char ch); // welcome obj3(); - no parameter passed


obj1= welcome (45, T);
constructor with parameter obj3= welcome - class name cannot be assingned to object

welcome(); // constructor
without parameter
void compute();
private:
int x; char ch;
};
Rewrite the following program after removing the
void main()
syntactical error(s) if any.
{
Item I; // ctr in private
#include<iostream.h> Purchase(); // to be called with object

Class Item // syntax c small


member funtion
I.Qty=5;//private cannot be accesed by obj
{ spelling }

long IId, Qty;


viod Item(long id=0, long qty=0){}
public:
void Purchase { cin>>IId>>Qty;}
void Sale() () Missing
{
cout<<setw(5)<<IId<<Old:<<
Qty<<endl; iomanip.h missing
cout<< New :<<Qty<<endl;
}}; class defn, not terminated
#include [iostream.h] - // syntax <> to be used
class MEMBER
{
int Mno;float Fees;
PUBLIC: // public:
void Register(){cin>>Mno>>Fees;}
void Display(){cout<<Mno<<" : "<<Fees<<endl;}
};
void main()
{
MEMBER M;
Register(); // - cannot be called without obj
M.Display();
}
class example {
int a,b; void main()
public : {
example () example E1,E2,E3;
{ E1.input();
a=0; E2.input();
b=0; E3.input() ;
} E1.dis();
~example() { } E2.dis();
static int count; E3.dis() ;
void input( ) example::dis_count() ;
{ }
a+=100;b+=200;++count;
}
static void dis_count() 100,2001
{ 100,2002
cout<<count <<endl; 100,2003
} 3
void dis()
{
cout<<a<<,<<b<<count<<endl;
}};
int example ::count = 0;

S-ar putea să vă placă și