Below is my C++ mid-term project.
BACKGROUND: A condo rental simulation where the user chooses the size and type of apartment, before choosing to either add, delete, modify or list the tenants in the apartment.
REQUEST: Everything runs accordingly, however, one of the requirements is that my code contains at least one struct function which I am not sure how to include. Please incorporate a struct into my code that is used when my code is ran without changing much of my code. My code requires arrays, and 3 class inheritance which I already have so please do not modify much of my class inheritances.
Thanks!
(PS please provide answer in C++)
#include
#include class Apartment public: Apartment() {} Apartment (int floor, int unit) FloorNum = floor; UnitNum = unit; Apartment() {} virtual std::string getSecondTenantName() return ""; virtual int getSecondTenantAge() return 0; int FloorNum; int UnitNum; }; class SingleRoomApartment: public Apartment public: SingleRoomApartment (int FloorNum, int UnitNum); SingleRoomApartment(); }; SingleRoomApartment:: SingleRoomApartment(int FloorNum, int UnitNum) : Apartment (FloorNum, UnitNum) Y class DoubleRoomApartment: public Apartment public: DoubleRoomApartment (int FloorNum, int UnitNum, std::string secondTenant, int age2); DoubleRoomApartment(); std::string getSecondTenantName(); int getSecondTenantAge(); std::string SecondTenantName; int SecondTenantAge; DoubleRoomApartment:: DoubleRoomApartment(int FloorNum, int UnitNum, std::string secondTenant, int age2): Apartment (FloorNum, UnitNum) SecondTenantName = secondTenant; SecondTenantAge = age2; std::string DoubleRoomApartment::getSecondTenantName() return SecondTenantName; int DoubleRoomApartment::getSecondTenantAge() return Second TenantAge; class Permanent Apartment: public Apartment public: Permanent Apartment(int FloorNum, int UnitNum); Permanent Apartment(); }; PermanentApartment::PermanentApartment(int FloorNum, int UnitNum): Apartment (FloorNum, UnitNum) using namespace std; class Tenant public: Tenant() Tenant_Age = 0; Tenant_Name = ""; Tenant_Months = 0; apartment = new Apartment(0,0); Tenant(int Age, string Name, int Months) Tenant_Age = Age; Tenant_Name = Name; Tenant_Months = 0; apartment = new Apartment(0,0); Tenant() {} void print(); string Tenant_Name; int Tenant_Age; int Tenant_Months; Apartment* apartment; }; void Tenant::print() std::string secondTenantName = apartment->getSecondTenantName(); if (secondTenantName != "") int second TenantAge = apartment->getSecondTenantAge(); coutTenant_Name=="") if (apartment Type == "SINGLE") allTenants[i]->apartment = new Single RoomApartment (FloorNum, UnitNum); allTenants[i]->Tenant_Months = Months Rent; else if (apartment Type == "DOUBLE") cout>secondTenant; cout>age2; allTenants[i]->apartment = new DoubleRoomApartment (FloorNum, UnitNum, secondTenant, age2); allTenants[i]->Tenant_Months = Months Rent; else allTenants [i]->apartment = new Permanent Apartment (FloorNum, UnitNum); allTenants [i]->Tenant_Months = 1000; allTenants[i]->Tenant_Name = Name; allTenants [i]->Tenant_Ager Age; // coutprint(); return; void CondoManagement: :ModifyRecord(std::string apartmentType, int FloorNum, int UnitNum, string Name, int Age, int MonthsRent, std::string secondTenant, int age2 = 0) for(int i = 0; is totalUnits; i++) if (apartmentType == "SINGLE") if(allTenants[i] ->apartment->FloorNum == FloorNum && allTenants[i]->apartment->UnitNum == UnitNum) allTenants[i]->Tenant_Name = Name; allTenants[i]->Tenant_Age= Age; allTenants (i)->Tenant_Months = MonthsRent; coutprint(); return; else if (apartment Type == "DOUBLE") if(allTenants[i]->apartment->FloorNum == FloorNum && allTenants[i]->apartment->UnitNum == UnitNum) allTenants [i]->Tenant_Name = Name; allTenants [i]->Tenant_Ager Age; allTenants[i]->Tenant_Months = MonthsRent; cout>secondTenant; cout>age2; allTenants[i]->apartment = new DoubleRoomApartment (FloorNum, UnitNum, secondTenant, age2); coutprint(); return; else if (apartment Type == "PERMANENT") if(allTenants[i]->apartment->FloorNum == FloorNum && allTenants[i]->apartment->UnitNum == UnitNum) allTenants [i]->Tenant_Name = Name; allTenants[i]->Tenant_Age= Age; allTenants[i]->Tenant_Months = 1000; coutprint(); return; coutapartment->FloorNum == FloorNum && allTenants [i]->apartment->UnitNum == UnitNum) delete allTenants[i]->apartment; allTenants[i]->Tenant_Name = ""; coutTenant_Name !="") coutapartment->FloorNumapartment- >UnitNumprint(); // Helper function, do the same for double and permanent void singleApartment (CondoManagement* condo_management) int command, floor, unit, age, month, FloorNum, UnitNum, age2; string name; cout>FloorNum; cout>UnitNum; while (true) cout>command; if (command >= 1 && command >floor; cout>unit; while(floor > FloorNum || floor UnitNum|| unit >floor; cout>unit; if (command == 1) cout>name; cout>age; cout>month; condo_management->AddRecord("SINGLE", floor, unit, name, age, month, "", age2); else if (command == 2) condo_management->DeleteRecord(floor, unit); else if (command == 3) cout>name; cout>age; cout>month; condo_management->ModifyRecord ("SINGLE", floor, unit, name, age, month,"", age2); else if (command == 0) return; else if (command == 4) condo_management->ListRecord(); else cout>FloorNum; cout>UnitNum; while (true) cout>command; if (command >= 1 && command >floor; cout>unit; while(floor > FloorNum | floor UnitNum|| unit >floor; cout>unit; if (command == 1) cout>name; cout>age; cout>month; condo_management->AddRecord ("DOUBLE", floor, unit, name, age, month, "", age2); else if (command == 2) condo_management->DeleteRecord(floor, unit); else if (command == 3) cout>name; cout>age; cout>month; condo_management->ModifyRecord ("DOUBLE", floor, unit, name, age, month, "", age2); else if (command == 0) return; else if (command == 4) condo_management->ListRecord(); else cout>FloorNum; cout>UnitNum; while (true) cout>command; if(command >= 1 && command >floor; cout>unit; while(floor > FloorNum || floor UnitNum|| unit >floor; cout>unit; if (command == 1) cout>name; cout>age; coutAddRecord("PERMANENT", floor, unit, name, age, month, "", age2); else if (command == 2) condo_management->DeleteRecord(floor, unit); else if (command == 3) cout>name; cout>age; coutModifyRecord("PERMANENT", floor, unit, name, age, month, "", age2); else if (command == 0) return; else if (command == 4) condo_management->ListRecord(); else coutAddRecord ("SINGLE", 1, 1, "cherry", 2, 2, ""); condo_management->AddRecord ("DOUBLE", 1, 2, "xyz", 2, 2, "abc"); condo_management->ListRecord();*/ while(true) { cout>choice; if (choice == 0) return 0; if (choice == 1) singleApartment (condo_management); else if (choice == 2) doubleApartment (condo_management); else if (choice == 3) permanent Apartment (condo_management); else cout #include class Apartment public: Apartment() {} Apartment (int floor, int unit) FloorNum = floor; UnitNum = unit; Apartment() {} virtual std::string getSecondTenantName() return ""; virtual int getSecondTenantAge() return 0; int FloorNum; int UnitNum; }; class SingleRoomApartment: public Apartment public: SingleRoomApartment (int FloorNum, int UnitNum); SingleRoomApartment(); }; SingleRoomApartment:: SingleRoomApartment(int FloorNum, int UnitNum) : Apartment (FloorNum, UnitNum) Y class DoubleRoomApartment: public Apartment public: DoubleRoomApartment (int FloorNum, int UnitNum, std::string secondTenant, int age2); DoubleRoomApartment(); std::string getSecondTenantName(); int getSecondTenantAge(); std::string SecondTenantName; int SecondTenantAge; DoubleRoomApartment:: DoubleRoomApartment(int FloorNum, int UnitNum, std::string secondTenant, int age2): Apartment (FloorNum, UnitNum) SecondTenantName = secondTenant; SecondTenantAge = age2; std::string DoubleRoomApartment::getSecondTenantName() return SecondTenantName; int DoubleRoomApartment::getSecondTenantAge() return Second TenantAge; class Permanent Apartment: public Apartment public: Permanent Apartment(int FloorNum, int UnitNum); Permanent Apartment(); }; PermanentApartment::PermanentApartment(int FloorNum, int UnitNum): Apartment (FloorNum, UnitNum) using namespace std; class Tenant public: Tenant() Tenant_Age = 0; Tenant_Name = ""; Tenant_Months = 0; apartment = new Apartment(0,0); Tenant(int Age, string Name, int Months) Tenant_Age = Age; Tenant_Name = Name; Tenant_Months = 0; apartment = new Apartment(0,0); Tenant() {} void print(); string Tenant_Name; int Tenant_Age; int Tenant_Months; Apartment* apartment; }; void Tenant::print() std::string secondTenantName = apartment->getSecondTenantName(); if (secondTenantName != "") int second TenantAge = apartment->getSecondTenantAge(); coutTenant_Name=="") if (apartment Type == "SINGLE") allTenants[i]->apartment = new Single RoomApartment (FloorNum, UnitNum); allTenants[i]->Tenant_Months = Months Rent; else if (apartment Type == "DOUBLE") cout>secondTenant; cout>age2; allTenants[i]->apartment = new DoubleRoomApartment (FloorNum, UnitNum, secondTenant, age2); allTenants[i]->Tenant_Months = Months Rent; else allTenants [i]->apartment = new Permanent Apartment (FloorNum, UnitNum); allTenants [i]->Tenant_Months = 1000; allTenants[i]->Tenant_Name = Name; allTenants [i]->Tenant_Ager Age; // coutprint(); return; void CondoManagement: :ModifyRecord(std::string apartmentType, int FloorNum, int UnitNum, string Name, int Age, int MonthsRent, std::string secondTenant, int age2 = 0) for(int i = 0; is totalUnits; i++) if (apartmentType == "SINGLE") if(allTenants[i] ->apartment->FloorNum == FloorNum && allTenants[i]->apartment->UnitNum == UnitNum) allTenants[i]->Tenant_Name = Name; allTenants[i]->Tenant_Age= Age; allTenants (i)->Tenant_Months = MonthsRent; coutprint(); return; else if (apartment Type == "DOUBLE") if(allTenants[i]->apartment->FloorNum == FloorNum && allTenants[i]->apartment->UnitNum == UnitNum) allTenants [i]->Tenant_Name = Name; allTenants [i]->Tenant_Ager Age; allTenants[i]->Tenant_Months = MonthsRent; cout>secondTenant; cout>age2; allTenants[i]->apartment = new DoubleRoomApartment (FloorNum, UnitNum, secondTenant, age2); coutprint(); return; else if (apartment Type == "PERMANENT") if(allTenants[i]->apartment->FloorNum == FloorNum && allTenants[i]->apartment->UnitNum == UnitNum) allTenants [i]->Tenant_Name = Name; allTenants[i]->Tenant_Age= Age; allTenants[i]->Tenant_Months = 1000; coutprint(); return; coutapartment->FloorNum == FloorNum && allTenants [i]->apartment->UnitNum == UnitNum) delete allTenants[i]->apartment; allTenants[i]->Tenant_Name = ""; coutTenant_Name !="") coutapartment->FloorNumapartment- >UnitNumprint(); // Helper function, do the same for double and permanent void singleApartment (CondoManagement* condo_management) int command, floor, unit, age, month, FloorNum, UnitNum, age2; string name; cout>FloorNum; cout>UnitNum; while (true) cout>command; if (command >= 1 && command >floor; cout>unit; while(floor > FloorNum || floor UnitNum|| unit >floor; cout>unit; if (command == 1) cout>name; cout>age; cout>month; condo_management->AddRecord("SINGLE", floor, unit, name, age, month, "", age2); else if (command == 2) condo_management->DeleteRecord(floor, unit); else if (command == 3) cout>name; cout>age; cout>month; condo_management->ModifyRecord ("SINGLE", floor, unit, name, age, month,"", age2); else if (command == 0) return; else if (command == 4) condo_management->ListRecord(); else cout>FloorNum; cout>UnitNum; while (true) cout>command; if (command >= 1 && command >floor; cout>unit; while(floor > FloorNum | floor UnitNum|| unit >floor; cout>unit; if (command == 1) cout>name; cout>age; cout>month; condo_management->AddRecord ("DOUBLE", floor, unit, name, age, month, "", age2); else if (command == 2) condo_management->DeleteRecord(floor, unit); else if (command == 3) cout>name; cout>age; cout>month; condo_management->ModifyRecord ("DOUBLE", floor, unit, name, age, month, "", age2); else if (command == 0) return; else if (command == 4) condo_management->ListRecord(); else cout>FloorNum; cout>UnitNum; while (true) cout>command; if(command >= 1 && command >floor; cout>unit; while(floor > FloorNum || floor UnitNum|| unit >floor; cout>unit; if (command == 1) cout>name; cout>age; coutAddRecord("PERMANENT", floor, unit, name, age, month, "", age2); else if (command == 2) condo_management->DeleteRecord(floor, unit); else if (command == 3) cout>name; cout>age; coutModifyRecord("PERMANENT", floor, unit, name, age, month, "", age2); else if (command == 0) return; else if (command == 4) condo_management->ListRecord(); else coutAddRecord ("SINGLE", 1, 1, "cherry", 2, 2, ""); condo_management->AddRecord ("DOUBLE", 1, 2, "xyz", 2, 2, "abc"); condo_management->ListRecord();*/ while(true) { cout>choice; if (choice == 0) return 0; if (choice == 1) singleApartment (condo_management); else if (choice == 2) doubleApartment (condo_management); else if (choice == 3) permanent Apartment (condo_management); else cout