Related questions with answers
A painting company has determined that for every 110 square feet of wall space, one gallon of paint and eight hours of labor will be required. The company charges $25.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 Input validation: Do not accept a value less than 1 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.
Solutions
Verified#include <iostream>
using namespace std;
#include <iostream>
#include <iomanip> //to format output
using namespace std;
//function prototype
void getData(int &numRooms, double &paintPrice, double &surface);
double calculatePaint(int numRooms, double surface);
double calculateLabor(int numRooms, double surface);
double calculatePaintCost(double, double);
double calculateLaborCost(double);
int main(){
//declare variables needed to store input
//and pass to other functions
int numRooms;
double paintPrice, surfacePerRoom;
//call function getData
getData(numRooms, paintPrice, surfacePerRoom);
//format output
cout << fixed << setprecision(2);
//display number of gallons needed
cout << calculatePaint(numRooms, surfacePerRoom) << " gallons of paint ";
cout << "are required!\n";
//display labor hours needed
cout << calculateLabor(numRooms, surfacePerRoom) << " hours of labor ";
cout << "are required!\n";
//display total cost of paint
cout << "The paint will cost $";
cout << calculatePaintCost(calculatePaint(numRooms, surfacePerRoom), paintPrice);
cout << ".\n";
//display total cost of labor
cout << "Labor charges are$";
cout << calculateLaborCost(calculateLabor(numRooms, surfacePerRoom));
cout << ".\n";
//display grand total
cout << "The grand total is $";
cout << calculatePaintCost(calculatePaint(numRooms, surfacePerRoom), paintPrice) +
calculateLaborCost(calculateLabor(numRooms, surfacePerRoom));
cout << ".\n";
//return 0 to mark successful termination of program
return 0;
}
void getData(int &numRooms, double &paintPrice, double &surface){
//prompt user to enter data
//then read from keyboard
cout << "How many rooms to paint?\n";
cin >> numRooms;
//validate input using while loop
while(numRooms < 1){
//print error message
cout << "Please enter a number greater than or equal to 1!\n";
cin >> numRooms;
}
cout << "What is the surface to be painted in each room in sq. ft?\n";
cin >> surface;
//validate input using while loop
while(surface < 0){
//print error message
cout << "Please enter a nonnegative value!\n";
cin >> surface;
}
cout << "What is the price per gallon of paint?\n";
cin >> paintPrice;
//validate input using while loop
while(paintPrice < 10.00){
//print error message
cout << "Please enter a number greater than or equal to 10!\n";
cin >> paintPrice;
}
}
double calculatePaint(int numRooms, double surface){
//divide by 110.00 to prevent
//integer division
return numRooms * surface / 110.00;
}
double calculateLabor(int numRooms, double surface){
//divide by 110.00 to prevent
//integer division
return 8 * numRooms * surface / 110.00;
}
double calculatePaintCost(double paintGallons, double paintPrice){
return paintGallons * paintPrice;
}
double calculateLaborCost(double laborHours){
return laborHours * 25.00;
}
Create a free account to view solutions
Create a free account to view solutions
Recommended textbook solutions

Starting Out with C++ from Control Structures to Objects
8th Edition•ISBN: 9780133769395 (7 more)Godfrey Muganda, Judy Walters, Tony Gaddis
Fundamentals of Database Systems
7th Edition•ISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
Introduction to Algorithms
3rd Edition•ISBN: 9780262033848Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
Introduction to Algorithms
4th Edition•ISBN: 9780262046305Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. CormenMore related questions
1/4
1/7