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

Suppose you have written a C++ program that calculates the amount of paint you n

ID: 3679668 • Letter: S

Question

Suppose you have written a C++ program that calculates the amount of paint you need tocover the walls in your family room. Two walls are 9 feet high and 19.5 feet wide. The othertwo walls are 9 feet high and 20.0 feet wide. The salesperson at the home improvement storetold you to buy 1 gallon of paint for every 150 square feet of wall you need to paint. Suppose you wrote the following code, but your program is not compiling. Take a few minutes to study this code, and then answer Questions 1 – 4.

// This program calculates the number of gallons of paint needed.

#include using namespace std;

int main()

{

double height1 = 9; double height2 = 9;

int width1 = 19.5; double width2 = 20.0;

double squareFeet;

int numGallons;

numGallons = squareFeet / 150;

squareFeet = (width1 * height1 + width2 * height2) * 2;

cout << "Number of Gallons: " << numGallons << endl;

return 0; }

1. When you compile this program, you receive a warning message from the cl compilerthat is similar to the following:

c:usersjo annc++ palchapter_2studentpaint.cpp(12) :

warning C4700: uninitialized local variable 'squareFeet '

used There are multiple problems with this program even though the compiler issued only one warning message, which is pointing out an uninitialized variable on line number12 in the source code file. You would know the compiler is complaining about line 12because of the (12) in the warning message. On the following lines, describe how to fixall of the problems you can identify.

2. You have two variables declared in this program to represent the height of your walls, height1 and height2 . Do you need both of these variables? If not, how would youchange the program? Be sure to identify all of the changes you would make.

Explanation / Answer

#include <iostream>
using namespace std;
int main()
{
double height1 = 9;
int width1 = 19.5; double width2 = 20.0;
double squareFeet;
int numGallons;
squareFeet = (width1 + width2) * height1 * 2;
numGallons = squareFeet / 150;
cout << "Number of Gallons: " << numGallons << endl;
return 0;
}

1.squareFeet variable declare but not initialized.In this above code it is initialized with calculation of square feet.

2.Two variable of height are required when they are different.If they same one height variable is enough

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote