Friday, January 13, 2017

Programming Challenge 6.18 - Paint Job Estimator

/* Paint Job Estimator - 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.
  
   This is 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
   also asks for the square feet of wall space in each room. It then
   displays 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

   The following functions are used:

      * showIntro()
      * getJobData()
      * calcLaborCost()
      * calcMaterialCost()
      * calcTotalCost()
      * displayEstimatedCost()

   Input Validation: No values less than 1 for the number of rooms, no
   value less than $10.00 for the price of paint, and no negative value
   for square footage of wall space are accepted. */

#include "Utility.h"

/* Prototypes: Show Introduction, Get job data, Calculate labor cost,
               Calculate material cost, Display estimated cost */
void showIntro();
void getJobData(int &, double &, double &);
double calcLaborCost(double, double &, int = 8, int = 110, double = 25.00);
double calcMaterialCost(double, double, double &, int = 110);
double calcTotalCost(double, double);
void displayEstimatedCost(int, double, double, double, double, double, double);

int main()
{
   /* Variable: Number of rooms */
   int numRooms = 0;

   /* Variables: Cost for paint, Total cost, Number of gallons needed,
                 Wallspace to paint, Standard charges (default argument),
                 Total labor cost, Total material cost, */
   double paintCost = 0.0,
          totalCost = 0.0,
          numGallons = 0.0,
          wallspace = 0.0,
          workHrsReq = 0.0,
          stdCharge = 0.0,
          totalLaborCost = 0.0,
          totalMaterialCost = 0.0,
          totalJobCost = 0.0;

   /* Call: showIntro */
   showIntro();

   /* Call: getJobData */
   getJobData(numRooms, paintCost, wallspace);

   /* Call: calcLaborCost */
   totalLaborCost = calcLaborCost(wallspace, workHrsReq);

   /* Call: calcMaterialCost */
   totalMaterialCost = calcMaterialCost(wallspace, paintCost, numGallons);

   /* Call: calcTotalCost */
   totalJobCost = calcTotalCost(totalLaborCost, totalMaterialCost);

   /* Call: showEstimatedCost */
   displayEstimatedCost(numRooms, wallspace, numGallons, workHrsReq,
                        totalMaterialCost, totalLaborCost, totalJobCost);

   pauseSystem();
   return 0;
}

/* **********************************************************
   Definition: showIntro

   This function displays an introduction of this program.
   ********************************************************** */
void showIntro()
{
   /* Display: Introduction */
   cout << "\t\tWELCOME TO ACME ACRES PAINT COMPANY\n\n"
        << "If you wish to paint your rooms with stylish new\n"
        << "colors, we are THE NUMBER ONE COMPANY for you!\n"
        << "With this program you can calculate the estimated\n"
        << "cost for the paint job.\n\n"
        << "All we need to know from you is:\n\n"
        << " * The number of rooms you wish us to paint\n"
        << " * The cost of paint you wish us to use\n"
        << " * The total square feet of wall space to paint\n\n"
        << "And we are right on our way to you!\n\n";
}

/* **********************************************************
   Definition: getJobData

   This function gets the following information:

      * The number of rooms to be painted
      * The price of paint per gallon
      * The square feet of wall space in each room

   This information is returned to main and its arguments are
   passed to calcLaborCost().
   ********************************************************** */

void getJobData(int &roomsToPaint, double &gallonPrice,
                double &sqFtTotal)
{
   /* Variable: Square feet of wall space*/
   double sqFtWallspace;

   /* Variable: Number of rooms */
   int numRooms = 1;

   /* Get: The number of rooms to be painted, The square feet of
           wall space, The price for paint

      Validate: Input */
   cout << "Step 1: How many rooms do you wish to be painted? ";
   cin >> roomsToPaint;

   while (roomsToPaint < 1)
   {
      cout << "\nFailure! You entered a number below 1 which is not\n"
           << "valid. Please repeat your input: ";
      cin >> roomsToPaint;
     
      /* Call: catchInifiniteLoop */
      catchInfiniteLoop();
   }

   cout << "\nStep 2: What is the price per gallon of paint? $ ";
   cin >> gallonPrice;

   while (gallonPrice < 10.0)
   {
      cout << "\nFailure! The price for a gallon of paint must at least\n"
           << "be $10 or above. Please repeat your input: $";
      cin >> gallonPrice;

      /* Call: catchInifiniteLoop */
      catchInfiniteLoop();
   }

   cout << "\nStep 3: Please enter the wall space (in square foot)\n"
        << "for each room\n\n";

   /* As long as roomNumber is lower than roomsToPaint the user is asked
      to enter the square feet of wallspace to be painted per room */
   for (int roomNumber = 1; roomNumber <= roomsToPaint; ++roomNumber)
   {
      cout << "room number " << roomNumber << ": ";
      cin >> sqFtWallspace;

      /* Validate: Input */
      while (sqFtWallspace < 1)
      {
         cout << "Failure! The square feet of wall space must be\n"
              << "greater than 0.\n";
         cout << "room number " << roomNumber << ": ";
         cin >> sqFtWallspace;

         /* Call: catchInfiniteLoop */
         catchInfiniteLoop();
      }

      /* Accumulate: The square feet total */
      sqFtTotal += sqFtWallspace;
   }
}

/* **********************************************************
   Definition calcLaborCost

   This function accepts the following arguments:

      * The square feet total of all rooms

   It calculates the total cost for labor for the job, and
   passes the work hours required to finish the job back to
   main.
   ********************************************************** */

double calcLaborCost(double sqFtWallspace, double &workHoursRequired,
                     int stdWorkHours, int stdWspace,
                     double stdCharge)

   /* Variable: Total labor cost */
   double totalLaborCost = 0.0;

   /* Calculate: The required hours of work */
   workHoursRequired = (sqFtWallspace / stdWspace) * stdWorkHours;
 
   /* Return: Total calculated total labor cost */
   return (totalLaborCost = workHoursRequired * stdCharge);
}

/* **********************************************************
   Definition calcMaterialCost

   This function accepts the following arguments:

      * The square feet total of all rooms
      * The cost of paint

   It calculates and returns the total material cost for the
   job, and passes the number of gallons required back to
   main.
   ********************************************************** */

double calcMaterialCost(double sqFtWallspace, double costOfPaint,
                        double &gallonsRequired, int stdWspace)

   /* Variable: Total material cost */
   double totalMaterialCost = 0.0;

   /* Calculate: The required number of gallons */
   gallonsRequired = (sqFtWallspace / stdWspace);

   /* Return: The calculated total material cost  */
   return (totalMaterialCost = gallonsRequired * costOfPaint);
}

/* **********************************************************
   Definition: calcTotalCost

   This function accepts three arguments:

      * The total labor cost
      * The total material cost
  
   It calculates and returns the total job cost.
   ********************************************************** */

double calcTotalCost(double laborCostTotal, double materialCostTotal)
{
   /* Variable: Total job cost */
   double totalJobCost = 0.0;

   /* Return: The total job cost */
   return (totalJobCost = laborCostTotal + materialCostTotal);
}

/* **********************************************************
   Definition displayEstimatedCost

   This function displays the following information:
     
      * 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
   ********************************************************** */

void displayEstimatedCost(int numRoomsTotal, double wallspaceTotal,
                          double gallonsTotal, double hoursTotal,
                          double paintCostTotal, double workCostTotal,
                          double jobCostTotal)
{
   /* Set up: Numeric output formatting */
   cout << fixed << showpoint << setprecision(2);

   /* Display: Total job cost - The total number of hours required to
               finish the job and the number of gallons needed for the
               job are rounded to the nearest whole numbers */
   cout << "\n\t\tACME ACRES PAINT COMPANY - ESTIMATED JOB COST\n\n"
        << "You wish us to paint " << numRoomsTotal << " rooms with "
        << " a wall space of " << wallspaceTotal << " square feet\n\n"
        << "Gallons Of Paint:\t\t\t\t\t "
        << setw(9) << right << (round(gallonsTotal))
        << "\nHours Of Work:\t\t\t\t\t\t "
        << setw(9) << right << (round(hoursTotal))
        << "\n\nPaint Cost Total:\t\t\t\t\t$ "
        << setw(8) << right << paintCostTotal
        << "\nLabor Cost Total:\t\t\t\t\t$ "
        << setw(8) << right << workCostTotal
        << "\n--------------------------------------------------"
        << "-------------------\n"
        << "Estimated Total Cost:\t\t\t\t\t$ "
        << setw(8) << right << jobCostTotal << endl;

   cout << "\nThanks for your inquiry and have a nice day!\n"
        << "(Press Enter To Exit)\n";

   pauseSystem();
}

Example Output



No comments:

Post a Comment