Question: Given the following ADT class definition: class rectangle { public: rectangle(); rectangle(double, double); void setLength(double); //Post: the length of the triangle is set to the
Given the following ADT class definition:
class rectangle
{
public:
rectangle();
rectangle(double, double);
void setLength(double);
//Post: the length of the triangle is set to the parameter value
void setWidth(double);
//Post: the width of the triangle is set to the parameter value
double lengthIs();
//Post: return value is the length of the rectangle
double widthIs();
//Post: return value is the width
double area();
//Post: returns the area of the rectangle
private:
double length;
double width;
};
a) Assume that the default constructor sets the private data members to 0, and the other constructor sets the private data members to the parameters.
i) Write the implementation code for the default constructor.
ii) Write the implementation code for the second constructor.
iii) Show how client code would declare a rectangle using the first constructor.
iv) Show how client code would declare a rectangle using the second constructor.
b) Add a public member function that allows a user to compare two rectangles. Show the prototype, and explain where you would put it. Give the function definition as well. This public member function returns true if the two rectangles have exactly the same dimensions and false otherwise. (If one rectangle has width 6 and length 7 and the other has width 7 and length 6, they should still be equal.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
