/****************************************************** ** Name: ** Filename: hollowsquare.cpp ** Project #: Deitel & Deitel 2.28 ** Project Description: Write a program that reads in the size of a square and then prints a hollow square of that size out of asterisks and blanks. Program should work for squares of all side sizes between 1 and 20. ** Output: A square with equal sides and hollow with blank spaces in the center of the square. ** Input: Size of the sides of a square ** Algorithm: Input size of side of square Run a loop to print number of rows and columns input Print character at beginning and end of rows and columns Print blanks in the middle of rows and columns End programs ******************************************************/ // Include files #include // used for cin, cout #include using namespace std; // Global Type Declarations // Function Prototypes void instruct (void); void pause (); //Global Variables - should not be used without good reason. int main () { // Declaration section int size,x,y; // Executable section instruct (); cout << "Enter the size of a side of the square: "; cin >> size ; { for ( x = 1; x <= size; x++ ) {for ( y = 1; y <= size; y++ ) {if ( x == 1 || x == size ) cout << "*"; else if ( y == 1 || y == size ) cout << "*"; else cout << " "; } cout << endl; } } pause (); return 0; } void instruct (void) { // Declaration section // Executable section cout << "The following program will print a hollow square using the\n" << "size that is input below. The size must be a number between\n" << "1 and 20.\n "<< endl; } void pause () { // Declaration section // Executable section cout << "\nPress any key to continue..."; getch(); cout << "\r"; cout << " "; cout << "\r"; } /* Program Output The following program will print a hollow square using the size that is input below. The size must be a number between 1 and 20. Enter the size of a side of the square: 12 ************ * * * * * * * * * * * * * * * * * * * * ************ Press any key to continue... */