Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help debug this C + + program please? #include using namespace std; class Rectangle { private: double length; double width; public: void setLength

Can someone help debug this C++ program please?
#include
using namespace std;
class Rectangle
{
private:
double length;
double width;
public:
void setLength(double len)
{ length = len; }
void setWidth(double wid)
{ width = wid; }
double getLength()
{ return length; }
double getWidth()
{ return width; }
double getArea()
{ return length * width; }
};
class Carpet
{
private:
double pricePerSqYd;
Rectangle size; // size is an instance of
// the Rectangle class
public:
void setPricePerYd(double p)
{ p = pricePerSqYd; }
void setDimensions(double len, double wid)
{ size.setLength(len);
size.setWidth (wid);
}
double getTotalPrice()
{ return (size.getArea()* size.getLength()); }
};
//************** Client Program *****************
int main()
{
Carpet purchase; // This variable is a Carpet object
double pricePerYd;
double length;
double length;
cout << "Room length in feet: ";
cin >> length;
cout << "Room width in feet : ";
cin >> width;
cout << "Carpet price per sq. yard: ";
cin >> pricePerYd;
purchase.setDimensions(length, width);
purchase.setPricePerYd(pricePerYd);
cout <<"
The total price of my new "<< length <<" x "<< width
<<" carpet is $"<< purchase.getTotalPrice()<< endl;
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

More Books

Students also viewed these Databases questions