Professional Documents
Culture Documents
Lab 11 Oop
Lab 11 Oop
Lab 11 Oop
Task 1:
Create Class Person with variables weight, height and gender. Create another Class Employee
with variables designation and HoursPerDay. Now create another class Teacher and inherit it
from Person and Employee and add function display() which should show all the details related
to teacher.
ANSWER:
Person.h:
#include<iostream>
#include<string>
using namespace std;
class person{
int height;
int weight;
string gender;
public:
void sethieght(int a);
int getheight();
void setweight(int a);
int getwieght();
void setgender(string a);
string getgender();
};
Teacher.h:
#include<iostream>
#include<string>
#include "employee.h"
using namespace std;
Employee.h:
public:
void setdesignation(string );
string getdesignation();
void sethours(int );
int gethours();
};
Main.cpp:
#include<iostream>
#include"teacher.h"
using namespace std;
int main(){
teacher obj1;
obj1.person::sethieght(44);
obj1.person::setweight(55);
obj1.person::setgender("male");
obj1.employee::setdesignation("Teacher");
obj1.employee::sethours(6);
obj1.display();
return 0;
}
Employee.cpp:
#include<iostream>
#include<string>
#include "employee.h"
using namespace std;
Person.cpp:
Task 2:
Create another class employee2 class in the EMPLOY program (Reference: Object Oriented
Programming by Robert Lafore, Chapter Inheritance). This new class should add a type double
data item called compensation, and also a string type called time to indicate whether the
employee is paid hourly, weekly, or monthly, with member functions input and display. For
simplicity you can change the manager, scientist, and laborer classes so they are derived from
employee2 and employee classes.
ANSWER:
Employee.h:
employee
{ private:
showdata() const;
};
Employee.cpp:
#include <iostream> #
include "Employee.h"
using namespace std; void
employee::getdata()
{ cout <<"Enter
> number;
Employee2.h:
double compensation;
string timeofpayment; void
input();
void display(); };
#include <iostream> #
include "Employee2.h"
using namespace std;
void employee2::input()
cout <<"Enter
timeofpayment;
void employee2::display()
# include "Labourer.h"
{ private: float
quotas; public:
Foreman.cpp:
# include "Foreman.h"
#include <iostream> using
namespace std; void
foreman::getdata()
{ laborer::getdata(); cout
<<"Enter quotas:"<<endl; cin >>
quotas; }
{ laborer::showdata();
cout <<"Quotas:"<<quotas; }
Labourer.h:
# include "Employee.h" # include
"Employee2.h" class laborer :
public employee
{ };
Labourer.cpp:
# include "Labourer.h"
#include <iostream> using
namespace std;
Manager.h:
# include "Employee.h" # include
"Employee2.h" class manager :
public employee
{ char title[LEN];
double dues; public:
void getdata(); void
showdata() const; };
Manager.cpp:
{ employee::showdata(); cout
Scientist.h:
{ private: int
publications; public:
void getdata(); void
showdata() const;
};
Scientist.cpp:
# include "Scientist.h"
#include <iostream> using
namespace std; void
scientist::getdata()
# include "Foreman.h"
#include <iostream>
using namespace std;
int main() { laborer
l1; laborer l2;
endl;
Total 40 Signature
Note : Attempt all tasks and get them checked by your Lab Instructor.