继承与派生 测试 圆类P225

//
// Created by 刘彪 on 2020/3/2.
//继承与派生 测试 圆类

#include <iostream>
#include <cmath>
using namespace std;
class Point{
protected:
    int x,y;
public:
    Point(){}
};

class Circle:public Point{
protected:
    double r,area;
public:
    Circle(int a,int b){
        x = a;
        y = b;//自己:继承而来
        r = sqrt(x*x +y*y);
        area = 3.1415926 * r*r;
    }
    void dispPoint(){
        cout<<"所经过点的坐标:("<<x<<","<<y<<")"<<endl;

    }
    void dispRadius(){
        cout<<"圆的半径"<<r<<endl;

    }
    void dispArea(){
        cout<<"圆的面积:"<<area<<endl;
    }

};

int main(){
    Circle c(10,25);
    c.dispPoint();
    c.dispRadius();
    c.dispArea();

    return 0;

}

全部评论

相关推荐

面我面我面我_秋招版:不是戈门,干哪来了,这就是java嘛
点赞 评论 收藏
分享
我只是一个小白菜:我还用不惯m4,也是山猪吃不了细糠了
投递字节跳动等公司10个岗位
点赞 评论 收藏
分享
09-29 15:01
门头沟学院 C++
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务