answersLogoWhite

0


Best Answer

void draw_box (const unsigned size)

{

if (!size) return; // size must be non-zero!

const char star {'*'}; // asterisk

const char nl {'\n'}; // newline

if (size==1)

{

// a box of size 1 is just a single asterisk

std::cout << star << nl;

return;

}

// else if (1 < size) ...

// the top and bottom lines are the same

const std::string line (size, star);

// hollow line (spaces)

const std::string hollow (size-2, ' ');

// draw the top line

std::cout << line << nl;

// draw the middle lines (if size>2)

for (unsigned i=2; i<size; ++i)

std::cout << star << hollow << star << nl;

// draw the bottom line

std::cout << line << nl;

}

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a c plus plus program to print a hollow square of a given size using asterisks and blanks?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program that input a positive integer and prints a triangle using for loop?

write a program that reads in the size of the side of square and then pints a hollow square of that size out of asterisks and blanks?


What is the meaning of SHS in steel sections?

Its a Square hollow section its a regual beam that is hollow.. in other words a metal tube beam.


What is the area of Mansfield Hollow Lake?

The area of Mansfield Hollow Lake is 1,780,616.8258560002 square meters.


What is the area of Half Tree Hollow?

The area of Half Tree Hollow is 1,600,000.0 square meters.


What is the area of Fool Hollow Lake?

The area of Fool Hollow Lake is 607,028.46336 square meters.


What is the area of Shanty Hollow Lake?

The area of Shanty Hollow Lake is 546,325.617024 square meters.


What is the area of Stillhouse Hollow Lake?

The area of Stillhouse Hollow Lake is 26.017 square kilometers.


Is a square hollow?

A square is a two-dimensional figure. The line segments that are its perimeter enclose a given area. This area might be considered the "inside" of the square, and might, in some sense, allow the square to be considered hollow.


What is the area of Bean Hollow State Beach?

The area of Bean Hollow State Beach is 178,061.6825856 square meters.


What is the area of Sleepy Hollow State Park?

The area of Sleepy Hollow State Park is 10.837 square kilometers.


What is the area of Chatfield Hollow State Park?

The area of Chatfield Hollow State Park is 1,440,680.8863744 square meters.


What is the area of Smoky Hollow Historic District?

The area of Smoky Hollow Historic District is 97,124.5541376 square meters.