Answer to Question #18939 in C++ for diganto007

Question #18939
The West eld Carpet Company has asked you to write an application that calculates
the price of carpeting for rectangular rooms. To calculate the price, you multiply the
area of the floor (width times length) by the price per square foot of carpet. For
example, the area of floor that is 12 feet long and 10 feet wide is 120 square feet. To
cover that floor with carpet that costs $8 per square foot would cost $960. (12 * 10 *
8 = 960.)now write a program using class that shows
application should display the total cost of the carpet.
1
Expert's answer
2012-11-19T12:17:01-0500
#include <iostream>
#include "Carpet.h"

using namespace std;

void Carpet::ShowPrice()
{
double price = width * length * pricePerSquareFoot;
cout << endl << "The price of the carpet is: " << price << "$" << endl;
}

void Carpet::InputWidth()
{
cout << "Please enter the price per square foot of a carpet: ";
cin >> this->width;
}

void Carpet::InputLength()
{
cout << "Please enter the width of the carpet: ";
cin >> this->length;
}

void Carpet::InputPricePerSquareFoot()
{
cout << "Please enter the length of the carpet: ";
cin >> this->pricePerSquareFoot;
}



class Carpet
{
private:
double pricePerSquareFoot;
double width;
double length;

public:
void ShowPrice();
void InputWidth();
void InputLength();
void InputPricePerSquareFoot();
};


#include <stdio.h>
#include <iostream>
#include "Carpet.h"

using namespace std;

void main()
{
Carpet c;

while (true)
{
& system("cls"); //clearing the console, for Windows only

& c.InputWidth();
& c.InputLength();
& c.InputPricePerSquareFoot();
& c.ShowPrice();

& cout << "\n\nDo you want to perform another calculations? (y/n): ";
& fflush(stdin);
& fflush(stdout);

& int a = toupper(getchar());
& if (a != 'Y')
& return;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS