Accelerated C + +: Programming practice with examples-practice Answers (9th)

Source: Internet
Author: User

my github Address: Https://github.com/CNhoward/Accerlerated-C-plus-plus

9-0. Compile, execute, and test the programs in this chapter.

Ans: See GitHub.

9-1 Reimplement Student_info The class so it calculates the final when grade reading the student's record, and stores that G Rade in the object. Reimplement the function to use this grade precomputed value.

Ans: See GitHub.

9-2. If we define the name function as a plain, non const member function, what other functions in our system must change And why?

Ans: We just need to modify the parameter type of the function compare (): Change the original bool Compare (const student_info& x,const student_info& y) to

BOOL Compare (Student_info X,student_info y)

The Tips:const object cannot call the const member function function;

Why did you change student_info& to Student_info x?

Because the sort (students.begin (), students.end (), compare), is passed to compare in the function as a const object, because a const object cannot be initialized with a non-const reference, Therefore, it needs to be changed to the value of transmission.

9-3. Our grade function is written to the throw an exception if a user tried to calculate a grade for a Student_info object whose Val UEs had not yet been read. Users who care is expected to catch this exception. Write A program this triggers the exception but does not catch it. Write a program, that catches the exception.

Ans: See GitHub.

9-4. Rewrite your program from the previous exercise valid the function, thereby avoiding the exception altogether.

Ans: See GitHub.

9-5. Write a class and associated functions to generate grades for students who take the course for Pass/fail credits. Assume that is only the midterm and final grades matter, and which a student passes with an average exam score greater than 60 . The report should lists the students in alphabetical order, and indicate P or F as the grade.

Ans: See GitHub.

9-6 Rewrite The Grading program for the Pass/fail students so and the report shows all the students who passed, followed By all the students who failed.

Ans: See GitHub.

9-7. The read_hw FUNCTION§4.1.3/57 solves a general problem (reading a sequence of values to a vector ) even though its name suggests that it should is part of the implementation of Student_info . Of course, we could change their name-but suppose, instead, that's wanted to integrate it with the rest of Student_info the code, In order to clarify the it is not intended for public access despite its apparent generality? How would?

Ans: See GitHub.


Accelerated C + +: Programming practice with examples-practice Answers (9th)

Related Article

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.