(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? Write a program that prompts the user to enter: a. The total number of units. b. The rent to occupy all the units. c. The increase in rent that results in a vacant unit. d. Amount to maintain a rented unit. The program then outputs the number of units to be rented to maximize the profit.

Respuesta :

Answer:

The program and output are attached below

Explanation:

Code to copy:-

#include "stdafx.h"

#include <iostream>

using namespace std;

int main()

{

    const int FLATS = 50;

    double rent, raise, maintenance, profit = 0, p;

    int n, vacantFlats = 0;

    cout <<"Enter rent to occupy all the units : ";

    cin >> rent;

    cout << "\nEnter increase in rent : ";

    cin >> raise;

    cout<<"\nEnter amount to maintain a rented unit : ";

    cin >> maintenance;

    //   calculate profit

    while ( ( FLATS - vacantFlats ) > 0 )

    {

         p = (FLATS - vacantFlats) * (rent - maintenance);

         if ( p > profit )

         {

             profit = p;

             n = ( FLATS - vacantFlats );

         }

         rent += raise;

         vacantFlats++;

    }

    cout << "\nNumber of units to be rented to "<< "maximize the profit = " << n <<"\n";

    system("PAUSE");

    return 0;

}

Ver imagen mirianmoses
Ver imagen mirianmoses