Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab 5 Description: Create the class, Rectangle, using the example in class as th

ID: 3529308 • Letter: L

Question

Lab 5 Description: Create the class, Rectangle, using the example in class as the basis. The class should have: - a default constructor that initializes the height and length data members - a constructor that takes to arguments and uses these to initialize height and length - a setValues function and a displayValues function In your main function: - instantiate an object of type Rectangle using no parameters - instantiate an object of type Rectangle with parameters - use the displayValues function to display the height and length for both objects Please make sure to use #include and #include as your headers. Also, make sure that program compiles successfully. Thank you. Ben

Explanation / Answer

#include<iostream>

using namespace std;


class Rectangle{

int height,length;

public:

Rectangle(){//default constructor

height=0;

length=0;

}


Rectangle(int h,int l){//constructor

height=h;

length=l;

}


void setValues(int h,int l){//sets both values

height=h;

length=l;

}


void displayValues(){

cout<<"Height: "<<height<<" Length: "<<length<<endl;

}

};


int main(){

Rectangle A, B(5,3);

cout<<"Rectangle A created with default constructor. ";

cout<<"Rectangle B created with height 5 and length 3. ";

cout<<endl<<"A: "<<endl;

A.displayValues();

cout<<endl<<"B: "<<endl;

B.displayValues();


cout<<endl<<"Press any key to continue . . .";

cin.get();

return 0;

}