Menu

(Solved) : C Mid Term Project Background Condo Rental Simulation User Chooses Size Type Apartment Cho Q43920907 . . .

Below is my C++ mid-term project.

BACKGROUND: A condo rental simulation where the user chooses thesize 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 therequirements is that my code contains at least one struct functionwhich I am not sure how to include. Please incorporate a structinto my code that is used when my code is ran without changing muchof my code. My code requires arrays, and 3 class inheritance whichI already have so please do not modify much of my classinheritances.

Thanks!

(PS please provide answer in C++)

#include <iostream> #include <string> class Apartment public: Apartment() {} Apartment (int floor, int unit) FloorNum = floorclass Permanent Apartment: public Apartment public: Permanent Apartment(int FloorNum, int UnitNum); Permanent Apartment(); };allTenants = new Tenant*[FloorNum*UnitNum]; for (int i = 0; i<FloorNum*UnitNum; i++) allTenants[i] = new Tenant(); totalUnitsfor(int i = 0; is totalUnits; i++) if (apartmentType == SINGLE) if(allTenants[i] ->apartment->FloorNum == FloorNum && allTeallTenants[i]->Tenant_Name = ; cout<<Deleted/Reset position < return; i <<endl; cout<<Tenant can not be deleted<<endl;cout<<Enter new name: ; cin>>name; cout<<Enter new age ; cin>>age; cout<<Enter months stay ; cin>>month; condo_managemeelse if (command == 3) cout<<Enter new name: ; cin>>name; cout<<Enter new age ; cin>>age; cout<<Enter months stay ; cincondo_management->DeleteRecord(floor, unit); else if (command == 3) cout<<Enter new name: ; cin>>name; cout<<Enter new age

#include <iostream> #include <string> 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(); cout<<“[First Tenant: “<<Tenant_Name<<“, First Age: “<<Tenant_Age<<“, Months Stay: “<<Tenant_Months<<“], [Second Tenant: “<<secondTenantName<<” Second Age: “<<secondTenantAge<<“]”<<endl; else cout<<” [“<<Tenant_Name<<“,”<<Tenant_Age<<“,”<<Tenant_Months<<“]”<<endl; class Condo Management public: CondoManagement(int FloorNum, int UnitNum) allTenants = new Tenant*[FloorNum*UnitNum]; for (int i = 0; i<FloorNum*UnitNum; i++) allTenants[i] = new Tenant(); totalUnits = FloorNum*UnitNum; CondoManagement (){ delete[] allTenants; void AddRecord(std::string apartmentType, int FloorNum, int UnitNum, string Name, int Age, int MonthsRent, std::string secondTenant, int age2); void DeleteRecord (int FloorNum, int UnitNum); void ModifyRecord(std::string apartment Type, int FloorNum, int UnitNum, string Name, int Age, int MonthsRent, std::string secondTenant, int age2); void ListRecord(); private: Tenant** allTenants; int tota lunits; //array index of the last tenant in the array; //Tenant[] allTenants; void CondoManagement: : AddRecord(std::string apartment Type, int FloorNum, int UnitNum, string Name, int Age, int MonthsRent, std::string secondTenant, int age2 = 0) { for(int i = 0; is totalUnits; i++) if (allTenants[i]->Tenant_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<<“Enter second tenant “; cin>>secondTenant; cout<<“Enter second tenant age “; cin>>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; // cout<<“Added to position ” << i <<“:”<<endl; allTenants [i]->print(); 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; cout<<“Updated position ” << i <<” to:”<<endl; allTenants[i]->print(); 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<<“Enter second tenant “; cin>>secondTenant; cout<<“Enter second tenant age “; cin>>age2; allTenants[i]->apartment = new DoubleRoomApartment (FloorNum, UnitNum, secondTenant, age2); cout<<“Updated position ” << i <<” to:”<<endl; allTenants[i]->print(); 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; cout<<“Updated position ” << i <<” to:”<<endl; allTenants[i]->print(); return; cout<<“Tenant can not be modifiedn”; 1/implementation void CondoManagement: : DeleteRecord(int FloorNum, int UnitNum) the record //it is not deleting the tenants in for(int i = 0; is totalUnits; i++) if(allTenants[i]->apartment->FloorNum == FloorNum && allTenants [i]->apartment->UnitNum == UnitNum) delete allTenants[i]->apartment; allTenants[i]->Tenant_Name = “”; cout<<“Deleted/Reset position” < return; i <<endl; cout<<“Tenant can not be deleted”<<endl; void CondoManagement::ListRecord() //not listing the tenants cout<<“====List of records====”<<endl; for(int i = 0; is totalUnits; i++) { if (allTenants[i]->Tenant_Name !=””) cout<<“Floor “<<allTenants[i]->apartment->FloorNum<<” Unit “<<allTenants[i]->apartment- >UnitNum<<” :”<<endl; allTenants[i]->print(); // 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<<“====Single Apartment====”<<endl; cout<<“Enter total number of floors”; cin>>FloorNum; cout<<“Enter total number of units per floor “; cin>>UnitNum; while (true) cout<<“Enter a command, O Exit, 1 Add, 2 Delete, 3 modify, 4 list “; cin>>command; if (command >= 1 && command <=3) cout<<“Enter floor number “; cin>>floor; cout<<“Enter unit number “; cin>>unit; while(floor > FloorNum || floor <0 || unit > UnitNum|| unit < 0){ cout<<“Invalid locationn”; cout<<“Enter floor number “; cin>>floor; cout<<“Enter unit number “; cin>>unit; if (command == 1) cout<<“Enter name: “; cin>>name; cout<<“Enter age “; cin>>age; cout<<“Enter months stay “; cin>>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<<“Enter new name: “; cin>>name; cout<<“Enter new age “; cin>>age; cout<<“Enter months stay “; cin>>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<<“invalid valuen”; void doubleApartment (CondoManagement* condo_management) int command, floor, unit, age, month, FloorNum, UnitNum, age2; string name; cout<<“====Double Apartment====”<<endl; cout<<“Enter total number of floors “; cin>>FloorNum; cout<<“Enter total number of units per floor “; cin>>UnitNum; while (true) cout<<“Enter a command, 0 Exit, 1 Add, 2 Delete, 3 modify, 4 list “; cin>>command; if (command >= 1 && command <=3) cout<<“Enter floor number “; cin>>floor; cout<<“Enter unit number “; cin>>unit; while(floor > FloorNum | floor <0 || unit > UnitNum|| unit < 0) { cout<<“Invalid locationn”; cout<<“Enter floor number”: cin>>floor; cout<<“Enter unit number “; cin>>unit; if (command == 1) cout<<“Enter name: “; cin>>name; cout<<“Enter age “; cin>>age; cout<<“Enter months stay “; cin>>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<<“Enter new name: “; cin>>name; cout<<“Enter new age “; cin>>age; cout<<“Enter months stay “; cin>>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<<“invalid valuen”; void permanent Apartment (CondoManagement* condo_management) int command, floor, unit, age, month, FloorNum, UnitNum, age2; string name; cout<<“====Permanent Apartment=s=”<<endls cout<<“Enter total number of floors “; cin>>FloorNum; cout<<“Enter total number of units per floor “; cin>>UnitNum; while (true) cout<<“Enter a command, 0 Exit, 1 Add, 2 Delete, 3 modify, 4 list “; cin>>command; if(command >= 1 && command <=3) cout<<“Enter floor number “; cin>>floor; cout<<“Enter unit number “; cin>>unit; while(floor > FloorNum || floor <0 || unit > UnitNum|| unit < 0){ cout<<“Invalid locationn”; cout<<“Enter floor number “; cin>>floor; cout<<“Enter unit number “; cin>>unit; if (command == 1) cout<<“Enter name: “; cin>>name; cout<<“Enter age “; cin>>age; cout<<“The tenant has bought the unit, therefore their months stay is set to 1000 months to represent their permanent stayn”; condo_management->AddRecord(“PERMANENT”, floor, unit, name, age, month, “”, age2); else if (command == 2) condo_management->DeleteRecord(floor, unit); else if (command == 3) cout<<“Enter new name: “; cin>>name; cout<<“Enter new age “; cin>>age; cout<<“The tenant has bought the unit, therefore their months stay is set to 1000 months to represent their permanent stayn”; condo_management->ModifyRecord(“PERMANENT”, floor, unit, name, age, month, “”, age2); else if (command == 0) return; else if (command == 4) condo_management->ListRecord(); else cout<<“invalid valuen”; int main() { int FloorNum, UnitNum; FloorNum = 1000; UnitNum = 1000; CondoManagement* condo_management = new CondoManagement (FloorNum, UnitNum); /*condo_management->AddRecord (“SINGLE”, 1, 1, “cherry”, 2, 2, “”); condo_management->AddRecord (“DOUBLE”, 1, 2, “xyz”, 2, 2, “abc”); condo_management->ListRecord();*/ while(true) { cout<<“Enter the type of condo you would like, o exit, 1 single room apartment, 2 double room apartment, 3 permanent apartment “; int choice; cin>>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<<“Invalid choice, please enter a valid choice: “; Show transcribed image text #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(); cout

Expert Answer


Answer to Below is my C++ mid-term project. BACKGROUND: A condo rental simulation where the user chooses the size and type of apa…

OR