1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
#include <iostream>
using namespace std;
//Global Constants
const int MINDIM = 2;
const int MAXDIM = 20;
//Function Prototypes
/*int Intro(const int, const int);
char AskSymbol();
int AskSizes(int, int);
void TopBot(char, int);
void Slice (char, int);
*/
//Display the program title and intro
int Intro(int MIN, const int MAX)
{
cout
<< "BOX DISPLAYING PROGRAM"
<< endl << endl
<< "This program will display a rectangle made from a symbol"
<< endl
<< "specified by the user and of a width and depth specified"
<< endl
<< "by the user. The program will accept user input of width"
<< endl
<< "and depth values between " << MINDIM << "and " << MAXDIM << " (inclusive) only."
<< endl << endl;
}
//Request and return a symbol to be used to display the rectangle
char AskSymbol()
{
//Local Variables of AskSymbol
char S;
int WIDE, DEEP;
//Request and store S
cout << "Symbol to display? ";
cin >> S;
return S; //Return S to main
}
//Request and return only valid width & depth values between 2 and 20 inclusive.
int AskSizes(int MIN, int MAX, int*WPTR, int *DPTR)
{
//Local Variables of AskSizes
int W, D;
do
{
if (MIN > W && W > MAX)
{
cout
<< "INVALID ENTRY: Enter a value between 2 and 20 inclusive - "
<< "\a";
}
{
cout
<< "Width (2-20)?";
cin >> W;
}
}
while ( MIN > W && W > MAX );
cout
<< "Depth (2-20)?";
cin >> D;
while ( MIN > D && D > MAX);
{
cout << "INVALID ENTRY: Enter a value between 2 and 20 inclusive - "
<< "\a"
<< "Depth (2-20)?";
cin >> D;
}
*DPTR = D;
*WPTR = W;
}
//Display a line made from the passed-in symbol by repeating it the passed-in width times.
void TopBot(char S, int W)
{
int I; //counting loop index
for (I = 1; I <= W; I++)
{
cout << S;
I++;
}
cout << endl;
}
//Display a line of (2 less than the passed-in width) spaces, with the passed-in symbol on both ends.
void Slice(char S, int W)
{
int I = 1;
cout << S;
for (I=1; I <=( W- 2); I++) //check
{
cout << " ";
I ++;
}
cout << S << endl;
}
//Creates the rectangle
int main ()
{
//Variables
char SYMB;
int C, WIDE, DEEP;
Intro(MINDIM, MAXDIM); //Pass MINDIM and MAXDIM to the Intro function
SYMB = AskSymbol(); //Return the value from AskSymbol to the variable SYMB
AskSizes (MINDIM, MAXDIM, &WIDE, &DEEP); //Return WIDE and DEEP
cout << endl;
TopBot(SYMB, WIDE);
C = 1;
while (C <= (DEEP-2))
{
Slice(SYMB, WIDE);
C + 1;
}
TopBot(SYMB, WIDE);
system ("pause");
return 0;
}
|