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

19.5 C++: Apartment Problem A real estate office handles, say, 50 apartment unit

ID: 3667577 • Letter: 1

Question

19.5 C++: Apartment Problem

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?

#include <iostream>
#include <iostream>
#include<fstream>
using namespace std;
int main()
{int i,apts=0;
double rent=0,inc=0,maint,max=0,totrent=0,month=0,maxapts=0;
ifstream in;
ofstream out;
in.open("input.txt");

out.open("output.txt");
in>>rent;
in>>inc;

out<<"units rented   Monthly Rent Monthly profit ";
for(i=0;i<apts;i++)
    {month=rent+(inc*i)+maint;
    totrent=month*(apts-i);
   out<<apts-i<<" "<<month<<" "<<totrent<<endl;
    if(totrent>max)
        {max=totrent;
        maxapts=apts-i;
        }
    }
out<<" Maximum profit of $"<<max<<" occurs when"<<maxapts<<" units are rented ";
return 0;
}

Explanation / Answer

import java.util.*; import java.io.*; public class ChapterFiveHomework { static Scanner console = new Scanner(System.in); public static void main(String[] args) throws FileNotFoundException { int units; double rent; double startRent; double rentInc; double maintenance; double totalMaintenance; double earnings; double earnings2; System.out.println("Enter the number of appartment units."); units = console.nextInt(); System.out.println("Enter the rent ammount when all units are occupied."); rent = console.nextDouble(); System.out.println("Enter the increase in rent that results in a vacant" +" unit."); rentInc = console.nextDouble(); System.out.println("Enter the ammount to maintain a rented unit."); maintenance = console.nextDouble(); earnings2 = (units-1)*(rent+rentInc)-maintenance*(units-1); earnings = units*rent-maintenance*units; do { units--; rent = rent+rentInc; earnings = (units--)*(rent+rentInc)-(maintenance*(units--)); } while (earnings > earnings2); System.out.println("Number of units to rent:" + (units)); System.out.printf("Ammount to charge for rent: %.2f", rent); } }

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