类的派生与继承、构造函数、函数重载、多态性等C++技术问题

2025-01-05 18:06:15
推荐回答(1个)
回答1:

class figure
{ public:
void erease()
{
cout<<"基类擦除"< system("CLS");
}
virtual void draw()
{
cout<<"基类画图"< }

};

class rectangle:public figure
{
public:
void draw()
{
cout<<"矩形画图"< for(int i=0;i<20;i++)
cout<<"*";
cout< for(int i=0;i<5;i++)
{ cout<<"*";
for(int j=0;j<18;j++)
cout<<" ";
cout<<"*"< }
for(int i=0;i<20;i++)
cout<<"*";
cout<
}
void center()
{
erease();
draw();

}

};

class triangle:public figure
{
public:
void draw()
{
cout<<"三角形画图"< for(int i=0;i<5;i++)
{
cout<<"*";
for(int j=0;j<2*i;j++)
cout<<" ";
cout<<"*";
cout< }
for(int i=0;i<10;i++)
cout<<"*";
cout< }
void center()
{
erease();
draw();

}
};
void main()
{
rectangle a;
triangle b;
a.center ();

cout<<"现在敲击任意键擦除重新画图"< cout< cout< system("PAUSE");
b.center ();

}