Skip to content

Commit ac66c5d

Browse files
committed
ch7 updated
7_31 to 7_35
1 parent 3796c49 commit ac66c5d

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
lines changed

Diff for: ch7/7_31.cc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Y;
2+
class X
3+
{
4+
Y *pY;
5+
};
6+
class Y
7+
{
8+
X x;
9+
};

Diff for: ch7/7_32.h

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#ifndef EX7_32_H
2+
#define EX7_32_H
3+
4+
class Screen;
5+
6+
class Window_mgr
7+
{
8+
public:
9+
using ScreenIndex = vector<Screen>::size_type;
10+
inline void clear(ScreenIndex);
11+
private:
12+
vector<Screen> screens{Screen(24, 80, ' ')};
13+
};
14+
15+
class Screen
16+
{
17+
public:
18+
typedef std::string::size_type pos;
19+
friend void Window_mgr::clear(ScreenIndex);
20+
Screen &set(char c)
21+
{
22+
contents[cursor] = c;
23+
return *this;
24+
}
25+
Screen &set(pos r, pos col, char c)
26+
{
27+
contents[r * width + col] = c;
28+
return *this;
29+
}
30+
Screen &display(std::ostream &os)
31+
{
32+
do_display(os);
33+
return *this;
34+
}
35+
const Screen &display(std::ostream &os) const
36+
{
37+
do_display(os);
38+
return *this;
39+
}
40+
Screen() = default;
41+
Screen(pos ht, pos wd, char c) : height(ht), width(wd), contents(ht * width, c) { }
42+
Screen(pos ht, pos wd) : height(ht), width(wd), contents(ht * wd, ' ') { }
43+
char get() const
44+
{
45+
return contents[cursor];
46+
}
47+
char get(pos ht, pos wd) const
48+
{
49+
return contents[ht * width + wd];
50+
}
51+
Screen &move(pos r, pos c)
52+
{
53+
cursor = r * width + c;
54+
return *this;
55+
}
56+
57+
private:
58+
void do_display(std::ostream &os) const
59+
{
60+
os << contents;
61+
}
62+
pos cursor = 0;
63+
pos height = 0, width = 0;
64+
std::string contents;
65+
};
66+
67+
void Window_mgr::clear(ScreenIndex i)
68+
{
69+
Screen &s = screens[i];
70+
s.contents = string(s.height * s.width, ' ');
71+
}
72+
73+
#endif

Diff for: ch7/7_33.cc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// pos Screen::size() const// should be Screen::pos
2+
// {
3+
// return height * width;
4+
// }

Diff for: ch7/7_34.cc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// there will be an error in dummy_fcn(pos height)

Diff for: ch7/7_35.cc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// typedef string Type;
2+
// Type initVal(); // use string
3+
// class Exercise {
4+
// public:
5+
// typedef double Type;
6+
// Type setVal(Type); // use double
7+
// Type initVal(); // use double
8+
// private:
9+
// int val;
10+
// };
11+
12+
// Type Exercise::setVal(Type parm) { // the first is string, the second is double
13+
// val = parm + initVal(); // initVal is undefined
14+
// return val;
15+
// }

0 commit comments

Comments
 (0)