Skip to content

Commit 50afff7

Browse files
committed
Add answer to ex1.15 and fixed some format
1 parent c931439 commit 50afff7

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

ch01/README.md

+28-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ std::cout << /* "*/" /* "/*" */;
132132

133133
Output:
134134

135-
/**/ */ /*
135+
/**/ */ /*
136136

137137
## [Exercise 1.9](ex1_9.cpp)
138138
## [Exercise 1.10](ex1_10.cpp)
@@ -144,7 +144,7 @@ of sum?
144144
```cpp
145145
int sum = 0;
146146
for (int i = -100; i <= 100; ++i)
147-
sum += i;
147+
sum += i;
148148
```
149149

150150
the loop sums the numbers from -100 to 100. the final value of sum is zero.
@@ -213,7 +213,32 @@ using a while. Are there advantages or disadvantages to using either form?
213213
the box on page 16. Familiarize yourself with the messages the compiler
214214
generates.
215215

216-
Nothing to present here.
216+
**Syntax Errors**:
217+
```c++
218+
int main(){
219+
std::cout << "Hello World!" << std::endl // semicolon missed
220+
return 0;
221+
}
222+
```
223+
224+
**Type errors**:
225+
```c++
226+
int main(){
227+
char s = "Hello World!"; // Here char should be std::string
228+
std::cout << s << endl;
229+
return 0;
230+
}
231+
```
232+
233+
**Declaration errors**:
234+
```c++
235+
int main(){
236+
int k = 0;
237+
std::cout << K << std::endl; // use of undeclared identifier 'K'
238+
return 0;
239+
}
240+
```
241+
217242

218243
## Exercise 1.16
219244

ch01/ex1_9.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@
22

33
#include <iostream>
44

5-
using std::cin;
6-
using std::cout;
7-
using std::endl;
8-
95
auto sum(int lo, int hi)
106
{
117
int sum = 0;
12-
while (lo < hi) sum += lo++;
8+
while (lo <= hi) sum += lo++;
139
return sum;
1410
}
1511

1612
int main()
1713
{
18-
cout << "sum is: " << sum(50, 100+1) <<endl;
14+
std::cout << "Sum of 50 to 100 inclusive is: " << sum(50, 100) << std::endl;
1915
return 0;
2016
}

ch13/ex13_22.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// Assume that we want HasPtr to behave like a value.
88
// That is, each object should have its own copy of the string to which the objects point.
9-
// We¡¯ll show the definitions of the copy-control members in the next section.
9+
// We'll show the definitions of the copy-control members in the next section.
1010
// However, you already know everything you need to know to implement these members.
1111
// Write the HasPtr copy constructor and copyassignment operator before reading on.
1212
//

0 commit comments

Comments
 (0)