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

Hi I need help please for my c++ class, help please !!! I\'m asked to output thi

ID: 3568448 • Letter: H

Question

Hi I need help please for my c++ class, help please !!!

I'm asked to output this shape using nested loops and functions. I'm giving the following.

The width and the length are entered by the user. Also I'm giving the following function that I must use in addition to the following lines in main. For extra-credit, create another function.

Note the second line of the shape is indeted from both sides.

Important Note: so int getPosNum() should verify that the user enter a positive number for both the width and length if entered a negative, the program should ask the user to re-enter. THE OUTPUT for both 5*5 should output a rectangle but the second, third, and forth line, should have only four characters, indented from both ends.

if the output was 4*4 then then output a rectangle with the second and third line having only three indented charaters from both ends.

int getPosNumber ()

int main

{

cout << " please enter the length" ;

cout << " please enter the width" ;

output is

x x x                   x x x x              x x x x
x x                      x x x                 x x x
x x x                   x x x x               x x x

                                                  x x x x                                                  

                                          

Explanation / Answer

#include <iostream>

using namespace std;

void Draw(int l, int b)
{
for(int i=0; i<b; i++)
{
if(i == 0 || i == b-1)
{
for(int j=0; j<l; j++)
{
cout<<"X ";
}
}
else
{
cout<<" ";
for(int j=0; j<l-1; j++)
{
cout<<"X ";
}
}
cout<<" ";
}
}

int getPosNum()
{
int n;
cin>>n;
  
while(n<0)
{
cout<<" Number not valid, re-enter: ";
cin>>n;
}
return n;
}
int main()
{
  
int length, breadth;

cout << "Please enter the length: " ;
length = getPosNum();

cout << " Please enter the width: " ;
breadth = getPosNum();

cout<<" ";

Draw(length, breadth);

return 0;
}

-----------------------------------

OUTPUT