//#pragma once
//Shape.h头文件
#include//
using namespace std;
//建立形状类
class Shape
{
public:
Shape(int a = 0, int b = 0);
void draw();
void set(int a,int b);//设置x和y
int getx();//获取x
int gety();//获取y/
private:
int x;//横坐标
int y;//纵坐标
};
//
- //Circle.h头文件
#include//
#include"Shape.h"
using namespace std;
class Circle :public Shape
{
int r;//圆的半径
public:
Circle(int x,int y,int c);
void Setr(int c);//设置半径r
double Area();//面积
void Move(int x_offset, int y_offset);//修改坐标
void drawCircle();
};
//
//Shape.cpp
#include//
#include"Shape.h"//
using namespace std;
const double Pi = 3.14159;
//初始化参数列表
Shape::Shape(int a,int b)
{
x = a;
y = b;
}
void Shape::draw()
{
cout << "draw in Shape:( "<< x << ',' << y<< ")"<< endl;
}
//设置xy的值
void Shape::set(int a, int b)
{
x = a;
y = b;
}
//获取x值
int Shape::getx()
{
return x;
}
//获取y值
int Shape::gety()
{
return y;
}
//
//Circle.cpp
#include//
#include"Circle.h"
using namespace std;
const double Pi = 3.14159;
//初始化成员列表
Circle::Circle(int x, int y, int c):Shape(x,y)
{
int r = c;
}
//设置半径
void Circle::Setr(int c=0)
{
r = c;
}
//面积
double Circle::Area()
{
return Pi * r*r ;
}
//修改坐标
void Circle::Move(int x_offset, int y_offset)
{
int x1 = getx();
int y1 = gety();
x1 += x_offset, y1 += y_offset;
set(x1, y1);
}
//打印
void Circle::drawCircle()
{
draw();
cout << "draw in circle:" << " ";
cout << "半径:" << r << " ";
cout << "面积:" << Area() << endl;
}
//
//main函数
#include//
#include"Circle.h"
using namespace std;
int main()
{
Circle s(3,3,3);
s.drawCircle();
s.Move(1, 2);
s.drawCircle();
s.set(4, 5);
s.Setr(3);
s.drawCircle();
s.Setr(5);
s.drawCircle();
system("pause");
return 0;
}