(Diamond of Asterisks) Modify Exercise 4.23 to read an odd number in the range 1 to 19 to specify the number of rows in the diamond, then display a diamond of the appropriate size.
What will be an ideal response?
```
// Drawing a diamond shape with the specified size.
#include
using namespace std;
int main()
{
int size; // number of rows in diamond
// loop until valid input
do
{
cout << "Enter an odd number for the diamond size (1-19): \n";
cin >> size;
} while ( ( size < 1 ) || ( size > 19 ) || ( ( size % 2 ) != 1 ) );
// top half
for ( int rows = 1; rows <= size - 2; rows += 2 )
{
// print preceding spaces
for ( int space = ( size - rows ) / 2; space > 0; space-- )
cout << ' ';
// print asterisks
for ( int asterisk = 1; asterisk <= rows; asterisk++ )
cout << '*';
cout << '\n';
} // end for
// bottom half
for ( rows = size; rows >= 0; rows -= 2 )
{
// print preceding spaces
for ( int space = ( size - rows ) / 2; space > 0; space-- )
cout << ' ';
// print asterisks
for ( int asterisk = 1; asterisk <= rows; asterisk++ )
cout << '*';
cout << '\n';
} // end for
cout << endl;
} // end main
```
You might also like to view...
A secure stamp of authentication on a document that is electronically encryption based is called ________
A) change history ID B) finalized ID C) Live ID D) digital ID
To select both a field label and field value to move in a report design, after selecting the field label press the ____ key to select the field value box.
A. Ctrl B. Alt C. F2 D. Shift