C++第一章上机作业2020-11-20
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c1535a6c17ea0b956e119809263a00bd.jpeg#pic_center)
#include<iostream>
using namespace std;
class Draw{
public:
Draw(char,int,int);
void DrawWall();
void DrawBox();
void DrawTriangle();
private:
char what;
int down;
int across;
};
Draw::Draw(char what,int down,int across){
this->what=what;
this->down=down;
this->across=across;
}
void Draw::DrawWall(){
for(int i=0;i<down;i++){
for(int j=0;j<across;j++)
cout<<what;
cout<<endl;
}
}
void Draw::DrawBox(){
for(int i=0;i<across;i++){
cout<<what;
}
cout<<endl;
for(int i=2;i<down;i++){
cout<<what;
for(int j=2;j<across;j++){
cout<<" ";
}
cout<<what<<endl;
}
for(int i=0;i<across;i++){
cout<<what;
}
cout<<endl;
}
void Draw::DrawTriangle(){
for(int i=1;i<=across;i++){
for(int j=1;j<=i;j++)cout<<what;
cout<<endl;
}
}
int main(){
int type=1;
char what;
int down,across;
while(1){
cout<<"请输入要绘制的图形:1-墙 2-框 3-三角,输入-1结束"<<endl;
cin>>type;
if(type==-1)break;
if(type>3||type<=0)cout<<"类型不符合要求,请重新来!"<<endl;
else{
cout<<"请输入图形的填充字母"<<endl;
cin>>what;
cout<<"请输入高度"<<endl;
cin>>down;
cout<<"请输入宽度"<<endl;
cin>>across;
switch(type){
case 1:Draw(what,down,across).DrawWall();break;
case 2:Draw(what,down,across).DrawBox();break;
case 3:Draw(what,down,across).DrawTriangle();break;
}
}
}
return 0;
}