Design the following classes in C++ . Person class is the base class for other c
ID: 665504 • Letter: D
Question
Design the following classes in C++. Person class is the base class for other classes.
Person – A Person contains a first name, last name, street address, zip code, and phone number. The class also includes a method that sets each data field, using a series of output/input commands and a display method that displays all of a Person’s information on a multiple lines at the command line on the screen.
CollegeEmployee – A CollegeEmployee descends from Person. A CollegeEmployee also includes a Social Security number, an annual salary, and a department name, as well as methods that override the Person methods to accept and display all CollegeEmployee data. (25 points)
Faculty – Faculty descends from CollegeEmployee. This class also includes a Boolean field that indicates whether the Faculty member is tenured, as well as methods that override the CollegeEmployee methods to accept and display this additional piece of information. (25 points)
Student – Student descends from Person. In addition to the fields available in Person, a Student contains a major field of study and a grade point average, as well as methods that override the Person methods to accept and display these additional facts. (25 points)
Write an application named CollegeList that declares an array of four “regular” CollegeEmployees, three Faculty, and seven Students. Prompt the user – using a menu to specify which type of person’s data will be entered (‘C’, ‘F’, or ‘S’), or allow the user to quit (‘Q’). While the user chooses to continue (that is, does not quit), accept data entry for the appropriate type of Person. If the user attempts to enter data for more than four CollegeEmployees, three Faculty, or seven Students, display an error message. When the user quits, display a report on the screen listing each group of Persons under the appropriate heading “College Employees,” “Faculty,” or “Students.” If the user has not entered data for one or more types of Persons during a session, display an appropriate message under the appropriate heading. (25 points)
Explanation / Answer
Answer:
/******** Cpp program for Person,College Employee,Faculty,Student************/
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
class Person
{
string per_firstName;
string per_lastName;
string per_streetAddress;
int per_zip;
int per_phoneNumber;
public:
Person()
{
per_firstName="";
per_lastName="";
per_streetAddress="";
per_zip=0;
per_phoneNumber=0;
}
void setPersonFirstName()
{
cout<<" ENTER FIRST NAME:";
cin>>per_firstName;
}
void setPersonLastName()
{
cout<<" ENTER LAST NAME:";
cin>>per_lastName;
}
void setPersonStreetAddress()
{
cout<<" ENTER STREET NAME:";
cin>>per_streetAddress;
}
void setPersonZipcode()
{
cout<<" ENTER ZIPCODE:";
cin>>per_zip;
}
void setPersonPhoneNumber()
{
cout<<" ENTER PHONENUMBER:";
cin>>per_phoneNumber;
}
string getPersonFirstName()
{
return per_firstName;
}
string getPersonLastName()
{
return per_lastName;
}
string getPersonStreetAddress( )
{
return per_streetAddress;
}
int getPersonZipcode()
{
return per_zip;
}
int getPersonPhoneNumber()
{
return per_phoneNumber;
}
void displayPersonInfo()
{
cout<<" FIRSTNAME:"<<getPersonFirstName();
cout<<" LASTNAME:"<<getPersonLastName();
cout<<" sTREET:"<<getPersonStreetAddress( );
cout<<" ZIPCODE:"<<getPersonZipcode();
cout<<" PHONENEUMBER:"<<getPersonPhoneNumber();
}
};
class CollegeEmployee:public Person
{
private:
int col_ssn;
float col_AnnualSalary;
string col_DepartmentName;
public:
CollegeEmployee()
{
Person();
col_ssn=0;
col_AnnualSalary=0.0;
col_DepartmentName="";
}
void setEmployeeFirstName()
{
Person::setPersonFirstName();
}
void setEmployeeLastName()
{
Person::setPersonLastName();
}
void setEmployeeStreetAddress()
{
Person::setPersonStreetAddress();
}
void setEmployeeZipcode()
{
Person::setPersonZipcode();
}
void setEmployeePhoneNumber()
{
Person::setPersonPhoneNumber();
}
void setEmployeeSSN()
{
cout<<"ENTER SSN:";
cin>>col_ssn;
}
void setEmployeeAnnualSalary()
{
cout<<" ENTER SALARY:";
cin>>col_AnnualSalary;
}
void setEmployeeDepartName()
{
cout<<" ENTER DEPARTMENT NAME:";
cin>>col_DepartmentName;
}
string getEmployeeFirstName()
{
return Person::getPersonFirstName();
}
string getEmployeeLastName()
{
return Person::getPersonLastName();
}
string getEmployeeStreetAddress( )
{
return Person::getPersonStreetAddress( );
}
int getEmployeenZipcode()
{
return Person::getPersonZipcode();
}
int getEmployeePhoneNumber()
{
return Person::getPersonPhoneNumber();
}
int getEmployeeSSN()
{
return col_ssn;
}
float getEmployeeAnnualSalary()
{
return col_AnnualSalary;
}
string getEmployeeDepartName()
{
return col_DepartmentName;
}
void displayCollegeEmployeeInfo()
{
Person::displayPersonInfo();
cout<<" EMPLOYEE SSN:"<<getEmployeeSSN();
cout<<" EMPLOYEE ANNULASALARY:"<<getEmployeeAnnualSalary();
cout<<" EMPLOYEE DEPARTNAME:"<<getEmployeeDepartName();
}
};
class Faculty:public CollegeEmployee
{
bool faculty_tenure;
public:
Faculty()
{
CollegeEmployee();
faculty_tenure=false;
}
void setFacultyFirstName()
{
CollegeEmployee::setEmployeeFirstName();
}
void setFacultyLastName()
{
CollegeEmployee::setEmployeeLastName();
}
void setFacultyStreetAddress()
{
CollegeEmployee::setEmployeeStreetAddress();
}
void setFacultyZipcode()
{
CollegeEmployee::setEmployeeZipcode();
}
void setFacultyPhoneNumber()
{
CollegeEmployee::setEmployeePhoneNumber();
}
void setFacultySSN()
{
CollegeEmployee::setEmployeeSSN();
}
void setFacultyAnnualSalary()
{
CollegeEmployee::setEmployeeAnnualSalary();
}
void setFacultyDepartName()
{
CollegeEmployee::setEmployeeDepartName();
}
void setFacultyTenure()
{
cout<<" HAS FACULTY TENURED:";
cin>>faculty_tenure;
}
string getFacultyFirstName()
{
return CollegeEmployee::getEmployeeFirstName();
}
string getFacultyLastName()
{
return CollegeEmployee::getEmployeeLastName();
}
string getFacultyStreetAddress( )
{
return CollegeEmployee::getEmployeeStreetAddress( );
}
int getFacultyZipcode()
{
return CollegeEmployee::getEmployeenZipcode();
}
int getFacultyPhoneNumber()
{
return CollegeEmployee::getEmployeePhoneNumber();
}
int getFacultySSN()
{
return CollegeEmployee::getEmployeeSSN();
}
float getFacultyAnnualSalary()
{
return CollegeEmployee::getEmployeeAnnualSalary();
}
string getFacultyDepartName()
{
return CollegeEmployee::getEmployeeDepartName();
}
bool getFacultyTenure()
{
return faculty_tenure;
}
void displayFacultyInfo()
{
CollegeEmployee::displayCollegeEmployeeInfo();
cout<<" EMPLOYEE TENURE:"<<getFacultyTenure();
}
};
class Student:public Person
{
string majorfield;
int stu_grade;
public:
Student()
{
Person();
majorfield="";
stu_grade=0;
}
void setStudentFirstName()
{
Person::setPersonFirstName();
}
void setStudentLastName()
{
Person::setPersonLastName();
}
void setStudentStreetAddress()
{
Person::setPersonStreetAddress();
}
void setStudentZipcode()
{
Person::setPersonZipcode();
}
void setStudentPhoneNumber()
{
Person::setPersonPhoneNumber();
}
void setStudentMajorField()
{
cout<<"ENTER MAJORFIELD:";
cin>>majorfield;
}
void setStudentAverageGrade()
{
cout<<" ENTER AVERAGE GRADE:";
cin>>stu_grade;
}
string getStudentFirstName()
{
return Person::getPersonFirstName();
}
string getStudentLastName()
{
return Person::getPersonLastName();
}
string getStudentStreetAddress( )
{
return Person::getPersonStreetAddress( );
}
int getStudentZipcode()
{
return Person::getPersonZipcode();
}
int getStudentPhoneNumber()
{
return Person::getPersonPhoneNumber();
}
string getStudentMajorField()
{
return majorfield;
}
int getStudentAverageGrade()
{
return stu_grade;
}
void displayStudentInfo()
{
Person::displayPersonInfo();
cout<<" STUDENT MAJOR FIELD:"<<getStudentMajorField();
cout<<" STUDENT AVERAGE GRADE:"<<getStudentAverageGrade();
}
};
int main()
{
CollegeEmployee col_array[4];
Faculty fac_array[3];
Student stu_array[7];
int col_count=0;
int fac_count=0;
int stu_count=0;
char whilech1;
do
{
cout<<" ENTER ANY OF THE FOLLOWING:";
cout<<" 'C'-College Employee";
cout<<" 'F'-Faculty";
cout<<" 'S'-Student";
char usCh1;
cin>>usCh1;
switch(usCh1)
{
case 'C':
col_array[col_count].setEmployeeFirstName();
col_array[col_count].setEmployeeLastName();
col_array[col_count].setEmployeeStreetAddress();
col_array[col_count].setEmployeeZipcode();
col_array[col_count].setEmployeePhoneNumber();
col_array[col_count].setEmployeeSSN();
col_array[col_count].setEmployeeAnnualSalary();
col_array[col_count].setEmployeeDepartName();
col_count++;
break;
case 'F':
fac_array[fac_count].setFacultyFirstName();
fac_array[fac_count].setFacultyLastName();
fac_array[fac_count].setFacultyStreetAddress();
fac_array[fac_count].setFacultyZipcode();
fac_array[fac_count].setFacultyPhoneNumber();
fac_array[fac_count].setFacultySSN();
fac_array[fac_count].setFacultyAnnualSalary();
fac_array[fac_count].setFacultyDepartName();
fac_array[fac_count].setFacultyTenure();
fac_count++;
break;
case 'S':
stu_array[stu_count].setStudentFirstName();
stu_array[stu_count].setStudentLastName();
stu_array[stu_count].setStudentStreetAddress();
stu_array[stu_count].setStudentZipcode();
stu_array[stu_count].setStudentPhoneNumber();
stu_array[stu_count].setStudentMajorField();
stu_array[stu_count].setStudentAverageGrade();
stu_count++;
break;
default:
cout<<" Quit:";
break;
}
int i=0;
cout<<" College Employees:";
for(i=0;i<col_count;i++)
{
col_array[col_count].displayCollegeEmployeeInfo();
}
cout<<" Faculty:";
for(i=0;i<fac_count;i++)
{
fac_array[fac_count].displayCollegeEmployeeInfo();
}
cout<<"Student";
for(i=0;i<stu_count;i++)
{
stu_array[stu_count].displayStudentInfo();
}
cout<<" DO U WANT TO CONTINUE:";
cin>>whilech1;
}while(whilech1=='y'||whilech1=='Y');
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.