📄 l7_6.cpp
字号:
#include <iostream.h>
#include <string.h>
class CPoint
{
private:
int X;
int Y;
public:
CPoint(int x=0, int y=0)
{
X=x;
Y=y;
}
CPoint(CPoint &p)
{
X=p.X;
Y=p.Y;
}
int GetX()
{
return X;
}
int GetY()
{
return Y;
}
};
class CShape
{
private:
char Color[10];
public:
CShape(char *c)
{
strcpy(Color,c);
}
void Draw()
{
cout << "Draw a Shape. The color is " << Color << endl;
}
void PrintColor()
{
cout << Color << endl;
}
};
class CLine:public CShape
{
private:
CPoint Start;
CPoint End;
public:
CLine(CPoint s, CPoint e, char *c):CShape(c),Start(s),End(e)
{}
void Draw()
{
cout << "Draw a Line from (" << Start.GetX() << "," << Start.GetY();
cout << ") to ("<< End.GetX() << "," << End.GetY() << "), with color ";
PrintColor();
}
};
class CCircle:public CShape
{
private:
CPoint Center;
int Radius;
public:
CCircle(CPoint ctr, int r, char *c):CShape(c),Center(ctr)
{
Radius = r;
}
void Draw()
{
cout << "Draw a Circle at center (" << Center.GetX() << "," ;
cout << Center.GetY()<< ") with radius " << Radius << " and color ";
PrintColor();
}
};
void main()
{
CShape s("Red");
CPoint p1(10,10), p2(100,100),p3(50,50);
CLine l(p1,p2,"Green");
CCircle c(p3, 20, "Black");
s.Draw();
l.Draw();
c.Draw();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -