1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#include <iostream>
using namespace std;
const double PRICE_PER_HOUR = 38.99; // Cost of labor per hour
const double AREA_PER_HOUR = 14.375; // Amount of wall space area (sq ft) that can be painted per hour.
void getRooms(int& rooms);
int getArea(int area, int countPar, int length, int height);
void displayError();
int addArea(int totArea, int area);
double calculateHours(double rate, int area);
double calculateCost(double rate, double hours);
void displayHours(double hours);
void displayCost(double cost);
int main()
{
int dummy_int;
int numberOfRooms = 0,
totalRooms = 0,
totalArea = 0,
count = 0;
double hoursOfLabor = 0.0,
costOfLabor = 0.0;
getRooms(numberOfRooms);
for (count = 1; count <= numberOfRooms; count++)
{
totalRooms = getArea(totalRooms, count);
if (totalRooms <= 20)
{
totalArea = addArea(totalArea, totalRooms);
}
else
{
displayError();
}
}
hoursOfLabor = calculateHours(AREA_PER_HOUR, totalArea);
costOfLabor = calculateCost(PRICE_PER_HOUR, hoursOfLabor);
displayHours(hoursOfLabor);
displayCost(costOfLabor);
cin >> dummy_int;
}
void getRooms(int& rooms)
{
cout << "Please enter the number of rooms to be painted: ";
cin >> rooms;
}
int getArea(int area, int countPar, int length, int height)
{
cout << "Please enter the height for room #" << countPar << " (in ft) : ";
cin >> height;
cout << "Please enter the length for room #" << countPar << " (in ft) : ";
cin >> length;
area = length * height;
return area;
}
int addArea(int totArea, int area)
{
return totArea + area;
}
void displayError()
{
cout << "Number of rooms must be less than or equal to 20, please try again." << endl;
return;
}
double calculateHours(const double rate, int area)
{
return area / rate;
}
double calculateCost(const double rate, double hours)
{
return hours * rate;
}
void displayHours(double hours)
{
cout << "Total hours of labor required: " << hours << " hours." << endl;
return;
}
void displayCost(double cost)
{
cout << "Total cost of labor: $" << cost << endl;
return;
}
|