C + + Primer 6.2.3 Practice Answers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.