




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 肉牛饲养技术分析总结
- 小书包课程体系讲解
- 现代体育教育技术
- 医院进修培训汇报
- 跳绳基本知识讲解
- 设备内部部件讲解
- 盆腔核磁检查技术
- 奢侈品包包讲解
- 学校流感处置指南解读
- 云南省玉溪市元江民中2026届化学高三第一学期期末调研模拟试题含解析
- 智人扩散路径重构-洞察及研究
- 三方委托付工程款协议书
- 2026年中考英语复习:初中英语课标词汇 80天语境背诵清单
- “苏超”现象:文化破圈、城市崛起与青年力量的融合交响-2026年高考语文作文热点话题素材积累与实战训练
- 制作教学课件的完整步骤
- 货运企业安全管理规范
- 《绿色物流与绿色供应链》PPT课件
- ISO13485-2016医疗器械质量管理体系全套资料(手册、程序文件、记录表单)
- 术前访视和术前准备注意事项.pptx
- 沪科版七年级数学上册全套ppt课件
- 特种车辆维护保养技术协议
评论
0/150
提交评论