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 132 133 134 135 136 137 138 139 140 141 142
|
#include <iostream>
using namespace std;
void line_specs(int& length, char& material, const int& border_length);
void border(const int& border_length);
int main()
{
char yesno, line_type, material;
int length, foo;
const int border_length = 20;
// Program Introduction
cout << "Welcome to the line drawing program." << endl;
start:
cout << "Would you like to draw a line?" << endl;
cin >> yesno;
if ((yesno == 'n') || (yesno =='N'))
goto end;
else if ((yesno == 'y') || (yesno =='Y'))
{
border(border_length);
goto affirmative;
}
else
cout << "ERROR" << endl;
goto start;
// Line Type Splitting
affirmative:
cout << "Enter the line type." << endl;
cout << "'V' for vertical, 'H' for horizontal, 'F' for diagonal-foreward, or 'B' for diagonal-backward ." << endl;
cin >> line_type;
if ((line_type == 'v') || (line_type == 'V'))
goto vertical;
else if ((line_type == 'h') || (line_type == 'H'))
goto horizontal;
else if ((line_type == 'f') || (line_type == 'F'))
goto diagonal;
else if ((line_type == 'b') || (line_type == 'B'))
goto backward;
else
cout << "ERROR" << endl;
goto affirmative;
// Vertical Line
vertical:
border(border_length);
line_specs(length, material, border_length);
for (int i = 0; i < length; i++)
{
cout << material << endl;
}
goto ask;
// Horizontal Line
horizontal:
border(border_length);
line_specs(length, material, border_length);
for (int i = 0; i < length; i++)
{
cout << material << " ";
}
cout << endl;
goto ask;
// Diagonal-Foreward Line
diagonal:
border(border_length);
line_specs(length, material, border_length);
for (int i = 0; i < length; i++)
{
for (int x = i; x > 0; x--)
cout << " ";
cout << material << endl;
}
cout << endl;
goto ask;
// Diagonal-Backward Line
backward:
border(border_length);
line_specs(length, material, border_length);
foo = length;
for (int i = 0; i < length; i++)
{
for (int x = 0; x < foo; x++)
cout << " ";
cout << material << endl;
foo--;
}
cout << endl;
goto ask;
// Program Reapeat Junction
ask:
cout << "Would you like to draw another line?" << endl;
cin >> yesno;
if ((yesno == 'n') || (yesno == 'N'))
goto end;
else if ((yesno == 'y') || (yesno == 'Y'))
goto affirmative;
else
{
cout << "ERROR" << endl;
goto ask;
}
end:
return 0;
}
// Line Specification Function
void line_specs(int& length, char& material, int border_length)
{
cout << "Input the desired length of the line." << endl;
cin >> length;
border(border_length);
cout << "Input the desired character with which" << endl;
cout << "to build the line." << endl << endl;
cin >> material;
border(border_length);
}
//Border Formating Function
void border(const int& border_length)
{
for (int i = 0; i < border_length; i++)
cout << "- ";
cout << endl;
}
|