⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prog8.cpp

📁 C++语言程序设计题典
💻 CPP
字号:
#include <iostream.h>
const Max=20;
class base
{
	int x,y;
public:
	base(int i,int j) { x=i;y=j; }
	void move() { cout << "将画笔移动到坐标(" << x << "," << y << ")"; }
	virtual void draw()=0;
};
class Point:public base
{
public:
	Point(int i,int j):base(i,j) {}
	void draw()
	{
		base::move();
		cout << ",画一个点。" << endl;
	}
};
class Circle:public base
{
	int r;
public:
	Circle(int i,int j,int k):base(i,j)
	{
		r=k;
	}
	void draw()
	{
		base::move();
		cout << ",画一个半径为" << r << "的圆。" << endl;
	}
};
class Line:public base
{
	int x1,y1;
public:
	Line(int i,int j,int k,int l):base(i,j)
	{
		x1=k;y1=l;
	}
	void draw()
	{
		base::move();
		cout << ",画一条到坐标(" << x1 << "," << y1 << ")的直线。" << endl;
	}
};
class Graphics
{
	int top;
	base *elems[Max];
public:
	Graphics() { top=0; }
    void push(base *g)
	{
		elems[top]=g;
		top++;
	}
	void draw()
	{
		for (int i=0;i<top;i++)
		{
			cout << "第" << i+1 << "步:";
			elems[i]->draw();
		}
	}
};
void main()
{
	Graphics g;
	g.push(new Point(3,5));
	g.push(new Line(1,2,3,5));
	g.push(new Circle(3,4,5));
	g.push(new Line(8,6,21,15));
	g.push(new Circle(8,2,3));
	g.push(new Point(6,9));
	cout << "画图步骤:" << endl;
	g.draw();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -