Needs to be completed in C++: Paint Job Estimator A painting company has determi
ID: 3676426 • Letter: N
Question
Needs to be completed in C++:
Paint Job Estimator
A painting company has determined that for every 115 square feet of wall space, one gallon of paint and eight hours
of labor will be required. The company charges $ 18.00 per hour for labor.
Write a modular program that allows the user to enter the number of rooms that are to be painted and the price of the
paint per gallon. It should also ask for the square feet of wall space in each room.
It should then display the following data:
• The number of gallons of paint required
• The hours of labor required
• The cost of the paint
• The labor charges
• The total cost of the paint job
Note that, since each room may be painted in a different color, you should use the worst case to estimate the paint
job, and your calculations cannot assume that some leftover paint from one room can be used for another room.
Input validation: Do not accept a value less than 2 for the number of rooms. Do not accept a value less than
$10.00 for the price of paint. Do not accept a negative value for square footage of wall space.
/*
Description: Programming Challenge 6.19
This program determines the price of a paint job from a company that charges
$18 per hour of labor.
Note:
All output is zeros.
*/
#include <iostream>
using namespace std;
//function prototypes
float numGals(float, float);
float paintPrice(float);
float wallArea(float, float, float);
float laborHrs(float, float);
void displayCost(float, float, float);
//runs program
int main()
{
//declaring varibales
float
price = 0.0f,
labor=0.0f,
totalArea=0.0f,
area=0.0f,
numRooms=0.0f,
numGallons = 0.0f,
hoursOfLabor=0.0f;
//calling function to get area that needs to be painted
wallArea(totalArea, area, numRooms);
//calling function to determine price of paint
paintPrice(price);
//calls numgals
numGals(totalArea, numGallons);
//calls laborhrs
laborHrs(numGallons, hoursOfLabor);
//calling function to display final result to user
displayCost(pricePerGallon, hoursOfLabor, numGallons);
//allows user to read the console
system("pause");
return 0;
}
//function to determine price of paint
float paintPrice(float pricePerGallon)
{
cout << "Please enter the price per gallon: ";
cin >> pricePerGallon;
return pricePerGallon;
}
//function to calculate total area that needs to be painted
float wallArea(float totalArea, float area, float numRooms)
{
//Asks user to enter a number and stores that value in the appropiate variable
cout << "Please enter the number of rooms you wish to paint: " << endl;
cin >> numRooms;
//while loop to ensure positive number is used
while (numRooms < 1)
{
cout << "Number of rooms must be at least one." << endl << "Please try again." << endl;
cin >> numRooms;
}
for (float i = 1; i <= numRooms; i++)
{
//displays for each room depending on number of rooms
cout << "Please enter the square feet of wall space for Room " << i << ": " << endl;
cin >> area;
//summing area
totalArea += area;
}
return totalArea;
}
//function to determine the number of gallons of paint
float numGals(float numGallons,float totalArea)
{
numGallons = totalArea / 115.0f;
cout << "The number of gallons of paint required: " << numGallons << " gallons" << endl;
return numGallons;
}
//function to determine hours of labor
float laborHrs(float numGallons, float hoursOfLabor)
{
hoursOfLabor = numGallons * 8.0f;
cout << "The hours of labor required: " << hoursOfLabor << " hours" << endl;
return hoursOfLabor;
}
//function to determine and display final results
void displayCost(float pricePerGallon, float hoursOfLabor, float numGallons)
{
float paintCost=0.0f;
float laborCost=0.0f;
float jobCost=0.0f;
paintCost = (numGallons*pricePerGallon);
cout << "Total cost of paint: $" << paintCost << endl;
laborCost = (hoursOfLabor * 18.0f);
cout << "Total cost of labor: $" << laborCost << endl;
jobCost = (paintCost + laborCost);
cout << "Total cost of job: $" << jobCost << endl;
}
Explanation / Answer
/*
Description: Programming Challenge 6.19
This program determines the price of a paint job from a company that charges
$18 per hour of labor.
Note:
All output is zeros.
*/
#include <iostream>
using namespace std;
//function prototypes
float numGals(float&, float);
float paintPrice(float&);
float wallArea(float&, float, float);
float laborHrs(float, float&);
void displayCost(float, float, float);
//runs program
int main()
{
//declaring varibales
float
price = 0.0f,
labor=0.0f,
totalArea=0.0f,
area=0.0f,
numRooms=0.0f,
numGallons = 0.0f,
hoursOfLabor=0.0f;
//calling function to get area that needs to be painted
wallArea(totalArea, area, numRooms);
//calling function to determine price of paint
paintPrice(price);
//calls numgals
numGals(numGallons, totalArea);
//calls laborhrs
laborHrs(numGallons, hoursOfLabor);
//calling function to display final result to user
displayCost(price, hoursOfLabor, numGallons);
//allows user to read the console
system("pause");
return 0;
}
//function to determine price of paint
float paintPrice(float &pricePerGallon)
{
cout << "Please enter the price per gallon: ";
cin >> pricePerGallon;
//while loop to ensure paint price as accepted
while (pricePerGallon < 10)
{
cout << "Price of paint should be atleast two." << endl << "Please try again." << endl;
cin >> pricePerGallon;
}
return pricePerGallon;
}
//function to calculate total area that needs to be painted
float wallArea(float &totalArea, float area, float numRooms)
{
//Asks user to enter a number and stores that value in the appropiate variable
cout << "Please enter the number of rooms you wish to paint: " << endl;
cin >> numRooms;
//while loop to ensure positive number is used
while (numRooms < 2)
{
cout << "Number of rooms must be at least two." << endl << "Please try again." << endl;
cin >> numRooms;
}
for (float i = 1; i <= numRooms; i++)
{
//displays for each room depending on number of rooms
cout << "Please enter the square feet of wall space for Room " << i << ": " << endl;
cin >> area;
while (area < 0)
{
cout << "Area cannot be negative." << endl << "Please try again." << endl;
cin >> area;
}
//summing area
totalArea += area;
}
return totalArea;
}
//function to determine the number of gallons of paint
float numGals(float &numGallons,float totalArea)
{
numGallons = totalArea / 115.0f;
cout << "The number of gallons of paint required: " << numGallons << " gallons" << endl;
return numGallons;
}
//function to determine hours of labor
float laborHrs(float numGallons, float &hoursOfLabor)
{
hoursOfLabor = numGallons * 8.0f;
cout << "The hours of labor required: " << hoursOfLabor << " hours" << endl;
return hoursOfLabor;
}
//function to determine and display final results
void displayCost(float pricePerGallon, float hoursOfLabor, float numGallons)
{
float paintCost=0.0f;
float laborCost=0.0f;
float jobCost=0.0f;
paintCost = (numGallons*pricePerGallon);
cout << "Total cost of paint: $" << paintCost << endl;
laborCost = (hoursOfLabor * 18.0f);
cout << "Total cost of labor: $" << laborCost << endl;
jobCost = (paintCost + laborCost);
cout << "Total cost of job: $" << jobCost << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.