Exercise 6.16
1 bool is_empty (conststringreturn s.empty ();}
Exercise 6.17
1 BOOLHave_upper (Const string&s)2 {3 for(auto c:s)4 {5 if(Isupper (c))6 return true;7 }8 return false;9 }Ten One voidTo_lower (string&s) A { - for(Auto &c:s) - { the if(Isupper (c)) -c =ToLower (c); - } - } + - intMain () + { A stringstr{"Hello World" }; at BOOLA =have_upper (str); -cout << a <<Endl; - to_lower (str); -cout << str <<Endl; -System"Pause"); - return 0; in}
Not the same, because one does not need to modify the value of S, while the other needs to modify the value of S;
Exercise 6.18
A) bool Compare (const matrix &a, const matrix &B);
Compare the size of two mitrix types;
b) vector<int>::iterator change_val (const int i, vector<int>::iterator &j);
Assigns the value of I to an element in an iterator;
Exercise 6.19
A) one more argument
b) Correct
c) Correct, 66 will automatically switch to double type
d) Correct, last number downward to int type
Exercise 6.20
The parameter should be a constant reference when the object we are bound to does not need to modify it or not. If set to a normal reference, once the parameter is changed, the bound object will be changed together, resulting in unpredictable consequences.
C + + Primer 6.2.3 Practice Answers