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
|
#include<iostream>
using namespace std;
void instructions();
int menu();
void draw_shape(int choice);
int get_size();
char get_char();
void draw_triangle(int size, char c);
void draw_diamond(int size, char c);
void draw_bottom(int size, char c);
int main()
{
int choice;
instructions();
choice = menu();
if(choice == 3)
{
cout << "You requested to quit, bye! \n";
return 0;
}
draw_shape(choice);
return 0;
}
void instructions()
{
cout << endl;
cout << "If you would like to build a traingle or diamond, enter 1 or 2. 1 for Triangle. 2 for Diamond. 3 to quit. ";
}
int menu()
{
int choice;
cout << endl << endl;
cout << "Your choice is: ";
cin >> choice;
return choice;
}
void draw_shape(int choice)
{
int size;
char c;
size = get_size();
c = get_char();
if (choice == 1) //after recieving the choice, sends data to next function, either to build a triangle or diamond
{
draw_triangle(size, c);
}
else if (choice == 2)
{
draw_diamond(size, c);
}
}
int get_size()
{
int size;
cout << "What would you like the size of the shape to be? ";
cin >> size;
return size;
}
char get_char()
{
char c;
cout << "What character would you like to use? ";
cin >> c;
return c;
}
void draw_diamond(int size, char c)
{
draw_triangle(size, c);
draw_bottom(size,c);
}
void draw_triangle(int size, char c)
{
for(int a=1; a<=size; a++)
{
for(int b=1; b<=a; b++)
{
cout << c;
}
cout << endl;
}
}
void draw_bottom(int size, char c) // The code in a similar backwards state as the draw triangle or diamond, sonas to build the bottom half of the diamond
{
for(int a = 1; a < size; a++)
{
for(int b = 1; b <= (size-a); b++)
{
cout << c;
}
cout << endl;
}
}
|