fork download
  1. //Eric Bernal CS1A Chapter 6, P. 374, #17
  2. //
  3. /*******************************************************************************
  4.  * CALCULATE PAINT JOB PRICE ESTIMATOR
  5.  *______________________________________________________________________________
  6.  * This program calculates the total estimated price of a paint job based off of
  7.  * a given number of rooms, square footage of wallspace per room, labor hours,
  8.  * labor cost per hour, cost of paint, and number of gallons of paint used.
  9.  * _____________________________________________________________________________
  10.  * INPUT
  11.  * numRooms : The number of rooms to be painted.
  12.  * pricePerGallon : The price of paint per gallon.
  13.  * sqftPerRoom : The square footage of wallspace to be painted per
  14.  * room
  15.  * OUTPUT
  16.  * numGallon : The number of paint gallons required for this job
  17.  * paintCost : The total cost of the required amount of paint
  18.  * hours : The number of hours this job will demand
  19.  * laborCost : The total cost of labor per hour for this job
  20.  * totalCost : The total cost of everything.
  21. * *****************************************************************************/
  22. #include <iostream>
  23. #include <iomanip>
  24. using namespace std;
  25.  
  26. // Global Constants Variables
  27. const float HOURLY_LABOR_WAGE = 18; //Labor cost per hour
  28. const int SQFT_COVERED_BY_ONE_GALLON = 115; //Wallspace a gallon covers
  29. const int HOURS_OF_WORK_PER_ONE_GALLON = 8; //Hours needed to use a gallon
  30.  
  31. // Function Prototypes:
  32. int numPaintGallons(int numRooms, int sqftPerRoom);
  33. int laborHoursRequired(int numGallonsPaintUsed);
  34.  
  35. int main() {
  36. // DATA DICTIONARY
  37. int numRooms; //INPUT - Number of rooms to be painted
  38. float pricePerGallon; //INPUT - Price per one gallon of paint
  39. int sqftPerRoom; //INPUT - Wallspace painted per room
  40. float numGallonsNecessary; //OUTPUT - Gallons required for this job
  41. float paintCost; //OUTPUT - Price of required paint amount
  42. float hoursWorked; //OUTPUT - Required number of hours of labor
  43. float laborCost; //OUTPUT - Price of the labor required
  44. float totalCost; //OUTPUT - Total price of this job
  45.  
  46. //Gather and validate input
  47. do
  48. {
  49. cout << "Enter the number of rooms that need to be painted (must be at"
  50. << " least one room): ";
  51. cin >> numRooms;
  52. cout << numRooms << endl;
  53. }
  54. while(numRooms <= 1);
  55.  
  56. do
  57. {
  58. cout << "Enter the price per gallon of paint (must be at least $10): ";
  59. cin >> pricePerGallon;
  60. cout << pricePerGallon << endl;
  61. }
  62. while(pricePerGallon <= 10);
  63.  
  64. do
  65. {
  66. cout << "Enter the square footage of the wall space per room that must"
  67. << " be painted (must be a positive integer): ";
  68. cin >> sqftPerRoom;
  69. cout << sqftPerRoom << endl;
  70. }
  71. while(sqftPerRoom < 0);
  72. cout << endl;
  73.  
  74. //Paint calculations
  75. numGallonsNecessary = numPaintGallons(numRooms, sqftPerRoom);
  76. paintCost = numGallonsNecessary * pricePerGallon;
  77.  
  78. //Labor calculations
  79. hoursWorked = laborHoursRequired(numGallonsNecessary);
  80. laborCost = hoursWorked * HOURLY_LABOR_WAGE;
  81.  
  82. //Total cost calculation
  83. totalCost = paintCost + laborCost;
  84.  
  85. //Display Output
  86. cout << "Gallons of paint required: " << numGallonsNecessary << " Gallons"
  87. << endl;
  88. cout << "Total labor hours required: " << hoursWorked << " Hours" << endl;
  89. cout << fixed << showpoint << setprecision(2);
  90. cout << "Cost of paint: $" << paintCost << endl;
  91. cout << "Cost of labor: $" << laborCost << endl;
  92. cout << "Total job cost: $" << totalCost << endl;
  93.  
  94. return 0;
  95. }
  96.  
  97. /*******************************************************************************
  98.  * This function calculates the number of gallons of paint necessary to complete
  99.  * this job, given the number of rooms and the wall square footage per room that
  100.  * is to be painted.
  101.  * ****************************************************************************/
  102. int numPaintGallons(int numRooms, int sqftPerRoom)
  103. {
  104. int sqftOfNeededCoverage; //The total square footage of coverage required
  105.  
  106. sqftOfNeededCoverage = numRooms * sqftPerRoom;
  107. return ((static_cast<float>(sqftOfNeededCoverage) / SQFT_COVERED_BY_ONE_GALLON) + 1);
  108. }
  109.  
  110. /*******************************************************************************
  111.  * This function calculates the number of hours of labor necessary to complete
  112.  * this job, given the number of gallons that must be used.
  113.  * ****************************************************************************/
  114. int laborHoursRequired(int numGallonsPaintUsed)
  115. {
  116. return HOURS_OF_WORK_PER_ONE_GALLON * numGallonsPaintUsed;
  117. }
Success #stdin #stdout 0s 5280KB
stdin
3 11 100
stdout
Enter the number of rooms that need to be painted (must be at least one room): 3
Enter the price per gallon of paint (must be at least $10): 11
Enter the square footage of the wall space per room that must be painted (must be a positive integer): 100

Gallons of paint required: 3 Gallons
Total labor hours required: 24 Hours
Cost of paint: $33.00
Cost of labor: $432.00
Total job cost: $465.00