Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ / This program nests one class inside another. It has a class / / with a member variable that is an instance of another
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 setLengthdouble len
length len;
void setWidthdouble 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 setPricePerYddouble p
p pricePerSqYd;
void setDimensionsdouble len, double wid
size.setLengthlen;
size.setWidth wid;
double getTotalPrice
return sizegetArea 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.setDimensionslength width;
purchase.setPricePerYdpricePerYd;
cout
The total price of my new length x width
carpet is $ purchase.getTotalPrice endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started