chapter 9

来源:互联网 发布:程序授权系统源码 编辑:程序博客网 时间:2024/06/04 19:57

Ex1,

#include<iostream>using namespace std;class Rectangle{public:double width_, height_;Rectangle(){width_ = 4.0;height_ = 40.0;}Rectangle(double width, double height) :width_{ 3.5 }, height_{ 35.9 }{width_ = width;height_ = height;}double getArea(){return width_*height_;}double getPerimeter(){return 2 * (width_ + height_);}};int main(){Rectangle myRectangle;cout << myRectangle.width_ << endl;cout << myRectangle.height_ << endl;cout << myRectangle.getArea() << endl;cout << myRectangle.getPerimeter() << endl;Rectangle myRectangle1;myRectangle1.width_ = 1;myRectangle1.height_ = 2;cout << myRectangle1.getArea() << endl;cout << myRectangle1.getPerimeter() << endl;return 0;}


原创粉丝点击