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
|
#include <string>
#include <iostream>
using namespace std;
void Draw(int, char, char);
int main()//Testing Draw
{
cout << "Testing Draw:\n";
Draw(6, '#', '$');
return 0;
}
void Draw(int size, char border, char fill)
{
bool stop = false;
bool control = false;//This Controls which direction is drawing the Diamond
int count = size;
int iterationCount = 1;
int fillCount = 1;
if(size == 1)//Special Diamond of Size 1
{
cout << border << endl;
}
else if(size == 2)//Special Diamond of Size 2
{
cout << border << endl;
cout << border << ' ' << border << endl;
cout << border << endl;
}
else if(size > 2)//All other Diamonds of sizes from 3 to 39
{
do
{//Start of Loop
//Controls Counter Directions
if(control = false)//Increments counter down to draw to center
{ count--; iterationCount++; fillCount = fillCount + 2;}
else if(control = true)//Increments the counter back up
{ count++; iterationCount--; fillCount = fillCount - 2;}
//End Counter Direction Control
if(count > 1)//Counts down from size, to 2
{
if(iterationCount == 1)//Special Case, prints out 1st layer, top and bottom
{
cout /*<< SPACES*/ << border << endl;
}
else if(iterationCount == 2)//Special Case, prints out 2nd layer, top and bottom
{
cout /*<< SPACES*/<< border << endl;
cout /*<< SPACES*/<< border << ' ' << border << endl;
cout /*<< SPACES*/<< border << endl;
}
else if(iterationCount > 2)//All other cases, through 39
{
cout /*<< SPACES*/<< border;
for(fillCount; fillCount <= fillCount + 2; fillCount++)//Draws The fill characters, Fill count is controlled by
/*There should be one less fill character for each space*/
{
if(fillCount % 2 == 1)//If count is an odd, write a space
cout << ' ';
else
cout << fill;//If count is even, write a fill
}
cout /*<< SPACES*/<< border << endl;
if(count == 1)//Draws center and Initializes BOOL to true, reversing the drawing
{
control = true;
}
}
}
else if(count > size)//If the count is greater than size, Stop Drawing
cout << "\nDiamond is complete\n";
stop = true;//
}while(stop = false);
}
}
|