(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
*****
* *
* *
* *
*****
What will be an ideal response?
```
// Displaying a square of asterisks.
#include
using namespace std;
int main()
{
int stars; // number of stars on a side
int column; // the current column of the square being printed
int row = 1; // the current row of the square being printed
// prompt and read the length of the side from the user
cout << "Enter length of side:";
cin >> stars;
// valid input, if invalid, set to default
if ( stars < 1 )
{
stars = 1;
cout << "Invalid Input\nUsing default value 1\n";
} // end if
else if ( stars > 20 )
{
stars = 20;
cout << "Invalid Input\nUsing default value 20\n";
} // end else if
// repeat for as many rows as the user entered
while ( row <= stars )
{
column = 1;
// and for as many columns as rows
while ( column <= stars )
{
if ( row == 1 )
cout << "*";
else if ( row == stars )
cout << "*";
else if ( column == 1 )
cout << "*";
else if ( column == stars )
cout << "*";
else
cout << " ";
column++; // increment column
} // end inner while
cout << endl;
row++; // increment row
} // end outer while
} // end main
```
You might also like to view...
What are the most important types of scanning?
What will be an ideal response?
If you are unsure if a graphic or word is a link, you can simply place your mouse pointer over the word or picture. If it is a link, the pointer changes to a(n) ____ pointer.
A. arrow B. hand C. hour glass D. globe
Here are several function members of a class. Tell whether each may be used as an l- value, only, an r-value only or both. B is a class that has mutators.
a)``` //declarations of these appear together in the //definition of class A int& A::f( ){ /* */} const int& A::f( )const{ /* */} ``` b)``` const int& A::f( ){ /* */} ``` c)``` const B A::f( ){ /* */} ``` d)``` B A::f( ){ /* */} ```
When you create a source, it is saved in two locations, which are:
A) the Source Manager and the Master List. B) the Master List and the Current List. C) the bibliography and the works cited. D) the style manual and the research guide.