Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A real estate office handles, say, 50 apartment units. When the rent is say, $60

ID: 3621311 • Letter: A

Question

A real estate office handles, say, 50 apartment units. When the rent is say, $600 per month, all the units are occupied. However, for each, say, $40 increase in rent, one unit becomes vacant. Moreover, each occupied unit requires an average of $27 per month for maintenance. How many units should be rented to maximize the profit?

The three input values (rent when all units are occupied($600), increase in rent that results in a vacant unit ($40) and amount to maintain a rentred unit ($27)) are READ FROM AN INPUT FILE, AND OUTPUT GOES TO A FILE PLEASE!!! :-) The output consists of a table showing

Number of units rented Monthly Rent Monthly Profit


with 50 lines, the first line showing 50 units rented, the next line showing 49, and so on. At the end of the table, an output statement tells

Maximum profit of $_______________________ occurs when _______ units are rented.


Please help me with the source code for this problem. I think this problem can be done by writing a function for the calculation and recalling it in a loop. Please help me, thanks.

Explanation / Answer

Glad to help - hope this is more clear. :) #include #include #include using namespace std; const int numUnits = 50; // This function calculates and returns the profit given the information about // how many rooms are occupied, what the minRent is (when all rooms are occupied) // what increase causes a room to become vacant, and how much maintenance costs double calculateProfit(int numOccupied, double minRent, double vacantIncrease, double maintenance) { // The current rent is the minimum rent plus the number of increases times the amount per increase double currentRent = minRent + (numUnits-numOccupied)*vacantIncrease; // The profit is the current rent times the number of units occupied minus the maintenance costs double profit = currentRent*numOccupied - maintenance*numOccupied; return profit; } int main() { string fileName; string outputFileName = "myOutput.txt"; ifstream inFile; ofstream outFile; double minRent, vacantIncrease, maintenance; double maxProfit = 0; int maxProfitUnits = 0; // The user gives the input file cout > fileName; // We open the input file inFile.open(fileName); // If we failed to open the file, exit the program if (inFile.fail()) { cout vacantIncrease >> maintenance; // Done with input file, so close it inFile.close(); // Now open the output file outFile.open(outputFileName); // For all units from the maximum down to 1 (not including 0) we want to calculate // and output the profit for that room for (int i = numUnits; i > 0; i--) { // get the profit from our handy function double profit = calculateProfit(i, minRent, vacantIncrease, maintenance); // write the data to the output file outFile
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote