Question: fix bug(s) in this code // This program nests one class inside another. It has a class // with a member variable that is an

fix bug(s) in this code

// This program nests one class inside another. It has a class // with a member variable that is an instance of another class. #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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!