Sunteți pe pagina 1din 22

Experiment No.

(PART B: TO BE COMPLETED BY STUDENTS)

Part B

(Students must submit the soft copy as per following segments within two hours of the practical.
The soft copy must be uploaded on the Blackboard or emailed to the concerned lab in charge
faculties at the end of the practical in case the there is no Black board access available)

Roll No. A008 Name: Pronoy Debdas


Class: MCA Batch: B1
Date of Experiment: 19/09/16 Date of Submission: 03/10/16
Grade: A

B.1 Software Code with Input and output:

(Paste your software code and program input and output in following format, if there is error
then paste the specific error in the output part. In case of error with due permission of the
faculty extension can be given to submit the error free code with output in due course of time.
Students will be graded accordingly.)

P1.

Code:

#include <iostream>

#include<string.h>

using namespace std;

class staff

protected:

string name;

int code;

public:

staff()

{
cin.sync();

cout<<"Enter Name: ";

getline(cin,name);

cout<<"Enter Code: ";

cin>>code;

cout<<endl;

void get()

cout<<"Name: "<<name<<endl;

cout<<"Code: "<<code<<endl;

cout<<endl;

};

class teacher : public staff

protected:

string subject;

string publication;

public:

teacher()

cout<<"Enter Subject: ";

cin>>subject;

cout<<"Enter Publication: ";


cin>>publication;

cout<<endl;

void get()

staff::get();

cout<<"Subject: "<<subject<<endl;

cout<<"Publication: "<<publication<<endl;

cout<<endl;

};

class officer : public staff

protected:

char grade;

public:

officer()

cout<<"Enter Grade: ";

cin>>grade;

cout<<endl;

void get()

{
staff::get();

cout<<"Grade: "<<grade<<endl;

cout<<endl;

};

class typist : public staff

protected:

int speed;

public:

typist()

cout<<"Enter Speed: ";

cin>>speed;

cout<<endl;

void get()

staff::get();

cout<<"Speed: "<<speed<<endl;

cout<<endl;

};

class regular : public typist

{
public:

void get()

typist::get();

cout<<endl;

};

class casual : public typist

protected:

int daily_wages;

public:

casual()

cout<<"Enter Daily Wages: ";

cin>>daily_wages;

cout<<endl;

void get()

typist::get();

cout<<"Daily wages: "<<daily_wages;

cout<<endl;

};
int main()

cout<<"Enter Details for staff: "<<endl;

staff ob1;

ob1.get();

cout<<"Enter Details for Teacher: "<<endl;

teacher ob2;

ob2.get();

cout<<"Enter Details for Officer: "<<endl;

officer ob3;

ob3.get();

cout<<"Enter Details for Typist: "<<endl;

typist ob4;

ob4.get();

cout<<"Enter Details for Regular Typist: "<<endl;

regular ob5;

ob5.get();

cout<<"Enter Details for Causal Typist: "<<endl;

casual ob6;

ob6.get();

return 0;

Output:
P2.

Code:

#include <iostream>

#include<string.h>

using namespace std;

class staff

protected:

string name;

int code;

public:

staff()

cin.sync();

cout<<"Enter Name: ";

getline(cin,name);

cout<<"Enter Code: ";

cin>>code;

cout<<endl;

void get()

cout<<"Name: "<<name<<endl;

cout<<"Code: "<<code<<endl;

cout<<endl;
}

};

class education

protected:

string highest_educational;

string highest_professional;

};

class teacher : public staff,education

protected:

string subject;

string publication;

public:

teacher()

cout<<"Enter Subject: ";

cin>>subject;

cout<<"Enter Publication: ";

cin>>publication;

cout<<"Enter Highest Educational Qualification: ";

cin>>highest_educational;

cout<<"Enter Highest Professional Qualification: ";

cin>>highest_professional;

cout<<endl;
}

void get()

staff::get();

cout<<"Subject: "<<subject<<endl;

cout<<"Publication: "<<publication<<endl;

cout<<"Highest Educational Qualification: "<<highest_educational<<endl;

cout<<"Highest Professional Qualification: "<<highest_professional<<endl;

cout<<endl;

};

class officer : public staff,education

protected:

char grade;

public:

officer()

cout<<"Enter Grade: ";

cin>>grade;

cout<<"Enter Highest Educational Qualification: ";

cin>>highest_educational;

cout<<"Enter Highest Professional Qualification: ";

cin>>highest_professional;
cout<<endl;

void get()

staff::get();

cout<<"Grade: "<<grade<<endl;

cout<<"Highest Educational Qualification: "<<highest_educational<<endl;

cout<<"Highest Professional Qualification: "<<highest_professional<<endl;

cout<<endl;

};

class typist : public staff

protected:

int speed;

public:

typist()

cout<<"Enter Speed: ";

cin>>speed;

cout<<endl;

void get()

staff::get();
cout<<"Speed: "<<speed<<endl;

cout<<endl;

};

class regular : public typist

public:

void get()

typist::get();

cout<<endl;

};

class casual : public typist

protected:

int daily_wages;

public:

casual()

cout<<"Enter Daily Wages: ";

cin>>daily_wages;

cout<<endl;

void get()
{

typist::get();

cout<<"Daily wages: "<<daily_wages;

cout<<endl;

};

int main()

cout<<"Enter Details for staff: "<<endl;

staff ob1;

ob1.get();

cout<<"Enter Details for Teacher: "<<endl;

teacher ob2;

ob2.get();

cout<<"Enter Details for Officer: "<<endl;

officer ob3;

ob3.get();

cout<<"Enter Details for Typist: "<<endl;

typist ob4;

ob4.get();

cout<<"Enter Details for Regular Typist: "<<endl;

regular ob5;

ob5.get();

cout<<"Enter Details for Causal Typist: "<<endl;

casual ob6;
ob6.get();

return 0;

Output:
P3.

Code:

#include <iostream>

#include<string.h>

using namespace std;

class person

protected:

string name;

int code;

public:
person()

cin.sync();

cout<<"Enter Name: ";

getline(cin,name);

cout<<"Enter Code: ";

cin>>code;

cout<<endl;

void display()

cout<<"Name: "<<name<<endl;

cout<<"Code: "<<code<<endl;

cout<<endl;

};

class account : virtual public person

protected:

int pay;

public:

account()

cout<<"Enter Pay: ";

cin>>pay;
cout<<endl;

void display()

person::display();

cout<<"Pay: "<<pay<<endl;

cout<<endl;

};

class admin : virtual public person

protected:

int experience;

public:

admin()

cout<<"Enter Experience: ";

cin>>experience;

cout<<endl;

void display()

cout<<"Experience: "<<experience<<endl;

cout<<endl;
}

};

class master : public admin, account

public:

void update()

cout<<"\nEnter New values: "<<endl;

cin.sync();

cout<<"Enter Name: ";

getline(cin,name);

cout<<"Enter Code: ";

cin>>code;

cout<<"Enter Pay: ";

cin>>pay;

cout<<"Enter Experience: ";

cin>>experience;

cout<<endl;

void display()

account::display();

admin::display();

};
int main()

cout<<"Enter Details: "<<endl;

master ob1;

ob1.display();

ob1.update();

ob1.display();

return 0;

Output:
B.2 Conclusion:

Learnt about the different kinds of inheritance. Learnt about the various implementations and uses
of inheritance. Learnt about virtual base classes and their uses (Their importance when dealing with
multiple inheritance, when a derived class inherits multiple copies of the same members).

B.3 Question of Curiosity

(To be answered by student based on the practical performed and learning/observations)

Q.1 State TRUE or FALSE

1. C++ allows multiple inheritance.

True. For cases where same members of a class are inherited multiple number of times,
C++ has the provision of virtual base classes, which makes sure that only one copy of
the members of the virtual base class is inherited.

2. Constructors are inherited.

False. Constructors are special members that share the class name and are used to create
objects and initialize data members. They cannot be inherited by the sub classes.

3. Private is a legal Base class specifier while inheritance.

True. The compiler does not give any error, but the classes derived from that base class
will not be able to inherit the private members.

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