Question 7.7. (TCO 2) Define and implement the overloaded constructors that supp
ID: 3851446 • Letter: Q
Question
Question 7.7. (TCO 2) Define and implement the overloaded constructors that support the following test function for a Rectangle class. The data members for the Rectangle class are: • length - integer number • width - integer number int main() { Rectangle r1(); //r1 will take all default value Rectangle r2(4, 5); //r2 will take all supplied value Rectangle r3(10); //r3 will take supplied length, width will take default value Rectangle r4= r2; //r4 will take the same value of r2 //the rest of the code }
Explanation / Answer
class Rectangle
{
public:
static const int DEFAULT_LENGTH=10;
static const int DEFAULT_Width=10;
Rectangle()
{
length = DEFAULT_LENGTH;
width =DEFAULT_WIDTH;
}
Rectangle(int l, int w)
{
length = l;
width = w;
}
Rectangle(int l)
{
length = l;
width = DEFAULT_WIDTH;
}
Rectangle(const Rectangle &obj)
{
length=obj.length;
width=obj.length;
}
private:
int length
int width;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.