Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help with this C++ problem Write a program that draws shapes on the conso

ID: 3844775 • Letter: P

Question

Please help with this C++ problem

Write a program that draws shapes on the console. The program will execute in a while loop to display a menu to the user. Users can select among 4 different shapes: a filled rectangle, an empty rectangle, a filled triangle, and an empty triangle. In order to draw a rectangle on the console, the program must request the desired width and height of the rectangle. Once the user enters these parameters, the program will use a nested for loop to draw the rectangle. For triangles, the program will request the height of the triangle before drawing a triangle of given height. For both rectangle and triangle shapes, users can select to fill each shape with the character or draw them empty with the ank space. The sample output for the filled rectangle option is provided below. 1. Filled Rectangle 2. pty Rectangle 3. Filled Triangle 4. Empty Triangle 5. Exit Enter option: 1 Enter height: 4 Enter width 1. Filled Rectangle 2. Empty Rectangle 3. Filled Triangle 4. Empty Triangle 5. Exit Enter option: 5 Good bye! The sample output for the empty rectangle option is provided below. 1. Filled Rectangle 2. Empty Rectangle 3. Filled Triangle 4. Empty Triangle 5. Exit Enter option: 2 Enter height: 6 Enter width 1. Filled Rectangle 2. Empty Rectangle 3. Filled Triangle 4. Empty Triangle 5. Exit Enter option: 5 Good bye!

Explanation / Answer

#include<iostream>
using namespace std;
int main()
{
   int i=0;
   int height=0,width=0;
   int p=0,k=0,x=0,j=0,y=0,i1=0;
   int t=0;
  
   while(i!=5)
   {
       cout<<"1. Filled Rectangle 2. Empty Rectangle 3. Filled Triangle 4. Empty Triangle 5. Exit";
       cout<<" Enter option: ";
       cin>>i;
       if(i==1 || i==2)
       {
       cout<<"Enter height: ";
       cin>>height;
       cout<<"Enter width: ";
       cin>>width;
      
       if(i==1)
       {
       cout<<endl;
       for(k=1; k<=height;k++)
       {
       for(p=1;p<=width;p++)
       {cout<<"* ";
       }
       cout<<endl;
       }
       cout<<endl;
       }
      
      
       if(i==2)
       {
       cout<<endl;
       for(k=1; k<=height;k++)
       {
       for(p=1;p<=width;p++)
       {
           if(k==1 || k==height)
       cout<<"* ";
       else
       {
           if(p==1 || p==width)
           cout<<"* ";
           else
           cout<<" ";
       }
      
       }
       cout<<endl;
       }
       cout<<endl;
       }
      
      
       }
      
       if(i==3 || i==4)
       {
       cout<<"Enter height: ";
       cin>>height;
       k=0;y=0;i1=0;
       if(i==3)
       {
           cout<<endl;
           for(i1=1; i1<=height; ++i1, k=0)
{
for(y=1; y<=height-i1; ++y)
{
cout<<" ";
}

while(k != 2*i1-1)
{
cout<<"* ";
++k;
}

cout<<endl;
}
cout<<endl;
   }


   if(i==4)
       {
           cout<<endl;
           for(i1=1; i1<=height; ++i1, k=0)
{
for(y=1; y<=height-i1; ++y)
{
cout<<" ";
}

while(k != 2*i1-1)
{
   if(k==(2*i1-2) || k==0 || i1==height)
cout<<"* ";
else
cout<<" ";
++k;
}

cout<<endl;
}
  
cout<<endl;
   }      
          
       }
      
      
       if(i==5)
       cout<<"Good bye!";
   }
  
   return 0;
}