项目1(拓展)--矩形类

来源:互联网 发布:2345看图王 mac 编辑:程序博客网 时间:2024/04/30 01:45
/**程序的版权和版本声明部分:*Copyright(c)2013,烟台大学计算机学院学生*All rights reserved.*文件名称:*作者:尚振伟*完成日期:2014年3月24日*版本号:v0.1*对任务及求解方法的描述部分:*输入描述:无*问题描述:*程序输入:*程序输出:*问题分析:*算法设计:*我的程序:*/#include <iostream>#include <Cmath>using namespace std;class Rectangle{public:    Rectangle(double,double);    double area();    double perimeter();    double dx();    void issquare();private:    double length;    double width;};Rectangle::Rectangle(double l,double w){    length=l;    width=w;}double Rectangle::area(){    return(length*width);}double Rectangle::perimeter(){    return(length+width);}double Rectangle::dx(){    double t;    t=sqrt(length*length+width*width);    return(t);}void Rectangle::issquare(){    if(length==width)    {        cout<<"此矩形是正方形"<<endl;    }    else    {        cout<<"此矩形不是正方形"<<endl;    }}int main(){    Rectangle r(5,6);    r.issquare();    cout<<"面积为:"<<r.area()<<endl;    cout<<"周长为:"<<r.perimeter()<<endl;    cout<<"对象线为:"<<r.dx()<<endl;    return 0;}


结果展示:

心得体会:小试牛刀,初体验。

0 0