-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrectangle.cpp
72 lines (64 loc) · 1.88 KB
/
rectangle.cpp
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
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int row,column,graphWidth,length, graphHeight,height;
char rectangle[130][130];
cout<<"\n\n\t\t\t###### Draw Rectangle #######\n";
cout << "\n\t\tEnter graph Height: ";
cin >> graphHeight;
cout << "\t\tEnter graph Width: ";
cin >> graphWidth;
cout<<"\t\tEnter length of rectangle: ";
cin>>length;
cout<<"\t\tEnter height of rectangle: ";
cin>>height;
cout<<"\n";
//scaling factor=2.0
height = (height/2.0) + 0.5;
graphHeight = (graphHeight/2.0) + 0.5;
for(row = 0; row <= graphHeight; row++)
{
for(column = 0; column <= graphWidth; column++)
{
rectangle[row][column] = ' ';
}
}
// Y-axis
for(int y = 0; y <= graphHeight; y++)
{
int x = graphWidth/2;
rectangle[y][x] = '|';
}
// X-axis
for(int x = 0; x <= graphWidth; x++)
{
int y = graphHeight/2;
rectangle[y][x] = '_';
}
// draw rectangle
int heightSide1 = (graphWidth/2 - length/2);
int heightSide2 = (graphWidth/2 - length/2) + length;
for(row = (graphHeight/2) - height/2; row <= (graphHeight/2) - height/2 + height; row++)
{
rectangle[row][heightSide1] = '.';
rectangle[row][heightSide2] = '.';
}
int lengthSide1 = graphHeight/2 - height/2;
int lengthSide2 = (graphHeight/2 - height/2) + height;
for(row = (graphWidth/2 - length/2); row <= (graphWidth/2 - length/2) + length; row++)
{
rectangle[lengthSide1][row] = '.';
rectangle[lengthSide2][row] = '.';
}
// print rectangle
for(row = 0; row <= graphHeight; row++)
{
for(column = 0; column <= graphWidth; column++)
{
cout<<rectangle[row][column];
}
cout<<endl;
}
}