-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchar-screen_v1.cpp
89 lines (73 loc) · 1.65 KB
/
char-screen_v1.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <vector>
using namespace std;
class Tela
{
vector<vector<char> > buffer;
public:
unsigned Xmax;
unsigned Ymax;
Tela(unsigned txmax, unsigned tymax);
void print(void);
void Moldura(void);
void putCharXY(int,int,char);
};
Tela::Tela(unsigned txmax, unsigned tymax)
{
Xmax = txmax; Ymax = tymax;
buffer.resize(Ymax);
for(unsigned y=0; y < Ymax; y++) buffer[y].resize(Xmax);
for(unsigned y=0; y < Ymax; y++)
for(unsigned x=0; x < Xmax; x++)
buffer[y][x] = ' ';
}
void Tela::Moldura(void)
{
for(unsigned x = 0; x < Xmax; x++ ) buffer[0][x] = '#';
for(unsigned y = 1; y < Ymax-1; y++) buffer[y][0] = buffer[y][Xmax-1] = '#';
for(unsigned x = 0; x < Xmax; x++ ) buffer[Ymax-1][x] = '#';
}
void Tela::putCharXY(int xp,int yp,char c)
{
buffer[yp][xp] = c;
}
void Tela::print(void)
{
for(unsigned y=0; y < Ymax; y++) {
for(unsigned x=0; x < Xmax; x++) cout << buffer[y][x];
cout << endl;
}
}
class Reta
{
int x,y;
public:
Reta (int px, int py) :x(px), y(py) {};
void desenha(Tela & t);
};
void
Reta::desenha(Tela & t)
{
unsigned yt;
for(unsigned xt = 1; xt < x; xt++) {
yt = (y*xt)/x;
t.putCharXY(xt,yt,'o');
}
}
int main()
{
char c;
cout << "Aula10 - Hierarquia de classes - TMAB 2016.1 - MR2(c)" << endl;
Tela t1(99,39);
t1.Moldura();
t1.print();
Reta r(80,15);
r.desenha(t1);
t1.print();
cin >> c;
Tela t2(80,20);
t2.Moldura();
r.desenha(t2);
t2.print();
return 0;
}