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;
Comments
Leave a comment