已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Test Bank for Problem Solving with C+: The Object of Programming, 6/e Chapter 5 Functions for All Sub TasksTRUE/FALSE1. A void function can return any valueANSWER: FALSE2. A void function can be used in an assignment.ANSWER: FALSE3. A void function may not be used in an output statement.ANSWER: TRUE4. Functions can return at most one value.ANSWER: TRUE5. The following is legal in a void functionreturn;ANSWER: TRUE6. In a function with call-by-reference parameters, the values of the actual arguments are passed to the function.ANSWER: FALSE, The actual variables (or more precisely their memory addresses) are passed.7. In a function with call-by-reference parameters, any changes to the formal parameters will change the actual arguments passed to the function.ANSWER: TRUE8. It is acceptable to have both call-by-value and call-by-reference parameters in the same function declaration.ANSWER: True9. It is illegal to call other functions from inside a function definition.ANSWER: FALSE10. A stub is a function that is completely defined and well testedANSWER: FALSESHORT ANSWER1. A _ is a main program that only checks that functions execute correctly.ANSWER: driver2. The values or variables listed in the function declaration are called _ to the function.ANSWER: (formal) parameters3. Given the following function definition fragment, for which values of myInt should the function be tested?int doSomething(int myInt)if(myInt 0)/do some stuff hereANSWER: -1, 0,14. When the address of the actual argument is passed to the formal parameter, this is called _ANSWER: call-by-reference or- pass-by-reference5. If we want to test if a given function works correctly, we would write a _ to test it.ANSWER: driver6. The variables passed a function are called _.ANSWER: arguments7. What is the correct way to call the following function? _void setDisplay();ANSWER: setDisplay();8. A function that does not return a value is known as a _ function.ANSWER: void9. What type of value does a void function return? _ANSWER: nothing10. What symbol is used to signify that a parameter is a reference parameter? _ANSWER: ampersand (&)11. What is the correct way to call the following function? Assume that you have two variables named intArgument (int) and floatArgument(float).void doThings(float x, int y);ANSWER: doThings(floatArgument, intArgument);12. Using functions in a program is called _.ANSWER: procedural abstraction13. pre and post conditions for a function should be written (before/after) the function definition is written.ANSWER: before14. A _ is a simplified version of a function used to test the main program.ANSWER: stub15. Testing a program with values that are close to values that will change the execution of a program is called _.ANSWER: boundary testingMULTIPLE CHOICE1. Which of the following is a legal call to the displayOutput function?void displayOutput(int total);a. void displayOutput(myTotal);b. displayOutput(int mytotal);c. displayOutput(myTotal);d. cout displayOutput(myTotal);ANSWER: C2. The precondition(s) for a function describe:a. What is true after the function is executedb. What the function doesc. How to call the functiond. What must be true before the function executesANSWER: D3. Which of the following is true for a void function?a. There cannot be a return statement.b. The value of void should be returned.c. The value of 0 should be returned.d. Nothing is returned.ANSWER: D4. Call-by-reference parameters are passeda. nothingb. the actual argument.c. the value in the actual argument.d. the address of the argument.ANSWER: B (我觉得B和D都对啊。)?5. If you need a function to get both the number of items and the cost per item from a user, which would be a good function declaration to use?a. int,float getData();b. int getData(float cost);c. void getData(int count, float cost);d. void getData(int& count, float& cost);ANSWER: D6. What is the output of the following function and function call?void calculateCost(int count, float& subTotal, float& taxCost);float tax = 0.0, subTotal = 0.0;calculateCost(15, subTotal,tax);cout The cost for 15 items is subtotal , and the tax for subTotal is tax endl;/end of fragmentvoid calculateCost(int count, float& subTotal, float& taxCost)if ( count 10)subTotal = count * 0.50;elsesubTotal = count * 0.20;taxCost = 0.1 * subTotal;a. The cost for 15 items is 3.00, and the tax for 3.00 is 0.30;b. The cost for 15 items is 0.00, and the tax for 3.00 is 0.00;c. The cost for 15 items is 0.00, and the tax for 3.00 is 0.30;d. The cost for 15 items is 3.00, and the tax for 3.00 is 0.00;ANSWER: A7. What is the output of the following function and function call?void calculateCost(int count, float& subTotal, float taxCost);float tax = 0.0, subtotal = 0.0;calculateCost(15, subtotal,tax);cout The cost for 15 items is subtotal , and the tax for subtotal is tax endl;/end of fragmentvoid calculateCost(int count, float& subTotal, float taxCost)if ( count 10)subTotal = count * 0.50;elsesubTotal = count * 0.20;taxCost = 0.1 * subTotal;a. The cost for 15 items is 3.00, and the tax for 3.00 is 0.30;b. The cost for 15 items is 0.00, and the tax for 3.00 is 0.00;c. The cost for 15 items is 0.00, and the tax for 3.00 is 0.30;d. The cost for 15 items is 3.00, and the tax for 3.00 is 0.00;ANSWER: D8. Which of the following function prototypes are not valid?a. void doSomething(int& x, int y);b. void doSomething( int& x, int& y);c. void doSomething( int x, int y);d. all are not valide. all are validANSWER: E9. You should make a parameter a reference parameter if:a. You need the function to change the value of the argument passed to the function.b. you need to be able to change the value of the parameter in the function, but not the value of the argument.c. Always.d. If any of the other parameters are reference parameters.ANSWER: A10. Which of the following are true?a. a function can call another function.b. as long as the function is defined anywhere in your program, it can be used anywhere else.c. a function definition can contain another function definition.d. if you have function prototypes, the order in which you define your functions is important.ANSWER: A11. The postcondition of a function a. determines how the function will complete its job.b. tells what must be true before the function executes.c. declares the function for the compiler.d. tells what will be true after the function executes.ANSWER: D12. What is the value of choice after the following statements?void getChoice(int& par_choice, in par_count);int choice, count=3;getChoice(choice, count);void getChoice(int& par_choice, in par_count)if(par_count0)par_choice =0;if(par_count = 0)par_choice=-1;elsepar_choice=99;return;a. 3b. 0c. 1d. 99ANSWER: D13. What is wrong with the following function body?void calculate(int count, float price, float& cost)if (count 0)cost=0.0;elsecost=count*price;return;a. void functions may not have a return statement.b. void functions must return a valuec. nothingd. can not mix reference and value parametersANSWER: C14. If you were to write a function for displaying the cost of an item to the screen, which function prototype would be most appropriate?a. void display();b. void display(float myCost);c. int display (float myCost);d. float display();ANSWER: B15. Given the function definitionvoid something ( int a, int& b )int c;c = a + 2;a = a * 3;b = c + a;what is the output of the following code fragment that invokes something? (All variables are of type int.)r = 1;s = 2;t = 3;something(t, s);cout r s t endl;a. 1 14 3b. 1 10 3c. 5 14 3d. 1 14 9e. none of the aboveANSWER: A16. Given the following function declaration and local variable declarations, which of the following is not a correct function call?int myInt;float myFloat;char ch;void someFunction(int& first, float second, char third);a. someFunction(1, 2.0, ch);b. someFunction(myInt, myFloat, ch);c. someFunction(myInt, 2.0, c);d. someFunction(myInt, myFloat, 1);ANSWER: A17. Given the following function definitionvoid shift(int& a, int&b)a=b;b=a;What is the output after the following function call?int first=0, second=10;shift(first, second);cout first second a)a=b;return a;elsereturn 0;float x=0, y=10,z;z=trial(y,x);cout z x y endl;a. 10 0 0 b. 0 10 0c. 10 0 0d. 0 0 10ANSWER: D19. When a void function is called, it is known asa. An output function.b. A returned value.c. An executable statement.d. A commentANSWER: C20. If a function needs to modify more than one variable, it musta. be pass by valueb. be a void functionc. return all values neededd. be a call by reference functionANSWER: D21. In the following function, what is passed to the first parameter?void f1( int& value1, int value2);int x,y;f1(x,y);a. The value of xb. nothing, it is a void functionc. the value of yd. the variable x (or its memory location)ANSWER: D22. Given the following function definitions and program fragments, what is the output?void f1(int& z, int &q)int temp;temp=q;q=z;z=temp;void f2( int& a, int& b)if( ab)f1(a,b);elsea=b;int x=3, y=4;f2(y,x);cout x y endl;a. 3 3b. 4 3c. 3 4d. 4 4ANSWER: A23. A simplified version of a function which is used to test the main program is calleda. A stubb. Abstractionc. Polymorphismd. A driverANSWER: A24. A simplified main program used to test functions is calleda. A stubb. Abstractionc. Polymorphismd. A driverANSWER: D25. Testing a function or program using test values that are at or near the values that change the outcome of the program is known as usinga. parametersb. functional decompositionc. boundary valuesd. a black-boxANSWER: C26. Call-by-reference should be useda. For all variablesb. When the function needs to change the value of one or more argumentsc. Neverd. only in void functionsANSWER: B27. Which of the following comments
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 产后抑郁的复发预防与维持治疗
- 产后抑郁的共病躯体化障碍诊疗
- 产后抑郁的母-婴互动干预研究
- 典型知识产权合同条款的审查技巧1
- 交叉设计在生物等效性试验中的运输条件影响
- 事故后PTSD心理危机干预教学
- 浅析《惊魂记》中的悬疑元素和恐怖元素
- 浅议工程管理中存在不足及解决方法
- 2007年度经教育部备案或批准设置的高等学校本科专业名单
- 工商企业管理专科毕业论文
- 2024-2025学年北京市海淀区七年级下英语期末考试题(含答案和音频)
- 智算中心异构计算资源协同与优化方案
- 工会经费审计课件
- 电焊外包安全管理协议合同
- 智能化产品开发-洞察及研究
- 臀大肌康复训练
- 不立案通知书
- 骨折卧床患者心理护理
- 火锅调味师培训课件
- 《思想道德与法治》课件-第一节 人生观是对人生的总的看法
- 中医护理艾箱灸操作流程
评论
0/150
提交评论