(Please use c++ code) 1. Write the code to implement the class Person. A person
ID: 3800303 • Letter: #
Question
(Please use c++ code)
1. Write the code to implement the class Person. A person has a name, address,telephone number and and E-Mail address. Be sure to include accessor functions to return each of these values. Create a derived class Student which has a class status (freshman, sophomore, junior, or senior) and create a derived class Employee which has the attributes office, salary, and date hired. Now define a class Faculty which is derived from Employee. The attributes for the Faculty class are rank (professor, associate, assistant, lecturer) and status (tenured, tenure-track, visiting, non-tenure-track). Define a class Staff derived from Employee. Staff has a single attribute indicating the position (job title). Write a test main program that creates a Person, Student, Employee, Faculty, and Staff object. Use accessor functions on each object to show they are working.
Explanation / Answer
#include <iostream>
using namespace std;
class Person //base class
{
private:
string name;
string address;
string telephoneNumber;
string email;
public:
Person(){} //default constructor
Person(string name,string address,string telephoneNumber,string email) //parameterized constructor
{
this->name = name ;
this->address = address;
this->telephoneNumber = telephoneNumber;
this->email = email;
}
//accessor functions
string getName()
{
return name;
}
string getAddress()
{
return address;
}
string getTelephoneNumber()
{
return telephoneNumber;
}
string getEmail()
{
return email;
}
};
class Student :public Person //derived from person class
{
private:
string status;
public:
Student(){}
//parameterized constructor passes arguments to base class constructor
Student(string name,string address,string telephoneNumber,string email,string status):Person(name,address,telephoneNumber,email)
{
this->status = status;
}
string getStatus()
{
return status;
}
};
class Employee :public Person
{
private:
string office;
double salary;
string dateHired;
public:
Employee(){}
//parameterized constructor passes arguments to base class constructor
Employee(string name,string address,string telephoneNumber,string email,string office,double salary,string dateHired):Person(name,address,telephoneNumber,email)
{
this->office = office;
this->salary = salary;
this->dateHired = dateHired;
}
string getOffice()
{
return office;
}
double getSalary()
{
return salary;
}
string getDateHired()
{
return dateHired;
}
};
class Faculty :public Employee
{
private:
string rank;
string status;
public:
Faculty(){}
//parameterized constructor passes arguments to base class constructor
Faculty(string name,string address,string telephoneNumber,string email,string office,double salary,string dateHired,string rank,string status):Employee(name,address,telephoneNumber,email,office,salary,dateHired)
{
this->rank =rank;
this->status = status;
}
string getRank()
{
return rank;
}
string getStatus()
{
return status;
}
};
class Staff : public Employee
{
private :
string position;
public:
Staff(){}
Staff(string name,string address,string telephoneNumber,string email,string office,double salary,string dateHired,string position):Employee(name,address,telephoneNumber,email,office,salary,dateHired)
{
this->position = position;
}
string getPosition()
{
return position;
}
};
int main()
{
Person person1("Nicholos Moore","45,Downtown,NYC","0797877877","nic@email.com");
cout<<"Person Address : "<<person1.getAddress();
Student student1("Samara Singh","576 LA","6769704","samara@email.com","freshman");
cout<<" Student Name : "<<student1.getName();
Employee employee1("John Smith","6465 street no 2,NYC","987564543","johnsmith@email.com","office No 1",5465.00,"January 14,2009");
cout<<" Employee telephone : "<<employee1.getTelephoneNumber();
Staff staff1("Candy Williams","6235 street no 7,NYC","9872222543","candy@email.com","office No 4",3460.00,"March 20,2001","Clerk");
cout<<" Staff office : "<<staff1.getOffice();
Faculty faculty1("Dr. David louis","345-Hillside,NJ","0123-66688797","drdavid@mail.com","Physics Department",8970.00,"september 25,2011","professor","tenured");
cout<<" Faculty Name : "<<faculty1.getName()<<" Address : "<<faculty1.getAddress()<<" Status : "<<faculty1.getStatus();
cout<<" Salary : "<<faculty1.getSalary();
return 0;
}
Output:
Student Name : Samara Singh
Employee Telephone : 987564543
Staff Office : office No 4
Faculty Name : Dr. David louis
Address: 345,Hillside NJ
Status : tenured
Salary : 8970
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.