>A02.exe What shape to draw ((f)ill, checkerboard (cb), (sq)uare, (x), or upper-
ID: 3751601 • Letter: #
Question
>A02.exe
What shape to draw ((f)ill, checkerboard (cb), (sq)uare, (x), or upper-left tri (ul) )? Enter ’q’ to exit.:
f
||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||
What shape to draw ((f)ill, checkerboard (cb), (sq)uare, (x), or upper-left tri (ul) )? Enter ’q’ to exit.:
cb
||| ||| ||| ||| |||
||| ||| ||| ||| |||
||| ||| ||| ||| |||
||| ||| ||| ||| |||
||| ||| ||| ||| |||
||| ||| ||| ||| |||
||| ||| ||| ||| |||
||| ||| ||| ||| |||
||| ||| ||| ||| |||
||| ||| ||| ||| |||
What shape to draw ((f)ill, checkerboard (cb), (sq)uare, (x), or upper-left tri (ul) )? Enter ’q’ to exit.:
sq
||||||||||||||||||||||||||||||
||| |||
||| |||
||| |||
||| |||
||| |||
||| |||
||| |||
||| |||
||||||||||||||||||||||||||||||
What shape to draw ((f)ill, checkerboard (cb), (sq)uare, (x), or upper-left tri (ul) )? Enter ’q’ to exit.:
x
||| |||
||| |||
||| |||
||| |||
||||||
||||||
||| |||
||| |||
||| |||
||| |||
What shape to draw ((f)ill, checkerboard (cb), (sq)uare, (x), or upper-left tri (ul) )? Enter ’q’ to exit.:
ul
||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||
||||||||||||||||||||||||
|||||||||||||||||||||
||||||||||||||||||
|||||||||||||||
||||||||||||
|||||||||
||||||
|||
What shape to draw ((f)ill, checkerboard (cb), (sq)uare, (x), or upper-left tri (ul) )? Enter ’q’ to exit.:
q
Can anyone solve this problem in C++
Explanation / Answer
#include <cstdio>
#include <iostream>
#include <string> //required to take string input
using namespace std;
int main() {
string in; //input
while(true){
cout << "What shape to draw ((f)ill, checkerboard (cb), (sq)uare, (x), or upper-left tri (ul) )? Enter ’q’ to exit.: ";
cin >> in;
if(in=="f"){ //fill
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
cout << "|||";
}
cout << " ";
}
}else if(in=="cb"){ //checkerboard
for(int i=0;i<10;i++){
for(int j=0;j<5;j++){
cout << "||| ";
}
cout << " ";
}
}else if(in=="sq"){ //square
for(int i=0;i<10;i++){
if(i==0 || i==9){
for(int j=0;j<10;j++){
cout << "|||";
}
}else{
cout << "||| |||";
}
cout << " ";
}
}else if(in=="x"){ //x
for(int i=0;i<10;i++){
for(int j=0;j<2;j++){
cout << "|||";
if(i!=4 && i!=5){
cout << " ";
}
}
cout << " ";
}
}else if(in=="ul"){ //upper-left triangle
for(int i=0;i<10;i++){
for(int j=0;j<10-i;j++){
cout << "|||";
}
cout << " ";
}
}else if(in=="q"){ //exit
return 0;
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.