Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NO print or println in any of your methods except the main method. A painting co

ID: 3671645 • Letter: N

Question

NO print or println in any of your methods except the main method.

A painting company has determined that for every 112 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 program that calculates the amount of paint, hours of labor, the cost of paint, labor charges, and the total cost for a given room. The square feet of wall space of the room will be given to you.   Your program must output the amount of paint, hours of labor, and the cost of paint, labor charges, and the total cost.  

You must declare class constants for the values 112, 8 and 18. You must use meaningful names.

You need to declare variables such as size, paintPrice,…

You need to run your program with the data provided as the sample output.

Your program must have the following methods besides the main method:

1.A method that receives the square feet as its parameter and returns the gallons of paint needed.

2.A method that receives the square feet as its parameter and returns the hours of labor required.

3.A method that receives the number of gallons of paint and cost of a gallon as its parameters and returns the cost of paint.

4.A methods that receives hours of labor needed as its parameter and returns the labor charges.

5.A method that receives the labor cost and the paint cost as its parameters and returns the total cost.

You must output the following

Room Size: 112

The cost of paint per gallon: 23.8

Gallons of paint: 1

Hours of labor: 8

Cost of paint: 24

Cost of labor: 144

Total cost: 168

Room Size: 2000

The cost of paint per gallon: 23.8

Gallons of paint: 18

Hours of labor: 143

Cost of paint: 425

Cost of labor: 2571

Total cost: 2996

Room Size: 4100

The cost of paint per gallon: 23.8

Gallons of paint: 37

Hours of labor: 293

Cost of paint: 871

Cost of labor: 5271

Total cost: 6143

Explanation / Answer

//required headers
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <sstream>

#include "../include/common.hpp"

inline float calculateChunks(int wallSpace, float perChunk = 115.0f)
{
return wallSpace / perChunk;
}

int main(int argc, char *argv[])
{
// Show which program is currently running and give some basic instructions
std::cout << "Chapter 6, Challenge 8: Paint Job Estimator"
            << std::endl << std::endl
            << "When prompted, enter the information requested."
            << std::endl << std::endl;

try
{
      // Get the number of rooms to paint
      int rooms = stringTo<int>(showPrompt("Number of rooms to paint"));

      // Check that the number of rooms to paint is positive
      if (rooms <= 0)
      {
        // Tell the user that the number of rooms to paint must be positive
        throw "The number of rooms to paint must be positive!";
      }

      // Get the cost of paint
      float cost = stringTo<float>(showPrompt("Cost of paint (per gallon)"));

      // Check that the cost of paint is at least $10.00
      if (cost < 10.0f)
      {
        // Tell the user that the cost of paint must be at least $10.00
        throw "The cost of paint must be at least $10.00!";
      }

      // Set the initial wallspace
      int totalWallSpace = 0;

      // Loop through the rooms
      for (int i = 0; i < rooms; ++i)
      {
        try
        {
            std::stringstream stream;

            // Create the prompt
            stream << "Wall space in room #" << i + 1;

            // Get the square feet of wall space
            int wallSpace = stringTo<int>(showPrompt(stream.str()));

            // Check that the square feet of wall space is positive
            if (wallSpace <= 0)
            {
              // Tell the user that the square feet of wall space must be positive
              throw "The square feet of wall space must be positive!";
            }

            // Add the wallspace to the total
            totalWallSpace += wallSpace;
        }
        catch (const char *exception)
        {
          // Tell the user an exception occurred
          std::cerr << "Exception: "
                    << std::endl
                    << exception
                    << std::endl;

          // Decrement `i` to repeat the same room
          --i;
        }
      }

      // Calculate the number of chunks required
      float chunks = calculateChunks(totalWallSpace);

      // Calculate the cost
      float paintCost = ceil(chunks) * cost, laborCost = chunks * 18.0f;

      // Add another new line
      std::cout << std::endl;

      // Show the information about the paint job
      std::cout << "     General " << std::endl
                << "------------- " << std::endl
                << "      Paint : "
                << std::setw(8) << std::right << ceil(chunks) << " gallon(s)" << std::endl
                << std::fixed << std::showpoint << std::setprecision(2)
                << "      Labor : "
                << std::setw(8) << std::right << chunks * 8.0f << " hour(s)" << std::endl
                << std::endl
                << "        Cost " << std::endl
                << "------------- " << std::endl
                << std::fixed << std::showpoint << std::setprecision(2)
                << "      Paint : $"
                << std::setw(8) << std::right << paintCost
                << std::endl
                << std::fixed << std::showpoint << std::setprecision(2)
                << "      Labor : $"
                << std::setw(8) << std::right << laborCost
                << std::endl
                << std::fixed << std::showpoint << std::setprecision(2)
                << "      Total : $"
                << std::setw(8) << std::right << paintCost + laborCost
                << std::endl;
}
catch (const char *exception)
{
    // Tell the user an exception occurred
    std::cerr << "Exception: "
              << std::endl
              << exception
              << std::endl;
}
}