Consider the following class definition class rectangleType { public: //Postcond
ID: 3645831 • Letter: C
Question
Consider the following class definition
class rectangleType
{
public:
//Postcondition: length = x; width = y;
void setLengthWidth(double x, double y);
//Output length and width;
void print() const;
//Calculate and return the area of the rectangle;
double area();
//Calculate and return the parameter;
double perimeter();
//Postcondition: length = 0; width = 0;
rectangleType();
//Postcondition: length = x; width = y;
rectangleType(double x, double y);
private:
double length;
double width;
};
// and the object declaration
rectangleType bigRect(14,10);
Which of the following statements is correct?
(Points : 4)
bigRect.setLengthWidth();
bigRect.setLengthWidth(3.0, 2.0);
bigRect.length = 2.0;
bigRect.length = bigRect.width;
Explanation / Answer
object declaration invokes the constructor, and hence now length=14 and width is 10 1.bigRect.setLengthWidth() is incorrect because the method has been declared with two arguments 2.bigRect.setLengthWidt(3.0,2.0) changes the length and width to 3.0 and 2.0 respectively. Hence it is correct notation 3.bigRect.length=2.0 initializes the length variable with 2.0. Hence it is also correct 4.bigRect.length=bigRect.width assigns the width value to length variable. For this the width variable must have been predefined.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.