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

Hi. I am so confused on the logic of this program. here is the assignment per in

ID: 3541423 • Letter: H

Question

Hi.  I am so confused on the logic of this program.  here is the assignment per instructor.  

Hi.  I am supposed to write an assignment per the instructions below.  Now, I'm okay with using the while loop and if/else statement.  That's no problem.  I just don't get the logic of incorporating strings into objects using the loops and if/else statements.  Can anyone give me any pointers?  The problem is below.  

"Read" means to use console input. Be sure to use understandable prompts, and remember to use a string buffer to read the "size". Include the 1-20 range in your prompt, so that the user knows what to expect. Check the size value, and if it's outside the 1-20 expected range, print no square.

As an enhancement, use a sentinel-controlled loop, to print squares until the user enters a size outside the 1-20 range. For example, the user enters 5 for size -- print a square of size 5, and prompt for a new size. Continue until the entered size is outside 1-20, and break out of the loop to end the program -- do not return from inside the loop. Note that since string buffers and atoi are being used, any non-numeric entry for size will be interpreted as zero, and will end the program.



(Square of Asterisks) Write a program that reads in the size of the side of a square then prints a hollow square of that size out of asterisks and blanks. Your program should work for squares of all side sizes between 1 and 20. For example, if your program reads a size of 5, it should print

Explanation / Answer

#include<iostream>


int main()

{

//u said to use atoi i assumed an array and than convert it into int

char size[3];

while(1)

{

std::cout<<"Enter size of Square : ";

std::cin>>size;

//numsize will have size of square

int numSize = atoi(size);

if(numSize<1||numSize>20)

break;

//Draw squaRE

for(int i=1;i<=numSize;i++)

{

for(int j=1;j<=numSize;j++)

{

//this if condition is true jut for first and last column and row

// otherwise else will be exicuted

if(i==1||i==numSize||j==1||j==numSize)

std::cout<<"*";

else

std::cout<<" ";

}

//for new line after each row

printf(" ");

}

}

getchar();

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote