//比较萌新的内容,具体操作都在注释里面了,欢迎来交流哦~
#include <iostream>
#include <stdlib.h>
using namespace std;
class point//定义"点"为父类
{
protected:
int x; int y;
public:
point()
{
x = 3;
y = 5;
}
point(int xx, int yy)
{
x = xx;
y = yy;
}
};
class circle :public point //定义“圆”为子类
{
protected:
double r;
public:
circle(int n)//初始化对象中含有一个参数时的初始化函数
{
r = 100;
}
circle(int x, int y) :point(x, y)//继承父类的x,y的数据,初始化对象中含有两个参数时的初始化函数
{
r = 2;
}
circle(int x, int y, double rr) :point(x, y)//继承父类的x,y的数据,初始化对象中含有三个参数时的初始化函数
{
r = rr;
}
void output()//输出点的数据
{
cout << "x=" << x << endl;
cout << "y=" << y << endl;
cout << "r=" << r << endl;
}
double area()//返回圆的面积
{
double s = 3.14*r*r;
return s;
}
void display()//输出圆的数据
{
cout << "圆心坐标为:" << "(" << x << "," << y << ")" << endl;
cout << "圆的半径为:" << r << endl;
cout << "圆的面积为:" << area() << endl;
}
};
int main()
{
circle A(1,2,3);//调用第三个初始化函数
A.output();
A.display();
system("pause");
return 0;
}