纯虚函数

#include<iostream>
using namespace std;
const double Pi = 3.14;

class Shape
{
public:
	virtual void draw() = 0;
};

class Cicle:public Shape
{
public:
	void set(int a, int b, int c) {r = a ; x = b; y=c;}
	int getr() {return r;}
	int getx() {return x;}
	int gety() {return y;}
	void draw() {cout << "圆形的面积" << (Pi * r*r) << endl;}
private:
	int r,x,y;
};

void main()
{
	Cicle ci;
	ci.set(2,4,6);
	cout << "r=" << ci.getr() << endl;
	cout << "x=" << ci.getx() << endl;
	cout << "y=" << ci.gety() << endl;
	ci.draw();
}

结果:

posted on 2022-10-26 21:04  进取  阅读(22)  评论(0编辑  收藏  举报