码迷,mamicode.com
首页 > 其他好文 > 详细

博客园第三次作业

时间:2018-04-08 19:01:11      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:alt   clu   length   names   end   public   div   cin   std   

4-11
#include<iostream> using namespace std; class Rectangle{ //定义矩形类 public: //公共成员接口 Rectangle(double i,double j); //构造函数 Rectangle(Rectangle &R); //复制构造函数 ~Rectangle(); //析构函数 double area(double length,double width){ return length*width; }; //计算矩形面积,内联函数 private: //私有成员接口 double length; double width; }; Rectangle::Rectangle(double i,double j){ //构造函数,定义数据类型 length = i; width = j; } Rectangle::Rectangle(Rectangle &R){ //析构函数 length = R.length; width = R.width; } Rectangle::~Rectangle() { } int main(){ double length,width; cout << "矩形的长 :" ; //输入长的值 cin >> length; cout << "矩形的宽 :"; //输入宽的值 cin >> width; Rectangle R1(length,width); //定义rectangle类的对象R1 cout << "矩形的面积 :" << R1.area(length,width) << endl; return 0; }


运行结果截图
技术分享图片




  

博客园第三次作业

标签:alt   clu   length   names   end   public   div   cin   std   

原文地址:https://www.cnblogs.com/yyq828/p/8746091.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!