Documente Academic
Documente Profesional
Documente Cultură
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)
(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>
class staff
protected:
string name;
int code;
public:
staff()
{
cin.sync();
getline(cin,name);
cin>>code;
cout<<endl;
void get()
cout<<"Name: "<<name<<endl;
cout<<"Code: "<<code<<endl;
cout<<endl;
};
protected:
string subject;
string publication;
public:
teacher()
cin>>subject;
cout<<endl;
void get()
staff::get();
cout<<"Subject: "<<subject<<endl;
cout<<"Publication: "<<publication<<endl;
cout<<endl;
};
protected:
char grade;
public:
officer()
cin>>grade;
cout<<endl;
void get()
{
staff::get();
cout<<"Grade: "<<grade<<endl;
cout<<endl;
};
protected:
int speed;
public:
typist()
cin>>speed;
cout<<endl;
void get()
staff::get();
cout<<"Speed: "<<speed<<endl;
cout<<endl;
};
{
public:
void get()
typist::get();
cout<<endl;
};
protected:
int daily_wages;
public:
casual()
cin>>daily_wages;
cout<<endl;
void get()
typist::get();
cout<<endl;
};
int main()
staff ob1;
ob1.get();
teacher ob2;
ob2.get();
officer ob3;
ob3.get();
typist ob4;
ob4.get();
regular ob5;
ob5.get();
casual ob6;
ob6.get();
return 0;
Output:
P2.
Code:
#include <iostream>
#include<string.h>
class staff
protected:
string name;
int code;
public:
staff()
cin.sync();
getline(cin,name);
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;
};
protected:
string subject;
string publication;
public:
teacher()
cin>>subject;
cin>>publication;
cin>>highest_educational;
cin>>highest_professional;
cout<<endl;
}
void get()
staff::get();
cout<<"Subject: "<<subject<<endl;
cout<<"Publication: "<<publication<<endl;
cout<<endl;
};
protected:
char grade;
public:
officer()
cin>>grade;
cin>>highest_educational;
cin>>highest_professional;
cout<<endl;
void get()
staff::get();
cout<<"Grade: "<<grade<<endl;
cout<<endl;
};
protected:
int speed;
public:
typist()
cin>>speed;
cout<<endl;
void get()
staff::get();
cout<<"Speed: "<<speed<<endl;
cout<<endl;
};
public:
void get()
typist::get();
cout<<endl;
};
protected:
int daily_wages;
public:
casual()
cin>>daily_wages;
cout<<endl;
void get()
{
typist::get();
cout<<endl;
};
int main()
staff ob1;
ob1.get();
teacher ob2;
ob2.get();
officer ob3;
ob3.get();
typist ob4;
ob4.get();
regular ob5;
ob5.get();
casual ob6;
ob6.get();
return 0;
Output:
P3.
Code:
#include <iostream>
#include<string.h>
class person
protected:
string name;
int code;
public:
person()
cin.sync();
getline(cin,name);
cin>>code;
cout<<endl;
void display()
cout<<"Name: "<<name<<endl;
cout<<"Code: "<<code<<endl;
cout<<endl;
};
protected:
int pay;
public:
account()
cin>>pay;
cout<<endl;
void display()
person::display();
cout<<"Pay: "<<pay<<endl;
cout<<endl;
};
protected:
int experience;
public:
admin()
cin>>experience;
cout<<endl;
void display()
cout<<"Experience: "<<experience<<endl;
cout<<endl;
}
};
public:
void update()
cin.sync();
getline(cin,name);
cin>>code;
cin>>pay;
cin>>experience;
cout<<endl;
void display()
account::display();
admin::display();
};
int main()
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).
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.
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.
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.