Question

In: Computer Science

6.27 Ch 2 Program: Painting a wall (C++) (4)Calculate the cost of the paint. Paint comes...

6.27 Ch 2 Program: Painting a wall (C++)
(4)Calculate the cost of the paint. Paint comes in six colors (Red, Yellow, Green, Blue, Black,White) Assign numbers 0-5 to these paint colors ie Red =0 and White =5. The costs for each of these paints is as follows:(2 pts) Now your program will be submission ready.

Main.cpp

#include <iostream>
#include <cmath>
using namespace std;
#include "paint.h"

int main() {
   double wallHeight;
   double wallWidth;
   double wallArea;
   double gallonsPaintNeeded;
   int cansNeeded,colorNum;
   Color paintColor;
   double costArray[numOfColors];

   cout << "Enter wall height (feet): "<<endl;
   cin >> wallHeight;
   cout << "Enter wall width (feet): "<<endl;
   cin >> wallWidth;
   cout<< "Enter paint color as an integer"<<endl;
   cout<<"Red   - Enter 0"<<endl;
   cout<<"Blue - Enter 1"<<endl;
   cout<<"Green - Enter 2"<<endl;
   cout<<"Yellow- Enter 3"<<endl;
   cout<<"Black - Enter 4"<<endl;
   cout<<"White - Enter 5"<<endl;
   cout<<"Your color ?"<<endl;
   cin>>colorNum;
   paintColor= (Color)colorNum; // cast the integer to type Color

// Calculate and output wall area
// FIXME (1): Calculate the wall's area
   cout << "Wall area: " << wallArea << " square feet" << endl;   // FIXME (1): Finish the output statement


   // FIXME (2): Calculate and output the amount of paint in gallons needed to paint the wall

   cout << "Paint needed: " << gallonsPaintNeeded << " gallons" << endl;

   // FIXME (3): Calculate and output the number of 1 gallon cans needed to paint the wall, rounded up to nearest integer

   cout << "Cans needed: " << cansNeeded <<" can(s)" << endl;
   //FIX ME (3) populate the cost Array and calculate the total cost of the paint

cout << "TotalCost: $" << totalCost<<" for "<<cansNeeded;
switch (paintColor){
case Red: cout<<" Red";
break;
case Blue: cout<<" Blue";
break;
case Green: cout<<" Green";
break;
case Yellow: cout<<" Yellow";
break;
case Black: cout<<" Black";
break;
case White: cout<<" White";
break;
}
cout<<" can(s)" << endl;
   return 0;
}

paint.h

#include<fstream>
const double squareFeetPerGallons = 350.0;
const double gallonsPerCan        = 1.0;
const int numOfColors =6;
enum Color {Red, Blue, Green, Yellow, Black,White};
double calculateWallArea(double height, double width){
// height times width
}
double calculatePaintAmount(double wallArea){
//wallarea divided by square feet per gallons
}
int calculateNumberOfCans(double paintAmount){
return ceil(paintAmount/gallonsPerCan); // round up the number of cans needed
}
void getColorCost(double costArray[]){
//open the data file and read into array
}
double calculateCost(Color paintColor, double costArray[],double numOfCans ){
// the cost of paint given the color and number of cans
}

cost.txt
1.99
2.99
0.99
2.99
0.49
0.99

Solutions

Expert Solution

// paint.h

#include<fstream>

#include <cmath>

using namespace std;

const double squareFeetPerGallons = 350.0;

const double gallonsPerCan        = 1.0;

const int numOfColors =6;

enum Color {Red, Blue, Green, Yellow, Black,White};

double calculateWallArea(double height, double width){

       return(height*width);

}

double calculatePaintAmount(double wallArea){

       return(wallArea/squareFeetPerGallons);

}

int calculateNumberOfCans(double paintAmount){

return ceil(paintAmount/gallonsPerCan); // round up the number of cans needed

}

void getColorCost(double costArray[]){

       ifstream fin("cost.txt"); // provide the full path to file

       if(fin.is_open())

       {

             int i=0;

             while((!fin.eof()) && (i < numOfColors))

             {

                    fin>>costArray[i];

                    i++;

             }

             fin.close();

       }else

       {

             for(int i=0;i<numOfColors;i++)

             {

                    costArray[i] = 0;

             }

       }

}

double calculateCost(Color paintColor, double costArray[],double numOfCans ){

// the cost of paint given the color and number of cans

       switch(paintColor)

       {

       case Red:

             return(numOfCans*costArray[0]);

             break;

       case Blue:

             return(numOfCans*costArray[1]);

             break;

       case Green:

             return(numOfCans*costArray[2]);

             break;

       case Yellow:

             return(numOfCans*costArray[3]);

             break;

       case Black:

             return(numOfCans*costArray[4]);

             break;

       case White:

             return(numOfCans*costArray[5]);

             break;

       default:

             return(0);

             break;

       }

}

//end of paint.h

// main.cpp : C++ program to calculate the cost of painting a wall

#include <iostream>

#include <cmath>

using namespace std;

#include "paint.h"

int main() {

   double wallHeight;

   double wallWidth;

   double wallArea;

   double gallonsPaintNeeded, totalCost;

   int cansNeeded,colorNum;

   Color paintColor;

   double costArray[numOfColors];

   cout << "Enter wall height (feet): "<<endl;

   cin >> wallHeight;

   cout << "Enter wall width (feet): "<<endl;

   cin >> wallWidth;

   cout<< "Enter paint color as an integer"<<endl;

   cout<<"Red   - Enter 0"<<endl;

   cout<<"Blue - Enter 1"<<endl;

   cout<<"Green - Enter 2"<<endl;

   cout<<"Yellow- Enter 3"<<endl;

   cout<<"Black - Enter 4"<<endl;

   cout<<"White - Enter 5"<<endl;

   cout<<"Your color ?"<<endl;

   cin>>colorNum;

   paintColor= (Color)colorNum; // cast the integer to type Color

   // Calculate and output wall area

   wallArea = calculateWallArea(wallHeight,wallWidth);

   cout << "Wall area: " << wallArea << " square feet" << endl;   // FIXME (1): Finish the output statement

   // Calculate and output the amount of paint in gallons needed to paint the wall

   gallonsPaintNeeded = calculatePaintAmount(wallArea);

   cout << "Paint needed: " << gallonsPaintNeeded << " gallons" << endl;

   // Calculate and output the number of 1 gallon cans needed to paint the wall, rounded up to nearest integer

   cansNeeded = calculateNumberOfCans(gallonsPaintNeeded);

   cout << "Cans needed: " << cansNeeded <<" can(s)" << endl;

   // populate the cost Array and calculate the total cost of the paint

   getColorCost(costArray);

   totalCost = calculateCost(paintColor,costArray,cansNeeded);

   cout << "TotalCost: $" << totalCost<<" for "<<cansNeeded;

   switch (paintColor){

             case Red: cout<<" Red";

                    break;

             case Blue: cout<<" Blue";

                    break;

             case Green: cout<<" Green";

                    break;

             case Yellow: cout<<" Yellow";

                    break;

             case Black: cout<<" Black";

                    break;

             case White: cout<<" White";

                    break;

       }

   cout<<" can(s)" << endl;

   return 0;

}

//end of program

Output:


Related Solutions

Ch 4 Program 5: RockPaperScissors.java                                    &
Ch 4 Program 5: RockPaperScissors.java                                                  Please adhere to the Standards for Programming Assignments and the Java Coding Guidelines. In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows Rock beats scissors because a rock can break a part of scissors Scissors beats paper because scissors can cut paper...
Write a program in PYTHON that determines the cost of painting the walls of a windowless...
Write a program in PYTHON that determines the cost of painting the walls of a windowless room. There is one door and it will be painted the same color as the walls. The problem requires a main function and two custom functions that are imported from a custom module that you create. In main, the program should prompt the user for five inputs shown in blue in the Sample Output below: the length, width, and height of the room in feet. the...
Write a program that determines the cost of painting the walls of a windowless room. There...
Write a program that determines the cost of painting the walls of a windowless room. There is one door and it will be painted the same color as the walls. The problem requires a main function and two custom functions that are imported from a custom module that you create. In main, the program should prompt the user for five inputs shown in blue in the Sample Output below: the length, width, and height of the room in feet. the...
3. Refer to Ch 4, pg 132- 4 in BM. We are going to calculate the...
3. Refer to Ch 4, pg 132- 4 in BM. We are going to calculate the velocity of the Earth today (let’s say 7 Feb 2020) using the vis viva equation. Take a deep breath... (a) Calculate the "mean anomaly" of the Earth M. This is the angle from perihelion to the position of Earth as if the Earth were in a circular orbit. You have to look up the perihelion of the Earth. See pg 34 in BM. This...
The thermal decomposition of dimethyl ether CH 3 2 O g CH 4 g H 2...
The thermal decomposition of dimethyl ether CH 3 2 O g CH 4 g H 2 g CO g is to be carried out in an isothermal 2.00-liter laboratory reactor at 600°C. The reactor is charged with pure dimethyl ether at a pressure of 350 torr. After about two hours, the reactor pressure is 875 torr. (a) Has the reaction proceeded to completion at the end of the two-hour period? If not, what percentage of the dimethyl ether has decomposed?...
7.7 Ch 7 Program: Online shopping cart (continued) (C) This program extends the earlier "Online shopping...
7.7 Ch 7 Program: Online shopping cart (continued) (C) This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase struct to contain a new data member. (2 pt) char itemDescription[ ] - set to "none" in MakeItemBlank() Implement the following related functions for the ItemToPurchase struct. PrintItemDescription() Has an ItemToPurchase parameter. Ex. of PrintItemDescription() output: Bottled Water: Deer Park, 12 oz. (2) Create three new files: ShoppingCart.h - struct definition and...
9.6 Ch 9 Program: Data visualization (in C) (1) Prompt the user for a title for...
9.6 Ch 9 Program: Data visualization (in C) (1) Prompt the user for a title for data. Output the title. (1 pt) Ex: Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored (2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt) Ex: Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number of novels You entered:...
Ch 4 Program 3  – Geometry Calculator Please adhere to the Standards for Programming Assignments and the...
Ch 4 Program 3  – Geometry Calculator Please adhere to the Standards for Programming Assignments and the Java Coding Guideline. : List of source code with comments to document Test output listed as comments at the end of your program GeometryCalculator.java (15 pts) Write a program that displays the following menu: Calculate the area of a circle Calculate the area of a rectangle Calculate the area of a triangle Calculate the volume of a cylinder Quit Prompt the user to enter...
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of...
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of x students’ grades (grades will be stored in an array). To do so, please follow these guidelines: - Your program should ask the user for the number of students that are in the class. This number should help you declare your array. - Use the function seen in class to scan the grades of the array. In other words, we will populate the array...
Question 2. Write a complete C++ program that uses a 2-dimensional array with 4 rows and...
Question 2. Write a complete C++ program that uses a 2-dimensional array with 4 rows and 30 columns. Row represents sections of a course and column represents the students, value inside each position of the array is the final exam grade for each students. Fill the array with random numbers between 40 and 100. Calculate the total, average, maximum, minimum for each section. Please do it simple. code
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT