第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

c++應用兩到三個類實現(xiàn)選擇圖形和尺寸輸出圖形

c++應用兩到三個類實現(xiàn)選擇圖形和尺寸輸出圖形

C++
臨摹微笑 2018-11-27 01:01:12
c++應用兩到三個類實現(xiàn)選擇圖形和尺寸輸出圖形?;蜻x擇0退出。實現(xiàn)輸出結(jié)果如下:
查看完整描述

1 回答

?
Cats萌萌

TA貢獻1805條經(jīng)驗 獲得超9個贊

#include<iostream>

using namespace std;

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

}
class Star : public Shape
{
public:
virtual void draw() const;
};
void Star::draw() const
{
int t,i,j,sp,s;

cout<<"請輸入尺寸:";
cin>>s;
cout<<"繪制自選圖形:"<<endl;
sp=(2*s-1)/2;
for(i=sp;i>=-sp;i--)
{
t=i>0 ? i : -i;
for(j=0;j<t;j++)
{
cout<<" ";
}
for(j=0;j<2*s-1-2*t;j++)
{
cout<<"*";
}
cout<<endl;
}
}
class Rectangle : public Shape
{
public:
virtual void draw() const;
};
void Rectangle::draw() const
{
int i,j,w,h;

cout<<"請輸入 寬 高:";
cin>>w>>h;
cout<<w<<" "<<h<<endl;
cout<<"繪制自選圖形:"<<endl;
for(i=h;i>0;i--)
{
for(j=w;j>0;j--)
{
cout<<"*";
}
cout<<endl;
}
}
int main(int argc,char* argv[])
{
int m;
Shape *pt[]={new Star(),new Rectangle()};
while(true)
{
cout<<"1- 星"<<endl<<"2- 矩形"<<endl;
cout<<"選擇一種圖形或者選0退出:";
cin>>m;
if(0==m)
{
break;
}
else if(1==m || 2==m)
{
pt[m-1]->draw();
}
else
{
cout<<"無法處理的命令!"<<endl;
}
}
delete pt[0];
delete pt[1];
return 0;
}



查看完整回答
反對 回復 2018-12-21
  • 1 回答
  • 0 關注
  • 699 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號