Question
Does this code meets these requirements? - Your program must be able to write all objects data to the binary file Community.dat, using the printToFile
- Your program must be able to write all objects data to the binary file Community.dat,
using the printToFile functions,
- Your program should be able to read and append to the Community.dat file as
needed, using the readFromFile functions,
- Your main file must be able to store/retrieve data to/from output/input files depending
on the users choice,
- It is not known how many objects will be added or their order of addition.
#include
class communityMember { unsigned long int id; string firstName; string lastName; string address; unsigned long int cellPhone;
public: communityMember() { } communityMember(unsigned long int id, string firstName, string lastName, string address, unsigned long int cellPhone) { this->id = id; this->firstName = firstName; this->lastName = lastName; this->address = address; this->cellPhone = cellPhone; } //setter methods void setId(unsigned long int id) { this->id = id; } void setFirstName(string firstName) { this->firstName = firstName; } void setLastName(string lastName) { this->lastName = lastName; }
void setAddress(string address) { this->address = address; }
void setCellPhone(unsigned long int cellPhone) { this->cellPhone = cellPhone; }
unsigned long int getId() { return id; }
string getFirstName() { return firstName; }
string getLastName() { return lastName; }
string getAddress() { return address; }
unsigned long int getCellPhone() { return cellPhone; }
virtual void ReadData() { cin >> id >> firstName >> lastName >> address >> cellPhone; }
virtual void print() { cout << "id: " << id << endl; cout << "Firstname: " << firstName << endl; cout << "Lastname: " << lastName << endl; cout << "Address: " << address << endl; cout << "Cellphone: " << cellPhone << endl; } };
class employee : public communityMember { double salary;
public: employee() { } employee(unsigned long int id, string firstName, string lastName, string address, unsigned long int cellPhone, double salary) : communityMember(id, firstName, lastName, address, cellPhone) { this->salary = salary; } void setSalary(double salary) { this->salary = salary; } double getSalary() { return salary; }
void ReadData() { communityMember::ReadData(); cin >> salary; }
void print() { communityMember::print(); cout << "Salary :" << salary << endl; } };
class student : public communityMember { double GPA; unsigned int courseLoadHours;
public: student() { } student(unsigned long int id, string firstName, string lastName, string address, unsigned long int cellPhone, double GPA, unsigned int courseLoadHours) : communityMember(id, firstName, lastName, address, cellPhone) { this->GPA = GPA; this->courseLoadHours = courseLoadHours; }
void setGPA(double gpa) { this->GPA = gpa; } void setCourseLoadHours(unsigned int clh) { this->courseLoadHours = clh; }
double getGPA() { return GPA; }
unsigned int getCourseLoadHours() { return courseLoadHours; }
void ReadData() { communityMember::ReadData(); cin >> GPA >> courseLoadHours; }
void print() { communityMember::print(); cout << "GPA :" << GPA << endl; cout << "Course Load Hours: " << courseLoadHours << endl; } };
class alumnus : public communityMember { unsigned int yearOfGraduation; string currentJob;
public: alumnus() { } alumnus(unsigned long int id, string firstName, string lastName, string address, unsigned long int cellPhone, double salary) : communityMember(id, firstName, lastName, address, cellPhone) { this->yearOfGraduation = yearOfGraduation; this->currentJob = currentJob; }
void setYearOfGraduation(unsigned int year) { yearOfGraduation = year; } void setCurrentJob(string job) { currentJob = job; }
unsigned int getYearOfGraduation() { return yearOfGraduation; }
string getCurrentJob() { return currentJob; }
void ReadData() { communityMember::ReadData(); cin >> yearOfGraduation >> currentJob; }
void print() { communityMember::print(); cout << "Yearof Graduation: " << yearOfGraduation << endl; cout << "Current job: " << currentJob << endl; } };
class faculty : public employee { string speciality; string academicRank;
public: faculty() { } faculty(unsigned long int id, string firstName, string lastName, string address, unsigned long int cellPhone, double salary, string speciality, string academicRank) : employee(id, firstName, lastName, address, cellPhone, salary) { this->speciality = speciality; this->academicRank = academicRank; }
void setSpeciality(string speciality) { this->speciality = speciality; } void setAcademicRank(string academicRank) { this->academicRank = academicRank; }
string getSpeciality() { return speciality; }
string getAcademicRank() { return academicRank; }
void ReadData() { employee::ReadData(); cin >> speciality >> academicRank; }
void print() { employee::print(); cout << "Speciality :" << speciality << endl; cout << "Academic Rank :" << academicRank << endl; } };
class staff : public employee { string department;
public: staff() { } staff(unsigned long int id, string firstName, string lastName, string address, unsigned long int cellPhone, double salary, string department) : employee(id, firstName, lastName, address, cellPhone, salary) { } void setDeparment(string department) { this->department = department; } string getDepartment() { return department; }
void ReadData() { employee::ReadData(); cin >> department; }
void print() { employee::print(); cout << "Department: " << department << endl; } };
class administrator : public faculty { string position;
public: administrator() { } administrator(unsigned long int id, string firstName, string lastName, string address, unsigned long int cellPhone, double salary, string speciality, string academicRank, string position) : faculty(id, firstName, lastName, address, cellPhone, salary, speciality, academicRank) { this->position = position; } void setPosition(string position) { this->position = position; } string getPosition() { return position; }
void ReadData() { faculty::ReadData(); cin >> position; }
void print() { faculty::print(); cout << "Position: " << position << endl; } };
class teacher : public faculty { unsigned int hoursPerWeek;
public: teacher() { } teacher(unsigned long int id, string firstName, string lastName, string address, unsigned long int cellPhone, double salary, string speciality, string academicRank, unsigned int hoursPerWeek) : faculty(id, firstName, lastName, address, cellPhone, salary, speciality, academicRank) { this->hoursPerWeek = hoursPerWeek; } void setHoursPerWeek(unsigned int hpw) { this->hoursPerWeek = hpw; } unsigned int getHoursPerWeek() { return hoursPerWeek; }
void ReadData() { faculty::ReadData(); cin >> hoursPerWeek; }
void print() { faculty::print(); cout << "Hours Per Week: " << hoursPerWeek << endl; } };
int main() {
communityMember cm; cm.ReadData(); cm.print(); cout << endl;
employee e; e.ReadData(); e.print(); cout << endl;
student std; std.ReadData(); std.print(); cout << endl;
alumnus alm; alm.ReadData(); alm.print(); cout << endl;
faculty fcl; fcl.ReadData(); fcl.print(); cout << endl;
staff stf; stf.ReadData(); stf.print(); cout << endl; administrator admin; admin.ReadData(); admin.print(); cout << endl;
teacher tchr; tchr.ReadData(); tchr.print(); cout << endl;
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started