Lab 11 Oop

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Bahria University, Lahore Campus

Department of Computer Sciences


Lab Journal 11
(Spring 2018)

Course: Object Oriented Programming Lab Date:


Course Code: CSL - 210 Max Marks: 40
Faculty’s Name: Aasim Ali Lab Engineer: Shoaib Khan

Name: Mohammad Jasim Waqar Enroll No: 03-135172-055

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;

class teacher : public employee{


public:
void display();
};

Employee.h:

Department of Computer Science, BULC


#include<iostream>
#include<string>
#include "person.h"
using namespace std;

class employee : public person {


string designation;
int HoursPerDay;

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;

void employee::setdesignation(string a){


designation = a;
}
string employee:: getdesignation(){
return designation;
}
void employee:: sethours(int a){
HoursPerDay = a;
}

int employee:: gethours(){


return HoursPerDay;
}

Person.cpp:

Department of Computer Science, BULC


#include<iostream>
#include<string>
#include"person.h"
using namespace std;

void person ::sethieght(int a){


height = a;
}
int person::getheight(){
return height;
}
void person:: setweight(int a){
weight = a;
}
int person:: getwieght(){
return weight;
}
void person::setgender(string a){
gender = a;
}
string person:: getgender(){
return gender;
}
Teacher.cpp:
#include<iostream>
#include<string>
#include "teacher.h"
using namespace std;

void teacher :: display(){


cout << "height :: " << getheight() << endl << "weight :: " <<
getwieght() << endl;
cout << "Gender :: "<<getgender()<<endl;
cout << "Designation :: " << getdesignation()<<endl;
cout << "Hours per day ::" << gethours()<<endl;
}

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:

const int LEN = 80; class

employee

{ private:

Department of Computer Science, BULC


char name[LEN]; unsigned

long number; public:

void getdata(); void

showdata() const;

};

Employee.cpp:

#include <iostream> #

include "Employee.h"
using namespace std; void
employee::getdata()

{ cout <<"Enter

Name:"<<endl;; cin >> name;

cout << "Enter Number:"<<endl; cin

> number;

void employee::showdata() const

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


<< "Number:"<<number;

Employee2.h:

# include <string> using


namespace std; class
employee2

double compensation;
string timeofpayment; void
input();

void display(); };

Department of Computer Science, BULC


Employee2.cpp:

#include <iostream> #

include "Employee2.h"
using namespace std;

void employee2::input()

cout <<"Enter

compensation:"<<endl;; cin >>


compensation; cout << "Enter
Timeofpayment:"<<endl; cin >>

timeofpayment;

void employee2::display()

{ cout << "Compensation:" <<compensation;

cout << "Time of Payment:"<<timeofpayment; }


Foreman.h:

# include "Labourer.h"

class foreman : public laborer,public employee,public employee2

{ private: float
quotas; public:

void getdata(); void


showdata() const; };

Foreman.cpp:

# include "Foreman.h"
#include <iostream> using
namespace std; void
foreman::getdata()

{ laborer::getdata(); cout
<<"Enter quotas:"<<endl; cin >>
quotas; }

Department of Computer Science, BULC


void foreman::showdata() const

{ 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:

#include <iostream> # include

"Manager.h" using namespace std;


void manager::getdata() {
employee::getdata(); cout
<<"Enter title:"; cin >> title;
cout <<"Enter golf club dues:";
cin >> dues; }

void manager::showdata() const

{ employee::showdata(); cout

<<"Title:"<< title; cout <<"Golf


club dues:"<<dues;

Scientist.h:

Department of Computer Science, BULC


# include "Employee.h" # include
"Employee2.h" class scientist :
public employee

{ private: int
publications; public:
void getdata(); void
showdata() const;

};

Scientist.cpp:

# include "Scientist.h"
#include <iostream> using
namespace std; void
scientist::getdata()

{ employee::getdata(); cout <<"Enter number of


publications:"<<endl; cin >> publications;

void scientist::showdata() const


{ employee::showdata();

cout <<"Number of publications:"<<publications; }


Main.cpp:

# include "Foreman.h"
#include <iostream>
using namespace std;
int main() { laborer
l1; laborer l2;

foreman f1; foreman

f2; cout << endl;

cout <<"Enter data for laborer 1"<<endl; l1.getdata(); cout


<<"Enter data for foreman 1"<<endl;

f1.getdata(); cout << endl; cout <<"Data


on Laborer 1"<<endl; l1.showdata(); cout
<<"Data on Foreman 1"<<endl;
f1.showdata(); cout << endl; cout <<

endl;

cout <<"Enter data for Laborer 2"<<endl; l2.getdata(); cout


<<"Enter data for Foreman 2"<<endl;

Department of Computer Science, BULC


f2.getdata(); cout << endl; cout <<"Data
on Laborer 2"<<endl; l2.showdata(); cout

<<"Data on Foreman 2"<<endl;


f2.showdata(); cout << endl; return 0;

Lab Grading Sheet :


Max Obtained
Task Comments(if any)
Marks Marks
1. 10
2. 10
3. 10
4. 10

Total 40 Signature

Note : Attempt all tasks and get them checked by your Lab Instructor.

Department of Computer Science, BULC

You might also like