File tree 3 files changed +31
-10
lines changed
3 files changed +31
-10
lines changed Original file line number Diff line number Diff line change @@ -132,7 +132,7 @@ std::cout << /* "*/" /* "/*" */;
132
132
133
133
Output:
134
134
135
- /**/ */ /*
135
+ /**/ */ /*
136
136
137
137
## [ Exercise 1.9] ( ex1_9.cpp )
138
138
## [ Exercise 1.10] ( ex1_10.cpp )
@@ -144,7 +144,7 @@ of sum?
144
144
``` cpp
145
145
int sum = 0 ;
146
146
for (int i = -100 ; i <= 100 ; ++i)
147
- sum += i;
147
+ sum += i;
148
148
```
149
149
150
150
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?
213
213
the box on page 16. Familiarize yourself with the messages the compiler
214
214
generates.
215
215
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
+
217
242
218
243
## Exercise 1.16
219
244
Original file line number Diff line number Diff line change 2
2
3
3
#include < iostream>
4
4
5
- using std::cin;
6
- using std::cout;
7
- using std::endl;
8
-
9
5
auto sum (int lo, int hi)
10
6
{
11
7
int sum = 0 ;
12
- while (lo < hi) sum += lo++;
8
+ while (lo <= hi) sum += lo++;
13
9
return sum;
14
10
}
15
11
16
12
int main ()
17
13
{
18
- cout << " sum is: " << sum (50 , 100 + 1 ) <<endl;
14
+ std:: cout << " Sum of 50 to 100 inclusive is: " << sum (50 , 100 ) << std:: endl;
19
15
return 0 ;
20
16
}
Original file line number Diff line number Diff line change 6
6
//
7
7
// Assume that we want HasPtr to behave like a value.
8
8
// 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.
10
10
// However, you already know everything you need to know to implement these members.
11
11
// Write the HasPtr copy constructor and copyassignment operator before reading on.
12
12
//
You can’t perform that action at this time.
0 commit comments