zoukankan      html  css  js  c++  java
  • YTU 2917: Shape系列-3

    2917: Shape系列-3

    时间限制: 1 Sec  内存限制: 128 MB
    提交: 372  解决: 237

    题目描述

    送给小亮的Rectangle类已完成,送给小华Circle类还没有完成。Circle类有整型的数据成员color(小强的Shape类中的color可以继续使用,无需新定义),浮点型的数据成员radius,求面积的成员函数area()。但是小聪没有为Circle类写构造函数和成员函数,请帮助小聪完成Circle类。

    小强写的Shape类:

    class Shape
    {
    public: 
     Shape();
     Shape(int c);
     int getcolor();
     double area();
    protected:
     int color;
    };
    Shape::Shape()
    {
     color=0;
    }
    Shape::Shape(int c)
    {
     color=c;
    }
    int Shape::getcolor()
    {
     return color;
    }
    double Shape::area()
    {
     return 10000;
    }
    小聪的测试函数:
    int main()
    {
    Circle cc=Circle(3,1);
    cout<<"Circle color:"<<cc.getcolor()<<endl
    <<"Circle radius:"<<cc.getradius()<<endl
    <<"Circle area:"<<cc.area()<<endl
    <<"Circle price:"<<cc.price()<<endl;
    return 0;
    }

    提示:不用提交全部程序,只提交补充部分(包括头文件和π的定义)。

    输入

    输出

    输出小聪测试的Circle类的各个数据。

    样例输出

    Circle color:3
    Circle radius:1
    Circle area:3.14
    Circle price:9.42
    

    im0qianqian_站在回忆的河边看着摇晃的渡船终年无声地摆渡,它们就这样安静地画下黄昏画下清晨......可怜

    #include<iostream>
    using namespace std;
    #define PI 3.14
    class Shape
    {
    public:
        Shape();
        Shape(int c);
        int getcolor();
        double area();
    protected:
        int color;
    };
    Shape::Shape()
    {
        color=0;
    }
    Shape::Shape(int c)
    {
        color=c;
    }
    int Shape::getcolor()
    {
        return color;
    }
    double Shape::area()
    {
        return 10000;
    }
    class Circle
    {
    public:
        int x,y;
        Circle(int a,int b);
        int getcolor();
        int getradius();
        double area();
        double price();
    };
    Circle::Circle(int a,int b)
    {
        x=a,y=b;
    }
    int Circle::getcolor()
    {
        return x;
    }
    int Circle::getradius()
    {
        return y;
    }
    double Circle::area()
    {
        return PI*y;
    }
    double Circle::price()
    {
        return x*PI;
    }
    int main()
    {
        Circle cc=Circle(3,1);
        cout<<"Circle color:"<<cc.getcolor()<<endl
            <<"Circle radius:"<<cc.getradius()<<endl
            <<"Circle area:"<<cc.area()<<endl
            <<"Circle price:"<<cc.price()<<endl;
        return 0;
    }
    


  • 相关阅读:
    【已解决】ERR_BLOCKED_BY_XSS_AUDITOR:Chrome 在此网页上检测到了异常代码:解决办法
    【已解决】Microsoft visual c++ 14.0 is required问题解决办法
    爬虫处理网站的bug---小于号未转化为实体符
    pymysql 在数据库中插入空值
    python 正则括号的使用及踩坑
    pymysql 解决 sql 注入问题
    python3 操作MYSQL实例及异常信息处理--用traceback模块
    LeetCode 837. 新21点 | Python
    LeetCode 面试题64. 求1+2+…+n | Python
    LeetCode 101. 对称二叉树 | Python
  • 原文地址:https://www.cnblogs.com/im0qianqian/p/5989655.html
Copyright © 2011-2022 走看看