补充Sales_data没有体现出的其他类特性

Screen.h

 1 #include <string>
2 #include <iostream>
3
4 class Screen {
5 public:
6 typedef std::string::size_type pos;
7 #if defined(IN_CLASS_INITS) && defined(DEFAULT_FCNS)
8 Screen() = default; // needed because Screen has another constructor
9 #else
10 Screen(): cursor(0), height(0), width(0) { }
11 #endif
12 // cursor initialized to 0 by its in-class initializer
13 Screen(pos ht, pos wd, char c): height(ht), width(wd),
14 contents(ht * wd, c) { }
15 friend class Window_mgr;
16 Screen(pos ht = 0, pos wd = 0):
17 cursor(0), height(ht), width(wd), contents(ht * wd, ' ') { }
18 char get() const // get the character at the cursor
19 { return contents[cursor]; } // implicitly inline
20 inline char get(pos ht, pos wd) const; // explicitly inline
21 Screen &clear(char = bkground);
22 private:
23 static const char bkground = ' ';
24 public:
25 Screen &move(pos r, pos c); // can be made inline later
26 Screen &set(char);
27 Screen &set(pos, pos, char);
28 // other members as before
29 // display overloaded on whether the object is const or not
30 Screen &display(std::ostream &os)
31 { do_display(os); return *this; }
32 const Screen &display(std::ostream &os) const
33 { do_display(os); return *this; }
34 private:
35 // function to do the work of displaying a Screen
36 void do_display(std::ostream &os) const {os << contents;}
37 // other members as before
38 private:
39 #ifdef IN_CLASS_INITS
40 pos cursor = 0;
41 pos height = 0, width = 0;
42 #else
43 pos cursor;
44 pos height, width;
45 #endif
46 std::string contents;
47 };
48
49 Screen &Screen::clear(char c)
50 {
51 contents = std::string(height*width, c);
52 return *this;
53 }
54
55 inline // we can specify inline on the definition
56 Screen &Screen::move(pos r, pos c)
57 {
58 pos row = r * width; // compute the row location
59 cursor = row + c; // move cursor to the column within that row
60 return *this; // return this object as an lvalue
61 }
62
63 char Screen::get(pos r, pos c) const // declared as inline in the class
64 {
65 pos row = r * width; // compute row location
66 return contents[row + c]; // return character at the given column
67 }
68
69 inline Screen &Screen::set(char c)
70 {
71 contents[cursor] = c; // set the new value at the current cursor location
72 return *this; // return this object as an lvalue
73 }
74 inline Screen &Screen::set(pos r, pos col, char ch)
75 {
76 contents[r*width + col] = ch; // set specified location to given value
77 return *this; // return this object as an lvalue
78 }

useScreen.cpp

 1 #include <iostream>
2 using std::cout; using std::endl;
3
4 #include <string>
5 using std::string;
6
7 #include "Screen.h"
8
9 int main()
10 {
11 Screen myScreen(5,3);
12 // move the cursor to a given position, and set that character
13 myScreen.move(4,0).set('#');
14
15 Screen nextScreen(5, 5, 'X');
16 nextScreen.move(4,0).set('#').display(cout);
17 cout << "\n";
18 nextScreen.display(cout);
19 cout << endl;
20
21 const Screen blank(5, 3);
22 myScreen.set('#').display(cout); // calls nonconst version
23 cout << endl;
24 blank.display(cout); // calls const version
25 cout << endl;
26
27 myScreen.clear('Z').display(cout); cout << endl;
28 myScreen.move(4,0);
29 myScreen.set('#');
30 myScreen.display(cout); cout << endl;
31 myScreen.clear('Z').display(cout); cout << endl;
32
33 // if move returns Screen not Screen&
34 Screen temp = myScreen.move(4,0); // the return value would be copied
35 temp.set('#'); // the contents inside myScreen would be unchanged
36 myScreen.display(cout);
37 cout << endl;
38 }

最新文章

  1. 安装了ruby后怎么安装sass
  2. C语言 &#183; 复习杂记
  3. 微信JSApi支付~集成到MVC环境后的最后一个坑(网上没有这种解决方案)
  4. NAT123内网映射端口
  5. Excel加密的Sheet如何hack
  6. VS 本机调试
  7. android——学习:网格布局——GridLayout
  8. hiho_1087_哈密顿环
  9. Java拾穗
  10. Contoso 大学 - 1 - 为 ASP.NET MVC 应用程序创建 EF 数据模型
  11. Virtual member call in a constructor
  12. memcache分布式实现、memcache分布…
  13. [转]java构造方法的访问修饰符
  14. 使用Fiddler改变线上js文件的引用路径
  15. 【转】网页禁止后退键BackSpace的JavaScript实现(兼容IE、Chrome、Firefox、Opera)
  16. [Oracle][DataGuard]Standby数据库文件有损坏时的处理方法
  17. [Android]记录一次处理app:transformDexArchiveWithExternalLibsDexMergerForDebug错误
  18. 异步编程之asyncio简单介绍
  19. 三部曲搭建本地nuget服务器(图文版)
  20. ASP.NET WebForm 与 IE10、IE11

热门文章

  1. 一次 outline 去除经验(非继承属性,看着像继承)
  2. Windows下C++/Fortran调用.exe可执行文件
  3. kong 结合 istio demo
  4. 整合一套高性能网关Kong
  5. --系统编程-网络-tcp客户端服务器编程模型、socket、htons、inet_ntop等各API详解、使用telnet测试基本服务器功能
  6. 结对编程_stage2
  7. keepalived安装及组合nginx配置负载实现高可用
  8. 【MQ中间件】RabbitMQ -- SpringBoot整合RabbitMQ(3)
  9. Java常用类库与技巧
  10. 数据库MySQL三