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
|
#include <iostream>
using namespace std;
int main () {
char input; // menu input variable
bool quit = false; // loop control variable
int c,k,x1, x2, x3, x4; // x coordinate variables;
int y1, y2, y3, y4;
char array[25][75]; // y coordinate variables;
int size, length, height; // shape dimention variables;
cout<<"This program displays the shape based on what the user wants and based on the\ncoordinates entered.\n\n";
cout<<"By: John Fynes, Shane McGuire, Andrei Kuzmiankov\n\n";
do {
cout << "Please select a shape: (s)quare, (r)ectangle, (t)riangle, or (q)uit:";
cin >> input;
k,c=0;
switch (input) {
case 's':
case 'S':
// coordinate input
cout << "\nEnter square corners in 4 x y pairs, all digits seperated by spaces:\n\n";
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
cout<<"\n";
// check all 4 coorinates form a square
size = y4 - y1;
if (x2 - x1 == size && y3 - y2 == size && x3 - x4 == size && size > 0) {
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++){
array[x][y]=42;
cout<<array[x][y];}
cout<<endl;
}
cout << endl;
for (int x = 0; x <=size; x++){
for (int y = 0; y <=size;y++){
array[x][y]=42;
while(x!=0&&x != size && y>0&& y<size-1){
array[x][y]=32;
y++;}
cout<<array[x][y];}
cout << endl;
}
cout<<endl;
} else {
cout << "Those corners do not produce a square. "<< "Please try again.\n";
}
cout<<endl;
break;
case 'r':
case 'R':
// coordinate input
cout << "\nEnter rectangle corners in 4 x y pairs, all digits seperated by spaces:\n\n";
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
cout<<"\n";
// check all 4 coordinates form a rectangle
length = x2 - x1;
height = y3 - y2;
if (y4 - y1 == height && x3 - x4 == length) {
for (int x = 0; x < length; x++) {
for (int y = 0; y < height; y++)
cout << "*";
cout << endl;}
cout<<endl;
for (int x = 0; x < length; x++) {
for (int y = 0; y < height; y++){
array[x][y]=42;
c++;
while(x !=0 && x != length-1 && y >= 0 && y < height - 2){
array[x][c]=32;
y++;}
cout<<array[x][c];}
cout << endl;
}
cout<<endl;
} else {
cout << "\nThose corners do not produce a rectangle. Please try again.\n";
}
cout<<endl;
break;
case 't':
case 'T':
// coordinate input
cout << "Enter triangle corners in 3 x y pairs, all digits seperated by spaces:\n\n";
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
cout<<"\n";
// check all 3 coordinates form a triangle
if (x2 - x1 == y3 - y1) {
size = x2 - x1;
for (int x = 0; x <= size; x++) {
for (int y = 0; y < x; y++)
cout << "*";
cout << endl;
}
cout<<endl;
for (int x = 0; x <= size; x++) {
for (int y = 0; y < x; y++){
array[x][y]=42;
c++;
while(x !=0 && x != size && y >= 0 && y < x - 2){
array[x][c]=32;
y++;}
cout<<array[x][y];}
cout << endl;
}
cout<<endl;
} else {
cout << "Those corners do not produce a triangle. Please try again.\n";
}
cout<<endl;
break;
case 'q':
case 'Q':
quit = true;
break;
default:
cout << "That was not a valid input\nPlease try again\n";
}
} while (!quit);
return 0;
}
|