




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Test Bank for Problem Solving with C+: The Object of Programming, 6/e Chapter 10 Defining ClassesTRUE/FALSE1. A struct variable is declared differently from a predefined type such as an int.ANSWER: FALSE2. Two different structure definitions may have the same member names.ANSWER: TRUE.3. A structure can only be passed to a function as a call-by-value parameterANSWER: FALSE4. A function may return a strucure.ANSWER: TRUE5. Different class may not have member functions with the same name.ANSWER: FALSE6. A class member function may be private.ANSWER: TRUE7. Class data members are almost always public.ANSWER: FALSE8. It is possible to have multiple private labels in a class definition.ANSWER: TRUE9. The assignment operator may not be used with objects of a class.ANSWER: FALSE10. All constructors for a class must be private.ANSWER: FALSEShort Answer1. The keyword _ defines a structure type definition.ANSWER: struct2. A structure definition ends with the closing brace and a _.ANSWER: semicolon3. A structure variable is a collection of smaller values called _ valuesANSWER: member4. When a structure contains another structure variable as one of its members, it is known as a _.ANSWER: hierarchical structure5. When several items (variables or variables and functions) are grouped together into a single package, that is known as _.ANSWER: (data) encapsulation6. The double colon (:) is known as the _ operator.ANSWER: scope resolution operator7. Who can access private members in a class?ANSWER: only other members of the class8. A member function that allows the user of the class to find out the value of a private data type is called a _.ANSWER: accessor function.9. A member function that allows the user of the class to change the value of a private data type is called a _.ANSWER: mutator function.10. If you have a class with a member function called display(ostream& out), that will send the values in the class to the parameter stream, and you need to call that function from within another member function, how would you call it to print the data to the screen? _ANSWER: display(cout);11. What can a constructor return? _ANSWER: nothing12. The name of a constructor is _ANSWER: the name of the class13. The constructor of a class that does not have any parameters is called a _ constructor.ANSWER: default14. In the following class constructor definition, the part of the header starting with a single colon is called the _.BankAccount:BankAccount(): balance(0), interest(0.0)ANSWER: initialization section15. A class in which modifications to the implementation appear to be invisible to the user of the class is known as _.ANSWER: an Abstract Data Type (ADT)16. A member function that gets called automatically when an object of the class is declared is called a _.ANSWER: constructorMultiple Choice1. In a structure definition, the identifiers declared in the braces are calleda. classesb. structsc. member namesd. variablesANSWER: C2. You specify an individual member of a struct by usinga. the assignment operatorb. an ampersandc. an underscored. The dot operatorANSWER: D3. To assign values to a structure variable, you use thea. equals operatorb. assignment operatorc. extraction operatord. less than operatorANSWER: B4. What is wrong witht the following structure definition?struct MyStructint size;float weight;a. Nothingb. Can not have mixed data types in a structurec. missing semicolond. Braces are not needed.ANSWER: C5. Given the following strucure definitions, what is the correct way to print the persons birth year?struct DateTypeint day;int month;int year;struct PersonTypeint age;float weight;DateType birthday;PersonType person;a. cout person.birthday.year;b. cout year;c. cout birthday.year;d. cout peson.year;ANSWER: A6. Given the following strucure definition, what is the correct way to initialize a variable called today?struct DateTypeint day;int month;int year;a. DateType today(1,1,2000);b. DateType today = (1,1,2000);c. DateType today = 1,1,2000);d. DateType today = 1,1,2000,0);ANSWER: C7. When defining a class, the class should be composed of the kind of values a vaiable of the class can contain, anda. member functions for that classb. the keyword privatec. other class definitionsd. nothing elseANSWER: A8. Which of the following is the correct function definition header for the getAge function which is a member of the Person class?a. int getAge();b. int getAge()c. int Person:getAge()d. int Person:getAge()ANSWER: D9. Given the following class definition and the following member function header, which is the correct way to output the private data?class Personpublic:void outputPerson(ostream& out);private:int age;float weight;int id;void outputPerson(ostream& out)/what goes here?a. out person.age person.weight person.id;b. out person;c. out age weight id;d. outputPerson(person);ANSWER: C10. Why do you want to usually make data members private in a class?a. so that no one can use the class.b. ensure data integrityc. provide data abstraction.d. provide information hiding.e. B and Df. B, C and DANSWER: F11. A member function of a class should be made privatea. alwaysb. only if it will never be usedc. if it will only be used by other members of the classd. never, it is illegal to make a member function private.ANSWER: C12. A member function that allow the user of the class to change the value in a data member is known asa. a mutator functionb. a mutationc. a manipulator functiond. an accessor functionANSWER: A13. A Member function that allows the user of the class to see the value in a data member is known asa. a mutator functionb. a mutationc. a manipulator functiond. an accessor functionANSWER: D14. If you design a class with private data members, and do not provide mutators and accessors, thena. The class cannot be usedb. The data can not be changed or viewed by anyone.c. None of the aboved. A and BANSWER: D15. A class member function that automatically initializes the data members of a class is called a. the init functionb. an operatorc. a constructord. a castANSWER: C16. If you have a class named myPersonClass, which of the following correctly declare a constructor in the class definition?a. myPersonClass:myPersonClass();b. myPersonClass();c. init();d. cast();ANSWER: B17. given the following class definition, how could you use the constructor to assign values to an object of this class?class CDAccountpublic:CDAccount();CDAccount(float interest, float newBalance);float getBalance();float getRate();void setRate(float interest);void setBalance(float newBalance);private:float balance, rate;and the following object declarationCDAccount myAccount;a. myAccount = CDAccount(float myRate, float myBalance);b. myAccount = CDAccount myRate, myBalance;c. myAccount = CDAccountmyRate, myBalance;d. myAccount = CDAccount(myRate, myBalance);ANSWER: D18. Given the following class definition, what is missing?class ItemClasspublic:ItemClass(int newSize, float newCost);int getSize();float getCost();void setSize(int newSize);void setCost(float newCost);private:int size;float cost;a. nothingb. a default constructorc. accessor functionsd. mutator functionsANSWER: B19. Given the following class definition, how would you declare an object of the class, so that the object automatically called the default constructor?class ItemClasspublic:ItemClass();ItemClass(int newSize, float newCost);int getSize();float getCost();void setSize(int newSize);void setCost(float newCost);private:int size;float cost;a. ItemClass() myItem;b. ItemClass myItem(1, 0.0);c. ItemClass myItem;d. ItemClass myItem();e. You can not do thisANSWER: C20. A data type consisting of data members and operations on those members which can be used by a programmer without knowing the implementation details of the data type is calleda. an abstract definition typeb. an available data typec. an abstract data typed. a primitive data typeANSWER: C21. Which part of the ADT tells the programmer using it how to use it?a. the implementationb. the interfacec. the abstractnessd. the scope resolutionANSWER: B22. If you are designing a class for an ADT, you can tell if the class is an ADT ifa. when you change the implementation of the class, none of the rest of the program needs to change.b. when you change the interface of the class, nothing else needs to change.c. you change the privte part and the rest of the program using the ADT does not compile.d. everything must be changed.ANSWER: A23. Developing an ADT means that the user of your class does not have to know the details about how the class is implemented. This is known asa. interfaceb. implementationc. testing and debuggingd. information hidingANSWER: D24. Given the following class, what would be the best declaration for a mutator function that allows the user of the class to change the age?class Winepublic:Wine();int getAge();float getCost();private:int age;float cost;a. int getAge(int newAge);b. Wine();c. void setAge();d. void setAge(int newAge);ANSWER: D25. Given the following class, what would be the best declaration for a constructor that would allow the user to initialize the object with an initial age and cost?class Winepublic:Wine();int getAge();float getCost();private:int age;float cost;a. int getAge(int newAge);b. Wine();c. Wine(int age);d.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 黑龙江省海林市高中化学 第二章 化学物质及其变化 第三节 氧化还原反应氧化剂和还原剂说课稿 新人教版必修1
- 河北省赞皇县七年级道德与法治上册 第三单元 师长情谊 第六课 师生之间 第1框 走近老师说课稿 新人教版
- 3.1 AI画家说课稿-2023-2024学年小学信息技术(信息科技)小学版(2024)人工智能通识(清华大学版)
- 7.15课向世界介绍我的学校-创作与发布(说课稿)-信息技术七年级上册同步备课(浙教版)
- 2025年租赁合同范本:办公楼租赁合同
- 2025企业借款合同范本版
- 九年级英语上册 Module 6 Problems Unit 1 If I start after dinner I'll finish it before I go to bed第二课时说课稿(新版)外研版
- 2023六年级英语下册 Module 2 Work and play Unit 4 Art说课稿 牛津沪教版(三起)
- 跨境电商物流模式说课稿-2025-2026学年中职专业课-跨境电商基础-电子商务-财经商贸大类
- 基础实验1 氧气的实验室制取与性质说课稿-2025-2026学年初中化学沪教版2024九年级上册-沪教版2024
- 四川省石渠县2025年上半年公开招聘辅警试题含答案分析
- 真菌生物膜毒力因子-洞察及研究
- 基孔肯雅热危害及预防课件
- 副校长在任职宣布会上的表态发言材料
- 同学互助基金管理办法
- 农行对导盲犬管理办法
- 2024年了解脑退化症及各项可用服务和支持的指南-澳大利亚脑退化症支持协会
- 三级综合医院健康管理学科建设模式:理论、实践与创新
- 2017年考研英语一真题
- 羊饲养管理技术课件
- 《乡土中国》第五章课件
评论
0/150
提交评论