Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Chapter 1 Data Abstraction: The Walls Multiple Choice Questions The specifications of an ADT’s operations indicate ______. a) what the operations do b) how to implement the operations c) how to store the data in the ADT d) how to carry out the operations Answer: a. 1. Data structures are part of an ADT’s ______. a) definition b) implementation c) specifications d) usage Answer: b. 2. 3. A(n) ______ allows two modules to communicate with each other. a) data structure b) axiom c) interface d) client Answer: c. An ADT’s ______ govern(s) what its operations are and what they do. a) specifications b) implementation c) documentation d) data structure Answer: a. 4. 5. Which element is the head of the following list: John, Kate, Fred, Mark, Jon, Adam, Drew? a) John b) Mark c) Drew d) Adam Answer: a. 6. In the following list: John, Kate, Fred, Mark, Jon, Adam, Drew which element is the tail of the list? a) John b) Mark c) Drew d) Adam Answer: c. 7. In the following list: John, Kate, Fred, Mark, Jon, Adam, Drew which element does not have a predecessor? a) John b) Mark c) Drew d) Kate Answer: a. Data Abstraction & Problem Solving with C++: Walls and Mirrors, Sixth Edition, by Frank Carrano and D.J. Henry, Pearson Education-Prentice Hall, 2013 1 8. The items in the ADT list are referenced by ______. a) name b) value c) position number d) position name Answer: c. 9. The insertion operation of the ADT list can insert new items ______. a) only at the front of the list b) only at the end of the list c) only in the middle of the list d) into any position of the list Answer: d. 10. In the ADT list, when an item is deleted from position i of the list, ______. a) the position of all items is decreased by 1 b) the position of each item that was at a position smaller than i is decreased by 1 c) the position of each item that was at a position greater than i is decreased by 1 d) the position of each item that was at a position smaller than i is increased by 1 while the position of each item that was at a position greater than i is decreased by 1 Answer: c. 11. In the ADT list, when an item is inserted into position i of the list, ______. a) the position of all items is increased by 1 b) the position of each item that was at a position smaller than i is increased by 1 c) the position of each item that was at a position greater than i is increased by 1 d) the position of each item that was at a position smaller than i is decreased by 1 while the position of each item that was at a position greater than i is increased by 1 Answer: c. 12. A client program depends solely on the ______ of the ADT. a) data members b) structure c) implementation d) behavior Answer: d. 13. Which of the following operations of the ADT list changes the list? a) remove b) isEmpty c) size d) get Answer: a. 14. The ADT sorted list inserts and deletes items by their ______. a) name b) value c) position name d) position number Answer: b. Data Abstraction & Problem Solving with C++: Walls and Mirrors, Sixth Edition, by Frank Carrano and D.J. Henry, Pearson Education-Prentice Hall, 2013 2 15. A(n) ______ can be used to precisely specify the behavior of each of the operations of an ADT. a) exception b) data structure c) axiom d) client Answer: c. 16. Object-oriented programming views a program as ______. a) a sequence of actions b) a collection of classes c) a group of methods d) an interaction among objects Answer: d. 17. An ADT’s operations are known as its ______. a) axioms b) methods c) variables d) interfaces Answer: b. 18. Encapsulation combines an ADT’s data with its operations to form a(n) ______. a) exception b) method c) object d) variable Answer: c. 19. A(n) ______ is a C++ construct that enables a programmer to define a new data type. a) class b) method c) data field d) object Answer: a. 20. A C++ class contains data members and ______. a) clients b) interfaces c) methods d) data structures Answer: c. 21. A(n) ______ is an instance of a class. a) method b) data field c) interface d) object Answer: d. 22. Which of the following is true about a constructor in C++? a) all constructors have a return type of void b) a constructor cannot have parameters c) a constructor has the same name as the class d) a class can only have a single constructor Answer: c. Data Abstraction & Problem Solving with C++: Walls and Mirrors, Sixth Edition, by Frank Carrano and D.J. Henry, Pearson Education-Prentice Hall, 2013 3 23. A(n) ______ is a class that inherits the members of another class. a) base class b) superclass c) abstract class d) subclass Answer: d. 24. Which of the following is true about a destructor in C++? a) a class can have several destructors b) the compiler will generate a destructor if the programmer does not provide one c) a programmer must provide a destructor for every class d) a destructor destroys all instances of a class Answer: b. 25. In C++, each class definition should be placed in a(n) ______. a) implementation file b) header file c) namespace d) package Answer: b. 26. C++ provides a mechanism for logically grouping class definitions and other declarations into a common declarative region known as a(n) ______. a) namespace b) interface c) header d) package Answer: a. 27. When defining class A so that any of its instances can invoke any of the publicly defined methods of class B, the keyword ______ precedes the name of class B. a) public b) global c) static d) final Answer: a. 28. A function can indicate that an error has occurred by ______ an exception. a) throwing b) catching c) implementing d) declaring Answer: a. 29. To ______ an exception means to deal with the error condition. a) declare b) catch c) implement d) try Answer: b. Data Abstraction & Problem Solving with C++: Walls and Mirrors, Sixth Edition, by Frank Carrano and D.J. Henry, Pearson Education-Prentice Hall, 2013 4 30. Which of the following is true about runtime exceptions? a) they must be handled locally b) they must be explicitly thrown from the method c) they are used in situations where the method has encountered a serious problem d) they can often be prevented by fail-safe programming Answer: d. True/False Questions 1. According to the principle of information hiding, a module should be completely isolated from other modules. Answer: False. 2. Data structures are part of an ADT’s implementation. Answer: True. 3. An abstract data type is another name for a data structure. Answer: False. 4. The head of a list does not have a successor. Answer: False. 5. All the items in a list must be of the same data type. Answer: True. 6. An application can use the operations of an ADT without knowing how the ADT is implemented. Answer: True. 7. By default, all members in a class are public. Answer: False. 8. A try block can only have one catch block associated with it. Answer: False. 9. In C++, the scope resolution operator is a colon (:). Answer: False. 10. Any instance of a subclass can be used in a program anywhere that an instance of the superclass can be used. Answer: True. Short Answer Questions 1. What are some of the benefits of modularity? Answer: A modular problem is easier to write, read, and modify. Modularity also isolates errors and eliminates redundancies. 2. What is functional abstraction? Answer: Functional abstraction is a design principle that separates the purpose and use of a module from its implementation. 3. What is information hiding? Answer: Information hiding is a process that hides certain implementation details within a module and makes them inaccessible from outside the module. Data Abstraction & Problem Solving with C++: Walls and Mirrors, Sixth Edition, by Frank Carrano and D.J. Henry, Pearson Education-Prentice Hall, 2013 5 4. What are the three types of operations on a data collection? Answer: The three types of operations on data are: Add data to a data collection. Remove data from a data collection. Ask questions about the data in a data collection. 5. What is data abstraction? Answer: Data abstraction is a design principle that separates the operations performed on a collection of data from the implementation of the operations. 6. What is an abstract data type (ADT)? Answer: An ADT is a collection of data together with a set of operations on that data. 7. What is a data structure? Answer: A data structure is a construct that is defined within a programming language to store a collection of data. 8. What is an axiom? Answer: An axiom is a mathematical rule. 9. What is a constructor? Answer: A constructor is a method that creates and initializes new instances of a class. 10. When and how are initializers used? Answer: Initializers are used within a constructor’s implementation to set data members to initial values. Each initializer uses a functional notation that consists of a data member name followed by its initial value enclosed in parentheses. A colon precedes the first (or only) initializer, and multiple initializers are separated by commas. 11. Under what circumstance is a compiler-generated default constructor created? Answer: A compiler-generated default constructor is created when the programmer does not include any constructor in a class. 12. Define the client of a class? Answer: The client of a class is a program or module that uses the class. 13. What is a superclass? Answer: A superclass is a class from which another class is derived. 14. What is the purpose of an exception? Answer: Exceptions are used for indicating errors during the execution of a program. 15. What is the difference between the physical size of an array and its logical size? Answer: The physical size of an array is the number of locations in the array. The logical size of an array is the number of items currently in the array. Data Abstraction & Problem Solving with C++: Walls and Mirrors, Sixth Edition, by Frank Carrano and D.J. Henry, Pearson Education-Prentice Hall, 2013 6