作业1 题目:12345678910111213141516171819202122232425262728293031323334353637383940#include<iostream>using namespace std;class Rectangle { private: float width, height;public: Rectangle();//无参数构造函数 Rectangle(float width, float height);//声明构造函数 void Setwidth(float width) {//设置新的宽度 this ->width = width; } void Setheight(float height) {//设置新的高度 this->height = height; } float getArea(){ return height * width; } float getPerimeter() { return (height + width) * 2; }};Rectangle::Rectangle() {//无参数构造函数使用 this->width = 1.0; this->height = 1.0;}Rectangle::Rectangle(float width, float height) {//有参数构造函数使用 this->width = width; this->height = height;}int main(void) { Rectangle rec_1;// cout << "无参构造函数的面积为:" << rec_1.getArea() <<" 长度为:" <<rec_1.getPerimeter()<< endl; Rectangle rec_2(4,5); cout << "有参构造函数的面积为:" << rec_2.getArea() << " 长度为:" << rec_2.getPerimeter() << endl; rec_2.Setheight(8);//长度修改为8 cout << "修改后的有参构造函数的面积为:" << rec_2.getArea() << " 长度为:" << rec_2.getPerimeter() << endl; system("pause"); return 0;}