tailieunhanh - C++ Weekend Crash Course phần 10

mô hình tiêu chuẩn của việc tạo ra một đối tượng mới như là một hình ảnh phản chiếu của bản gốc bằng cách sử dụng bản sao constructor MyClass (MyClass &). Không rõ ràng là C + + cho phép định dạng thứ hai mà newerMC được tạo ra bằng cách sử dụng các nhà xây dựng bản sao. | 466 Appendix A n1 0 else n1 1 The outer if statement has no else clause and thus n1 remains unchanged. 7. Because the n1 is not less than 5 the body of the while control is never executed. In the case of the control the body is executed once even though n1 is no less than 5. In this case n1 ends up with a value of 11. The difference between the two loops is that the always executes its body at least once even if the conditional clause is false from the beginning. 8. double cube double d return d d d Because the Intel processor in your PC handles integers and floatingpoint variables differently the machine code generated by the two functions cube int and cube double are completely different. 9. The expression cube matches the function cube double thus cube double is passed the double value and returns the double value which is demoted to 9 and assigned to the variable n. Although the result is the same how you got there is different. 10. The compiler generates an error because the first cube int function and the final function have identical names. Remember that the return type is not part of the function s full name. Answers to Part Reviews 467 Saturday Afternoon Review Answers 1. class Student public char szLastName 128 int nGrade 1- first grade 2- second grade etc. double dGPA 2. void readAndDisplay Student s input student information cout Enter the student s name cout Grade 1- first grade 2- second. n cin cout GPA cin output student info cout nStudent information n cout n cout n cout n 3. void readAndDisplayAverage Student s input student information cout Enter the student s name cout Grade 1- first grade 2- second. n cin cout GPA 468 Appendix A enter in three GPAs to be averaged double dGrades 3 cin dGrade 0 cin dGrade 1 cin dGrade 2 dGrade 0 dGrade 1 dGrade 2 3 output student info cout nStudent information n cout .

TỪ KHÓA LIÊN QUAN