Your assignment is to implement a computer program in C++ to implement the below application.
According to Dummies.com the following algorithm determines the amount of paint you need to paint the walls of a four-sided room:
1. Add together the length of each wall. (For example, if each of the four walls are 14, 20, 14, 20 feet respectively then the total length is 14 + 20 + 14 + 20 = 68 feet)
2. Multiply the sum by the wall height, to find the total wall area. (In the example, if the wall height is 8 feet then the wall area is: 68 × 8 = 544 square feet)
3. Subtract 20 square feet for each door and 15 square feet for each window to find the actual amount of wall area you're painting. (So, if there are two doors and two windows, subtract 70 square feet: 544 – 70 = 474 square feet)
4. Divide this figure by the paint coverage (set at 350 square feet per gallon), and the result is the number of gallons to purchase. (Note: for the purposes of this assignment, the paint coverage is always set at 350 square feet per gallon.) 474 ÷ 350 = 1.4
5. Since paint is only sold in gallon increments, the final result is 2 gallons. The easiest way to round up, as required, is to use the C++ ceil() function. Don’t forget to #include <cmath> in your program header.
Sample Dialog:
Welcome to Robert's Paint Estimator
What is the length of wall 1: 14
What is the length of wall 2: 20
What is the length of wall 3: 14
What is the length of wall 4: 20
The total length of the wall is 68 feet
What is the height of the wall: 8
The total area of the wall is 544 square feet
How many doors are there: 2
How many windows are there: 2
Wall area to paint is 474 square feet
This will require 2 gallons of paint
Thank you for using Robert's Paint Estimator.
Design Considerations 1) Your program should follow exactly the example dialog above except that the name Robert should be replaced with your name. Please follow the formatting in the example exactly. In particular, be sure you output the required gallons rounded up to the next highest integer. 2) The text in red bold is that which is input by the user. The rest is output by your program. 3) Note: Of course, the results should be calculated by your program depending on what data the user inputs. In other words, your program needs to provide a general solution that will work for walls of all sizes, not just the example given above.
Program:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
string name;
int wall1, wall2, wall3, wall4, total, height, area;
int doors, windows, paintArea;
float gallons;
cout<<"Enter your name : ";
cin >> name; // Input of your name to display
cout << "Welcome to " << name << "'s Paint Estimator" << endl;
// Input for length of walls
cout<<"What is the length of wall 1: ";
cin >> wall1;
cout<<"What is the length of wall 2: ";
cin >> wall2;
cout<<"What is the length of wall 3: ";
cin >> wall3;
cout<<"What is the length of wall 4: ";
cin >> wall4;
total = wall1 + wall2 + wall3 + wall4;
// Output total length of the wall
cout << "The total length of the wall is " << total << " feet" << endl;
cout<<"What is the height of wall: ";
cin >> height; // Input height of the wall
area = total * height;
// Output total area of the wall
cout << "The total area of the wall is " << area << " square feet" << endl;
// Input for number of doors and windows
cout<<"How many doors are there: ";
cin >> doors;
cout<<"How many windows are there: ";
cin >> windows;
paintArea = area - (doors * 20 + windows * 15); // Get painting area
// Output paint area
cout << "Wall area to paint is " << paintArea << " square feet" << endl;
gallons = (float)paintArea / 350; // Get number of gallons
// Output the gallons using ceil() function
cout << "This will require " << ceil(gallons) << " gallons of paint" << endl;
cout << "Thank you for using " << name << "'s Paint Estimator" << endl;
return 0;
}
Output:
Get Answers For Free
Most questions answered within 1 hours.