In: Computer Science
Previous Lab Code files:
PersonType.h:
#include <string>
using namespace std;
class personType
{
public:
void print() const;
void setName(string first, string middle, string last);
void setLastName(string last);
void setFirstName(string first);
void setMiddleName(string middle);
bool isLastName(string last) const;
bool isFirstName(string first) const;
string getFirstName() const;
string getMiddleName() const;
string getLastName() const;
personType(string first = "", string middle = "", string last = "");
private:
string firstName;
string middleName;
string lastName;
};
PersonTypeImp:
#include <iostream>
#include <string>
#include "personType.h"
using namespace std;
void personType::print() const
{
cout << firstName << " " << middleName << "
" << lastName;
}
void personType::setName(string first, string middle, string
last)
{
firstName = first;
middleName = middle;
lastName = last;
}
void personType::setLastName(string last)
{
lastName = last;
}
void personType::setFirstName(string first)
{
firstName = first;
}
void personType::setMiddleName(string middle)
{
middleName = middle;
}
bool personType::isLastName(string last) const
{
return (lastName == last);
}
bool personType::isFirstName(string first) const
{
return (firstName == first);
}
string personType::getFirstName() const
{
return firstName;
}
string personType::getMiddleName() const
{
return middleName;
}
string personType::getLastName() const
{
return lastName;
}
//constructor
personType::personType(string first, string middle, string
last)
{
firstName = first;
middleName = middle;
lastName = last;
}
Main:
#include <iostream>
#include "personType.h"
using namespace std;
int main()
{
personType student("Mary", "Beth", "Regan");
student.print();
cout<<endl;
if (student.isLastName("Regan"))
cout<<"Student\'s last name is Regan"<<endl;
else
cout<<"Student\'s last name is not Regan"<<endl;
if (student.isFirstName("Mary"))
cout<<"Student\'s first name is Mary"<<endl;
else
cout<<"Student\'s first name is not Mary"<<endl;
return 0;
}
Question:
Suppose that a class employeeType is derived from the class personType (see the previous lab code). Create employeeType class with following members
public members
void setData(string n = "", string d = "", int a = 0, double p = 0);
void setName(string n);
string getName() const;
void setDepartment(string dept);
string getDepartment() const;
void setAge(int a);
int getAge() const;
void setPay(double p);
double getPay() const;
employee(string n = "", string d = "", int a = 0, double p = 0);
Private members
string name;
string department;
int age;
double pay;
Write a program to test employeeType.
Language is C++
#include <iostream>
#include <string>
#include "personType.h"
using namespace std;
class employeeType : personType
{
private:
string name;
string department;
int age;
double pay;
public:
void setData(string n = "", string d = "", int a = 0, double p = 0)
{
name=n;
department=d;
age=a;
pay=pay;
}
void setName(string n)
{
name=n;
}
string getName() const
{
return name;
}
void setDepartment(string dept)
{
department=dept;
}
string getDepartment() const
{
return department;
}
void setAge(int a)
{
age=a;
}
int getAge() const
{
return age;
}
void setPay(double p)
{
pay=p;
}
double getPay() const
{
return pay;
}
employeeType(string n = "", string d = "", int a = 0, double p = 0)
{
name=n;
department=d;
age=a;
pay=p;
}
void print()//print overload
{
cout<<"Name: "<<name<<" department: "<<department<<" age: "<<age<<" pay: "<<pay;
}
};
int main()
{
employeeType employee("John","Business",25,250000);
employee.print();
cout<<endl;
return 0;
}
I hope it helps.