forked from jieniyimiao/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed ex7_23_24_25.cpp to ex7_23.h/cpp and ex7_24.h
1. `const pos h`'s `const` is unnecessary. 2. the second contructs get contents by a `while` loop. unnecessary. 3. the third contructs may not get the point of question. (**a character**) 4. we should add inline member functions in this exercise.
- Loading branch information
Showing
5 changed files
with
92 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// ex7_23.cpp | ||
// Exercise 7.23 | ||
// | ||
// Created by pezy on 11/14/14. | ||
// Copyright (c) 2014 pezy. All rights reserved. | ||
// | ||
|
||
//#include "ex7_23.h" | ||
#include "ex7_24.h" | ||
|
||
char Screen::get(pos r, pos c) const | ||
{ | ||
pos row = r * width; | ||
return contents[row + c]; | ||
} | ||
|
||
Screen& Screen::move(pos r, pos c) | ||
{ | ||
pos row = r * width; | ||
cursor = row + c; | ||
return *this; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// ex7_23.h | ||
// Exercise 7.23 | ||
// | ||
// Created by pezy on 11/14/14. | ||
// Copyright (c) 2014 pezy. All rights reserved. | ||
// | ||
|
||
#ifndef CP5_ex7_23_h | ||
#define CP5_ex7_23_h | ||
|
||
#include <string> | ||
|
||
class Screen { | ||
public: | ||
using pos = std::string::size_type; | ||
|
||
Screen() = default; | ||
Screen(pos ht, pos wd, char c):height(ht),width(wd),contents(ht*wd, c){} | ||
|
||
char get() const { return contents[cursor]; } | ||
inline char get(pos r, pos c) const; | ||
inline Screen& move(pos r, pos c); | ||
|
||
private: | ||
pos cursor = 0; | ||
pos height = 0, width = 0; | ||
std::string contents; | ||
}; | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// ex7_24.cpp | ||
// Exercise 7.24 | ||
// | ||
// Created by pezy on 11/14/14. | ||
// Copyright (c) 2014 pezy. All rights reserved. | ||
// | ||
|
||
#ifndef CP5_ex7_24_h | ||
#define CP5_ex7_24_h | ||
|
||
#include <string> | ||
|
||
class Screen { | ||
public: | ||
using pos = std::string::size_type; | ||
|
||
Screen() = default; // 1 | ||
Screen(pos ht, pos wd, pos n):height(ht),width(wd),contents(n, ' '){} // 2 | ||
Screen(pos ht, pos wd, char c):height(ht),width(wd),contents(ht*wd, c){} // 3 | ||
|
||
char get() const { return contents[cursor]; } | ||
inline char get(pos r, pos c) const; | ||
inline Screen& move(pos r, pos c); | ||
|
||
private: | ||
pos cursor = 0; | ||
pos height = 0, width = 0; | ||
std::string contents; | ||
}; | ||
|
||
#endif |