Cpp-Primer-5th-Exercises-Chapter-9

Exercise 9.1 1 2 3 4 // (a): list // (b): deque // (c): vector (vector.sort()) Exercise 9.2 1 2 3 4 5 int main() { std::list<std::deque<int>> sample; } Exercise 9.3 1 2 3 4 // iterators which make a iterator range must be: // 1. both point to one container's elements, or point to the off the end element of one container // 2.

Cpp-Primer-5th-Exercises-Chapter-8

Exercise 8.1 1 2 3 4 5 6 7 8 9 10 11 12 istream &unlimit_inputs(istream &is) { char c; while(!is.eof()) { is >> c; cout << c << endl; } is.clear(); return is; } Exercise 8.2 1 2 3 4 5 6 7 8 extern istream &unlimit_inputs(istream &); int main() { int i = 0; (unlimit_inputs(cin)) >> i; cout << i << endl; } Exercise 8.

Cpp-Primer-5th-Exercises-Chapter-7

Exercise 7.1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 struct Sales_data { string bookNo; unsigned units_sold = 0; double revenue = 0.0; }; int main() { Sales_data item1, item2; if(cin >> item1.bookNo >> item1.units_sold >> item1.revenue) { while(cin >> item2.

Cpp-Primer-5th-Exercises-Chapter-6

Exercise 6.1 1 2 3 // parameters of function: local variables are to be implicitly defined and initialized when the function is called. // arguments of function: initialize values that assigned to objects(paramenters of a function) when a function is called Exercise 6.2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 // a: type of function unmatchs its return value // string f() // { // string s; // // .

Cpp-Primer-5th-Exercises-Chapter-5

Exercise 5.1 1 2 3 // null statement is a statement just contains a ';' // applied on certain place which needs a statement required by the rule of syntax, while by logical there is nothing needed to be handled. Exercise 5.2 1 2 // block is a sequence of statements and declarations surrounded by curly braces, also called as compound statement, may be blank inside curly braces.