Design the following classes in C++ . Person class is the base class for other c
ID: 665411 • 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.
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.
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.
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.
It's a C++ assignment
write in c++ code and show output
Explanation / Answer
collegeList:
#ifndef COLLEGELIST_H_
#define COLLEGELIST_H_
class CollegeList {
public:
CollegeList();
virtual ~CollegeList();
};
int main(void)
{
CollegeEmployee colleges[4];
Faculty facultys[3];
Student students[7];
cout << "Enter your choice 'C’, ‘F’,‘S’ OR 'Q'" << endl;
char choice;
int var;
while(true)
{
getline(cin, chioce);
if('C'== choice)
{
for (var = 0; var < 4; ++var) {
CollegeEmployee collegeEmployee;
cout<<"Enter first name: " << endl;
getline(cin, collegeEmployee.firstName);
cout<<"Enter Last name: " << endl;
getline(cin, collegeEmployee.lastName);
cout<<"Enter address: " << endl;
getline(cin, collegeEmployee.streetaddr);
cout<<"Enter zipcode: " << endl;
getline(cin, collegeEmployee.zipcode);
cout<<"Enter zipcode: " << endl;
getline(cin, collegeEmployee.phoneno);
cout<<"Enter SocialSecuritynumber: " << endl;
getline(cin, collegeEmployee.SocialSecuritynumber);
cout<<"Enter annualSalary: " << endl;
getline(cin, collegeEmployee.annualSalary);
cout<<"Enter departmentname: " << endl;
getline(cin, collegeEmployee.departmentname);
colleges[var]=collegeEmployee;
}
}
else if ('F'== choice) {
for (var = 0; var < 3; ++var) {
cout<<"Enter first name: " << endl;
Faculty fac;
getline(cin, fac.firstName);
cout<<"Enter Last name: " << endl;
getline(cin, fac.lastName);
cout<<"Enter address: " << endl;
getline(cin, fac.streetaddr);
cout<<"Enter zipcode: " << endl;
getline(cin, fac.zipcode);
cout<<"Enter zipcode: " << endl;
getline(cin, fac.phoneno);
cout<<"Enter zipcode: " << endl;
getline(cin, fac.phoneno);
cout<<"Enter tenured: " << endl;
getline(cin, fac.facultyTenured);
facultys[var]=fac;
}
}
else if ('S'== choice) {
for (var = 0; var < 7; ++var) {
Student stu;
cout<<"Enter first name: " << endl;
getline(cin, stu.firstName);
cout<<"Enter Last name: " << endl;
getline(cin, stu.lastName);
cout<<"Enter address: " << endl;
getline(cin, stu.streetaddr);
cout<<"Enter zipcode: " << endl;
getline(cin, stu.zipcode);
cout<<"Enter phone no: " << endl;
getline(cin, stu.phoneno);
cout<<"Enter studentField: " << endl;
getline(cin, stu.studentField);
cout<<"Enter studentGrade: " << endl;
getline(cin, stu.studentGrade);
students[var]=stu;
}
}
else if ('Q'== choice) {
for (var = 0; var < 4; ++var) {
CollegeEmployee cemp=colleges[var];
cout<<"firstname:"<< cemp.getFirstName()<<endl;
cout<<"lastname:"<< cemp.getLastName()<<endl;
cout<<"streetaddr:"<< cemp.getStreetaddr()<<endl;
cout<<"zipcode:"<< cemp.getZipcode()<<endl;
cout<<"sercurity no:"<< cemp.getSocialSecuritynumber()<<endl;
cout<<"annual sal:"<< cemp.getAnnualSalary()<<endl;
cout<<"dept::"<< cemp.getDepartmentname()<<endl;
}
for (var = 0; var < 3; ++var) {
Faculty f=facultys[var];
cout<<"firstname:"<< f.getFirstName()<<endl;
cout<<"lastname:"<< f.getLastName()<<endl;
cout<<"streetaddr:"<< f.getStreetaddr()<<endl;
cout<<"zipcode:"<< f.getZipcode()<<endl;
cout<<"tenured:"<< f.isFacultyTenured()<<endl;
}
for (var = 0; var < 7; ++var) {
Student s=students[var];
cout<<"firstname:"<< s.getFirstName()<<endl;
cout<<"lastname:"<< s.getLastName()<<endl;
cout<<"streetaddr:"<< s.getStreetaddr()<<endl;
cout<<"zipcode:"<< s.getZipcode()<<endl;
cout<<"student grade:"<<s.getStudentGrade()<<endl;
cout<<"student field:"<< s.getStudentField()<<endl;
}
exit(0);
}
}
return 0;
}
#endif /* COLLEGELIST_H_ */
Person.h
#ifndef PERSON_H_
#define PERSON_H_
class Person {
public:
Person();
virtual ~Person();
char getFirstName() const {
return firstName;
}
void setFirstName(char firstName) {
this->firstName = firstName;
}
char getLastName() const {
return lastName;
}
void setLastName(char lastName) {
this->lastName = lastName;
}
int getPhoneno() const {
return phoneno;
}
void setPhoneno(int phoneno) {
this->phoneno = phoneno;
}
char getStreetaddr() const {
return streetaddr;
}
void setStreetaddr(char streetaddr) {
this->streetaddr = streetaddr;
}
int getZipcode() const {
return zipcode;
}
void setZipcode(int zipcode) {
this->zipcode = zipcode;
}
public:
char firstName;
char lastName;
char streetaddr;
int zipcode;
int phoneno;
};
#endif /* PERSON_H_ */
collegeEmployee.h
#ifndef COLLEGEEMPLOYEE_H_
#define COLLEGEEMPLOYEE_H_
#include "Person.h"
class CollegeEmployee: public Person {
public:
CollegeEmployee();
virtual ~CollegeEmployee();
double getAnnualSalary() const {
return annualSalary;
}
void setAnnualSalary(double annualSalary) {
this->annualSalary = annualSalary;
}
char getDepartmentname() const {
return departmentname;
}
void setDepartmentname(char departmentname) {
this->departmentname = departmentname;
}
int getSocialSecuritynumber() const {
return SocialSecuritynumber;
}
void setSocialSecuritynumber(int socialSecuritynumber) {
SocialSecuritynumber = socialSecuritynumber;
}
public:
int SocialSecuritynumber;
double annualSalary;
char departmentname;
};
#endif /* COLLEGEEMPLOYEE_H_ */
Faculty.h
#ifndef FACULTY_H_
#define FACULTY_H_
#include "CollegeEmployee.h"
class Faculty: public CollegeEmployee {
public:
Faculty();
virtual ~Faculty();
bool isFacultyTenured() const {
return facultyTenured;
}
void setFacultyTenured(bool facultyTenured) {
this->facultyTenured = facultyTenured;
}
bool facultyTenured;
};
#endif /* FACULTY_H_ */
Student.h
#ifndef STUDENT_H_
#define STUDENT_H_
#include "Faculty.h"
#include <iostream>
#include <studio.h>
class Student: public Faculty {
public:
Student();
virtual ~Student();
char getStudentField() const {
return studentField;
}
void setStudentField(char studentField) {
this->studentField = studentField;
}
char getStudentGrade() const {
return studentGrade;
}
void setStudentGrade(char studentGrade) {
this->studentGrade = studentGrade;
}
public:
char studentField;
char studentGrade;
};
#endif /* STUDENT_H_ */
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.