chapter11_6e友元

上传人:第*** 文档编号:33609368 上传时间:2018-02-16 格式:DOC 页数:8 大小:46KB
返回 下载 相关 举报
chapter11_6e友元_第1页
第1页 / 共8页
chapter11_6e友元_第2页
第2页 / 共8页
chapter11_6e友元_第3页
第3页 / 共8页
chapter11_6e友元_第4页
第4页 / 共8页
chapter11_6e友元_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《chapter11_6e友元》由会员分享,可在线阅读,更多相关《chapter11_6e友元(8页珍藏版)》请在金锄头文库上搜索。

1、Test Bank for Problem Solving with C+: The Object of Programming, 6/e Chapter 11 Friends and Overloaded OperatorsTRUE/FALSE1. Friend functions are members of the class.ANSWER: FALSE2. All operators can be overloaded.ANSWER: FALSE3. If you have mutators and accessors, you should not have friend funct

2、ions alsoANSWER: FALSE4. Friend functions may directly modify or access the private data members.ANSWER: TRUE5. The following is a properly declared overloaded insertion operator for myClass.ostreamANSWER: TRUE6. Functions that are constant member functions may call the class mutator functions.ANSWE

3、R: FALSE7. Functions that are constant member functions may call constant class accessor functions.ANSWER: TRUE8. You cannot create new operators (such as the quote).ANSWER: TRUE9. Operators must be friends of the class.ANSWER: FALSE10. You may not change the precedence of operators by overloading t

4、hemANSWER: TRUEShort Answer1. If a given task being performed by a function involves more than one object, then that function should normally be a _ function.ANSWER: friend2. If a given task being performed by a function involves one object, then that function should normally be a _ function.ANSWER:

5、 member3. A _ function is not a member of the class, but has access to the private members of the class.ANSWER: friend4. An overloaded extraction or insertion operator should return _ANSWER: a reference to the stream5. A friend function needs to be passed an object of the class. If the friend only n

6、eeds to access the object, but not change its data members, then the object should be passed as _ANSWER: a constant reference6. An operator that expects only one parameter is called a _ operatorANSWER: unary7. An operator that expects two parameters is called a _ operator.ANSWER: binary8. In order t

7、o do automatic type conversion for your class, you would write _Test Bank for Problem Solving with C+: The Object of Programming, 6/e Chapter 11 Friends and Overloaded OperatorsANSWER: overloaded functions or overloaded constructors9. Putting the keyword const after the function declaration guarante

8、es _ANSWER: That the function will not change the calling object.10. Putting the keyword const in front of a pass by reference parameter guarantees _ANSWER: that the function will not modify that parameter.Multiple Choice1. How many members (data and functions) does the following class have?class Ra

9、tionalpublic:Rational();Rational(int numer, int denom);Rational(int whole);int getNumerator();int getDenominator();friend void display(ostreamprivate:int numerator;int denominator;a. 2b. 6c. 5d. 7e. 8ANSWER: D2. Who can access private data in a class?a. members of the classb. friends of the classc.

10、everyoned. B and C A and Be. no oneANSWER: D3. Given the following class, which is the correct function header for the display function?class Rationalpublic:Rational();Rational(int numer, int denom);Rational(int whole);Test Bank for Problem Solving with C+: The Object of Programming, 6/e Chapter 11

11、Friends and Overloaded Operatorsint getNumerator();int getDenominator();friend void display(ostreamprivate:int numerator;int denominator;a. friend void display(ostream& out, const Rational& value)b. void display(ostream& out, const Rational& value)c. void Rational:display(ostream& out, const Rationa

12、l& value)d. friend void Rational:display(ostream& out, const Rational& value)ANSWER: B4. Operators can be overloaded asa. friends of a classb. members of a classc. non-friends, non-members of a classd. All of the aboveANSWER: D5. If we have a full selection of accessor and mutator functions, why wou

13、ld we have friend functions?a. You should not have themb. More efficient access to the private data members.c. The friend function must call the accessor or mutator functions anyway.d. none of the aboveANSWER: B6. Since accessors functions in a class do not modify or mutate the data members of the o

14、bject, the function should have the _ modifier.a. referenceb. friendc. constd. privateANSWER: C7. Why should you generally pass an object of the class to a friend function as a reference parameter?a. If the friend function changes the values of the data member(s).b. If the friend function will not c

15、hange the values of the data member(s).c. It is more efficient to pass the object by reference.d. A and Be. A and CANSWER: E8. If c is a character variable that contains a digit, what does the following function return?int digit_to_int(char c)Test Bank for Problem Solving with C+: The Object of Prog

16、ramming, 6/e Chapter 11 Friends and Overloaded Operatorsreturn ( int(c) int(0);a. The ASCII value of cb. The character value of cc. The integer equivalent of the digit stored in cd. none of the aboveANSWER: C9. What is wrong with the following member function definition given the class below?class Rationalpublic:Rational();Rational(int n

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号