Skip to content

Commit

Permalink
Merge pull request Mooophy#697 from icgw/master
Browse files Browse the repository at this point in the history
Add answer to ex1.15 and fixed some format
  • Loading branch information
pezy authored Dec 6, 2018
2 parents c931439 + 50afff7 commit 688a4b4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
31 changes: 28 additions & 3 deletions ch01/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ std::cout << /* "*/" /* "/*" */;

Output:

/**/ */ /*
/**/ */ /*

## [Exercise 1.9](ex1_9.cpp)
## [Exercise 1.10](ex1_10.cpp)
Expand All @@ -144,7 +144,7 @@ of sum?
```cpp
int sum = 0;
for (int i = -100; i <= 100; ++i)
sum += i;
sum += i;
```

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

Nothing to present here.
**Syntax Errors**:
```c++
int main(){
std::cout << "Hello World!" << std::endl // semicolon missed
return 0;
}
```

**Type errors**:
```c++
int main(){
char s = "Hello World!"; // Here char should be std::string
std::cout << s << endl;
return 0;
}
```

**Declaration errors**:
```c++
int main(){
int k = 0;
std::cout << K << std::endl; // use of undeclared identifier 'K'
return 0;
}
```


## Exercise 1.16

Expand Down
8 changes: 2 additions & 6 deletions ch01/ex1_9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

#include <iostream>

using std::cin;
using std::cout;
using std::endl;

auto sum(int lo, int hi)
{
int sum = 0;
while (lo < hi) sum += lo++;
while (lo <= hi) sum += lo++;
return sum;
}

int main()
{
cout << "sum is: " << sum(50, 100+1) <<endl;
std::cout << "Sum of 50 to 100 inclusive is: " << sum(50, 100) << std::endl;
return 0;
}
2 changes: 1 addition & 1 deletion ch13/ex13_22.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
// Assume that we want HasPtr to behave like a value.
// That is, each object should have its own copy of the string to which the objects point.
// We¡¯ll show the definitions of the copy-control members in the next section.
// We'll show the definitions of the copy-control members in the next section.
// However, you already know everything you need to know to implement these members.
// Write the HasPtr copy constructor and copyassignment operator before reading on.
//
Expand Down

0 comments on commit 688a4b4

Please sign in to comment.