fork download
  1. //Charlotte Davies-Kiernan CS1A Chapter 6 P. 374 #16
  2. //
  3. /******************************************************************************
  4.  *
  5.  * Compute Paint Job
  6.  * ____________________________________________________________________________
  7.  * This program uses the number of rooms to be painted, square feet of wall
  8.  * space in each room, and the price of the paint per gallon to then display
  9.  * the number of gallons of paint required, the hours of labor required, the
  10.  * cost of the paint, the labor charges, and the total cost of the paint job.
  11.  *
  12.  * Formulas Used:
  13.  * Gallons of paint required = (total square feet / square feet per gallon)
  14.  * Hours of labor required = (gallons * hours per gallon)
  15.  * Paint cost = gallons * paint price
  16.  * Labor cost = labor hours * labor rate
  17.  * Total cost = paint cost + labor cost
  18.  * ____________________________________________________________________________
  19.  * Input
  20.  * rooms //Number of rooms needed to be painted
  21.  * paintPrice //Price of paint per gallon
  22.  * totalSqFt //Total square feet amount that needs to be painted
  23.  * sqFt //Square feet per room
  24.  * sq_ft_per_gallon //Constant rate of square feet painted per gallon
  25.  * hours_per_gallon //Constant rate of labor per gallon
  26.  * laborRate //Constant hourly pay for labor
  27.  * Output
  28.  * gallons //Number of gallons of paint required
  29.  * laborHours //The hours of labor required
  30.  * paintCost //The cost of the paint
  31.  * laborCost //The labor charges
  32.  * totalCost //The total cost of the paint job
  33.  *****************************************************************************/
  34. #include <iostream>
  35. #include <iomanip>
  36. #include <cmath> //For ceil
  37. using namespace std;
  38. //Global Constants
  39. float sq_ft_per_gallon = 115.0;
  40. float hours_per_gallon = 8.0;
  41. float laborRate = 18.00;
  42. //Function Prototypes
  43. float calculateGallons(float totalSqFt);
  44. float calculateLaborHours(float gallons);
  45. float calculatePaintCost(float gallons, float paintPrice);
  46. float calculateLaborCost(float laborHours);
  47. void displayResults (float gallons, float laborHours, float paintCost, float laborCost, float totalCost);
  48.  
  49. int main() {
  50. //Data Dictionary
  51. float rooms; //INPUT - Number of rooms needed to be painted
  52. float paintPrice; //INPUT - Price of paint per gallon
  53. float totalSqFt; //INPUT - Total square feet amount that needs to be painted
  54. float sqFt; //INPUT - Square feet per room
  55. float gallons; //OUTPUT - Number of gallons of paint required
  56. float laborHours; //OUTPUT - The hours of labor required
  57. float paintCost; //OUTPUT - The cost of the paint
  58. float laborCost; //OUTPUT - The labor charges
  59. float totalCost; //OUTPUT - The total cost of the paint job
  60.  
  61. cout << fixed << setprecision(2);
  62. cout << "Painting Company Cost Estimator: " << endl;
  63.  
  64. //Get User Input
  65. cout << "Enter the number of rooms to be painted: " << endl;
  66. cin >> rooms;
  67. if (rooms < 1){
  68. cout << "Please re-enter number of rooms (1 or more)" << endl;
  69. cin >> rooms;
  70. }
  71. cout << "Enter the price of paint per gallon: $"<< endl;
  72. cin >> paintPrice;
  73. if (paintPrice < 10.00){
  74. cout << "Invalid input, please enter a price more than $10.00" << endl;
  75. cin >> paintPrice;
  76. }
  77. //Calculate Total Square Feet
  78. totalSqFt = 0.0;
  79. for (int i = 1; i <= rooms; i++){
  80. cout << "Room " << i << endl;
  81. cout << "Enter wall space (in square feet): " << endl;
  82. cin >> sqFt;
  83. if (sqFt < 0){
  84. cout << "Invalid Measurement, please enter a non negative number: " << endl;
  85. cin >> sqFt;
  86. }
  87. totalSqFt += sqFt;
  88. }
  89. //Calculations
  90. gallons = calculateGallons(totalSqFt);
  91. laborHours = calculateLaborHours(gallons);
  92. paintCost = calculatePaintCost(gallons, paintPrice);
  93. laborCost = calculateLaborCost(laborHours);
  94. totalCost = paintCost + laborCost;
  95.  
  96. //Display Results
  97. displayResults(gallons, laborHours, paintCost, laborCost, totalCost);
  98. return 0;
  99. }
  100. float calculateGallons(float totalSqFt){
  101. return ceil(totalSqFt / sq_ft_per_gallon); //ceil rounds up to the next whole gallon
  102. }
  103. float calculateLaborHours(float gallons){
  104. return gallons * hours_per_gallon;
  105. }
  106. float calculatePaintCost(float gallons, float paintPrice){
  107. return gallons * paintPrice;
  108. }
  109. float calculateLaborCost(float laborHours){
  110. return laborHours * laborRate;
  111. }
  112. //Display Function
  113. void displayResults(float gallons, float laborHours, float paintCost, float laborCost, float totalCost){
  114. cout << "Paint Job Summary: " << endl;
  115. cout << "Gallons of paint required: " << gallons << endl;
  116. cout << "Hours of labor required: " << laborHours << endl;
  117. cout << "Cost of paint: $" << paintCost << endl;
  118. cout << "Labor charges: $" << laborCost << endl;
  119. cout << "Total Cost of Paint Job: $" << totalCost << endl;
  120. }
Success #stdin #stdout 0.01s 5296KB
stdin
5
12
350
200
400
450
375


stdout
Painting Company Cost Estimator: 
Enter the number of rooms to be painted: 
Enter the price of paint per gallon: $
Room 1
Enter wall space (in square feet): 
Room 2
Enter wall space (in square feet): 
Room 3
Enter wall space (in square feet): 
Room 4
Enter wall space (in square feet): 
Room 5
Enter wall space (in square feet): 
Paint Job Summary: 
Gallons of paint required: 16.00
Hours of labor required: 128.00
Cost of paint: $192.00
Labor charges: $2304.00
Total Cost of Paint Job: $2496.00