C++ Programming From Problem Analysis to Program Design 8th Edition Malik Test Bank

Page 1

C++ Programming From Problem Analysis to Program Design 8th Edition Malik Test bank

richard@qwconsultancy.com

1|Pa ge


Name:

Class:

Date:

Chapter 1 1. The basic commands that a computer performs are input (get data), output (display result), storage, and performance of arithmetic and logical operations. a. True b. False ANSWER: True FEEDBACK: Correct Reading data (input), displaying results (output), storage, and performing arithmetic and logical operations are the basic commands which are performed by a computer. Incorrect Reading data (input), displaying results (output), storage, and performing arithmetic and logical operations are the basic commands which are performed by a computer.

POINTS: 1 REFERENCES: 4 – Elements of a Computer System QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.02 Explore the hardware and software components of a computer system DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/16/2020 10:45 PM 2. Main memory is directly connected to the CPU. a. True b. False ANSWER: True FEEDBACK: Correct The main memory (also called random access memory) is directly connected to the central processing unit (CPU). Incorrect The main memory (also called random access memory) is directly connected to the central processing unit (CPU).

POINTS: 1 REFERENCES: 4 – Central Processing Unit and Main Memory QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.02 Explore the hardware and software components of a computer system DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 1:42 AM 3. When the computer is turned off, everything in secondary memory is lost. a. True b. False ANSWER: False FEEDBACK: Correct When the computer is turned off, everything in the main memory is lost, but the secondary memory stores information permanently. Incorrect When the computer is turned off, everything in the main memory is lost, but the secondary memory stores information permanently. Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 1 POINTS: 1 REFERENCES: 5 – Central Processing Unit and Main Memory QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.02 Explore the hardware and software components of a computer system DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 1:44 AM 4. The devices that feed data and programs into computers are called output devices. a. True b. False ANSWER: False FEEDBACK: Correct The devices that feed data and programs into computers are called input devices. A mouse, scanner, webcam, and keyboard are examples of input devices. Incorrect The devices that feed data and programs into computers are called input devices. A mouse, scanner, webcam, and keyboard are examples of input devices.

POINTS: 1 REFERENCES: 5 – Input/Output Devices QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.02 Explore the hardware and software components of a computer system DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 1:46 AM 5. Information stored in main memory must be transferred to some other device for permanent storage. a. True b. False ANSWER: True FEEDBACK: Correct Information stored in the main memory is lost when the computer is turned off, so the information should be transferred to some other device like hard disk (HD) for permanent storage. Incorrect Information stored in the main memory is lost when the computer is turned off, so the information should be transferred to some other device like hard disk (HD) for permanent storage.

POINTS: 1 REFERENCES: 5 – Central Processing Unit and Main Memory QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.02 Explore the hardware and software components of a computer system DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 1:47 AM Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 1 6. The device that stores information permanently (unless the device becomes unusable or you change the information by rewriting it) is called primary storage. a. True b. False ANSWER: False FEEDBACK: Correct A secondary storage device is used to store information permanently until the device becomes unusable or someone rewrites the information stored in it. Incorrect A secondary storage device is used to store information permanently until the device becomes unusable or someone rewrites the information stored in it.

POINTS: 1 REFERENCES: 5 – Central Processing Unit and Main Memory QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.02 Explore the hardware and software components of a computer system DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 1:49 AM 7. The command that does the linking on Visual C++ Express (2013 or 2016) and Visual Studio 2015 is Make or Remake. a. True b. False ANSWER: False FEEDBACK: Correct The Build or Rebuild is the command, which does the linking on Visual C++ Express (2013 or 2016) and Visual Studio 2015. Incorrect The Build or Rebuild is the command, which does the linking on Visual C++ Express (2013 or 2016) and Visual Studio 2015.

POINTS: 1 REFERENCES: 11 – Processing a C++ Program QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.08 - Explore how a C++ program is processed DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 1:51 AM 8. When you compile your program, the compiler identifies the logic errors and suggests how to correct them. a. True b. False ANSWER: False FEEDBACK: Correct The syntax errors in a program can be identified by a compiler while compiling the program. Also, the compiler suggests how to correct the errors. Incorrect The syntax errors in a program can be identified by a compiler while compiling the program. Also, the compiler suggests how to correct the errors.

POINTS: REFERENCES:

1 11 – Processing a C++ program

Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 1 QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.08 - Explore how a C++ program is processed DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 4:18 AM 9. To develop a program to solve a problem, you start by analyzing the problem. a. True b. False ANSWER: True FEEDBACK: Correct To solve a problem by developing a program, the problem must be analyzed first. Incorrect To solve a problem by developing a program, the problem must be analyzed first.

POINTS: 1 REFERENCES: 12 – Programming with the Problem Analysis–Coding–Execution Cycle QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.09 - Learn what an algorithm is and explore problem-solving techniques DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 4:18 AM 10. C++ programs have always been portable from one compiler to another. a. True b. False ANSWER: False FEEDBACK: Correct In the early 1980s through the early 1990s, the C++ language was evolving in slightly different ways in different compilers. Therefore,C++ programs were not always portable from one compiler to another. Incorrect In the early 1980s through the early 1990s, the C++ language was evolving in slightly different ways in different compilers. Therefore,C++ programs were not always portable from one compiler to another.

POINTS: 1 REFERENCES: 22 – ANSI/ISO Standard C++ QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.11 - Become aware of ANSI/ISO Standard C++, C++11, C++14 DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 5/11/2020 4:29 PM 11. Several categories of computers exist, such as ____. a. microframe, midframe, and miniframe b. midsize, microframe, and mainframe c. mainsize, midsize, and microsize d. mainframe, midsize, and micro Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 1 ANSWER: FEEDBACK:

d a. Incorrect. There is no computer category called microframe, midframe, or miniframe. b. Incorrect. Microframe is not a defined term in categories of computers.

c. Incorrect. Mainsize and microsize are not defined terms in categories of computers. d. Correct. Several categories of computers exist, such as mainframe, midsize, and micro.

POINTS: 1 REFERENCES: 3 – A Brief Overview of the History of Computers QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.01 - Learn about different types of computers DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 5/11/2020 4:31 PM 12. The basic commands that a computer performs are ____, and performance of arithmetic and logical operations. a. input, file, list b. output, folder, storage c. input, output, storage d. storage, directory, log ANSWER: c FEEDBACK: a. Incorrect. A file is an object used to store data and list is an abstract data type. b. Incorrect. Folder is a directory used to organize computer files. c. Correct. Input, output, storage, and performance of arithmetic and logical operations are the basic commands performed by a computer. d. Incorrect. A directory represents a location of the files stored in a computer.

POINTS: 1 REFERENCES: 4 – Elements of a Computer System QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.02 Explore the hardware and software components of a computer system DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 2:00 AM 13. Main memory is called ____. a. read only memory b. random access memory c. readily available memory d. random read only memory ANSWER: b FEEDBACK: a. Incorrect. Read only memory (ROM) is a non-volatile memory, which contains boot-up programs of a computer. b. Correct. Main memory is also called random access memory (RAM).

c. Incorrect. There is no memory called readily available memory. d. Incorrect. There is no memory called random read only memory. Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 1 POINTS: 1 REFERENCES: 4 – Central Processing Unit and Main Memory QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.02 Explore the hardware and software components of a computer system DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 2:01 AM 14. The ____ is the brain of the computer and the single most expensive piece of hardware in your personal computer. a. MM b. ROM c. RAM d. CPU ANSWER: d FEEDBACK: a. Incorrect. Main memory (MM) is also called as random access memory (RAM) used to load all programs for execution.

b. Incorrect. Read only memory (ROM) is a non-volatile memory, which contains programs to boot-up a computer. c. Incorrect. Random access memory (RAM) is also called as main memory (MM), which is connected directly to the central processing unit (CPU). d. Correct. The central processing unit (CPU) is the brain of a computer and it is the most expensive piece of hardware in a personal computer. It is used to execute all instructions.

POINTS: 1 REFERENCES: 4 – Central Processing Unit and Main Memory QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.02 Explore the hardware and software components of a computer system DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 5/11/2020 4:33 PM 15. Main memory is an ordered sequence of items, called ____. a. pixels b. registers c. memory cells d. addresses ANSWER: c FEEDBACK: a. Incorrect. Pixel is also called as picture element; it is a smallest piece of an image. The combination of pixels will form a computer display. b. Incorrect. Register is a type of computer memory used to store processing data.

c. Correct. Main memory is an ordered sequence of items, called memory cells. d. Incorrect. An address represents a specific location in a computer memory. POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 4 – Central Processing Unit and Main Memory Multiple Choice False

Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 1 LEARNING OBJECTIVES: PDDS.MALI.01.02 Explore the hardware and software components of a computer system DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 2:04 AM 16. The devices that feed data and programs into computers are called ____ devices. a. entry b. input c. output d. secondary ANSWER: b FEEDBACK: a. Incorrect. There is no device called entry device in computer technology. b. Correct. The devices that feed data and programs into computers are called input devices. Examples of an input device are a keyboard, scanner, and mouse. c. Incorrect. The devices that help to show computer results are called output devices. Examples of output devices are monitors and printers. d. Incorrect. There is no device called secondary device in computer technology (secondary storage device is used to store data permanently).

POINTS: 1 REFERENCES: 5 – Input/Output Devices QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.02 Explore the hardware and software components of a computer system DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 4:16 AM 17. The devices that the computer uses to display results are called ____ devices. a. exit b. entry c. output d. input ANSWER: c FEEDBACK: a. Incorrect. The devices fixed at the building doors to open and close the doors are referred as exit devices. b. Incorrect. The devices fixed at the entrance of a building are referred as entry devices. c. Correct. The devices that the computer uses to display results are called output devices. Examples of output devices are monitors and printers. d. Incorrect. The devices that feed data and programs into computers are called input devices. Examples of input devices are a keyboard, scanner, and mouse.

POINTS: 1 REFERENCES: 5 – Input/Output Devices QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.02 Explore the hardware and software components of a computer system DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/27/2020 12:07 AM Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 1 18. ____ programs perform a specific task. a. Application b. System c. Operating d. Service ANSWER: a FEEDBACK: a. Correct. Application programs perform a specific task. Games and word processors are examples of application programs. b. Incorrect. System programs control the computer. Operating system (OS) is an example of system program. c. Incorrect. Operating programs is not a defined term in computer programming.

d. Incorrect. A service program is a collection of runnable procedures. POINTS: 1 REFERENCES: 5 – Software QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.02 Explore the hardware and software components of a computer system DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 5/11/2020 4:33 PM 19. The ____ handles the overall activity of the computer and provides services. a. central processing unit b. operating system c. arithmetic logic unit d. control unit ANSWER: b FEEDBACK: a. Incorrect. The central processing unit (CPU) is the brain of a computer and it is a most expensive piece of hardware in a personal computer. It is used to execute all instructions. b. Correct. Operating system is a system program that handles the overall activity of the computer and provides services. c. Incorrect. Arithmetic logic unit (ALU) performs arithmetic and logical operations.

d. Incorrect. Control unit (CU) directs the operations of a processor. POINTS: 1 REFERENCES: 5 – Software QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.02 Explore the hardware and software components of a computer system DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 5/11/2020 4:34 PM 20. ____ represent information with a sequence of 0s and 1s. a. Analog signals b. Application programs c. Digital signals d. System programs ANSWER: c Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 1 FEEDBACK:

a. Incorrect. Analog signals are continuously varying wave signals; it is represented with the sine waves. b. Incorrect. Application programs perform a specific task. Games and word processors are examples of application programs. c. Correct. Digital signal is a type of electrical signal. The digital signals represent information with a sequence of 0s and 1s. A low voltage will be represented by a 0 and a high voltage will be represented by a 1. d. Incorrect. System programs control the computer. Operating system (OS) is an example of system program.

POINTS: 1 REFERENCES: 6 – The Language of a Computer QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.03 - Learn about the language of a computer DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 5/11/2020 4:35 PM 21. A sequence of eight bits is called a ____. a. binary digit b. byte c. character d. double ANSWER: b FEEDBACK: a. Incorrect. The digit 0 or 1 is called a binary digit, or bit. b. Correct. Byte is a unit used to represent digital information. A sequence of eight binary digits (bits) is called a byte.

c. Incorrect. The term character represents any number, letter, special symbol, or space. For example, "A" is a character. d. Incorrect. double is a data type. POINTS: 1 REFERENCES: 6 – The Language of a Computer QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.03 - Learn about the language of a computer DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 5/11/2020 4:36 PM 22. The digit 0 or 1 is called a binary digit, or ____. a. bit b. bytecode c. Unicode d. hexcode ANSWER: a FEEDBACK: a. Correct. The digit 0 or 1 is called a binary digit, or bit. A sequence of eight binary digits is called a byte. b. Incorrect. Bytecode is object code which is processed by a program.

c. Incorrect. Unicode is an international encoding standard. It consists of 65,536 characters. Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 1 d. Incorrect. Hexcode uses hexadecimal values to represent colors. POINTS: 1 REFERENCES: 6 – The Language of a Computer QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.03 - Learn about the language of a computer DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 4:14 AM 23. The term GB refers to ____. a. giant byte b. gigabyte c. group byte d. great byte ANSWER: b FEEDBACK: a. Incorrect. Giant byte is not a defined term in binary units. b. Correct. The binary unit gigabyte is also referred to as GB. 1 gigabyte (GB) contains 1024 megabytes (MB). c. Incorrect. Group byte is not a defined term in binary units (groups of bytes can be referred to a specific unit; 1 kilobyte is group of 1024 bytes). d. Incorrect. There is no binary unit called great byte.

POINTS: 1 REFERENCES: 6 – The Language of a Computer QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.03 - Learn about the language of a computer DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 4:13 AM 24. ____ consists of 65,536 characters. a. ASCII-8 b. ASCII c. Unicode d. EBCDIC ANSWER: c FEEDBACK: a. Incorrect. The eight-bit extended American Standard Code for Information Interchange (ASCII) data set consists of 256 characters. b. Incorrect. American Standard Code for Information Interchange (ASCII) data set consists of 128 characters. c. Correct. Unicode is an international encoding standard. It consists of 65,536 characters. Two bytes are required to store a Unicode character. d. Incorrect. The Extended Binary Code Decimal Interchange Code (EBCDIC) is an eight-bit character encoding.

POINTS: 1 REFERENCES: 7 – The Language of a Computer QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.03 - Learn about the language of a computer Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 1 DATE CREATED: DATE MODIFIED:

10/5/2016 1:36 PM 2/26/2020 4:13 AM

25. A program called a(n) ____ translates instructions written in high-level languages into machine code. a. assembler b. decoder c. compiler d. linker ANSWER: c FEEDBACK: a. Incorrect. Assembler is a program which translates an assembly language program into equivalent machine language program. b. Incorrect. Decoder is an electronic device used to translate signals from one form to another. c. Correct. A compiler is a program which translates instructions written in high-level languages into machine code. d. Incorrect. Linker is a program used to combine the object program with other programs in the library.

POINTS: 1 REFERENCES: 9 – The Evolution of Programming Languages QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.04 - Learn about the evolution of programming languages DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 4:09 AM 26. A program called a(n) ____ combines the object program with the programs from libraries. a. assembler b. decoder c. linker d. compiler ANSWER: c FEEDBACK: a. Incorrect. Assembler is a program which translates an assembly language program into equivalent machine language program. b. Incorrect. Decoder is an electronic device used to translate signals from one form to another. c. Correct. Linker is a program which combines the object program with the programs from libraries. d. Incorrect. A compiler is a program which translates instructions written in highlevel languages into machine code.

POINTS: 1 REFERENCES: 10 – Processing a C++ Program QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.08 - Explore how a C++ program is processed DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 4:12 AM 27. A program that loads an executable program into main memory is called a(n) ____. a. compiler b. loader Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 1 c. linker ANSWER: FEEDBACK:

d. assembler b a. Incorrect. A compiler is a program which translates instructions written in highlevel languages into machine code. b. Correct. A loader is a program that loads an executable program into main memory. c. Incorrect. Linker is a program which combines the object program with the programs from libraries. d. Incorrect. Assembler is a program which translates an assembly language program into equivalent machine language program.

POINTS: 1 REFERENCES: 10 – Processing a C++ Program QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.08 - Explore how a C++ program is processed DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 4:12 AM 28. A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time is called a(n) ____. a. algorithm b. linker c. analysis d. design ANSWER: a FEEDBACK: a. Correct. An algorithm is a step-by-step problem-solving process; it helps to find a solution in a finite amount of time. b. Incorrect. Linker is a program which combines the object program with the programs from libraries. c. Incorrect. Analysis is the first step in solving a problem.

d. Incorrect. The term design refers to a plan for the building of a system. POINTS: 1 REFERENCES: 11 – Programming with the Problem Analysis–Coding–Execution Cycle QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.09 - Learn what an algorithm is and explore problem-solving techniques DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 6/1/2020 12:37 PM 29. Dividing a problem into smaller subproblems is called ____ design. a. OOD b. top-down refinement c. structured d. analog ANSWER: c FEEDBACK: a. Incorrect. Object Oriented Design (OOD) is an extensively used programming methodology. b. Incorrect. The top-down refinement is not a defined term in structured programming. Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 1 c. Correct. The structured design is the process of dividing a problem into smaller subproblems. d. Incorrect. Analog is a type of electrical signal. The analog signals are continuously varying wave signals; it is represented with the sine waves.

POINTS: 1 REFERENCES: 20 – Structured Programming QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.10 - Become aware of structured-design and object-oriented design programming methodologies DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 4:23 AM 30. A(n) ____ consists of data and the operations on those data. a. disk b. compiler c. interpreter d. object ANSWER: d FEEDBACK: a. Incorrect. A disk is a secondary storage used to store information permanently. b. Incorrect. A compiler is a program which translates instructions written in highlevel languages into machine code. c. Incorrect. An interpreter is a program used to execute high-level language instructions. d. Correct. An object consists of data and the operations on those data. An object is the combination of data and operations on the data.

POINTS: 1 REFERENCES: 21 – Object-Oriented Programming QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.10 - Become aware of structured-design and object-oriented design programming methodologies DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 4:24 AM 31. The programming language C++ evolved from ____. a. BASIC b. assembly c. C d. C+ ANSWER: c FEEDBACK: a. Incorrect. BASIC is a high-level programming language. b. Incorrect. Assembly is a low-level programming language designed to make the programmer's job easier. c. Correct. The C++ programming language is evolved from the programming language C. d. Incorrect. There is no programming language called "C+".

POINTS:

1

Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 1 REFERENCES: 22 – ANSI/ISO Standard C++ QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.01.11 - Become aware of ANSI/ISO Standard C++, C++11, C++14 DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 4:25 AM 32. The ____________________ handles the overall activity of the computer and provides services such as memory management, input/output activities, and storage management. ANSWER: operating system POINTS: 1 REFERENCES: 5 – Software QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.01.02 Explore the hardware and software components of a computer system DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/27/2020 12:43 AM 33. ____________________ signals represent information with a sequence of 0s and 1s. ANSWER: Digital POINTS: 1 REFERENCES: 6 – The Language of a Computer QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.01.03 - Learn about the language of a computer DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/27/2020 12:17 AM 34. The ASCII data set consists of ____________________ characters. ANSWER: 128 POINTS: 1 REFERENCES: 7 – The Language of a Computer QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.01.03 - Learn about the language of a computer DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 4:27 AM 35. Assembly language uses easy-to-remember instructions called ____________________. Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 1 ANSWER: mnemonics POINTS: 1 REFERENCES: 8 – The Evolution of Programming Languages QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.01.04 - Learn about the evolution of programming languages DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 4:28 AM 36. ____________________ languages include FORTRAN, COBOL, Pascal, C, C++, Java, and Python. ANSWER: High-level POINTS: 1 REFERENCES: 8 – The Evolution of Programming Languages QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.01.04 - Learn about the evolution of programming languages DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 4:29 AM 37. In a C++ program, statements that begin with the symbol # are called ____________________ directives. ANSWER: preprocessor POINTS: 1 REFERENCES: 9 – Processing a C++ Program QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.01.08 - Explore how a C++ program is processed DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 2:55 AM 38. In object-oriented design, the first step in the problem-solving process is to identify the components called ____________________, which form the basis of the solution, and to determine how they interact with one another. ANSWER: objects POINTS: 1 REFERENCES: 20 – Object-Oriented Programming QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.01.10 - Become aware of structured-design and object-oriented design programming methodologies DATE CREATED: 10/5/2016 1:36 PM Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 1 DATE MODIFIED:

2/26/2020 4:30 AM

39. In ____________________ design, the final program is a collection of interacting objects. ANSWER: object-oriented object oriented OO oo POINTS: 1 REFERENCES: 21 – Object-Oriented Programming QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.01.10 - Become aware of structured-design and object-oriented design programming methodologies DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 4:31 AM 40. In C++, the mechanism that allows you to combine data and operations on the data into a single unit is called a(n) ____________________. ANSWER: class POINTS: 1 REFERENCES: 21 – Object-Oriented Programming QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.01.10 - Become aware of structured-design and object-oriented design programming methodologies DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 4:32 AM

Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 2 1. In C++, reserved words are the same as predefined identifiers. a. True b. False ANSWER: False FEEDBACK: Correct Reserved words are typically referred as keywords. They cannot be redefined within in any programs. Incorrect Reserved words are typically referred as keywords. They cannot be redefined within in any programs.

POINTS: 1 REFERENCES: 36 – Reserved Words (Keywords) QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.01 - Become familiar with the basic components of a C++ program, including functions, special symbols, and identifiers DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 8:25 PM 2. The maximum number of significant digits in values of the double type is 15. a. True b. False ANSWER: True FEEDBACK: Correct The maximum number of digits in data type double is 15. Incorrect The maximum number of digits in data type double is 15.

POINTS: 1 REFERENCES: 41 – Floating-Point Data Types QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.02 - Explore simple data types DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 2:58 AM 3. The maximum number of significant digits in float values is up to 6 or 7. a. True b. False ANSWER: True FEEDBACK: Correct The maximum number of digits in the data type float is 6 or 7. Incorrect The maximum number of digits in the data type float is 6 or 7.

POINTS: 1 REFERENCES: 41 – Floating-Point Data Types QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.02 - Explore simple data types Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 2 DATE CREATED: DATE MODIFIED:

10/5/2016 1:36 PM 3/12/2020 3:00 AM

4. An operator that has only one operand is called a unique operator. a. True b. False ANSWER: False FEEDBACK: Correct An operator that consists of only one operator is known as unary operators. Incorrect An operator that consists of only one operator is known as unary operators.

POINTS: 1 REFERENCES: 45 – Arithmetic Operators, Operator Precedence, and Expressions QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.03 - Discover how to use arithmetic operators DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 8:43 PM 5. If a C++ arithmetic expression has no parentheses, operators are evaluated from left to right. a. True b. False ANSWER: True FEEDBACK: Correct In the absence of parentheses in a C++ arithmetic expression, using the precedence rules, operators are usually evaluated from left to right. Incorrect In the absence of parentheses in a C++ arithmetic expression, using the precedence rules, operators are usually evaluated from left to right.

POINTS: 1 REFERENCES: 46 – Order of Precedence QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.04 - Examine how a program evaluates arithmetic expressions DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 8:45 PM 6. A mixed arithmetic expression contains all operands of the same type. a. True b. False ANSWER: False FEEDBACK: Correct An arithmetic expression consisting of operands of different data types are usually called a mixed arithmetic expression. Incorrect An arithmetic expression consisting of operands of different data types are usually called a mixed arithmetic expression.

POINTS: REFERENCES:

1 48 – Mixed Expressions

Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 2 QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.04 - Examine how a program evaluates arithmetic expressions DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 8:47 PM 7. Suppose a = 5. After the execution of the statement ++a; the value of a is 6. a. True b. False ANSWER: True FEEDBACK: Correct The pre-increment operator increments the value of a by 1. Incorrect The pre-increment operator increments the value of a by 1.

POINTS: 1 REFERENCES: 70 – Increment and Decrement Operators QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.09 - Become familiar with the use of increment and decrement operators DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 4:05 AM 8. The escape sequence \r moves the insertion point to the beginning of the next line. a. True b. False ANSWER: False FEEDBACK: Correct The escape sequence \r moves the cursor to the start of the current line. Incorrect The escape sequence \r moves the cursor to the start of the current line.

POINTS: 1 REFERENCES: 77 – Output QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.10 - Examine ways to output results using output statements DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 4:06 AM 9. A comma is also called a statement terminator. a. True b. False ANSWER: False FEEDBACK: Correct In C++, a semicolon is known as a statement terminator. Incorrect In C++, a semicolon is known as a statement terminator.

POINTS: REFERENCES:

1 88 – Use of Semicolons, Brackets, and Commas

Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 2 QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.13 - Explore how to properly structure a program, including using comments to document a program DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 9:03 PM 10. Suppose we declare a variable sum as an int. The statement "sum += 7;" is equivalent to the statement "sum = sum + 7;". a. True b. False ANSWER: True FEEDBACK: Correct Using the compound operator +=, one can rewrite the assignment statement a = a + b as a += b. Incorrect Using the compound operator +=, one can rewrite the assignment statement a = a + b; as a+=b. POINTS: 1 REFERENCES: 93 – More on Assignment Statements QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.14 - Become familiar with compound statements DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 4:08 AM 11. The ____ rules of a programming language tell you which statements are legal, or accepted, by the programming language. a. semantic b. logical c. syntax d. grammatical ANSWER: c FEEDBACK: a. Incorrect. Semantic rules decide the meaning of instructions in a programming language. b. Incorrect. Logical rules do not decide whether the given statement is legal or accepted by the programming language. c. Correct. Syntax rules decide whether the given statement is legal or accepted by the programming language. d. Incorrect. Grammatical rules do not decide whether the given statement is legal or accepted by the programming language.

POINTS: 1 REFERENCES: 34 – The Basics of a C++ Program QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.01 - Become familiar with the basic components of a C++ program, including functions, special symbols, and identifiers DATE CREATED: 10/5/2016 1:36 PM Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 2 DATE MODIFIED:

2/26/2020 9:09 PM

12. Which of the following is a reserved word in C++? a. char b. Char c. CHAR d. character ANSWER: FEEDBACK:

a a. Correct. In C++, char is a reserved word. b. Incorrect. In C++, Char is not a reserved word. c. Incorrect. In C++, CHAR is not a reserved word. d. Incorrect. In C++, character is not a reserved word.

POINTS: 1 REFERENCES: 35 – Reserved Words (Keywords) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.01 - Become familiar with the basic components of a C++ program, including functions, special symbols, and identifiers DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 4:09 AM 13. Which of the following is a legal identifier? a. program! b. program_1 c. 1program d. program 1 ANSWER: FEEDBACK:

b a. Incorrect. A legal C++ identifier contains digits, letters, and the underscore character and must start with a letter or underscore character; however, the program! has the symbol !so it is not a legal identifier. b. Correct. A legal C++ identifier contains digits, letters, and the underscore character and must start with a letter or underscore character.

c. Incorrect. A legal C++ identifier contains digits, letters, and the underscore character and must start with a letter or underscore character; however, the 1program starts with a number so it is not a legal identifier. d. Incorrect. A legal C++ identifier contains digits, letters, and the underscore character and must start with a letter or underscore character; however, the program 1 has a space in between so it is not a legal identifier. POINTS: 1 REFERENCES: 36 – Identifiers QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.01 - Become familiar with the basic components of a C++ program, including functions, special symbols, and identifiers DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 4:11 AM 14. ____ is a valid int value. Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 2 a. 46,259 c. 462.59 ANSWER: FEEDBACK:

b. 46259 d. -32.00 b a. Incorrect. Commas are not used in an integer value. Thus, 46,259 an invalid int value. b. Correct. 46259 is a valid integer. c. Incorrect. 462.59 is a float or a double value. d. Incorrect. -32.59 is a float or a double value.

POINTS: 1 REFERENCES: 39 – Simple Data Types QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.02 - Explore simple data types DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 4:14 AM 15. ____ is a valid char value. a. "-129" b. ‘A’ c. "A" d. 129 ANSWER: FEEDBACK:

b a. Incorrect. A value belonging to char data type is a single character, enclosed within single quotation marks; Thus, "-129" is not a valid character value. b. Correct. A value belonging to char data type is a single character, enclosed within single quotation marks. Thus, ‘A’ is a valid character value. c. Incorrect. A value belonging to char data type is a single character, enclosed within single quotation marks; Thus, "A" is not a valid character value. d. Incorrect. A value belonging to char data type is a single character, enclosed within single quotation marks. Thus, 129 is not a valid character value.

POINTS: 1 REFERENCES: 40 – Simple Data Types QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.02 - Explore simple data types DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 4:16 AM 16. An example of a floating point data type is ____. a. int b. char c. double d. short ANSWER: c FEEDBACK: a. Incorrect. The data type int is not an example of a floating point data type. b. Incorrect. The data type char is not an example of a floating point data type. Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 2 c. Correct. The data type double is an example of a floating point data type. d. Incorrect. The data type short is not an example of a floating point data type. POINTS: 1 REFERENCES: 41 – Floating-Point Data Types QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.02 - Explore simple data types DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 4:18 AM 17. The memory allocated for a float value is ____ bytes. a. two b. four c. eight d. sixteen ANSWER: b FEEDBACK: a. Incorrect. The memory allocated for a float data type value is 4 bytes. Thus, two bytes is not a suitable option. b. Correct. The memory allocated for a float data type value is 4 bytes. c. Incorrect. The memory allocated for a float data type value is 4 bytes. Thus, eight bytes is not a suitable option. d. Incorrect. The memory allocated for a float data type value is 4 bytes. Thus, sixteen bytes is not a suitable option. POINTS: 1 REFERENCES: 41 – Floating-Point Data Types QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.02 - Explore simple data types DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 9:39 PM 18. The value of the expression 17 % 7 is ____. a. 1 b. 2 c. 3 d. 4 ANSWER: FEEDBACK:

c

POINTS:

1

a. Incorrect. The operator % determines the remainder of the division. Thus, 17 % 7 = 3. b. Incorrect. The operator % determines the remainder of the division. Thus, 17 % 7 = 3. c. Correct. The operator % determines the remainder of the division. Thus, 17 % 7 = 3. d. Incorrect. The operator % determines the remainder of the division. Thus, 17 % 7 = 3.

Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 2 REFERENCES: 43 – Arithmetic Operators, Operator Precedence, and Expressions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.03 - Discover how to use arithmetic operators DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 4:21 AM 19. The value of the expression 33/10, assuming both values are integral data types, is ____. a. 0.3 b. 3 c. 3.0 d. 3.3 ANSWER: FEEDBACK:

b a. Incorrect. When the operator / is used with int data type, it performs ordinary division and performs quotient as result and integer division truncates the fractional part. Thus, 33/10 = 3. b. Correct. When the operator / is used with int data type, it performs ordinary division and performs quotient as result and integer division truncates the fractional part. Thus, 33/10 = 3. c. Incorrect. When the operator / is used with int data type, it performs ordinary division and performs quotient as result and integer division truncates the fractional part. Thus, 33/10 = 3. d. Incorrect. When the operator / is used with int data type, it performs ordinary division and performs quotient as result and integer division truncates the fractional part. Thus, 33/10 = 3.

POINTS: 1 REFERENCES: 43-44 – Arithmetic Operators, Operator Precedence, and Expressions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.03 - Discover how to use arithmetic operators DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 4:24 AM 20. The expression static_cast<int>(9.9) evaluates to ____. a. 9 b. 10 c. 9.9 d. 9.0 ANSWER: FEEDBACK:

a a. Correct. In the evaluation of static_cast<dataTypeName>(expression), first the expression is evaluated and its value is converted to the data type specified by dataTypeName. Thus, the evaluation result is 9. b. Incorrect. In the evaluation of static_cast<dataTypeName>(expression), first the expression is evaluated and its value is converted to the data type specified by dataTypeName. Thus, the evaluation result is 9. c. Incorrect. In the evaluation of

Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 2 static_cast<dataTypeName>(expression), first the expression is evaluated and its value is converted to the data type specified by dataTypeName. Thus, the evaluation result is 9. d. Incorrect. In the evaluation of static_cast<dataTypeName>(expression), first the expression is evaluated and its value is converted to the data type specified by dataTypeName. Thus, the evaluation result is 9. POINTS: 1 REFERENCES: 51 – Type Conversion (Casting) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.04 - Examine how a program evaluates arithmetic expressions DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 4:41 AM 21. The expression static_cast<int>(6.9) + static_cast<int>(7.9) evaluates to ____. a. 13 b. 14 c. 14.8 d. 15 ANSWER: FEEDBACK:

a a. Correct. In the evaluation of static_cast<dataTypeName>(expression), first the expression is evaluated and its value is converted to the data type specified by dataTypeName. Thus, the evaluation result is 6+7 = 13. b. Incorrect. In the evaluation of static_cast<dataTypeName>(expression), first the expression is evaluated and its value is converted to the data type specified by dataTypeName. Thus, the evaluation result is 6+7 = 13. c. Incorrect. In the evaluation of static_cast<dataTypeName>(expression), first the expression is evaluated and its value is converted to the data type specified by dataTypeName. Thus, the evaluation result is 6+7 = 13. d. Incorrect. In the evaluation of static_cast<dataTypeName>(expression), first the expression is evaluated and its value is converted to the data type specified by dataTypeName. Thus, the evaluation result is 6+7 = 13.

POINTS: 1 REFERENCES: 51 – Type Conversion (Casting) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.04 - Examine how a program evaluates arithmetic expressions DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 4:43 AM 22. The length of the string "computer science" is ____. Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 2 a. 14 b. 15 c. 16 d. 18 ANSWER: FEEDBACK:

c a. Incorrect. The length of the string is the number of character in the string including any spaces in it. Thus the length of the string "computer science" is 16. b. Incorrect. The length of the string is the number of character in the string including any spaces in it. Thus the length of the string "computer science" is 16. c. Correct. The length of the string is the number of character in the string including any spaces in it. Thus the length of the string "computer science" is 16. d. Incorrect. The length of the string is the number of character in the string including any spaces in it. Thus the length of the string "computer science" is 16.

POINTS: 1 REFERENCES: 53 – string Type QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.05 - Become familiar with the string data type DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 10:00 PM 23. In a C++ program, one and two are double variables and input values are 10.5 and 30.6. After the statement cin >> one >> two; executes, ____. a. one = 10.5, two = 10.5 b. one = 10.5, two = 30.6 c. one = 30.6, two = 30.6 d. one = 11, two = 31 ANSWER: FEEDBACK:

b a. Incorrect. The statement reads the value 10.5 and stores it in one and reads the value 30.6 and stores it in two. b. Correct. The statement reads the value 10.5 and stores it in one and reads the value 30.6 and stores it in two. c. Incorrect. The statement reads the value 10.5 and stores it in one and reads the value 30.6 and stores it in two. d. Incorrect. The statement reads the value 10.5 and stores it in one and reads the value 30.6 and stores it in two.

POINTS: 1 REFERENCES: 65 – Input (Read) Statement QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.08 - Discover how to input data into memory using input statements DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 10:03 PM Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 2 24. Suppose that count is an int variable and count = 1. After the statement count++; executes, the value of count is ____. a. 1 b. 2 c. 3 d. 4 ANSWER: b FEEDBACK: a. Incorrect. The post-increment operator increments the value of count by 1. Thus, the value of count after the execution of count++; is 2. b. Correct. The post-increment operator increments the value of count by 1. Thus, the value of count after the execution of count++; is 2. c. Incorrect. The post-increment operator increments the value of count by 1. Thus, the value of count after the execution of count++; is 2. d. Incorrect. The post-increment operator increments the value of count by 1. Thus, the value of count after the execution of count++; is 2. POINTS: 1 REFERENCES: 69-70 – Increment and Decrement Operators QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.09 - Become familiar with the use of increment and decrement operators DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/13/2020 12:25 AM 25. Suppose that alpha and beta are int variables. The statement alpha = --beta; is equivalent to the statement(s) ____. a. alpha = 1 - beta; b. alpha = beta - 1; c. beta = beta - 1; alpha = beta; d. alpha = beta; beta = beta - 1; ANSWER: c FEEDBACK: a. Incorrect. In the statement alpha = --beta, first beta is decremented by a value 1 and then assigned to alpha; so alpha = 1 – beta; is not a valid choice. b. Incorrect. In the statement alpha = --beta, first beta is decremented by a value 1 and then assigned to alpha; so alpha = beta - 1; is not a valid choice. c. Correct. In the statement alpha = --beta, first beta is decremented by a value 1 and then assigned to alpha. d. Incorrect. In the statement alpha = --beta, first beta is decremented by a value 1 and then assigned to alpha; so alpha = beta; beta = beta 1; is not a valid choice. POINTS: REFERENCES:

1 70-71 – Increment and Decrement Operators

Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 2 QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.09 - Become familiar with the use of increment and decrement operators DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 10:15 PM 26. Suppose that alpha and beta are int variables. The statement alpha = beta--; is equivalent to the statement(s) ____. a. alpha = 1 - beta; b. alpha = beta - 1; c. beta = beta - 1; alpha = beta; d. alpha = beta; beta = beta - 1; ANSWER: d FEEDBACK: a. Incorrect. In the statement alpha = beta--;, first the value of beta is assigned to alpha and then beta is decremented by 1; so alpha = 1 beta; is not a valid choice. b. Incorrect. In the statement alpha = beta--;, first the value of beta is assigned to alpha and then beta is decremented by 1; so alpha = beta 1; is not a valid choice. c. Incorrect. In the statement alpha = beta--;, first the value of beta is assigned to alpha and then beta is decremented by 1; so beta = beta 1; alpha = beta; is not a valid choice. d. Correct. In the statement alpha = beta--;, first the value of beta is assigned to alpha and then beta is decremented by 1; so alpha = beta; beta = beta - 1; is a valid choice. POINTS: 1 REFERENCES: 70-71 – Increment and Decrement Operators QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.09 - Become familiar with the use of increment and decrement operators DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 10:23 PM 27. Suppose that alpha and beta are int variables. The statement alpha = beta++; is equivalent to the statement(s) ____. a. alpha = 1 + beta; b. alpha = alpha + beta; c. alpha = beta; beta = beta + 1; d. beta = beta + 1; alpha = beta; ANSWER:

c

Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 2 FEEDBACK:

a. Incorrect. In the statement alpha = beta++;, first the value of beta is assigned to alpha and then beta is incremented by 1; so alpha = 1 + beta; is not a valid choice. b. Incorrect. In the statement alpha = beta++;, first the value of beta is assigned to alpha and then beta is incremented by 1; so "alpha = alpha + beta; is not a valid choice. c. Correct. In the statement alpha = beta++;, first the value of beta is assigned to alpha and then beta is incremented by 1; so alpha = beta; beta = beta + 1; is a valid choice. d. Incorrect. In the statement alpha = beta++;, first the value of beta is assigned to alpha and then beta is incremented by 1; so beta = beta 1; alpha = beta; is not a valid choice.

POINTS: 1 REFERENCES: 70-71 – Increment and Decrement Operators QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.09 - Become familiar with the use of increment and decrement operators DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 10:27 PM 28. Suppose that alpha and beta are int variables. The statement alpha = ++beta; is equivalent to the statement(s) ____. a. beta = beta + 1; alpha = beta; b. alpha = beta; beta = beta + 1; c. alpha = alpha + beta; d. alpha = beta + 1; ANSWER: FEEDBACK:

a

POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 70-71 – Increment and Decrement Operators Multiple Choice False

a. Correct. In the statement alpha = ++beta;, first beta is incremented by 1 and then the value of beta is assigned to alpha. b. Incorrect. In the statement alpha = ++beta;, first beta is incremented by 1 and then the value of beta is assigned to alpha; so alpha = beta; beta = beta + 1; is not a valid choice. c. Incorrect. In the statement alpha = ++beta;, first beta is incremented by 1 and then the value of beta is assigned to alpha; so alpha = alpha + beta; is not a valid choice. d. Incorrect. In the statement alpha = ++beta;, first beta is incremented by 1 and then the value of beta is assigned to alpha; so alpha = beta + 1; is not a valid choice.

Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 2 LEARNING OBJECTIVES: PDDS.MALI.02.09 - Become familiar with the use of increment and decrement operators DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/13/2020 12:28 AM 29. Choose the output of the following C++ statement: cout << "Sunny " << '\n' << "Day " << endl; a. Sunny \nDay b. Sunny \nDay endl c. Sunny Day d. Sunny \n Day ANSWER: FEEDBACK:

c a. Incorrect. When a newline escape sequence \n is used in output statement, the insertion point or cursor point moves to the beginning of the next line. Thus, Sunny is printed in the first line and \n moves the cursor to the next line and printing Day; thus, Sunny \nDay is not a suitable choice. b. Incorrect. When a newline escape sequence \n is used in output statement, the insertion point or cursor point moves to the beginning of the next line. Thus, Sunny is printed in the first line and \n moves the cursor to the next line and printing Day; thus, Sunny \nDay endl is not a suitable choice. c. Correct. When a newline escape sequence \n is used in output statement, the insertion point or cursor point moves to the beginning of the next line. Thus, Sunny is printed in the first line and \n moves the cursor to the next line and printing Day. d. Incorrect. When a newline escape sequence \n is used in output statement, the insertion point or cursor point moves to the beginning of the next line. Thus, Sunny is printed in the first line and \n moves the cursor to the next line and printing Day; thus, Sunny \n Day is not a suitable choice.

POINTS: 1 REFERENCES: 72 – Output QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.10 - Examine ways to output results using output statements DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 5/11/2020 4:44 PM 30. Which of the following is the newline character? a. \r b. \n c. \l d. \b ANSWER: b FEEDBACK: a. Incorrect. The escape sequence \r is return. b. Correct. The escape sequence \n is newline character. c. Incorrect. There is no escape sequence called \l. Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 2 d. Incorrect. The escape sequence \b is backspace. POINTS: 1 REFERENCES: 72 – Output QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.10 - Examine ways to output results using output statements DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 11:25 PM 31. Consider the following code. // Insertion Point 1 using namespace std; const float PI = 3.14; int main() { //Insertion Point 2 float r = 2.0; float area; area = PI * r * r; cout << "Area = " << area <<endl; return 0; } // Insertion Point 3 In this code, where does the include statement belong? a. Insertion Point 1 b. Insertion Point 2 c. Insertion Point 3 d. Anywhere in the program ANSWER: a FEEDBACK: a. Correct. Typically, include statements are included in the top of the C++ program. b. Incorrect. Typically, include statements are included in the top of the C++ program; thus, //Insertion Point 2 is not valid. c. Incorrect. Typically, include statements are included in the top of the C++ program; thus, //Insertion Point 3 is not valid. d. Incorrect. Typically, include statements are included in the top of the C++ program and not anywhere in the program. POINTS: 1 REFERENCES: 82 – Creating a C++ Program QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.11 - Learn how to use preprocessor directives and why they are necessary DATE CREATED: 10/5/2016 1:36 PM Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 2 DATE MODIFIED:

3/12/2020 11:29 PM

32. ____ are executable statements that inform the user what to do. a. Variables b. Prompt lines c. Named constants d. Expressions ANSWER: b FEEDBACK: a. Incorrect. Variables are memory locations for storing data. b. Correct. Prompt lines are executable lines that tell the programmer what to do c. Incorrect. Named constants are used to tell the user to mark the memory locations in which data cannot be changed during the program execution. d. Incorrect. Expressions are not executable statements that tell the programmer what to do.

POINTS: 1 REFERENCES: 89 – Program Style and Form QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.13 - Explore how to properly structure a program, including using comments to document a program DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 5/11/2020 4:45 PM 33. The declaration int a, b, c; is equivalent to which of the following? a. inta , b, c; b. int a,b,c; c. int abc; d. int a b c; ANSWER: b FEEDBACK: a. Incorrect. The declaration inta , b, c; contains a syntax error since there is no gap between identifier int and variable a. b. Correct. The declaration int a,b,c; is equivalent to int a , b, c;. c. Incorrect. The declaration int abc; is not equivalent to int a , b, c; since int abc; declares the variable abc. d. Incorrect. The declaration int a b c; contains a syntax error since there are no commas separating the variables a, b, and c. POINTS: 1 REFERENCES: 90 – Form and Style QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.13 - Explore how to properly structure a program, including using comments to document a program DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/12/2020 11:36 PM 34. Suppose that alpha and beta are int variables and alpha = 5 and beta = 10. After the statement alpha *= beta; executes, ____. Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 2 a. alpha = 5 c. alpha = 50 ANSWER: FEEDBACK:

b. alpha = 10 d. alpha = 50.0 c a. Incorrect. The statement alpha *= beta results in multiplying the values of alpha and beta; that is, alpha * beta = 5 * 10 = 50, and then storing the result in alpha. Thus, alpha = 5 is not a valid choice. b. Incorrect. The statement alpha *= beta results in multiplying the values of alpha and beta; that is, alpha * beta = 5 * 10 = 50, and then storing the result in alpha. Thus, alpha = 10 is not a valid choice. c. Correct. The statement alpha *= beta results in multiplying the values of alpha and beta; that is, alpha * beta = 5 * 10 = 50, and then storing the result in alpha. d. Incorrect. The statement alpha *= beta results in multiplying the values of alpha and beta; that is, alpha * beta = 5 * 10 = 50, and then storing the result in alpha. Thus, alpha = 50.0 is not a valid choice because alpha is an int variable.

POINTS: 1 REFERENCES: 92 – More on Assignment Statements QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.14 - Become familiar with compound statements DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/13/2020 12:32 AM 35. Suppose that sum and num are int variables and sum = 5 and num = 10. After the statement sum += num executes, ____. a. sum = 0 b. sum = 5 c. sum = 10 d. sum = 15 ANSWER: d FEEDBACK: a. Incorrect. The statement sum += num; results in adding the values of sum and num; that is, sum + num = 5 + 10 = 15, and then storing the result in sum. Thus, sum = 0 is not a valid choice. b. Incorrect. The statement sum += num; results in adding the values of sum and num; that is, sum + num = 5 + 10 = 15, and then storing the result in sum. Thus, sum = 5 is not a valid choice. c. Incorrect. The statement sum += num; results in adding the values of sum and num; that is, sum + num = 5 + 10 = 15, and then storing the result in sum. Thus, sum = 10 is not a valid choice. d. Correct. The statement sum += num; results in adding the values of sum and num; that is, sum + num = 5 + 10 = 15, and then storing the result in sum. POINTS: REFERENCES:

1 93 – More on Assignment Statements

Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 2 QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.02.14 - Become familiar with compound statements DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 3/13/2020 12:06 AM 36. ____________________ is the process of planning and creating a program. ANSWER: Programming programming POINTS: 1 REFERENCES: 28 – QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.02.01 - Become familiar with the basic components of a C++ program, including functions, special symbols, and identifiers DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 11:45 PM 37. A(n) ____________________ is a memory location whose contents can be changed. ANSWER: variable POINTS: 1 REFERENCES: 33 – A Quick Look at a C++ Program QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.02.01 - Become familiar with the basic components of a C++ program, including functions, special symbols, and identifiers DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 11:48 PM 38. A(n) ____________________ is a collection of statements, and when it is activated, or executed, it accomplishes something. ANSWER: subprogram sub program sub-program function module POINTS: 1 REFERENCES: 33 – The Basics of a C++ Program QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.02.01 - Become familiar with the basic components of a C++ program, Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 2 DATE CREATED: DATE MODIFIED:

including functions, special symbols, and identifiers 10/5/2016 1:36 PM 2/26/2020 11:50 PM

39. ____________________ functions are those that have already been written and are provided as part of the system. ANSWER: Predefined predefined Standard standard POINTS: 1 REFERENCES: 33-34 – The Basics of a C++ Program QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.02.01 - Become familiar with the basic components of a C++ program, including functions, special symbols, and identifiers DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 11:52 PM 40. ____________________ rules determine the meaning of instructions. ANSWER: Semantic semantic POINTS: 1 REFERENCES: 34 – The Basics of a C++ Program QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.02.01 - Become familiar with the basic components of a C++ program, including functions, special symbols, and identifiers DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/26/2020 11:54 PM 41. ____________________ can be used to identify the authors of the program, give the date when the program is written or modified, give a brief explanation of the program, and explain the meaning of key statements in a program. ANSWER: Comments comments POINTS: 1 REFERENCES: 34 – The Basics of a C++ Program QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.02.01 - Become familiar with the basic components of a C++ program, including functions, special symbols, and identifiers DATE CREATED: 10/5/2016 1:36 PM Copyright Cengage Learning. Powered by Cognero.

Page 19


Name:

Class:

Date:

Chapter 2 DATE MODIFIED:

2/26/2020 11:59 PM

42. The smallest individual unit of a program written in any language is called a(n) ____________________. ANSWER: token POINTS: 1 REFERENCES: 35 – The Basics of a C++ Program QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.02.01 - Become familiar with the basic components of a C++ program, including functions, special symbols, and identifiers DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/27/2020 12:02 AM 43. In a C++ program, ____________________ are used to separate special symbols, reserved words, and identifiers. ANSWER: whitespaces whitespace white spaces white space POINTS: 1 REFERENCES: 37 – The Basics of a C++ Program QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.02.01 - Become familiar with the basic components of a C++ program, including functions, special symbols, and identifiers DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/27/2020 12:05 AM 44. The ____________________ type is C++ ’s method for allowing programmers to create their own simple data types. ANSWER: enumeration POINTS: 1 REFERENCES: 38 – Simple Data Types QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.02.02 - Explore simple data types DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/27/2020 12:07 AM 45. The memory space for a(n) ____________________ data value is 4 bytes. ANSWER: int. POINTS: 1 REFERENCES: 39 – Simple Data Types Copyright Cengage Learning. Powered by Cognero.

Page 20


Name:

Class:

Date:

Chapter 2 QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.02.02 - Explore simple data types DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/27/2020 3:26 AM 46. The maximum number of significant digits is called the ____________________. ANSWER: precision POINTS: 1 REFERENCES: 42 – Floating-Point Data Types QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.02.02 - Explore simple data types DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/27/2020 12:10 AM 47. When a value of one data type is automatically changed to another data type, a(n) ____________________ type coercion is said to have occurred. ANSWER: implicit POINTS: 1 REFERENCES: 50 – Type Conversion (Casting) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.02.04 - Examine how a program evaluates arithmetic expressions DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/27/2020 12:13 AM 48. A(n) ____________________ is a sequence of zero or more characters. ANSWER: string POINTS: 1 REFERENCES: 53 – string Type QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.02.05 - Become familiar with the string data type DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/27/2020 12:16 AM 49. In C++, you can use a(n) ____________________ to instruct a program to mark those memory locations in which data is fixed throughout program execution. Copyright Cengage Learning. Powered by Cognero.

Page 21


Name:

Class:

Date:

Chapter 2 ANSWER:

named constant constant POINTS: 1 REFERENCES: 54 – Variables, Assignment Statements, and Input Statements QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.02.07 - Learn about variable declaration DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/27/2020 12:18 AM 50. A data type is called ____________________ if the variable or named constant of that type can store only one value at a time. ANSWER: simple POINTS: 1 REFERENCES: 57 – Variables, Assignment Statements, and Input Statements QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.02.07 - Learn about variable declaration DATE CREATED: 10/5/2016 1:36 PM DATE MODIFIED: 2/27/2020 12:19 AM

Copyright Cengage Learning. Powered by Cognero.

Page 22


Name:

Class:

Date:

Chapter 3 1. It is a good idea to redefine cin and cout in your programs. a. True b. False ANSWER: False FEEDBACK: Correct Redefining cin and cout in the programs is not a good idea as its already defined and have specific meanings in C++. Incorrect Redefining cin and cout in the programs is not a good idea as its already defined and have specific meanings in C++. POINTS: 1 REFERENCES: 125 – I/O Streams and Standard I/O Devices QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.01 - Learn what a stream is and examine input and output streams DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/12/2020 11:04 PM 2. In the statement cin >> x;, x can be a variable or an expression. a. True b. False ANSWER: False FEEDBACK: Correct In the given C++ statement, the extraction operator >> is binary. Left-side to extraction operator is the input stream variable cin and right-side to extraction operator is variable x. The purpose of cin is to read and store values in variables, where variables refer to memory locations. Incorrect In the given C++ statement, the extraction operator >> is binary. Left-side to extraction operator is the input stream variable cin and right-side to extraction operator is variable x. The purpose of cin is to read and store values in variables, where variables refer to memory locations. POINTS: 1 REFERENCES: 125 – cin and the Extraction Operator >> QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.02 - Explore how to read data from the standard input device DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/12/2020 11:09 PM 3. The following statements will result in input failure if the input values are not on a separate line. (Assume that x and y are int variables.) cin >> x; cin >> y; a. True b. False ANSWER: False Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 3 FEEDBACK:

Correct

The input values can be in the same line separated by whitespaces or in separate lines. Incorrect The input values can be in the same line separated by whitespaces or in separate lines.

POINTS: 1 REFERENCES: 130 – cin and the Extraction Operator >> QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.05 - Become familiar with input failure DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 2:49 AM 4. The number of input data extracted by cin and >> depends on the number of variables appearing in the cin statement. a. True b. False ANSWER: True FEEDBACK: Correct The number of input data extracted by cin and >> is based on the number of variables in the statement. If more number of inputs are given, then it just skips the additional input and take only required number of inputs. Incorrect The number of input data extracted by cin and >> is based on the number of variables in the statement. If more number of inputs are given, then it just skips the additional input and take only required number of inputs. POINTS: 1 REFERENCES: 126 – cin and the Extraction Operator >> QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.02 - Explore how to read data from the standard input device DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/12/2020 11:17 PM 5. The extraction operator >> skips only all leading blanks when searching for the next data in the input stream. a. True b. False ANSWER: False FEEDBACK: Correct The extraction operator >> not only skips leading blanks but also skips all leading whitespaces. Whitespaces consist of blanks and certain non-printable characters such as tabs and new line characters. Incorrect The extraction operator >> not only skips leading blanks but also skips all leading whitespaces. Whitespaces consist of blanks and certain non-printable characters such as tabs and new line characters. POINTS: REFERENCES: QUESTION TYPE:

1 126 – cin and the Extraction Operator >> True / False

Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 3 HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.02 - Explore how to read data from the standard input device DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/12/2020 11:18 PM 6. When reading data into a char variable, after skipping any leading whitespace characters, the extraction operator >> finds and stores only the next character; reading stops after reading a single character. a. True b. False ANSWER: True FEEDBACK: Correct To input data into a char variable, after skipping any leading whitespaces, the extraction operator >> extracts the next character from the input stream and stores it in the char variable appearing in the input statement. Incorrect To input data into a char variable, after skipping any leading whitespaces, the extraction operator >> extracts the next character from the input stream and stores it in the char variable appearing in the input statement. POINTS: 1 REFERENCES: 127 – cin and the Extraction Operator >> QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.02 - Explore how to read data from the standard input device DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 2:53 AM 7. Entering a char value into an int variable causes serious errors, called input failure. a. True b. False ANSWER: True FEEDBACK: Correct While giving the inputs one should be more cautious because computers does not tolerate with the mismatch of variables. Incorrect While giving the inputs one should be more cautious because computers does not tolerate with the mismatch of variables.

POINTS: 1 REFERENCES: 130 – cin and the Extraction Operator >> QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.05 - Become familiar with input failure DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 2/27/2020 11:59 PM 8. If input failure occurs in a C++ program, the program terminates immediately and displays an error message. a. True b. False Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 3 ANSWER: FEEDBACK:

False Correct

If input failure occurs in a C++ program, the program does not terminate immediately displaying an error message, instead program quietly continues to execute with whatever values are stored in the variables and produces incorrect results. Incorrect If input failure occurs in a C++ program, the program does not terminate immediately displaying an error message, instead program quietly continues to execute with whatever values are stored in the variables and produces incorrect results.

POINTS: 1 REFERENCES: 140 – Input Failure QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.05 - Become familiar with input failure DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 2/28/2020 12:04 AM 9. In an output statement, each occurrence of endl advances the cursor to the end of the current line on an output device. a. True b. False ANSWER: False FEEDBACK: Correct The manipulator endl is used to move the insertion point to the beginning of the next line. Incorrect The manipulator endl is used to move the insertion point to the beginning of the next line. POINTS: 1 REFERENCES: 144 – Output and Formatting Output QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.07 - Discover how to use manipulators in a program to format output DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/12/2020 11:20 PM 10. You can use the function getline to read a string containing blanks. a. True b. False ANSWER: True FEEDBACK: Correct Function getLine reads all characters in the line including any blanks, if any, until it reaches end of the current line. Incorrect Function getLine reads all characters in the line including any blanks, if any, until it reaches end of the current line. POINTS: REFERENCES: QUESTION TYPE:

1 157 – Input/Output and the string Type True / False

Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 3 HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.08 - Learn how to perform input and output operations with the string data type DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/12/2020 11:21 PM 11. Suppose that x is an int variable and y is a double variable. The input is: 10 20.7 Choose the values after the following statement executes: cin >> x >> y;. a. x = 10, y = 20 b. x = 10, y = 20.0 x = 10, y = 20.7 c. d. x = 10, y = 21.0 ANSWER: FEEDBACK:

c a. Incorrect. Since x is an int variable and y is a double variable, after reading 10 into x, the extraction operator reads and stores 20.7 into y. Thus, after the statement cin >> x >> y; executes x = 10 and y = 20.7. b. Incorrect. Since x is an int variable and y is a double variable, after reading 10 into x, the extraction operator reads and stores 20.7 into y. Thus, after the statement cin >> x >> y; executes x = 10 and y = 20.7. c. Correct. Since x is an int variable and y is a double variable, after reading 10 into x, the extraction operator reads and stores 20.7 into y. Thus, after the statement cin >> x >> y; executes x = 10 and y = 20.7. d. Incorrect. Since x is an int variable and y is a double variable, after reading 10 into x, the extraction operator reads and stores 20.7 into y. Thus, after the statement cin >> x >> y; executes x = 10 and y = 20.7.

POINTS: 1 REFERENCES: 125-126 – cin and the Extraction Operator >> QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.02 - Explore how to read data from the standard input device DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/12/2020 11:29 PM 12. Suppose that x and y are int variables. Which of the following is a valid input statement? a. cin >> x >> cin >> y; b. cin >> x >> y; c. cin << x << y; d. cout << x << y; ANSWER: FEEDBACK:

b a. Incorrect. The statement cin >> x >> cin >> y; will throw syntax error since the cin keyword has been used twice in the statement. b. Correct. The statement cin >> x >> y; is used to read values for the variables x and y. c. Incorrect. Insertion operator << is used to output the data. d. Correct. The statement cout << x << y; is used to print the values stored in

Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 3 the variables x and y. POINTS: 1 REFERENCES: 125-126 – cin and the Extraction Operator >> QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.02 - Explore how to read data from the standard input device DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 12:17 AM 13. Suppose that x is an int variable, y is a double variable, and ch is a char variable. The input is: 15A 73.2 Choose the values after the following statement executes: cin >> x >> ch >> y; a. x = 15, ch = 'A', y = 73.2 b. x = 15, ch = 'A', y = 73.0 c. x = 15, ch = 'a', y = 73.0 d. This statement results in an error because there is no space between 15 and A. ANSWER: a FEEDBACK: a. Correct. The extraction operators first reads and stores 15 into x and reading stops after 5. Next the extraction operator reads 'A' and stores into ch and reading stops after 'A'. Then the extraction operator reads and stores 73.2 into y. In the given input, the first integer value 15 will be stored into the variable x, the next character value 'A' will be stored into the variable ch, and the last decimal value 73.2 will be stored into the variable y. b. Incorrect. Since the last variable y is declared as double, the last decimal value 73.2 will be stored into the variable y. c. Incorrect. Since 'A' is entered uppercase, 'A' will be stored into ch. Also since y is a double variable, 73.2 will be stored into y. The char data type will print the given character as it is, so it is not possible to get 'a' instead of 'A' and since the last variable y is declared as decimal, the last decimal value 73.2 will be stored into the variable y. d. Incorrect. The extraction operators first reads and stores 15 into x and reading stops after 5. Next the extraction operator reads 'A' and stores into ch and reading stops after 'A'. Then the extraction operator reads and stores 73.2 into y. Therefore, not having a space between 15 and 'A' will not result in an error since ch is a char variable. POINTS: 1 REFERENCES: 127-128 – cin and the Extraction Operator >> QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.02 - Explore how to read data from the standard input device Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 3 DATE CREATED: DATE MODIFIED:

10/5/2016 1:37 PM 3/13/2020 2:55 AM

14. Suppose that alpha is an int variable and ch is a char variable. The input is: 17 A What are the values after the following statements execute? cin >> alpha; cin >> ch; a. alpha = 17, ch = ' ' b. alpha = 1, ch = 7 c. alpha = 17, ch = 'A' d. alpha = 17, ch = 'a' ANSWER: c FEEDBACK: a. Incorrect. The space between 17 and A is a whitespace. The first cin statement will read 17 and stores it into the variable alpha and after skipping all leading whitespaces the second cin statement will read A and stores it into the variable Ch. b. Incorrect. The first cin statement will read 17 and store it into the variable alpha and the second cin statement will read A and store it into the variable ch, so it is not possible to get 1 in alpha and 7 in ch. c. Correct. The first cin statement will read 17 and store it into the variable alpha and the second cin statement will read A and store it into the variable ch. d. Incorrect. In the input, A is uppercase. The first cin statement will read 17 and store it into the variable alpha and the second cin statement will read A and store it into the variable ch. POINTS: 1 REFERENCES: 128 – cin and the Extraction Operator >> QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.02 - Explore how to read data from the standard input device DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 12:39 AM 15. Suppose that x is an int variable, y is a double variable, and z is an int variable. The input is: 15 76.3 14 Choose the values after the following statement executes: cin >> x >> y >> z; a. x = 15, y = 76, z = 14 b. x = 15, y = 76, z = 0 c. x = 15, y = 76.3, z = 14 d. x = 15.0, y = 76.3, z = 14.0 Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 3 ANSWER: FEEDBACK:

c a. Incorrect. The value of y will be 76.3 since y is declared as double. b. Incorrect. The value of y will be 76.3 since the y is declared as double and the value of z will be 14 since z is declared as int. c. Correct. The first value 15 will be stored into the variable x, the second value 76.3 will be stored into the variable y, and the last value 14 will be stored into the variable z. d. Incorrect. Since x and z are int variables, x is 15 and z is 14.

POINTS: 1 REFERENCES: 127-128 – cin and the Extraction Operator >> QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.02 - Explore how to read data from the standard input device DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 12:43 AM 16. Suppose that ch1, ch2, and ch3 are variables of the type char. The input is: A B C Choose the value of ch3 after the following statement executes: cin >> ch1 >> ch2 >> ch3; a. 'A' b. 'B' c. 'C' d. '\n' ANSWER: FEEDBACK:

POINTS: REFERENCES:

c a. Incorrect. The first value, A, in the first line will be stored into the variable ch1, the second value, B, in the first line will be stored into the variable ch2, and the third value, C, in the second line will be stored into the variable ch3, so it is not possible to get 'A' in ch3. b. Incorrect. The first value, A, in the first line will be stored into the variable ch1, the second value, B, in the first line will be stored into the variable ch2, and the third value, C, in the second line will be stored into the variable ch3, so it is not possible to get 'B' in ch3. c. Correct. The first value, A, in the first line will be stored into the variable ch1, the second value , B, in the first line will be stored into the variable ch2, and the third value, C, in the second line will be stored into the variable ch3. d. Incorrect. The first value, A, in the first line will be stored into the variable ch1, the second value, B, in the first line will be stored into the variable ch2 and the third value, C, in the second line will be stored into the variable ch3, so it is not possible to get '\n' in ch3. 1 127-128 – cin and the Extraction Operator >>

Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 3 QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.02 - Explore how to read data from the standard input device DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 5/11/2020 5:03 PM 17. Suppose that x and y are int variables, and z is a double variable. The input is: 28 32.6 12 Choose the values of x, y, and z after the following statement executes: cin >> x >> y >> z; a. x = 28, y = 32, z = 0.6 b. x = 28, y = 32, z = 12.0 c. x = 28, y = 12, z = 32.6 d. x = 28, y = 12, z = 0.6 ANSWER: FEEDBACK:

a

POINTS: REFERENCES: QUESTION TYPE:

1 127-129 – cin and the Extraction Operator >> Multiple Choice

a. Correct. The statement cin >> x >> y >> z; first reads and stores 28 into x, then reads and stores 32 into y, since y is an int variable. After reading and storing 32 into y, the reading stops after 32, just before the dot. Next the value .6, which is a decimal value, will be read and stored into z since z is a double variable. After reading .6 into z, the reading stops after 6. The last input value 12 will remain into the input stream for further input, if any. b. Incorrect. The statement cin >> x >> y >> z; first reads and stores 28 into x, then reads and stores 32 into y, since y is an int variable. After reading and storing 32 into y, the reading stops after 32, just before the dot. Next the value .6, which is a decimal value, will be read and stored into z since z is a double variable. After reading .6 into z, the reading stops after 6. The last input value 12 will remain into the input stream for further input, if any. c. Incorrect. The statement cin >> x >> y >> z; first reads and stores 28 into x, then reads and stores 32 into y, since y is an int variable. After reading and storing 32 into y, the reading stops after 32, just before the dot. Next the value .6, which is a decimal value, will be read and stored into z since z is a double variable. After reading .6 into z, the reading stops after 6. The last input value 12 will remain into the input stream for further input, if any. d. Incorrect. The statement cin >> x >> y >> z; first reads and stores 28 into x, then reads and stores 32 into y, since y is an int variable. After reading and storing 32 into y, the reading stops after 32, just before the dot. Next the value .6, which is a decimal value, will be read and stored into z since z is a double variable. After reading .6 into z, the reading stops after 6. The last input value 12 will remain into the input stream for further input, if any.

Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 3 HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.02 - Explore how to read data from the standard input device DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 1:12 AM 18. Suppose that x is an int variable, ch is a char variable, and the input is: 276. Choose the values after the following statement executes: cin >> ch >> x; a. ch = '2', x = 76 b. ch = '276', x = '.' c. ch = ' ', x = 276 d. ch = 'b', x = 76 ANSWER: a FEEDBACK: a. Correct. In the cin statement cin >> ch >> x;, the first variable after the first >> is ch and the second variable is x. Also ch is a char variable and x is an int variable. Therefore, the input statement first reads 2 and stores it as '2' into ch and the reading stops just after 2. Next since x is an int variable, the input statement will read 76 and store it into x. b. Incorrect. In the cin statement cin >> ch >> x;, the first variable after the first >> is ch and the second variable is x. Also ch is a char variable and x is an int variable. Therefore, the input statement first reads 2 and stores it as '2' into ch and the reading stops just after 2. Next since x is an int variable, the input statement will read 76 and store it into x. c. Incorrect. In the cin statement cin >> ch >> x;, the first variable after the first >> is ch and the second variable is x. Also ch is a char variable and x is an int variable. Therefore, the input statement first reads 2 and stores it as '2' into ch and the reading stops just after 2. Next since x is an int variable, the input statement will read 76 and store it into x. d. Incorrect. In the cin statement cin >> ch >> x;, the first variable after the first >> is ch and the second variable is x. Also ch is a char variable and x is an int variable. Therefore, the input statement first reads 2 and stores it as '2' into ch and the reading stops just after 2. Next since x is an int variable, the input statement will read 76 and stores it into x. POINTS: 1 REFERENCES: 129 – cin and the Extraction Operator >> QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.02 - Explore how to read data from the standard input device DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/16/2020 11:56 PM 19. Suppose that x and y are int variables, ch is a char variable, and the input is: 4 2 A 12 Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 3 Choose the values of x, y, and ch after the following statement executes: cin >> x >> ch >> y; a. x = 4, ch = 2, y = 12 b. x = 4, ch = A, y = 12 c. x = 4, ch = ' ', y = 2 d. This statement results in input failure ANSWER: d FEEDBACK: a. Incorrect. In the cin statement cin >> x >> ch >> y;, the first variable after the first >> is x, the second variable is ch, and the third variable is y. This input statement first read 4 and stores it into x, then reads 2 and stores it as '2' into ch. The next value in the input stream is A, which is not an integer. Therefore, trying to read and store A into y will result into input failure since y is an int variable. b. Incorrect. In the cin statement cin >> x >> ch >> y;, the first variable after the first >> is x, the second variable is ch, and the third variable is y. This input statement first read 4 and stores it into x, then reads 2 and stores it as '2' into ch. The next value in the input stream is A, which is not an integer. Therefore, trying to read and store A into y will result into input failure since y is an int variable. c. Incorrect. In the cin statement cin >> x >> ch >> y;, the first variable after the first >> is x, the second variable is ch, and the third variable is y. This input statement first read 4 and stores it into x, then reads 2 and stores it as '2' into ch. The next value in the input stream is A, which is not an integer. Therefore, trying to read and store A into y will result into input failure since y is an int variable. d. Correct. In the cin statement cin >> x >> ch >> y;, the first variable after the first >> is x, the second variable is ch, and the third variable is y. This input statement first read 4 and stores it into x, then reads 2 and stores it as '2' into ch. The next value in the input stream is A, which is not an integer. Therefore, trying to read and store A into y will result into input failure since y is an int variable. This statement results into input failure. POINTS: 1 REFERENCES: 130 – cin and the Extraction Operator >> QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.02 - Explore how to read data from the standard input device DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 1:17 AM 20. Suppose that ch1 and ch2 are char variables, and alpha is an int variable. The input is: A 18 What are the values after the following statement executes? cin.get(ch1); cin.get(ch2); Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 3 cin >> alpha; a. ch1 = 'A', ch2 = ' ', alpha = 18 b. ch1 = 'A', ch2 = '1', alpha = 8 c. ch1 = 'A', ch2 = ' ', alpha = 1 d. ch1 = 'A', ch2 = '\n', alpha = 1 ANSWER: FEEDBACK:

a a. Correct. The function get does not skip leading whitespaces and reads the next character, including a whitespace, if any. The first statement cin.get(ch1), reads and stores 'A' into ch1, the reading stops just after A. The second statement, cin.get(ch2), reads the space after A and stores it into ch2. The third statement, cin >> alpha;, reads and stores 18 into alpha. Therefore, after the given statements execute, ch1 = 'A', ch2 = ' ', and alpha = 18. b. Incorrect. The function get does not skip leading whitespaces and reads the next character, including a whitespace, if any. The first statement cin.get(ch1), reads and stores 'A' into ch1, the reading stops just after A. The second statement, cin.get(ch2), reads the space after A and stores it into ch2. The third statement, cin >> alpha;, reads and stores 18 into alpha. Therefore, after the given statements execute, ch1 = 'A', ch2 = ' ', and alpha = 18. c. Incorrect. The function get does not skip leading whitespaces and reads the next character, including a whitespace, if any. The first statement cin.get(ch1), reads and stores 'A' into ch1, the reading stops just after A. The second statement, cin.get(ch2), reads the space after A and stores it into ch2. The third statement, cin >> alpha;, reads and stores 18 into alpha. Therefore, after the given statements execute, ch1 = 'A', ch2 = ' ', and alpha = 18. d. The function get does not skip leading whitespaces and reads the next character, including a whitespace, if any. The first statement cin.get(ch1), reads and stores 'A' into ch1, the reading stops just after A. The second statement, cin.get(ch2), reads the space after A and stores it into ch2. The third statement, cin >> alpha;, reads and stores 18 into alpha. Therefore, after the given statements execute, ch1 = 'A', ch2 = ' ', and alpha = 18.

POINTS: 1 REFERENCES: 134 – cin and the get Function QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.03 - Learn how to use predefined functions in a program DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 1:24 AM 21. When you want to process only partial data, you can use the stream function ____ to discard a portion of the input. a. clear b. skip c. delete d. ignore Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 3 ANSWER: FEEDBACK:

d a. Incorrect. The stream function, clear, restores input stream to a working state. The stream function, ignore, is used to process partial data and to discard portion of input. b. Incorrect. There's no built-in stream function skip. The stream function, ignore, is used to process partial data and to discard portion of input. c. Incorrect. There's no built-in stream function delete. The stream function, ignore,is used to process partial data and to discard portion of input. d. Correct. The stream function ignore is used to discard portion of the input within a line. In other words, stream function ignore processes only partial data within a line.

POINTS: 1 REFERENCES: 134 – cin and the ignore Function QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.04 Explore how to use the input stream functions get, ignore, putback, and peek DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 1:34 AM 22. Suppose that ch1, ch2, and ch3 are variables of the type char. The input is: A B C What is the value of ch3 after the following statements execute? cin.get(ch1); cin.get(ch2); cin.get(ch3); a. 'A' b. 'B' c. 'C' d. '\n' ANSWER: FEEDBACK:

b a. Incorrect. The function get does not skip leading whitespaces and reads the next character, including a whitespace, if any. The first statement cin.get(ch1), reads and stores 'A' into ch1, the reading stops just after A. The second statement, cin.get(ch2), reads the space after A and stores it into ch2. The third statement, cin.get(ch3), reads and stores 'A' into ch3. Therefore, after the given statements execute ch3 = 'B'. b. Correct. The function get does not skip leading whitespaces and reads the next character, including a whitespace, if any. The first statement cin.get(ch1), reads and stores 'A' into ch1, the reading stops just after A. The second statement, cin.get(ch2), reads the space after A and stores it into ch2. The third statement, cin.get(ch3), reads and stores 'A' into ch3. Therefore, after the given statements execute ch3 = 'B'.

Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 3 c. Incorrect. The function get does not skip leading whitespaces and reads the next character, including a whitespace, if any. The first statement cin.get(ch1), reads and stores 'A' into ch1, the reading stops just after A. The second statement, cin.get(ch2), reads the space after A and stores it into ch2. The third statement, cin.get(ch3), reads and stores 'A' into ch3. Therefore, after the given statements execute ch3 = 'B'. d. Incorrect. The function get does not skip leading whitespaces and reads the next character, including a whitespace, if any. The first statement cin.get(ch1), reads and stores 'A' into ch1, the reading stops just after A. The second statement, cin.get(ch2), reads the space after A and stores it into ch2. The third statement, cin.get(ch3), reads and stores 'A' into ch3. Therefore, after the given statements execute ch3 = 'B'. POINTS: 1 REFERENCES: 134 – cin and the get Function QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.04 Explore how to use the input stream functions get, ignore, putback, and peek DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 1:35 AM 23. Suppose that alpha, beta, and gamma are int variables and the input is: 100 110 120 200 210 220 300 310 320 What is the value of gamma after the following statements execute? cin >> alpha; cin.ignore(100, '\n'); cin >> beta; cin.ignore(100,'\n'); cin >> gamma; a. 100 b. 200 c. 300 d. 320 ANSWER: FEEDBACK:

c a. Incorrect. The statement cin.ignore(100, '\n'); ignores either the next 100 characters or all characters until the newline character is found, whichever comes first. The first statement, cin >> alpha;, reads and stores 100 into alpha, and the second statement, cin.ignore(100, "\n");, skips the remaining input in the first line. Next, the third statement, cin >> beta;, reads and stores 200 into beta, and the fourth statements, cin.ignore(100, "\n");, skips the remaining input in the second line. Then the last statement, cin >> gamma;, reads and stores 300 into gamma. Therefore, after the given statements execute, gamma = 300.

Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 3 b. Incorrect. The statement cin.ignore(100, '\n'); ignores either the next 100 characters or all characters until the newline character is found, whichever comes first. The first statement, cin >> alpha;, reads and stores 100 into alpha, and the second statement, cin.ignore(100, "\n");, skips the remaining input in the first line. Next, the third statement, cin >> beta;, reads and stores 200 into beta, and the fourth statements, cin.ignore(100, "\n");, skips the remaining input in the second line. Then the last statement, cin >> gamma;, reads and stores 300 into gamma. Therefore, after the given statements execute, gamma = 300. c. Correct. The statement cin.ignore(100, '\n'); ignores either the next 100 characters or all characters until the newline character is found, whichever comes first. The first statement, cin >> alpha;, reads and stores 100 into alpha, and the second statement, cin.ignore(100, "\n");, skips the remaining input in the first line. Next, the third statement, cin >> beta;, reads and stores 200 into beta, and the fourth statements, cin.ignore(100, "\n");, skips the remaining input in the second line. Then the last statement, cin >> gamma;, reads and stores 300 into gamma. Therefore, after the given statements execute, gamma = 300. d. Incorrect. The statement cin.ignore(100, '\n'); ignores either the next 100 characters or all characters until the newline character is found, whichever comes first. The first statement, cin >> alpha;, reads and stores 100 into alpha, and the second statement, cin.ignore(100, "\n");, skips the remaining input in the first line. Next, the third statement, cin >> beta;, reads and stores 200 into beta, and the fourth statements, cin.ignore(100, "\n");, skips the remaining input in the second line. Then the last statement, cin >> gamma;, reads and stores 300 into gamma. Therefore, after the given statements execute, gamma = 300. POINTS: 1 REFERENCES: 135 – cin and the ignore Function QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.04 Explore how to use the input stream functions get, ignore, putback, and peek DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 2:11 AM 24. Suppose that ch1 and ch2 are char variables and the input is: WXYZ What is the value of ch2 after the following statements execute? cin.get(ch1); cin.putback(ch1); cin >> ch2; a. W c. Y

b. X d. Z

Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 3 ANSWER: FEEDBACK:

a a. Correct. The stream function putback lets you put the last character extracted from the input stream by the get function back into the input stream. The first statement, cin.get(ch1);, reads W and stores it into ch1. Next, the statement, cin.putback(ch1);, puts W back into the input stream. So after the execution of this statement, the reading marker is before W. Therefore, the next statement, cin >> ch2;, reads W and stores it into ch2. Therefore, after the last statement executes, ch2 = 'W'. b. Incorrect. The stream function putback lets you put the last character extracted from the input stream by the get function back into the input stream. The first statement, cin.get(ch1);, reads W and stores it into ch1. Next, the statement, cin.putback(ch1);, puts W back into the input stream. So after the execution of this statement, the reading marker is before W. Therefore, the next statement, cin >> ch2;, reads W and stores it into ch2. Therefore, after the last statement executes, ch2 = 'W'. c. Incorrect. The stream function putback lets you put the last character extracted from the input stream by the get function back into the input stream. The first statement, cin.get(ch1);, reads W and stores it into ch1. Next, the statement, cin.putback(ch1);, puts W back into the input stream. So after the execution of this statement, the reading marker is before W. Therefore, the next statement, cin >> ch2;, reads W and stores it into ch2. Therefore, after the last statement executes, ch2 = 'W'. d. Incorrect. The stream function putback lets you put the last character extracted from the input stream by the get function back into the input stream. The first statement, cin.get(ch1);, reads W and stores it into ch1. Next, the statement, cin.putback(ch1);, puts W back into the input stream. So after the execution of this statement, the reading marker is before W. Therefore, the next statement, cin >> ch2;, reads W and stores it into ch2. Therefore, after the last statement executes, ch2 = 'W'.

POINTS: 1 REFERENCES: 137-138 – putback and the peek Function QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.04 Explore how to use the input stream functions get, ignore, putback, and peek DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 1:38 AM 25. Suppose that ch1 and ch2 are char variables and the input is: WXYZ What is the value of ch2 after the following statements execute? cin >> ch1; ch2 = cin.peek(); cin >> ch2; Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 3 a. W b. X c. Y d. Z ANSWER: FEEDBACK:

b a. Incorrect. The peek function returns the next character from the input stream but does not remove the character from that stream. The firs statement, cin >> ch1;, reads and stores the character W into ch1 and the reading marker is after just before X. The next statement, ch2 = cin.peek();, reads and stores the next character X into ch2, but does not remove X from the input stream. Therefore, after the second statement executes, the reading marker is still before X. Next, the third statement, cin >> ch2;, reads and stores the next (non whitespace) character X into ch2. After the execution of the given statements, ch2 = 'X'. b. Correct. The peek function returns the next character from the input stream but does not remove the character from that stream. The firs statement, cin >> ch1;, reads and stores the character W into ch1 and the reading marker is after just before X. The next statement, ch2 = cin.peek();, reads and stores the next character X into ch2, but does not remove X from the input stream. Therefore, after the second statement executes, the reading marker is still before X. Next, the third statement, cin >> ch2;, reads and stores the next (non whitespace) character X into ch2. After the execution of the given statements, ch2 = 'X'. c. Incorrect. The peek function returns the next character from the input stream but does not remove the character from that stream. The firs statement, cin >> ch1;, reads and stores the character W into ch1 and the reading marker is after just before X. The next statement, ch2 = cin.peek();, reads and stores the next character X into ch2, but does not remove X from the input stream. Therefore, after the second statement executes, the reading marker is still before X. Next, the third statement, cin >> ch2;, reads and stores the next (non whitespace) character X into ch2. After the execution of the given statements, ch2 = 'X'. d. Incorrect. The peek function returns the next character from the input stream but does not remove the character from that stream. The firs statement, cin >> ch1;, reads and stores the character W into ch1 and the reading marker is after just before X. The next statement, ch2 = cin.peek();, reads and stores the next character X into ch2, but does not remove X from the input stream. Therefore, after the second statement executes, the reading marker is still before X. Next, the third statement, cin >> ch2;, reads and stores the next (non whitespace) character X into ch2. After the execution of the given statements, ch2 = 'X'.

POINTS: 1 REFERENCES: 138 – putback and the peek Function QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.04 Explore how to use the input stream functions get, ignore, putback, and peek Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 3 DATE CREATED: DATE MODIFIED:

10/5/2016 1:37 PM 3/13/2020 1:40 AM

26. In C++, the dot is an operator called the ____ operator. a. dot access b. member access c. data access d. member ANSWER: b FEEDBACK: a. Incorrect. There's no operator called dot access in C++. b. Correct. In C++, dot is an operator, called member access operator. c. Incorrect. There's no operator called data access in C++. d. Incorrect. There's no operator called member in C++. POINTS: 1 REFERENCES: 139 – The Dot Notation between I/O Stream Variables and I/O Functions: A Precaution QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.8e.03.04 - Explore how to use the input stream functions get, ignore, putback, and peek DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 2/28/2020 3:23 AM 27. Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(2); cout << x << ' ' << y << ' ' << z << endl; a. 25.67 356.87 7623.96 b. 25.67 356.87 7623.97 c. 25.67 356.88 7623.97 d. 25.67 356.876 7623.967 ANSWER: c FEEDBACK: a. Incorrect. The setprecision manipulator will throw two decimal digits of the y value from 356.876 to 356.88 and z value from 7623.9674 to 7623.97; so it is not possible to get 356.87 for y and 7623.96for z. b. Incorrect. The setprecision manipulator will throw two decimal digits of the y value from 356.876 to 356.88; so it is not possible to get 356.87 for y. c. Correct. The manipulator setprecision to control the output of floating-point numbers. When executed the output values of x, y, and z are 25.67, 356.88, and 7623.97, respectively. d. Incorrect. The setprecision manipulator will throw two decimal digits of the y value from 356.876 to 356.88 and z value from 7623.9674 to 7623.97; so it is not possible to get 356.876 for y and 7623.967 for z. POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 145-147 – fixed Manipulator, showpoint Manipulator, setprecision Manipulator Multiple Choice False

Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 3 LEARNING OBJECTIVES: PDDS.MALI.03.07 - Discover how to use manipulators in a program to format output DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 1:44 AM 28. Suppose that x = 55.68, y = 476.859, and z = 23.8216. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3); cout << x << ' ' << y << ' ' << setprecision(2) << z << endl; a. 55.680 476.859 23.82 b. 55.690 476.860 23.82 c. 55.680 476.860 23.82 d. 55.680 476.859 23.821 ANSWER: a FEEDBACK: a. Correct. The manipulator fixed is used to output numbers in a fixed decimal format, the manipulator showpoint is used to output number with the decimal point and trailing zeros, if any, and the manipulator setprecision is used to output numbers to a fixed number of decimal places. The statement, cout << setprecision(3);, sets the output of numbers to three decimal places. The third statement after outputting the values of x and y with three decimal place, uses setprecision to set the output of numbers to two decimal places. So the value of z is output with two decimal places. Since x = 55.68 has only two decimal places and the precision is three decimal places, x is printed as 55.680. b. Incorrect. The manipulator fixed is used to output numbers in a fixed decimal format, the manipulator showpoint is used to output number with the decimal point and trailing zeros, if any, and the manipulator setprecision is used to output numbers to a fixed number of decimal places. The statement, cout << setprecision(3);, sets the output of numbers to three decimal places. The third statement after outputting the values of x and y with three decimal place, uses setprecision to set the output of numbers to two decimal places. So the value of z is output with two decimal places. Since x = 55.68 has only two decimal places and the precision is three decimal places, x is printed as 55.680. c. Incorrect. The manipulator fixed is used to output numbers in a fixed decimal format, the manipulator showpoint is used to output number with the decimal point and trailing zeros, if any, and the manipulator setprecision is used to output numbers to a fixed number of decimal places. The statement, cout << setprecision(3);, sets the output of numbers to three decimal places. The third statement after outputting the values of x and y with three decimal place, uses setprecision to set the output of numbers to two decimal places. So the value of z is output with two decimal places. Since x = 55.68 has only two decimal places and the precision is three decimal places, x is printed as 55.680. d. Incorrect. The manipulator fixed is used to output numbers in a fixed decimal format, the manipulator showpoint is used to output number with the decimal point and trailing zeros, if any, and the manipulator setprecision is used to output numbers to a fixed number of decimal places. The statement, cout << setprecision(3);, sets the output of numbers to three decimal places. The third statement after outputting the values of x and y with three decimal place, Copyright Cengage Learning. Powered by Cognero.

Page 19


Name:

Class:

Date:

Chapter 3 uses setprecision to set the output of numbers to two decimal places. So the value of z is output with two decimal places. Since x = 55.68 has only two decimal places and the precision is three decimal places, x is printed as 55.680. POINTS: 1 REFERENCES: 145-147 – fixed Manipulator, showpoint Manipulator, setprecesion Manipulator QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.07 - Discover how to use manipulators in a program to format output DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 1:45 AM 29. Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3) << x << ' '; cout << setprecision(4) << y << ' ' << setprecision(2) << z << endl; a. 1565.683 85.8000 123.98 b. 1565.680 85.8000 123.98 c. 1565.683 85.7800 123.98 d. 1565.683 85.780 123.980 ANSWER: c FEEDBACK: a. Incorrect. The manipulator fixed is used to output numbers in a fixed decimal format, the manipulator showpoint is used to output number with the decimal point and trailing zeros, if any, and the manipulator setprecision is used to output numbers with a fixed number of decimal places. The value of x is output with three decimal places, the value of y is output with four decimal places, and the value of z is output with two decimal places. Because y = 85.78 has only two decimal places, it is output as 85.7800. Also, because z = 123.982 has three decimal places, the output value of z, which is 123.98, is rounded to two decimal places. b. Incorrect. The manipulator fixed is used to output numbers in a fixed decimal format, the manipulator showpoint is used to output number with the decimal point and trailing zeros, if any, and the manipulator setprecision is used to output numbers with a fixed number of decimal places. The value of x is output with three decimal places, the value of y is output with four decimal places, and the value of z is output with two decimal places. Because y = 85.78 has only two decimal places, it is output as 85.7800. Also, because z = 123.982 has three decimal places, the output value of z, which is 123.98, is rounded to two decimal places. c. Correct. The manipulator fixed is used to output numbers in a fixed decimal format, the manipulator showpoint is used to output number with the decimal point and trailing zeros, if any, and the manipulator setprecision is used to output numbers with a fixed number of decimal places. The value of x is output with three decimal places, the value of y is output with four decimal places, and the value of z is output with two decimal places. Because y = 85.78 has only Copyright Cengage Learning. Powered by Cognero.

Page 20


Name:

Class:

Date:

Chapter 3 two decimal places, it is output as 85.7800. Also, because z = 123.982 has three decimal places, the output value of z, which is 123.98, is rounded to two decimal places. d. Incorrect. The manipulator fixed is used to output numbers in a fixed decimal format, the manipulator showpoint is used to output number with the decimal point and trailing zeros, if any, and the manipulator setprecision is used to output numbers with a fixed number of decimal places. The value of x is output with three decimal places, the value of y is output with four decimal places, and the value of z is output with two decimal places. Because y = 85.78 has only two decimal places, it is output as 85.7800. Also, because z = 123.982 has three decimal places, the output value of z, which is 123.98, is rounded to two decimal places. POINTS: 1 REFERENCES: 145-147 – fixed Manipulator, showpoint Manipulator, setprecision Manipulator QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.07 - Discover how to use manipulators in a program to format output DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 1:47 AM 30. What is the output of the following statements? cout << setfill('*'); cout << "12345678901234567890" << endl cout << setw(5) << "18" << setw(7) << "Happy" << setw(8) << "Sleepy" << endl; a. 12345678901234567890 ***18 Happy Sleepy b. 12345678901234567890 ***18**Happy**Sleepy c. 12345678901234567890 ***18**Happy Sleepy d. 12345678901234567890 ***18**Happy Sleepy** ANSWER: b FEEDBACK: a. Incorrect. The manipulator setw is used to output the value of an expression in a specific number of columns. If the number of columns specified by setw exceeds the number of columns required by the expression, the output of the expression is rightjustified and the unused columns to the left are filled with spaces. The manipulator setfill is used to fill the unused columns with a Copyright Cengage Learning. Powered by Cognero.

Page 21


Name:

Class:

Date:

Chapter 3 character other than a space. The statement, cout << setfill('*');, fills the unused columns with the character *. The value of 18 is output in five columns. Because it only requires two columns, the three columns to the left of 18 are filled with *. The value of "Happy" is output in 7 columns and it only requires five columns, the first two columns are filled with *. The value of "Sleepy" is output in eight columns and requires only six columns, so the left two columns are filled with *. b. Correct. The manipulator setw is used to output the value of an expression in a specific number of columns. If the number of columns specified by setw exceeds the number of columns required by the expression, the output of the expression is rightjustified and the unused columns to the left are filled with spaces. The manipulator setfill is used to fill the unused columns with a character other than a space. The statement, cout << setfill('*');, fills the unused columns with the character *. The value of 18 is output in five columns. Because it only requires two columns, the three columns to the left of 18 are filled with *. The value of "Happy" is output in 7 columns and it only requires five columns, the first two columns are filled with *. The value of "Sleepy" is output in eight columns and requires only six columns, so the left two columns are filled with *. c. Incorrect. The manipulator setw is used to output the value of an expression in a specific number of columns. If the number of columns specified by setw exceeds the number of columns required by the expression, the output of the expression is rightjustified and the unused columns to the left are filled with spaces. The manipulator setfill is used to fill the unused columns with a character other than a space. The statement, cout << setfill('*');, fills the unused columns with the character *. The value of 18 is output in five columns. Because it only requires two columns, the three columns to the left of 18 are filled with *. The value of "Happy" is output in 7 columns and it only requires five columns, the first two columns are filled with *. The value of "Sleepy" is output in eight columns and requires only six columns, so the left two columns are filled with *. d. Incorrect. The manipulator setw is used to output the value of an expression in a specific number of columns. If the number of columns specified by setw exceeds the number of columns required by the expression, the output of the expression is rightjustified and the unused columns to the left are filled with spaces. The manipulator setfill is used to fill the unused columns with a character other than a space. The statement, cout << setfill('*');, fills the unused columns with the character *. The value of 18 is output in five columns. Because it only requires two columns, the three columns to the left of 18 are filled with *. The value of "Happy" is output in 7 columns and it only requires five columns, the first two columns are filled with *. The value of "Sleepy" is output in eight columns and requires only six columns, so the left two columns are filled with *. POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 152-153 – setfill Manipulator Multiple Choice False

Copyright Cengage Learning. Powered by Cognero.

Page 22


Name:

Class:

Date:

Chapter 3 LEARNING OBJECTIVES: PDDS.MALI.03.07 - Discover how to use manipulators in a program to format output DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 1:49 AM 31. What is the output of the following statements? cout << "123456789012345678901234567890" << endl cout << setfill('#') << setw(10) << "Mickey" << setfill(' ') << setw(10) << "Donald" << setfill('*') << setw(10) << "Goofy" << endl; a. 123456789012345678901234567890 ####Mickey Donald*****Goofy b. 123456789012345678901234567890 ####Mickey####Donald*****Goofy c. 123456789012345678901234567890 ####Mickey####Donald#####Goofy d. 23456789012345678901234567890 ****Mickey####Donald#####Goofy ANSWER: a FEEDBACK: a. Correct. The manipulator setw is used to output the value of an expression in a specific number of columns. If the number of columns specified by setw exceeds the number of columns required by the expression, the output of the expression is rightjustified and the unused columns to the left are filled with spaces. The manipulator setfill is used to fill the unused columns with a character other than a space. The expression setfill('#') fills the unused columns with the character #. The expression setfill(' ') fills the unused columns with the space character. The expression setfill('*') fills the unused columns with the character *. "Mickey" is output in 10 columns and it requires only six columns, the left four columns are filled with #. "Donald" is output in 10 columns and it requires only six columns, the left four columns are filled with the space character. "Goofy" is output in 10 columns and it requires only five columns, the left five columns are filled with *. b. Incorrect. The manipulator setw is used to output the value of an expression in a specific number of columns. If the number of columns specified by setw exceeds the number of columns required by the expression, the output of the expression is rightjustified and the unused columns to the left are filled with spaces. The manipulator setfill is used to fill the unused columns with a character other than a space. The expression setfill('#') fills the unused columns with the character #. The expression setfill(' ') fills the unused columns with the space character. The expression setfill('*') fills the unused columns with the character *. "Mickey" is output in 10 columns and it requires only six columns, the left four columns are filled with #. "Donald" is output in 10 columns and it requires only six columns, the left four columns are filled with the space character. "Goofy" is output in 10 columns and it requires Copyright Cengage Learning. Powered by Cognero.

Page 23


Name:

Class:

Date:

Chapter 3 only five columns, the left five columns are filled with *. c. Incorrect. The manipulator setw is used to output the value of an expression in a specific number of columns. If the number of columns specified by setw exceeds the number of columns required by the expression, the output of the expression is rightjustified and the unused columns to the left are filled with spaces. The manipulator setfill is used to fill the unused columns with a character other than a space. The expression setfill('#') fills the unused columns with the character #. The expression setfill(' ') fills the unused columns with the space character. The expression setfill('*') fills the unused columns with the character *. "Mickey" is output in 10 columns and it requires only six columns, the left four columns are filled with #. "Donald" is output in 10 columns and it requires only six columns, the left four columns are filled with the space character. "Goofy" is output in 10 columns and it requires only five columns, the left five columns are filled with *. d. Incorrect. The manipulator setw is used to output the value of an expression in a specific number of columns. If the number of columns specified by setw exceeds the number of columns required by the expression, the output of the expression is rightjustified and the unused columns to the left are filled with spaces. The manipulator setfill is used to fill the unused columns with a character other than a space. The expression setfill('#') fills the unused columns with the character #. The expression setfill(' ') fills the unused columns with the space character. The expression setfill('*') fills the unused columns with the character *. "Mickey" is output in 10 columns and it requires only six columns, the left four columns are filled with #. "Donald" is output in 10 columns and it requires only six columns, the left four columns are filled with the space character. "Goofy" is output in 10 columns and it requires only five columns, the left five columns are filled with *. POINTS: 1 REFERENCES: 152-153 – setfill Manipulator QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.07 - Discover how to use manipulators in a program to format output DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 1:50 AM 32. ____ is a parameterized stream manipulator. a. endl b. fixed c. scientific d. setfill ANSWER: FEEDBACK:

d a. Incorrect. endl is a manipulator without parameter that's used to insert new line. b. Incorrect. fixed is a manipulator without parameter used to output floatingpoint numbers in a fixed decimal format. c. Incorrect. scientific is a manipulator without parameter used to output floating-point numbers in a scientific format. d. Correct. Manipulators with parameters are called parameterized stream

Copyright Cengage Learning. Powered by Cognero.

Page 24


Name:

Class:

Date:

Chapter 3 manipulator. Example setprecision, setw, and setfill. POINTS: 1 REFERENCES: 156 – left and right Manipulators QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.07 - Discover how to use manipulators in a program to format output DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 2:15 AM 33. Manipulators without parameters are part of the ____ header file. a. iostream b. iomanip c. ifstream d. pmanip ANSWER: FEEDBACK:

a a. Correct. Manipulators without parameters are part of the iostream header file. b. Incorrect. Manipulators without parameters are part of the iostream header file. To use a parameterized stream manipulator in a program, you must include the header file iomanip. c. Incorrect. Manipulators without parameters are part of the iostream header file. Ifstream is a data type in fstream header file. d. Incorrect. Manipulators without parameters are part of the iostream header file. There is no header file called pmanip in C++ programming.

POINTS: 1 REFERENCES: 156 – left and right Manipulators QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.07 - Discover how to use manipulators in a program to format output DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 2:19 AM 34. Consider the following program segment. ifstream inFile; //Line 1 int x, y; //Line 2 ... //Line 3 inFile >> x >> y; //Line 4 Which of the following statements at Line 3 can be used to open the file progdata.dat and input data from this file into x and y at Line 4? a. inFile.open("progdata.dat"); b. inFile(open,"progdata.dat"); c. open.inFile("progdata.dat"); Copyright Cengage Learning. Powered by Cognero.

Page 25


Name:

Class:

Date:

Chapter 3 d. open(inFile,"progdata.dat"); ANSWER: a FEEDBACK: a. Correct. inFile.open("progdata.dat") is correct syntax to open the file. b. Incorrect. The syntax to open a file is fileStreamVariable.open(sourceName);. Therefore, the correct statement to open the file progdata.dat and input data from this file into x and y is: inFile.open("progdata.dat"); c. Incorrect. The syntax to open a file is fileStreamVariable.open(sourceName);. Therefore, the correct statement to open the file progdata.dat and input data from this file into x and y is: inFile.open("progdata.dat"); d. Incorrect. The syntax to open a file is fileStreamVariable.open(sourceName);. Therefore, the correct statement to open the file progdata.dat and input data from this file into x and y is: inFile.open("progdata.dat"); POINTS: 1 REFERENCES: 172 – Programming Example: Student Grade QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.10 - Become familiar with file input and output DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 2:20 AM 35. Suppose that outFile is an ofstream variable and output is to be stored in the file outputData.out. Which of the following statements opens the file outputData.out and associates outFile to the output file? a. outFile("outputData.out"); b. outFile.open("outputData.out"); c. open(outFile,"outputData.out"); d. open.outFile("outputData.out"); ANSWER: FEEDBACK:

b a. Incorrect. The syntax to open a file is fileStreamVariable.open(sourceName);. Therefore, the correct statement to open the file outputData.out and associate outFile to it is: outFile.open("outputData.out"); b. Correct. outFile.open("outputData.out") opens the file to store the output data. c. Incorrect. The syntax to open a file is fileStreamVariable.open(sourceName);. Therefore, the correct statement to open the file outputData.out and associate outFile to it is: outFile.open("outputData.out"); d. Incorrect. The syntax to open a file is fileStreamVariable.open(sourceName);. Therefore, the correct statement to open the file outputData.out and associate outFile to it is:

Copyright Cengage Learning. Powered by Cognero.

Page 26


Name:

Class:

Date:

Chapter 3 outFile.open("outputData.out"); POINTS: 1 REFERENCES: 172 – Programming Example: Student Grade QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.03.10 - Become familiar with file input and output DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 3/13/2020 2:22 AM 36. The function ____________________ returns the next character in the input stream; it does not remove the character from the input stream. peek ANSWER: POINTS: 1 REFERENCES: 137 – putback and the peek Function QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.03.04 Explore how to use the input stream functions get, ignore, putback, and peek DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 2/28/2020 8:19 PM 37. C++ comes with a wealth of functions, called ____________________ functions, that are written by other programmers. ANSWER: predefined pre defined pre-defined POINTS: 1 REFERENCES: 130-131 – Using Predefined Functions in a Program QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.03.03 - Learn how to use predefined functions in a program DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 2/28/2020 9:21 PM 38. C++ has a special name for the data types istream and ostream. They are called ____________________. ANSWER: classes POINTS: 1 REFERENCES: 139 – The Dot Notation between I/O Stream Variables and I/O Functions: A Precaution QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic Copyright Cengage Learning. Powered by Cognero.

Page 27


Name:

Class:

Date:

Chapter 3 LEARNING OBJECTIVES: PDDS.MALI.03.04 Explore how to use the input stream functions get, ignore, putback, and peek DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 2/28/2020 8:25 PM 39. In C++, the dot is an operator called the ____________________operator. ANSWER: member access POINTS: 1 REFERENCES: 139 – The Dot Notation between I/O Stream Variables and I/O Functions: A Precaution QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.03.03 - Learn how to use predefined functions in a program DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 2/28/2020 8:27 PM 40. C++ provides a header file called ____________________, which is used for file I/O. fstream ANSWER: POINTS: 1 REFERENCES: 161 – File Input/Output QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.03.10 - Become familiar with file input and output DATE CREATED: 10/5/2016 1:37 PM DATE MODIFIED: 2/28/2020 8:28 PM

Copyright Cengage Learning. Powered by Cognero.

Page 28


Name:

Class:

Date:

Chapter 4 1. A control structure alters the normal sequential flow of execution in a program. a. True b. False ANSWER: True FEEDBACK: Correct In a program, control structures alters the normal sequential flow of execution. Incorrect In a program, control structures alters the normal sequential flow of execution.

POINTS: 1 REFERENCES: 188 – Control Structures QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.01 - Learn about control structures DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 2/27/2020 1:23 AM 2. The result of a logical expression cannot be assigned to an int variable, but it can be assigned to a bool variable. a. True b. False ANSWER: False FEEDBACK: Correct One can either use a bool variable or an int variable for storing the result of a logical expression. Incorrect One can either use a bool variable or an int variable for storing the result of a logical expression. POINTS: 1 REFERENCES: 199 – Logical (Boolean) Operators and Logical Expressions QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.04 - Examine int and bool data types and logical (Boolean) expressions DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/12/2020 3:19 AM 3. In C++, both ! and != are relational operators. a. True b. False ANSWER: False FEEDBACK: Correct The operator != is a relational operator and the operator! is a logical operator. Incorrect The operator != is a relational operator and the operator ! is a logical operator.

POINTS: 1 REFERENCES: 189 – SELECTION: if AND if . . . else QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.01 - Learn about control structures DATE CREATED: 10/5/2016 1:38 PM Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 4 DATE MODIFIED:

3/13/2020 12:43 AM

4. The operators !, &&, and || are called relational operators. a. True b. False ANSWER: False FEEDBACK: Correct The operators !, &&, and || are logical operators. Incorrect The operators !, &&, and || are logical operators.

POINTS: 1 REFERENCES: 199 – Logical (Boolean) Operators and Logical Expressions QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.05 - Examine logical operators DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 12:45 AM 5. The expression (x >= 0 && x <= 100) evaluates to false if either x < 0 or x >= 100. a. True b. False ANSWER: False FEEDBACK: Correct When the value of x = 100, the expression (x >= 0 && x <= 100) evaluates to true. Incorrect When the value of x = 100, the expression (x >= 0 && x <= 100) evaluates to true. POINTS: 1 REFERENCES: 200-201 – Logical (Boolean) Operators and Logical Expressions QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.06 - Explore how to form and evaluate logical (Boolean) expressions DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 12:47 AM 6. Suppose P and Q are logical expressions. The logical expression P && Q is true if both P and Q are true. a. True b. False ANSWER: True FEEDBACK: Correct As per the definition of the and operator, &&, expression1 && expression2 is true if and only if both expression1 and expression2 are true. Incorrect As per the definition of the and operator, &&, expression1 &&

expression2 is true if and only if both expression1 and expression2 are true. Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 4 POINTS: 1 REFERENCES: 200 – Logical (Boolean) Operators and Logical Expressions QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.06 - Explore how to form and evaluate logical (Boolean) expressions DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 12:53 AM 7. In C++, && has a higher precedence than ||. a. True b. False ANSWER: True FEEDBACK: Correct As per the precedence of operators, the or operator || has a lesser precedence than the and operator &&. Incorrect As per the precedence of operators, the or operator || has a lesser precedence than the and operator &&. POINTS: 1 REFERENCES: 202 – Order of Precedence QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.06 - Explore how to form and evaluate logical (Boolean) expressions DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 2:25 AM 8. In C++, the operators != and == have the same order of precedence. a. True b. False ANSWER: True FEEDBACK: Correct As per the precedence of operators, the not equal to operator !=and the equal to operator == have the same order of precedence. Incorrect As per the precedence of operators, the not equal to operator !=and the equal to

operator == have the same order of precedence. POINTS: 1 REFERENCES: 202 – Order of Precedence QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.06 - Explore how to form and evaluate logical (Boolean) expressions DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 1:11 AM 9. A compound statement functions as if it was a single statement. a. True Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 4 b. False ANSWER: FEEDBACK:

True Correct A compound statement typically acts a single statement. Incorrect A compound statement typically acts a single statement.

POINTS: 1 REFERENCES: 207 – Compound (Block of) Statements QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.07 - Learn how relational operators work with the string type DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 2/27/2020 1:50 AM 10. If the expression in an assert statement evaluates to true, the program terminates. a. True b. False ANSWER: False FEEDBACK: Correct A program terminates when an expression in the statement assert evaluates to false. Incorrect A program terminates when an expression in the statement assert evaluates to

false. POINTS: 1 REFERENCES: 237 – Terminating a Program with the assert Function QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.13 - Learn to use the assert function to terminate a program DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 1:14 AM 11. In a ____ control structure, the computer executes particular statements depending on some condition(s). a. selected b. responsive c. selection d. sequence ANSWER: c FEEDBACK: a. Incorrect. C++ does not have selected control structure. b. Incorrect. C++ does not have responsive control structure. c. Correct. The selection control structure executes specific statements based on some conditions. d. Incorrect. The sequence control structure does not execute specific statements based on some conditions.

POINTS: 1 REFERENCES: 188 – Control Structures QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.01 - Learn about control structures Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 4 DATE CREATED: DATE MODIFIED:

10/5/2016 1:38 PM 2/27/2020 2:00 AM

12. What does <= mean? a. less than b. greater than c. less than or equal to d. greater than or equal to ANSWER: c FEEDBACK: a. Incorrect. The less than is represented as <. b. Incorrect. The greater than is represented as >. c. Correct. The less than or equal to is represented as <=. d. Incorrect. The greater than or equal to is represented as >=. POINTS: 1 REFERENCES: 189 – SELECTION: if AND if . . . else QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.03 - Discover how to use the selection control structures if and if . . . else DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 1:18 AM 13. Which of the following is a relational operator? a. = b. == c. ! d. && ANSWER: FEEDBACK:

b a. Incorrect. The operator = is assignment operator. b. Correct. The operator == is a relational operator. c. Incorrect. The operator ! is a logical operator. d. Incorrect. The operator && is a logical operator.

POINTS: 1 REFERENCES: 189 – SELECTION: if AND if . . . else QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.03 - Discover how to use the selection control structures if and if . . . else DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 1:21 AM 14. Which of the following is the "not equal to" relational operator? a. ! b. | c. != d. & ANSWER: FEEDBACK:

c a. Incorrect. The operator ! is not a relational operator. It is a logical operator. b. Incorrect. The operator | is not a relational operator.

Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 4 c. Correct. The operator != is "not equal to" relational operator. d. Incorrect. The operator & does not represent the "not equal to" relational operator. POINTS: 1 REFERENCES: 189 – Control Structures QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.02 - Examine relational operators DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 1:24 AM 15. Suppose x is 5 and y is 7. Choose the value of the following expression: (x != 7) && (x <= y) a. false c. 0 ANSWER: FEEDBACK:

b. true d. null b a. Incorrect. If x is 5 and y is 7, then (x != 7) && (x <= y) = (5 != 7) && (5 <= 7) = true && true = true. b. Correct. If x is 5 and y is 7, then (x != 7) && (x <= y) = (5 != 7) && (5 <= 7) = true && true = true. c. Incorrect. If x is 5 and y is 7, then (x != 7) && (x <= y) = (5 != 7) && (5 <= 7) = true && true = true. d. Incorrect. If x is 5 and y is 7, then (x != 7) && (x <= y) = (5 != 7) && (5 <= 7) = true && true = true.

POINTS: 1 REFERENCES: 200 – Logical (Boolean) Operators and Logical Expressions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.04 - Examine int and bool data types and logical (Boolean) expressions DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 1:33 AM 16. Suppose that x is an int variable. Which of the following expressions always evaluates to true? a. (x > 0) || ( x <= 0) b. (x >= 0) || (x == 0) c. (x > 0) && ( x <= 0) d. (x > 0) && (x == 0) ANSWER: a FEEDBACK: a. Correct. If x is an int variable, then x = 0, x > 0, or x < 0. Thus, either x > 0 is true or x <= true. Also, true || true = true, false || true = true, and true || false = true. Therefore, (x > 0) || ( x <= 0) will always evaluate to true. b. Incorrect. Suppose x = 5. Then x >= 0 is false and x == 0 is false. Therefore, (x >= 0) || (x == 0) = false || false = false. Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 4 c. Incorrect. Suppose x = 5. Then x > 0 is true and x <= 0 is false. Therefore, (x > 0) && ( x <= 0)) = true && false = false. d. Incorrect. Suppose x = 5. Then x > 0 is true and x == 0 is false. Therefore, (x > 0) && ( x == 0)) = true && false = false. POINTS: 1 REFERENCES: 201 – Logical (Boolean) Operators and Logical Expressions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.04 - Examine int and bool data types and logical (Boolean) expressions DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 1:36 AM 17. Which of the operators %, =, !, and * has the highest precedence? a. ! b. * c. % d. = ANSWER: FEEDBACK:

a a. Correct. The precedence of the operators %, =, !, and * from highest to lowest is: ! (highest), % and * (second highest), = (lowest). Note that % and * have the same level of precedence. b. Incorrect. The precedence of the operators %, =, !, and * from highest to lowest is: ! (highest), % and * (second highest), = (lowest). Note that % and * have the same level of precedence. c. Incorrect. The precedence of the operators %, =, !, and * from highest to lowest is: ! (highest), % and * (second highest), = (lowest). Note that % and * have the same level of precedence. d. Incorrect. The precedence of the operators %, =, !, and * from highest to lowest is: ! (highest), % and * (second highest), = (lowest). Note that % and * have the same level of precedence.

POINTS: 1 REFERENCES: 202 – Order of Precedence QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.06 - Explore how to form and evaluate logical (Boolean) expressions DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 1:38 AM 18. Which of the operators &&, =, !, and || has the lowest precedence? a. ! b. || c. && d. = ANSWER: FEEDBACK:

d a. Incorrect. The precedence of the operators &&, =, !, and || from highest to lowest is: ! (highest), && (second highest), || (third highest), = (lowest). Thus, = has the lowest precedence.

Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 4 b. Incorrect. The precedence of the operators &&, =, !, and || from highest to lowest is: ! (highest), && (second highest), || (third highest), = (lowest). Thus, = has the lowest precedence. c. Incorrect. The precedence of the operators &&, =, !, and || from highest to lowest is: ! (highest), && (second highest), || (third highest), = (lowest). Thus, = has the lowest precedence. d. Correct. The precedence of the operators &&, =, !, and || from highest to lowest is: ! (highest), && (second highest), || (third highest), = (lowest). Thus, = has the lowest precedence. POINTS: 1 REFERENCES: 202 – Order of Precedence QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.06 - Explore how to form and evaluate logical (Boolean) expressions DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 1:40 AM 19. Which of the following expressions correctly determines that x is greater than 10 and less than 20? a. 10 < x < 20 b. (10 < x < 20) c. 10 < x && x < 20 d. 10 < x || x < 20 ANSWER: FEEDBACK:

c a. Incorrect. The expression 10 < x < 20 is an incorrect expression and results in syntax error. b. Incorrect. The expression (10 < x < 20) is an incorrect expression and results in syntax error. c. Correct. The expression 10 < x && x < 20 determines that the value of x is greater than the value 10 and the value of x is less than the value 20. d. Incorrect. The expression 10 < x || x < 20 determines that the value of x is greater than the value 10 or the value of x is less than the value 20.

POINTS: 1 REFERENCES: 200 – Logical (Boolean) Operators and Logical Expressions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.06 - Explore how to form and evaluate logical (Boolean) expressions DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 1:43 AM 20. You can use either a(n) ____ or a ____ to store the value of a logical expression. a. float, double b. char, string c. int, bool d. float, string ANSWER: c FEEDBACK: a. Incorrect. One cannot either use a float variable or a double variable for storing the result of a logical expression. Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 4 b. Incorrect. One cannot either use a char variable or a string variable for storing the result of a logical expression. c. Correct. One can either use a bool variable or an int variable for storing the result of a logical expression. d. Incorrect. One cannot either use a float variable or a string variable for storing the result of a logical expression. POINTS: 1 REFERENCES: 199 – bool Data Type and Logical (Boolean) Expressions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.04 - Examine int and bool data types and logical (Boolean) expressions DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 1:45 AM 21. What is the output of the following C++ code? int x = 35; int y = 45; int z; if (x > y) z = x + y; else z = y – x; cout << x << " " << y << " " << z << endl; a. 35 45 80 c. 35 45 –10 ANSWER: FEEDBACK:

b. 35 45 10 d. 35 45 0 b a. Incorrect. In this program segment, x = 35 and y = 45. In the if statement, the expression (x > y) = (35 > 45) = false. So the statement in the body of else, that is, z = y – x executes. Thus, z = y - x = 45 -35 = 10. Therefore, the cout statement outputs: 35 45 10 Thus, it does not output 35 45 80. b. Correct. In this program segment, x = 35 and y = 45. In the if statement, the expression (x > y) = (35 > 45) = false. So the statement in the body of else, that is, z = y – x executes. Thus, z = y - x = 45 -35 = 10. Therefore, the cout statement outputs: 35 45 10 c. Incorrect. In this program segment, x = 35 and y = 45. In the if statement, the expression (x > y) = (35 > 45) = false. So the statement in the body of else, that is, z = y – x executes. Thus, z = y - x = 45 -35 = 10. Therefore, the cout statement outputs: 35 45 10 Thus, it does not output 35 45 -10.

Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 4 d. Incorrect. In this program segment, x = 35 and y = 45. In the if statement, the expression (x > y) = (35 > 45) = false. So the statement in the body of else, that is, z = y – x executes. Thus, z = y - x = 45 -35 = 10. Therefore, the cout statement outputs: 35 45 10 Thus, it does not output 35 45 0. POINTS: 1 REFERENCES: 195 – Two-Way Selection QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.03 - Discover how to use the selection control structures if and if . . . else DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 1:46 AM 22. When one control statement is located within another, it is said to be ____. a. blocked b. compound c. nested d. closed ANSWER: c FEEDBACK: a. Incorrect. There is no such term called blocked control statement. b. Incorrect. A sequence of statements enclosed within a curly brace is known as a compound statement. c. Correct. When a control statement is placed inside another control statement, it is called nested. d. Incorrect. There is no such term called closed control statement.

POINTS: 1 REFERENCES: 208 – Multiple Selections: Nested if QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.07 - Learn how relational operators work with the string type DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 2/27/2020 2:48 AM 23. Which of the following will cause a logical error if you are attempting to compare x to 5? a. if (x == 5) b. if (x = 5) if (x <= 5) c. d. if (x >= 5) ANSWER: FEEDBACK:

b a. Incorrect. Since the logical expression (x== 5) is used in the if statement, it will cause no logical error. b. Correct. Since the assignment expression (x = 5) is used in the if statement, it will cause a logical error. c. Incorrect. Since the logical expression (x <= 5) is used in the if statement, it will cause no logical error. d. Incorrect. Since the logical expression (x >= 5) is used in the if statement, it will cause no logical error.

Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 4 POINTS: 1 REFERENCES: 222 – Confusion between the Equality Operator (==) and the Assignment Operator (=) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.12 - Learn how to avoid bugs by avoiding partially understood concepts DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 1:49 AM 24. Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y / x > 0) ? x : y;. a. 2 b. 3 c. 4 d. 6 ANSWER: a FEEDBACK: a. Correct. In the given conditional expression, (y / x > 0) evaluates to true, thus the result is x; that is, 2. b. Incorrect. In the given conditional expression, (y / x > 0) evaluates to true, thus the result is x; that is, 2. c. Incorrect. In the given conditional expression, (y / x > 0) evaluates to true, thus the result is x; that is, 2. d. Incorrect. In the given conditional expression, (y / x > 0) evaluates to true, thus the result is x; that is, 2. POINTS: 1 REFERENCES: 223 – Conditional Operator (?:) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.09 - Learn how the conditional operator, ?:, works DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 1:51 AM 25. What is the value of x after the following statements execute? int x; x = (5 <= 3 && 'A' < 'F') ? 3 : 4 a. 2 b. 3 c. 4 d. 5 ANSWER: FEEDBACK:

c a. Incorrect. The expression (5 <= 3 && 'A' < 'F') evaluates to (false && true), which evaluates to false. Thus, the value assigned to x is 4. b. Incorrect. The expression (5 <= 3 && 'A' < 'F') evaluates to (false && true), which evaluates to false. Thus, the value assigned to x is 4. c. Correct. The expression (5 <= 3 && 'A' < 'F') evaluates to (false && true), which evaluates to false. Thus, the value assigned to x is 4. d. Incorrect. The expression (5 <= 3 && 'A' < 'F') evaluates to (false

Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 4 && true), which evaluates to false. Thus, the value assigned to x is 4. POINTS: 1 REFERENCES: 223 – Conditional Operator (?:) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.09 - Learn how the conditional operator, ?:, works DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 1:53 AM 26. What is the output of the following code? char lastInitial = 'S'; switch (lastInitial) { case 'A': cout << "section 1" <<endl; break; case 'B': cout << "section 2" <<endl; break; case 'C': cout << "section 3" <<endl; break; case 'D': cout << "section 4" <<endl; break; default: cout << "section 5" <<endl; } a. section 2 c. section 4 ANSWER: FEEDBACK:

POINTS:

b. section 3 d. section 5 d a. Incorrect. The value of lastInitial is 'S' and it does not match with any case label. So the statement following the default label will be executed. Thus, the output is: section 5 b. Incorrect. The value of lastInitial is 'S' and it does not match with any case label. So the statement following the default label will be executed. Thus, the output is: section 5 c. Incorrect. The value of lastInitial is 'S' and it does not match with any case label. So the statement following the default label will be executed. Thus, the output is: section 5 d. Correct. The value of lastInitial is 'S' and it does not match with any case label. So the statement following the default label will be executed. Thus, the output is: section 5 1

Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 4 REFERENCES: 227-229 – switch Structures QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.11 - Discover how to use a switch statement in a program DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 2:12 AM 27. What is the output of the following C++ code? int x = 55; int y = 5; switch (x % 7) { case 0: case 1: y++; case 2: case 3: y = y + 2; case 4: break; case 5: case 6: y = y – 3; } cout << y << endl; a. 2 b. 5 c. 8 d. 10 ANSWER: FEEDBACK:

a a. Correct. In the switch statement, the value of the expression x % 7 is 55 % 7, which evaluates to 6. Thus, the value of the x % 7 matches with the case label 6. So the statement y = y – 3 will be executed, that is, y = 5 - 3 = 2. So the output of the C++ code is: 2 b. Incorrect. In the switch statement, the value of the expression x % 7 is 55 % 7, which evaluates to 6. Thus, the value of the x % 7 matches with the case label 6. So the statement y = y – 3 will be executed, that is, y = 5 - 3 = 2. So the output of the C++ code is: 2 c. Incorrect. In the switch statement, the value of the expression x % 7 is 55 % 7, which evaluates to 6. Thus, the value of the x % 7 matches with the case label 6. So the statement y = y – 3 will be executed, that is, y = 5 - 3 = 2. So the output of the C++ code is: 2 d. Incorrect. In the switch statement, the value of the expression x % 7 is 55 %

Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 4 7, which evaluates to 6. Thus, the value of the x % 7 matches with the case label 6. So the statement y = y – 3 will be executed, that is, y = 5 - 3 = 2. So the output of the C++ code is: 2 POINTS: 1 REFERENCES: 227-230 – switch Structures QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.11 - Discover how to use a switch statement in a program DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 2:14 AM 28. For a program to use the assert function, it must include which of the following preprocessor command? a. #include <asserts> b. #include <cassert> c. #include <assertc> d. #include NDEBUG ANSWER: FEEDBACK:

b a. Incorrect. C++ does not have asserts header file. b. Correct. To use the function assert in a program, the preprocessor command #include <cassert> must be included in the program. c. Incorrect. C++ does not have assertc header file. d. Incorrect. C++ does not have NDEBUG header file. Moreover, in the include statement the name of a header file is enclosed between < and >. The header #include NDEBUG is not the appropriate header for using the function assert in a program.

POINTS: 1 REFERENCES: 238 – Terminating a Program with the assert Function QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.13 - Learn to use the assert function to terminate a program DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 2:16 AM 29. Which of the following will cause a logical error if you are attempting to compare x to 5? a. if (x == 5) b. if (x = 5) c. if (x <= 5) d. if (x >= 5) ANSWER: b FEEDBACK: a. Incorrect. Since a logical expression (x == 5) is used inside an if statement, it will cause no logical error. b. Correct. Since an assignment expression (x = 5) is used inside an if statement, it will cause a logical error. c. Incorrect. Since a logical expression (x <= 5) is used inside an if statement, it will cause no logical error. d. Incorrect. Since a logical expression (x >= 5) is used inside an if statement, it will cause no logical error. Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 4 POINTS: 1 REFERENCES: 222 – Confusion between the Equality Operator (==) and the Assignment Operator (=) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.12 - Learn how to avoid bugs by avoiding partially understood concepts DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 2:19 AM 30. You can disable assert statements by using which of the following preprocessor command? a. #include <cassert> b. #define <assert> c. #clear NDEBUG d. #define NDEBUG ANSWER: FEEDBACK:

d a. Incorrect. This statement includes the header file cassert in the program. b. Incorrect. The correct statement is: #define NDEBUG c. Incorrect. The correct statement is: #define NDEBUG d. Correct. The preprocessor command #define NDEBUG is used to disable assert statements in a program.

POINTS: 1 REFERENCES: 238 – Terminating a Program with the assert Function QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.04.13 - Learn to use the assert function to terminate a program DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 3/13/2020 2:20 AM 31. The value of the expression 7 + 8 <= 15 is ____________________. ANSWER: true True POINTS: 1 REFERENCES: 200-201 – Logical (Boolean) Operators and Logical Expressions QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.04.06 - Explore how to form and evaluate logical (Boolean) expressions DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 2/27/2020 3:24 AM 32. Putting ____________________ in front of a logical expression reverses the value of that logical expression. ANSWER: ! POINTS: 1 REFERENCES: 200 – Logical (Boolean) Operators and Logical Expressions QUESTION TYPE: Completion Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 4 HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.04.06 - Explore how to form and evaluate logical (Boolean) expressions DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 2/27/2020 3:33 AM 33. The value of the expression 6 < 5 || 'g' > 'a' && 7 < 4 is ____________________. ANSWER: false False POINTS: 1 REFERENCES: 200-201 – Logical (Boolean) Operators and Logical Expressions QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.04.06 - Explore how to form and evaluate logical (Boolean) expressions DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 2/27/2020 3:43 AM 34. Suppose found = true and num = 6. The value of the expression (!found) || (num > 6) is ____________________. ANSWER: false False POINTS: 1 REFERENCES: 200-201 – Logical (Boolean) Operators and Logical Expressions QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.04.06 - Explore how to form and evaluate logical (Boolean) expressions DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 2/27/2020 3:35 AM 35. The ____________________ of relational and logical operators is said to be from left to right. ANSWER: associativity POINTS: 1 REFERENCES: 202 – Order of Precedence QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.04.06 - Explore how to form and evaluate logical (Boolean) expressions DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 2/27/2020 3:36 AM 36. Putting a semicolon after the parentheses following the expression in an if statement (that is, before the statement) is Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 4 a(n) ____________________ error. ANSWER: semantic POINTS: 1 REFERENCES: 194 – SELECTION: if AND if . . . else QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.04.03 - Discover how to use the selection control structures if and if . . . else DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 2/27/2020 3:38 AM 37. Consider the following statements. int score; string grade; if (score >= 65) grade = "pass"; else grade = "fail"; If score is equal to 75, the value of grade is "____________________". pass ANSWER: POINTS: 1 REFERENCES: 195 – Two-Way Selection QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.04.03 - Discover how to use the selection control structures if and if . . . else DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 2/27/2020 3:40 AM 38. The term ____________________ describes a process in which the computer evaluates a logical expression from left to right and stops as soon as the value of the expression is known. ANSWER: short-circuit evaluation short circuit evaluation POINTS: 1 REFERENCES: 212 – Multiple Selections: Nested if QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.04.08 - Become aware of short-circuit evaluation DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 2/27/2020 3:41 AM 39. Once an input stream enters a(n) ____________________ state, all subsequent input statements associated with that Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 4 input stream are ignored, and the computer continues to execute the program, which produces erroneous results. ANSWER: fail POINTS: 1 REFERENCES: 218-219 – Input Failure and the if Statement QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.04.12 - Learn how to avoid bugs by avoiding partially understood concepts DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 2/27/2020 3:42 AM 40. In a switch statement, if the value of the expression does not match any of the case values, the statements following the ____________________ label execute. default ANSWER: POINTS: 1 REFERENCES: 228 – switch Structures QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.04.11 - Discover how to use a switch statement in a program DATE CREATED: 10/5/2016 1:38 PM DATE MODIFIED: 2/27/2020 3:42 AM

Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 5 1. In the following while loop, statement acts as a decision maker. while (expression) statement a. True b. False ANSWER: False FEEDBACK: Correct

In this while loop, statement does not act as a decision maker. expression acts as a decision maker. Incorrect In this while loop, statement does not act as a decision maker. expression acts as a decision maker.

POINTS: 1 REFERENCES: 269 – while Looping (Repetition) Structure QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.02 - Learn how to use a while loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 2:39 AM 2. The following while loop terminates when j > 20. j = 0; while (j < 20) j++; a. True b. False ANSWER: FEEDBACK:

False Correct

In this C++ code, j is initialized to 0. If j < 20, the body of the while loop executes. Each time the body of the loop executes, the value of j is incremented by 1. Therefore, when j becomes 20, the loop terminates.

Incorrect In this C++ code, j is initialized to 0. If j < 20, the body of the while loop

executes. Each time the body of the loop executes, the value of j is incremented by 1. Therefore, when j becomes 20, the loop terminates. POINTS: 1 REFERENCES: 269 – while Looping (Repetition) Structure QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.02 - Learn how to use a while loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 2:42 AM 3. The number of iterations of a counter-controlled loop is known in advance. Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 5 a. True b. False ANSWER: FEEDBACK:

True Correct

When you know exactly how many times certain statements execute, typically, a counter-controlled loop is used. Incorrect When you know exactly how many times certain statements execute, typically, a counter-controlled loop is used.

POINTS: 1 REFERENCES: 303 – for Looping (Repetition) Structure QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.04 - Learn how to use a for loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 12:20 AM 4. Assume all variables are properly declared. The output of the following C++ code is 2 3 4 5. n = 1; while (n < 5) { n++; cout << n << " "; } cout << endl; a. True b. False ANSWER: True FEEDBACK: Correct

Before the while loop, n is initialized to 1. If n < 5, the body of the while loop executes. Each time the body of the while loop execute, first it increments the value of n by 1, and then outputs the value of n. Because n is initialized to 1 before the while loop, the first output is 2. When n is 4, n < 5 is true and the body of the while loop executes. So it increments n to 5 and then outputs the value of n. When n is 5, n < 5 is false and the loop terminates. Therefore, the output is 2 3 4 5.

Incorrect Before the while loop, n is initialized to 1. If n < 5, the body of the while

loop executes. Each time the body of the while loop execute, first it increments the value of n by 1, and then outputs the value of n. Because n is initialized to 1 before the while loop, the first output is 2. When n is 4, n < 5 is true and the body of the while loop executes. So it increments n to 5 and then outputs the value of n. When n is 5, n < 5 is false and the loop terminates. Therefore, the output is 2 3 4 5. POINTS: REFERENCES: QUESTION TYPE:

1 271 – while Looping (Repetition) Structure True / False

Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 5 HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.02 - Learn how to use a while loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 2:43 AM 5. In a counter-controlled while loop, the loop control variable must be initialized before the loop. a. True b. False ANSWER: True FEEDBACK: Correct The loop control variable must be initialized before a counter-controlled while loop. Incorrect The loop control variable must be initialized before a counter-controlled while loop. POINTS: 1 REFERENCES: 274 – Case 1: Counter-Controlled while Loops QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.03 - Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and EOF-controlled repetition structures DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 2:44 AM 6. In the case of a sentinel-controlled while loop, the first item is read before the while loop is entered. a. True b. False ANSWER: True FEEDBACK: Correct In the case of a sentinel-controlled while loop, the first item is read before the while loop so that the loop test expression (decision maker) will have a valid value to evaluate the loop test expression. Incorrect In the case of a sentinel-controlled while loop, the first item is read before the while loop so that the loop test expression (decision maker) will have a valid value to evaluate the loop test expression. POINTS: 1 REFERENCES: 277 – Case 2: Sentinel-Controlled while Loops QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.03 - Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and EOF-controlled repetition structures DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 2:47 AM 7. In a sentinel-controlled while loop, the body of the loop continues to execute until the EOF symbol is read. a. True Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 5 b. False ANSWER: FEEDBACK:

False In a sentinel-controlled while loop, loop continues to execute as long as the program has not read the sentinel. Incorrect In a sentinel-controlled while loop, loop continues to execute as long as the program has not read the sentinel. Correct

POINTS: 1 REFERENCES: 277 – Case 2: Sentinel-Controlled while Loops7 QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.03 - Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and EOF-controlled repetition structures DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 2:49 AM 8. The loop control variable in a flag-controlled while loop is a bool variable. a. True b. False ANSWER: True FEEDBACK: Correct A flag-controlled while loop uses a bool variable to control the loop. Incorrect A flag-controlled while loop uses a bool variable to control the loop.

POINTS: 1 REFERENCES: 283 – Case 3: Flag-Controlled while Loops QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.03 - Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and EOF-controlled repetition structures DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 2:50 AM 9. The control statements in the for loop include the initial statement, loop condition, and update statement. a. True b. False ANSWER: True FEEDBACK: Correct The control statements in the for loop include the initial statement, loop condition, and update statement. Incorrect The control statements in the for loop include the initial statement, loop condition, and update statement. POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 298 – for Looping (Repetition) Structure True / False False

Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 5 LEARNING OBJECTIVES: PDDS.MALI.05.04 - Learn how to use a for loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 2:52 AM 10. Assume that all variables are properly declared. The following for loop executes 20 times. for (i = 0; i <= 20; i++) cout << i; a. True b. False ANSWER: False FEEDBACK: Correct The initial statement of the loop is i = 0; and the loop condition is i <= 20; the loop executes 21 times. Incorrect The initial statement of the loop is i = 0; and the loop condition is "i

<= 20; the loop executes 21 times. POINTS: 1 REFERENCES: 299 – for Looping (Repetition) Structure QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.04 - Learn how to use a for loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:59 AM 11. In ____ structures, the computer repeats particular statements a certain number of times depending on some condition(s). a. looping b. branching c. selection d. sequence ANSWER: a FEEDBACK: a. Correct. A computer system repeats a specific statement a specific number of times based on some conditions in a looping structure. b. Incorrect. A branching structure can make a computer system to start executing a different instruction sequence and so deviate from its default behavior of executing instructions. c. Incorrect. A selection structure selects a specific statement based on some case conditions. d. Incorrect. A sequence structure usually does not repeat a specific statement a specific number of times based on some conditions.

POINTS: 1 REFERENCES: 268 – Why Is Repetition Needed? QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.01 - Learn about repetition (looping) control structures DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 12:44 AM Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 5 12. What is the output of the following C++ code? count = 1; num = 25; while (count < 25) { num = num - 1; count++; } cout << count << " " << num << endl; a. 24 0 c. 25 0 ANSWER: FEEDBACK:

b. 24 1 d. 25 1 d a. Incorrect. Before the while loop, count is initialized to 1 and num is initialized to 25. If count < 25, the body of the while loop executes. Each time the body of the while loop executes, first it decrements the value of num by 1, and then increments the value of count by 1. If count is 1, then num is 25; if count is 2, then num is 24; and so on. The loop terminates when count is 25. When count is 25, num is 1. Therefore, the output is: 25 1 b. Incorrect. Before the while loop, count is initialized to 1 and num is initialized to 25. If count < 25, the body of the while loop executes. Each time the body of the while loop executes, first it decrements the value of num by 1, and then increments the value of count by 1. If count is 1, then num is 25; if count is 2, then num is 24; and so on. The loop terminates when count is 25. When count is 25, num is 1. Therefore, the output is: 25 1 c. Incorrect. Before the while loop, count is initialized to 1 and num is initialized to 25. If count < 25, the body of the while loop executes. Each time the body of the while loop executes, first it decrements the value of num by 1, and then increments the value of count by 1. If count is 1, then num is 25; if count is 2, then num is 24; and so on. The loop terminates when count is 25. When count is 25, num is 1. Therefore, the output is: 25 1 d. Correct. Before the while loop, count is initialized to 1 and num is initialized to 25. If count < 25, the body of the while loop executes. Each time the body of the while loop executes, first it decrements the value of num by 1, and then increments the value of count by 1. If count is 1, then num is 25; if count is 2, then num is 24; and so on. The loop terminates when count is 25. When count is 25, num is 1. Therefore, the output is: 25 1

POINTS: 1 REFERENCES: 271 – while Looping (Repetition) Structure QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.02 - Learn how to use a while loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 2:57 AM 13. What is the output of the following C++ code? Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 5 num = 10; while (num > 10) num = num - 2; cout << num << endl; a. 0 b. 6 c. 8 d. 10 ANSWER: FEEDBACK:

d a. Incorrect. Before the while loop, num is initialized to 10. If num > 10, the body of the while loop executes. Because num = 10 and 10 > 10 is false, the body of the while loop does not execute. The next statement executed is the cout statement, which outputs the value of num, which is 10. Therefore, the output is: 10 b. Incorrect. Before the while loop, num is initialized to 10. If num > 10, the body of the while loop executes. Because num = 10 and 10 > 10 is false, the body of the while loop does not execute. The next statement executed is the cout statement, which outputs the value of num, which is 10. Therefore, the output is: 10 c. Incorrect. Before the while loop, num is initialized to 10. If num > 10, the body of the while loop executes. Because num = 10 and 10 > 10 is false, the body of the while loop does not execute. The next statement executed is the cout statement, which outputs the value of num, which is 10. Therefore, the output is: 10 d. Correct. Before the while loop, num is initialized to 10. If num > 10, the body of the while loop executes. Because num = 10 and 10 > 10 is false, the body of the while loop does not execute. The next statement executed is the cout statement, which outputs the value of num, which is 10. Therefore, the output is: 10

POINTS: 1 REFERENCES: 271 – while Looping (Repetition) Structure QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.02 - Learn how to use a while loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 2:59 AM 14. A loop that continues to execute endlessly is called a(n) ____ loop. a. end b. unhinged c. infinite d. definite ANSWER: c FEEDBACK: a. Incorrect. There is no termend loop in C++. b. Incorrect. There is no termunhinged loop in C++. c. Correct. An infinite loop is the loop that continues to run endlessly. d. Incorrect. There is no term definite loop in C++. Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 5 POINTS: 1 REFERENCES: 269 – while Looping (Repetition) Structure QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.02 - Learn how to use a while loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 12:56 AM 15. Consider the following code. int limit, triple, entry; int reps = 0; cin >> limit; while (reps < limit) { cin >> entry; triple = entry * 3; cout << triple; reps++; } cout << endl; This code is an example of a(n) ____ while loop. a. flag-controlled b. counter-controlled c. EOF-controlled d. sentinel-controlled ANSWER: b FEEDBACK: a. Incorrect. Before the while loop, reps is initialized to 0 and the cin statement inputs an int value in limit. If reps < limit, the body of the while loop executes. Each iteration of the while loop, if any, increments the value of reps by 1. So reps acts as a counter. It is a counter-controlled while loop. b. Correct. Before the while loop, reps is initialized to 0 and the cin statement inputs an int value in limit. If reps < limit, the body of the while loop executes. Each iteration of the while loop, if any, increments the value of reps by 1. So reps acts as a counter. It is a counter-controlled while loop. c. Incorrect. Before the while loop, reps is initialized to 0 and the cin statement inputs an int value in limit. If reps < limit, the body of the while loop executes. Each iteration of the while loop, if any, increments the value of reps by 1. So reps acts as a counter. It is a counter-controlled while loop. d. Incorrect. Before the while loop, reps is initialized to 0 and the cin statement inputs an int value in limit. If reps < limit, the body of the while loop executes. Each iteration of the while loop, if any, increments the value of reps by 1. So reps acts as a counter. It is a counter-controlled while loop. Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 5 POINTS: 1 REFERENCES: 274 – Case 1: Counter-Controlled while Loops QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.03 - Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and EOF-controlled repetition structures DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:02 AM 16. Suppose sum and num are int variables, and the input is 18 25 61 6 -1. What is the output of the following code? sum = 0; cin >> num; while (num != -1) { sum = sum + num; cin >> num; } cout << sum << endl; a. 92 b. 109 c. 110 d. 119 ANSWER: FEEDBACK:

c a. Incorrect. Before the while loop sum is initialized to 0 and cin statement inputs the first value, 18, into num. So before the execution of the while loop sum = 0 and num = 18. If the value of num is not equal to -1, the body of the while loop executes. Each iteration of the while loop first updates the value of sum by adding to its value the value of num and then the cin statements inputs the next value into num. After reading 6 into num, the loop condition is evaluated and because 6 is not equal to -1, the loop body executes. After updating the value of sum by adding 6, the cin statements reads -1 and stores it into num. So now num is -1, loop condition fails and the loop terminates. Essentially, the while loop stores the sum of 18, 25, 61, and 6, which is 110, into sum. The cout statement outputs the value of sum. Thus, the output is: 110 b. Incorrect. Before the while loop sum is initialized to 0 and cin statement inputs the first value, 18, into num. So before the execution of the while loop sum = 0 and num = 18. If the value of num is not equal to -1, the body of the while loop executes. Each iteration of the while loop first updates the value of sum by adding to its value the value of num and then the cin statements inputs the next value into num. After reading 6 into num, the loop condition is evaluated and because 6 is not equal to -1, the loop body executes. After updating the value of sum by adding 6, the cin statements reads -1 and stores it into num. So now num is -1, loop condition fails and the loop terminates. Essentially, the while loop stores the sum of 18, 25, 61, and 6, which is 110, into sum. The cout statement outputs the value of sum. Thus, the output is: 110 c. Correct. Before the while loop sum is initialized to 0 and cin statement inputs

Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 5 the first value, 18, into num. So before the execution of the while loop sum = 0 and num = 18. If the value of num is not equal to -1, the body of the while loop executes. Each iteration of the while loop first updates the value of sum by adding to its value the value of num and then the cin statements inputs the next value into num. After reading 6 into num, the loop condition is evaluated and because 6 is not equal to -1, the loop body executes. After updating the value of sum by adding 6, the cin statements reads -1 and stores it into num. So now num is -1, loop condition fails and the loop terminates. Essentially, the while loop stores the sum of 18, 25, 61, and 6, which is 110, into sum. The cout statement outputs the value of sum. Thus, the output is: 110 d. Incorrect. Before the while loop sum is initialized to 0 and cin statement inputs the first value, 18, into num. So before the execution of the while loop sum = 0 and num = 18. If the value of num is not equal to -1, the body of the while loop executes. Each iteration of the while loop first updates the value of sum by adding to its value the value of num and then the cin statements inputs the next value into num. After reading 6 into num, the loop condition is evaluated and because 6 is not equal to -1, the loop body executes. After updating the value of sum by adding 6, the cin statements reads -1 and stores it into num. So now num is -1, loop condition fails and the loop terminates. Essentially, the while loop stores the sum of 18, 25, 61, and 6, which is 110, into sum. The cout statement outputs the value of sum. Thus, the output is: 110 POINTS: 1 REFERENCES: 270-272 – while Looping (Repetition) Structure QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.02 - Learn how to use a while loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:12 AM 17. A(n) ____-controlled while loop uses a bool variable to control the loop. a. counter b. sentinel c. flag d. EOF ANSWER: c FEEDBACK: a. Incorrect. A counter-controlled while loop uses a counter to control the loop. b. Incorrect. A sentinel-controlled while loop uses a sentinel value to control the loop. c. Correct. A flag-controlled while loop uses a bool value to control the loop. d. Incorrect. A EOF-controlled while loop uses the value returned by input stream variable, such as cin to control the loop. POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 283 – Case 2: Sentinel-Controlled while Loops Multiple Choice False

Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 5 LEARNING OBJECTIVES: PDDS.MALI.05.03 - Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and EOF-controlled repetition structures DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:14 AM 18. Which of the following statements generates a random number between 0 and 50? a. srand(time(0)); b. srand(time(10)); num = rand() % 50; num = rand()/50; c. srand(time(0)); d. srand(time(10)); num = rand()50; num = rand() % 50; ANSWER: FEEDBACK:

a a. Correct. To generate a random number between 0 and 50, use the statements srand(time(0)); and num = rand() % 50. b. Incorrect. The expression time(10) will result in syntax error. Also, the value expression rand() / 50 will not necessarily be between 0 and 50. c. Incorrect. The expression rand()50; will result in syntax error because there is no arithmetic operator between rand() and 50. To generate a random number between 0 and 50, use the expression rand() % 50. d. Incorrect. The expression time(10) will result in syntax error

POINTS: 1 REFERENCES: 284 – Number Guessing Game QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.03 - Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and EOF-controlled repetition structures DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 4/20/2020 11:40 AM 19. Consider the following code. (Assume that all variables are properly declared.) cin >> ch; while (cin) { cout << ch; cin >> ch; } This code is an example of a(n) ____ while loop. a. sentinel-controlled b. flag-controlled c. EOF-controlled d. counter-controlled ANSWER: c FEEDBACK: a. Incorrect. The while loop uses the input stream variable cin to control the body of the loop. This is an EOF-controlled while loop. b. Incorrect. The while loop uses the input stream variable cin to control the body of the loop. This is an EOF-controlled while loop. Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 5 c. Correct. The while loop uses the input stream variable cin to control the body of the loop. This is an EOF-controlled while loop. d. Incorrect. The while loop uses the input stream variable cin to control the body of the loop. This is an EOF-controlled while loop. POINTS: 1 REFERENCES: 287 – Case 4: EOF-Controlled while Loops QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.03 - Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and EOF-controlled repetition structures DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:20 AM 20. What is the next Fibonacci number in the following sequence? 1, 1, 2, 3, 5, 8, 13, 21, ... a. 34 b. 43 c. 56 d. 273 ANSWER: FEEDBACK:

a a. Correct. In the Fibonacci sequence, the nth number is given by an= an-1+ an-2

when n ≥ 3. In this Fibonacci sequence, the first 8 numbers are given and a8 = 21 and a7 = 13. Therefore, the next number in the sequence is a9 = a9-1 + a9-2 = a8 + a7 = 21 + 13 = 34. b. Incorrect. In the Fibonacci sequence, the nth number is given by an= an-1+ an-2 when n ≥ 3. In this Fibonacci sequence, the first 8 numbers are given and a8 = 21 and a7 = 13. Therefore, the next number in the sequence is a9 = a9-1 + a9-2 = a8 + a7 = 21 + 13 = 34. Thus, 43 is not the correct option. c. Incorrect. In the Fibonacci sequence, the nth number is given by an= an-1+ an-2 when n ≥ 3. In this Fibonacci sequence, the first 8 numbers are given and a8 = 21 and a7 = 13. Therefore, the next number in the sequence is a9 = a9-1 + a9-2 = a8 + a7 = 21 + 13 = 34. Thus, 56 is not the correct option. d. Incorrect. In the Fibonacci sequence, the nth number is given by an= an-1+ an-2 when n ≥ 3. In this Fibonacci sequence, the first 8 numbers are given and a8 = 21 and a7 = 13. Therefore, the next number in the sequence is a9 = a9-1 + a9-2 = a8 + a7 = 21 + 13 = 34. Thus, 273 is not the correct option.

POINTS: 1 REFERENCES: 293 – More on Expressions in while Statements QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.03 - Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and EOF-controlled repetition structures DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 1:18 AM 21. What is the initial statement in the following for loop? (Assume that all variables are properly declared.) Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 5 int i; for (i = 1; i < 20; i++) cout << "Hello World"; cout << "!" << endl; a. i = 1; c. i++; ANSWER: FEEDBACK:

b. i < 20; d. cout << "Hello World"; a a. Correct. In this for loop, the initial statement is i = 1;. b. Incorrect. In this for loop, the initial statement is i = 1;. The statement i < 20; is the loop condition. c. Incorrect. In this for loop, the initial statement is i = 1;. The statement i++; is the update statement. d. Incorrect. In this for loop, the initial statement is i = 1;. The statement cout << "Hello World"; is the output statement.

POINTS: 1 REFERENCES: 298 – for Looping (Repetition) Structure QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.04 - Learn how to use a for loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:23 AM 22. What is the output of the following C++ code? int j; for (j = 10; j <= 10; j++) cout << j << " "; cout << j << endl; a. 10 c. 10 11 ANSWER: FEEDBACK:

b. 10 10 d. 11 11 c a. Incorrect. The initial statement in the for loop initializes j to 10. Because 10 <= 10 is true, the for loop body executes, which outputs 10. Next, the update statement, j++, increments the value of j by 1, and so now the value of j is 11. Because 11 <=10 is false, the for loop terminates. The statement following the for loop is the second cout statement, which output the value of j, that is, 11. Therefore, the output of this C++ code is: 10 11 b. Incorrect. The initial statement in the for loop initializes j to 10. Because 10 <= 10 is true, the for loop body executes, which outputs 10. Next, the update statement, j++, increments the value of j by 1, and so now the value of j is 11. Because 11 <=10 is false, the for loop terminates. The statement following the for loop is the second cout statement, which output the value of

Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 5 j, that is, 11. Therefore, the output of this C++ code is: 10 11 c. Correct. The initial statement in the for loop initializes j to 10. Because 10 <= 10 is true, the for loop body executes, which outputs 10. Next, the update statement, j++, increments the value of j by 1, and so now the value of j is 11. Because 11 <=10 is false, the for loop terminates. The statement following the for loop is the second cout statement, which output the value of j, that is, 11. Therefore, the output of this C++ code is: 10 11 d. Incorrect. The initial statement in the for loop initializes j to 10. Because 10 <= 10 is true, the for loop body executes, which outputs 10. Next, the update statement, j++, increments the value of j by 1, and so now the value of j is 11. Because 11 <=10 is false, the for loop terminates. The statement following the for loop is the second cout statement, which output the value of j, that is, 11. Therefore, the output of this C++ code is: 10 11 POINTS: 1 REFERENCES: 299 – for Looping (Repetition) Structure QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.04 - Learn how to use a for loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:25 AM 23. Suppose sum, num, and j are int variables, and the input is 4 7 12 9 -1. What is the output of the following code? cin >> sum; cin >> num; for (j = 1; j <= 3; j++) { cin >> num; sum = sum + num; } cout << sum << endl; a. 24 b. 25 c. 41 d. 42 ANSWER: FEEDBACK:

a a. Correct. The first cin statement reads and stores the first input value into sum and the second cin statement reads and stores the second input value into num. Therefore, before the for loop, sum = 4 and num = 7. Next, in the for loop, the initial statement initializes j = 1. Because 1 <= 3 is true, the for loop body executes. The for loop executes three times and each iteration of the for loop first reads and stores a number into num and then updates the value of sum by adding to its value, the value of num. Note that before executing the body of the for loop, the first value read and stores into num is 7. However, during the first iteration of the for loop, the next value is read and stored into num. Therefore, in the first iteration of the for loop, the value of num is 12, which is

Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 5 added to the value of sum. After the for loop terminates, sum = 4 + 12 + 9 - 1 = 24. Therefore, the cout statement outputs: 24. b. Incorrect. The first cin statement reads and stores the first input value into sum and the second cin statement reads and stores the second input value into num. Therefore, before the for loop, sum = 4 and num = 7. Next, in the for loop, the initial statement initializes j = 1. Because 1 <= 3 is true, the for loop body executes. The for loop executes three times and each iteration of the for loop first reads and stores a number into num and then updates the value of sum by adding to its value, the value of num. Note that before executing the body of the for loop, the first value read and stores into num is 7. However, during the first iteration of the for loop, the next value is read and stored into num. Therefore, in the first iteration of the for loop, the value of num is 12, which is added to the value of sum. After the for loop terminates, sum = 4 + 12 + 9 - 1 = 24. Therefore, the cout statement outputs: 24. c. Incorrect. The first cin statement reads and stores the first input value into sum and the second cin statement reads and stores the second input value into num. Therefore, before the for loop, sum = 4 and num = 7. Next, in the for loop, the initial statement initializes j = 1. Because 1 <= 3 is true, the for loop body executes. The for loop executes three times and each iteration of the for loop first reads and stores a number into num and then updates the value of sum by adding to its value, the value of num. Note that before executing the body of the for loop, the first value read and stores into num is 7. However, during the first iteration of the for loop, the next value is read and stored into num. Therefore, in the first iteration of the for loop, the value of num is 12, which is added to the value of sum. After the for loop terminates, sum = 4 + 12 + 9 - 1 = 24. Therefore, the cout statement outputs: 24. d. Incorrect. The first cin statement reads and stores the first input value into sum and the second cin statement reads and stores the second input value into num. Therefore, before the for loop, sum = 4 and num = 7. Next, in the for loop, the initial statement initializes j = 1. Because 1 <= 3 is true, the for loop body executes. The for loop executes three times and each iteration of the for loop first reads and stores a number into num and then updates the value of sum by adding to its value, the value of num. Note that before executing the body of the for loop, the first value read and stores into num is 7. However, during the first iteration of the for loop, the next value is read and stored into num. Therefore, in the first iteration of the for loop, the value of num is 12, which is added to the value of sum. After the for loop terminates, sum = 4 + 12 + 9 - 1 = 24. Therefore, the cout statement outputs: 24. POINTS: 1 REFERENCES: 298-299 – for Looping (Repetition) Structure QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.04 - Learn how to use a for loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:31 AM Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 5 24. Suppose j, sum, and num are int variables, and the input is 26 34 61 4 -1. What is the output of the code? sum = 0; cin >> num; for (int j = 1; j <= 4; j++) { sum = sum + num; cin >> num; } cout << sum << endl; a. 124 b. 125 c. 126 d. 127 ANSWER: FEEDBACK:

b a. Incorrect. Before the for loop, sum is initialized to 0 and the first cin statement reads and stores the first input value into num. Therefore, before the for loop, sum = 0 and num = 26. Next, in the for loop, the initial statement initializes j = 1. Because 1 <= 4 is true, the for loop body executes. The for loop executes four times and each iteration of the for loop first updates the value of sum by adding, to its value, the value of num, and then reads and stores the next number into num. Before the fourth iteration of the for loop, num is 4. Therefore, in the fourth iteration, j = 4, and first the value of sum is updated and then the next value is read and stored into num. That is, at the end of the fourth iteration num is -1. Then j becomes 5 and because 5 <= 4 is false, the loop terminates. This C++ code output the sum of the numbers 26, 34, 61, and 4, which is 125. b. Correct. Before the for loop, sum is initialized to 0 and the first cin statement reads and stores the first input value into num. Therefore, before the for loop, sum = 0 and num = 26. Next, in the for loop, the initial statement initializes j = 1. Because 1 <= 4 is true, the for loop body executes. The for loop executes four times and each iteration of the for loop first updates the value of sum by adding, to its value, the value of num, and then reads and stores the next number into num. Before the fourth iteration of the for loop, num is 4. Therefore, in the fourth iteration, j = 4, and first the value of sum is updated and then the next value is read and stored into num. That is, at the end of the fourth iteration num is -1. Then j becomes 5 and because 5 <= 4 is false, the loop terminates. This C++ code output the sum of the numbers 26, 34, 61, and 4, which is 125. c. Incorrect. Before the for loop, sum is initialized to 0 and the first cin statement reads and stores the first input value into num. Therefore, before the for loop, sum = 0 and num = 26. Next, in the for loop, the initial statement initializes j = 1. Because 1 <= 4 is true, the for loop body executes. The for loop executes four times and each iteration of the for loop first updates the value of sum by adding, to its value, the value of num, and then reads and stores the next number into num. Before the fourth iteration of the for loop, num is 4. Therefore, in the fourth iteration, j = 4, and first the value of sum is updated and then the next value is read and stored into num. That is, at the end of the fourth iteration num is -1. Then j becomes 5 and because 5 <= 4 is false,

Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 5 the loop terminates. This C++ code output the sum of the numbers 26, 34, 61, and 4, which is 125. d. Incorrect. Before the for loop, sum is initialized to 0 and the first cin statement reads and stores the first input value into num. Therefore, before the for loop, sum = 0 and num = 26. Next, in the for loop, the initial statement initializes j = 1. Because 1 <= 4 is true, the for loop body executes. The for loop executes four times and each iteration of the for loop first updates the value of sum by adding, to its value, the value of num, and then reads and stores the next number into num. Before the fourth iteration of the for loop, num is 4. Therefore, in the fourth iteration, j = 4, and first the value of sum is updated and then the next value is read and stored into num. That is, at the end of the fourth iteration num is 1. Then j becomes 5 and because 5 <= 4 is false, the loop terminates. This C++ code output the sum of the numbers 26, 34, 61, and 4, which is 125. POINTS: 1 REFERENCES: 298-299 – for Looping (Repetition) Structure QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.04 - Learn how to use a for loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:34 AM 25. Which of the following is a repetition structure in C++? a. if b. switch c. while...do d. do...while ANSWER: FEEDBACK:

d a. Incorrect. In C++, if is a branching structure. b. Incorrect. In C++, switch is a selection structure. c. Incorrect. In C++, while...do is not a repetition structure. d. Correct. In C++, do...while is a repetition structure.

POINTS: 1 REFERENCES: 309 – do...while Looping (Repetition) Structure QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.05 - Learn how to use a do ... while loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:36 AM 26. Which executes first in a do...while loop? a. body of the loop b. loop condition c. the expression d. break statement ANSWER:

a

Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 5 FEEDBACK:

a. Correct. In a do...while loop, the body of the loop is executed first. b. Incorrect. In a do...while loop, loop condition is executed after executing the body of the loop. c. Incorrect. In a do...while loop, the expression, which is usually the loop condition is executed after executing the body of the loop. d. Incorrect. A do...while loop may or may not have a break statement.

POINTS: 1 REFERENCES: 309 – do...while Looping (Repetition) Structure QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.05 - Learn how to use a do ... while loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:37 AM 27. What is the value of x after the following statements execute? int x = 5; int y = 30; do x = x * 2; while (x < y); a. 5 b. 10 c. 20 d. 40 ANSWER: FEEDBACK:

d a. Incorrect. Before the loop, x = 5 and y = 30. The loop terminates when x >= y. Every iteration of the loop executes the statement x = x * 2;, and this statement is executed three times. Therefore, when the loop terminates, x = 40. b. Incorrect. Before the loop, x = 5 and y = 30. The loop terminates when x >= y. Every iteration of the loop executes the statement x = x * 2;, and this statement is executed three times. Therefore, when the loop terminates, x = 40. c. Incorrect. Before the loop, x = 5 and y = 30. The loop terminates when x >= y. Every iteration of the loop executes the statement x = x * 2;, and this statement is executed three times. Therefore, when the loop terminates, x = 40. d. Correct. Before the loop, x = 5 and y = 30. The loop terminates when x >= y. Every iteration of the loop executes the statement x = x * 2;, and this statement is executed three times. Therefore, when the loop terminates, x = 40.

POINTS: 1 REFERENCES: 309 – do...while Looping (Repetition) Structure QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.05 - Learn how to use a do ... while loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:39 AM Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 5 28. What is the output of the following loop? count = 5; cout << 'St'; do { cout << 'o'; count--; } while (count <= 5); a. St c. Stop ANSWER: FEEDBACK:

b. Sto d. This is an infinite loop. d a. Incorrect. Since the value of count is always less than or equal to 5, the do...while loop executes infinitely. Thus, the output is not St. b. Incorrect. Since the value of count is always less than or equal to 5, the do...while loop executes infinitely. Thus, the output is not Sto. c. Incorrect. Since the value of count is always less than or equal to 5, the do...while loop executes infinitely. Thus, the output is not Stop. d. Correct. Since the value of count is always less than or equal to 5, the do...while loop executes infinitely.

POINTS: 1 REFERENCES: 309 – do...while Looping (Repetition) Structure QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.05 - Learn how to use a do ... while loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:41 AM 29. ____ loops are called posttest loops. a. break b. for c. while d. do...while ANSWER: FEEDBACK:

d a. Incorrect. The break statement is not a loop. b. Incorrect. In a for loop the loop condition is executed before the body of the loop. Thus, for loop is called pretest loop. c. Incorrect. In a whileloop the loop condition is executed before the body of the loop. Thus, while loop is called pretest loop. d. Correct. In a do...while loop body is executed before executing the loop condition (expression). Thus, do...while loop is called aposttest loop.

POINTS:

1

Copyright Cengage Learning. Powered by Cognero.

Page 19


Name:

Class:

Date:

Chapter 5 REFERENCES: 310 – do...while Looping (Repetition) Structure QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.05 - Learn how to use a do ... while loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:43 AM 30. Which of the following loops does not have an entry condition? a. EOF-controlled while loop b. sentinel-controlled while loop c. do...while loop d. for loop ANSWER: FEEDBACK:

c a. Incorrect. The EOF-controlled while loop has an entry condition and the body of this loop may never execute. b. Incorrect. The sentinel-controlled while loop has an entry condition and the body of this loop may never execute. c. Correct. The do...while loop does not have an entry condition but has an exit condition. d. Incorrect. The for loop has an entry condition and the body of this loop may never execute.

POINTS: 1 REFERENCES: 310 – do...while Looping (Repetition) Structure QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.05 - Learn how to use a do ... while loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:45 AM 31. Which of the following loops is guaranteed to execute at least once? a. counter-controlled while loop b. for loop c. do...while loop d. sentinel-controlled while loop ANSWER: c FEEDBACK: a. Incorrect. In a counter-controlled while loop, the expression (loop condition) is executed before executing the body of the loop. Therefore, a counter-controlled while loop may not execute at all. b. Incorrect. In a for loop, the loop condition is executed before executing the body of the loop. Therefore, a for loop may not execute at all. c. Correct. In a do...while loop, the loop body is executed before executing the expression (loop condition). Therefore, a do...while loop executes at least once. d. Incorrect. In a sentinel-controlled while loop, the expression (loop condition) is executed before executing the body of the loop. Therefore, a sentinel-controlled while loop may not execute at all. POINTS:

1

Copyright Cengage Learning. Powered by Cognero.

Page 20


Name:

Class:

Date:

Chapter 5 REFERENCES: 310 – do...while Looping (Repetition) Structure QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.05 - Learn how to use a do ... while loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:46 AM 32. In a loop, the ____ statement can be used to eliminate the use of certain (flag) variables. a. while b. switch c. break d. if ANSWER: c FEEDBACK: a. Incorrect. A while statement cannot be used as an expression (the loop condition) in a loop. b. Incorrect. A switch statement cannot be used as an expression (the loop condition) in a loop. c. Correct. The usage of "break" statement(s) can eliminate the usage of flag variables. d. Incorrect. An if statement cannot be used as an expression (the loop condition) in a loop. POINTS: 1 REFERENCES: 313 – break and continue Statements QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.06 - Examine break and continue statements DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:48 AM 33. What executes immediately after a continue statement is executed in a while and do-while loop? a. loop-continue test b. update statement c. the statement following the body of the loop. d. the body of the loop ANSWER: a FEEDBACK: a. Correct. In a while and do-while loop, the loop-continue test (expression) is executed immediately after a continue statement is executed. b. Incorrect. In a while and do-while loop, the loop-continue test (expression) is executed immediately after a continue statement is executed. Typically, the update statement is used to update the value of a variable. c. Incorrect. In a while and do-while loop, the loop-continue test (expression) is executed immediately after a continue statement is executed. d. Incorrect. In a while and do-while loop, the loop-continue test (expression) is executed immediately after a continue statement is executed. POINTS: REFERENCES: QUESTION TYPE:

1 315 – break and continue Statements Multiple Choice

Copyright Cengage Learning. Powered by Cognero.

Page 21


Name:

Class:

Date:

Chapter 5 HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.06 - Examine break and continue statements DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:50 AM 34. When a continue statement is executed in a ____, the update statement always executes. a. while loop b. for loop c. switch structure d. do...while loop ANSWER: b FEEDBACK: a. Incorrect. When a continue statement is executed in a while loop, the update statement may not always execute. b. Correct. When a continue statement is executed in a for loop, the update statement always executes. c. Incorrect. A continue statement is not used in a switch structure. d. Incorrect. When a continue statement is executed in a do...while loop, the update statement may not always execute. POINTS: 1 REFERENCES: 315 – break and continue Statements QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.05.06 - Examine break and continue statements DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:52 AM 35. To generate a random number, you can use the function rand from the header file ____________________. cstdlib ANSWER: POINTS: 1 REFERENCES: 284 – Number Guessing Game QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.05.03 - Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and EOF-controlled repetition structures DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 2:22 AM 36. The function eof is a member of the data type ____________________. istream ANSWER: POINTS: 1 REFERENCES: 287 – Case 4: EOF-Controlled while Loops QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic Copyright Cengage Learning. Powered by Cognero.

Page 22


Name:

Class:

Date:

Chapter 5 LEARNING OBJECTIVES: PDDS.MALI.05.03 - Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and EOF-controlled repetition structures DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 2:24 AM 37. A semicolon at the end of the for statement (just before the body of the loop) is a(n) ____________________ error. ANSWER: semantic POINTS: 1 REFERENCES: 300 – for Looping (Repetition) Structure QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.05.04 - Learn how to use a for loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 2:25 AM 38. In a while and for loop, the loop condition is evaluated before executing the body of the loop. Therefore, while and for loops are called ____________________ loops. ANSWER: pretest POINTS: 1 REFERENCES: 310 – do...while Looping (Repetition) Structure QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.05.05 - Learn how to use a do ... while loop in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 2:27 AM 39. The ____________________ statement is typically used for two purposes: • To exit early from a loop. • To skip the remainder of a switch structure. break ANSWER: POINTS: 1 REFERENCES: 313 – break and continue Statements QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.05.06 - Examine break and continue statements DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 2:28 AM 40. A loop ____________________ is a set of statements that remains true each time the loop body is executed. ANSWER: invariant Copyright Cengage Learning. Powered by Cognero.

Page 23


Name:

Class:

Date:

Chapter 5 POINTS: 1 REFERENCES: 324 – Avoiding Bugs by Avoiding Patches QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.05.08 - Learn how to avoid bugs by avoiding patches DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 2:30 AM

Copyright Cengage Learning. Powered by Cognero.

Page 24


Name:

Class:

Date:

Chapter 6 1. Using functions greatly enhances a program’s readability because it reduces the complexity of the function main. a. True b. False ANSWER: True FEEDBACK: Correct Usage of functions can enhance the readability of the program since it minimizes "main" function's complexity. Incorrect Usage of functions can enhance the readability of the program since it minimizes "main" function's complexity. POINTS: 1 REFERENCES: 348 – QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.01 - Learn about standard (predefined) functions and discover how to use them in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:14 AM 2. Once you write and properly debug a function, you can use it in the program (or different programs) again and again without having to rewrite the same code repeatedly. a. True b. False ANSWER: True FEEDBACK: Correct Once programmers write and debug a function appropriately, they can employ the function in the same program or different programs repeatedly without rewriting the function again. Incorrect Once programmers write and debug a function appropriately, they can employ the function in the same program or different programs repeatedly without rewriting the function again.

POINTS: 1 REFERENCES: 352 – User-Defined Functions QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.02 - Learn about user-defined functions DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 3:38 AM 3. If the formal parameter list of a function is empty, the parentheses after the function name are not needed. a. True b. False ANSWER: False FEEDBACK: Correct If the function's parameter list is empty, the parentheses are still required after the function name. Incorrect If the function's parameter list is empty, the parentheses are still required after the function name. Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 6 POINTS: 1 REFERENCES: 356 – Syntax: Actual Parameter List QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.03 - Examine value-returning functions, including actual and formal parameters DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 8:02 PM 4. The following function heading in a C++ program is valid: int funcExp(int u, char v, float g) a. True b. False ANSWER: True FEEDBACK: Correct The valid function heading is returnType FunctionName(Formal parameter list). Incorrect The valid function heading is returnType FunctionName(Formal parameter list). POINTS: 1 REFERENCES: 356 – Syntax: Actual Parameter List QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.03 - Examine value-returning functions, including actual and formal parameters DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:21 AM 5. The data type of a variable in a return statement must match the function type. a. True b. False ANSWER: True FEEDBACK: Correct The data type of the value that variable or expression computes must match the function type. Incorrect The data type of the value that variable or expression computes must match the function type.

POINTS: 1 REFERENCES: 356 – return Statement QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.04 - Explore how to construct and use a value-returning, user-defined function in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 8:07 PM Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 6 6. The execution of a return statement in a user-defined function terminates the program. a. True b. False ANSWER: False FEEDBACK: Correct Execution of a return statement in the main function results in the program termination. The execution of a return statement in a user-defined function terminates the function. Incorrect Execution of a return statement in the main function results in the program termination. The execution of a return statement in a user-defined function terminates the function. POINTS: 1 REFERENCES: 357 – return Statement QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.04 - Explore how to construct and use a value-returning, user-defined function in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:16 AM 7. In C++, a function prototype is the function heading without the body of the function. a. True b. False ANSWER: True FEEDBACK: Correct A function prototype is usually the function heading ending with a semicolon ";" without the function body. Incorrect A function prototype is usually the function heading ending with a semicolon ";" without the function body. POINTS: 1 REFERENCES: 360 – Function Prototype QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 5/11/2020 5:12 PM 8. Assume that all variables are properly declared. The following statement in a value-returning function is legal. if (x % 2 == 0) return x; else return x + 1; a. True b. False Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 6 ANSWER: FEEDBACK:

True Correct

If the value of x is an even number, it returns x; otherwise, it returns x + 1.

Incorrect If the value of x is an even number, it returns x; otherwise, it returns x + 1.

POINTS: 1 REFERENCES: 363 – Value-Returning Functions: Some Peculiarities QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:19 AM 9. The following return statement returns the value 10. return 10, 16; a. True b. False ANSWER: FEEDBACK:

False If a return statement has more than one expression, it returns only the value of the last expression. Therefore, this return statement returns 16. Incorrect If a return statement has more than one expression, it returns only the value of the last expression. Therefore, this return statement returns 16. Correct

POINTS: 1 REFERENCES: 363 – Value-Returning Functions: Some Peculiarities QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:22 AM 10. The function main is always compiled first, regardless of where in the program the function main is placed. a. True b. False ANSWER: False FEEDBACK: Correct When the main function is placed in the middle or at the end of the program, all function definitions appearing before the function main are compiled before the function main. Incorrect When the main function is placed in the middle or at the end of the program, all

function definitions appearing before the function main are compiled before the function main. POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 375 – Flow of Compilation and Execution True / False False

Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 6 LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:23 AM 11. The standard header file for the abs(x)function is ____. a. <cmath> b. <ioinput> c. <cctype> d. <cstdlib> ANSWER: a FEEDBACK: a. Correct. The function abs(x) is defined in the standard header file cmath. b. Incorrect. There is no standard header file called ioinput. It is defined in the header file cmath. c. Incorrect. The function abs(x is not defined in the standard header file cctype. It is defined in the header file cmath. d. Incorrect. The function abs(x) is not defined in the standard header file cstdlib.It is defined in the header file cmath. POINTS: 1 REFERENCES: 349 – Predefined Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.01 - Learn about standard (predefined) functions and discover how to use them in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 3:24 AM 12. To use the predefined function tolower, the program must include the header file ____. a. <cctype> b. <iostream> c. <cmath> d. <cstdlib> ANSWER: FEEDBACK:

a a. Correct. The predefined function tolower()is defined in the standard header file cctype. b. Incorrect. The predefined function tolower()is not defined in the standard header file <iostream>. It is defined in the header file cctype. c. Incorrect. The predefined function tolower()is not defined in the standard header file cmath. It is defined in the header file cctype. d. Incorrect. The predefined function tolower()is not defined in the standard header file cstdlib. It is defined in the header file cctype.

POINTS: 1 REFERENCES: 350 – Predefined Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.01 - Learn about standard (predefined) functions and discover how to use them in a program DATE CREATED: 10/5/2016 1:39 PM Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 6 DATE MODIFIED:

3/13/2020 4:00 AM

13. The output of the statement: cout << tolower('$') << endl; is ____. a. '$' b. '0' c. '1' d. An error, because you cannot use tolower with '$'. ANSWER: FEEDBACK:

a a. Correct The expression tolower(x) returns the lowercase value of x if x is uppercase; otherwise it returns x. Because '$' is not an uppercase, it returns '$'. Therefore, the output of the cout statement is: $ b. Incorrect. The expression tolower(x) returns the lowercase value of x if x is uppercase; otherwise it returns x. Because '$' is not an uppercase, it returns '$'. Therefore, the output of the cout statement is: $ c. Incorrect. The expression tolower(x) returns the lowercase value of x if x is uppercase; otherwise it returns x. Because '$' is not an uppercase, it returns '$'. Therefore, the output of the cout statement is: $ d. Incorrect. The expression tolower(x) returns the lowercase value of x if x is uppercase; otherwise it returns x. Because '$' is not an uppercase, it returns '$'. Therefore, the output of the cout statement is: $

POINTS: 1 REFERENCES: 350 – Predefined Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.01 - Learn about standard (predefined) functions and discover how to use them in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:02 AM 14. Assume the following. static_cast<int>('a') = 97 static_cast<int>('A') = 65 The output of the statement: cout << static_cast<int>(tolower('B')) << endl; is ____. a. 65 c. 96 ANSWER:

b. 67 d. 98 d

Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 6 FEEDBACK:

a. Incorrect. The expression tolower('B') evaluates to 'b', and the expression static_cast<int>('b') evaluates to 98. Therefore, the output of the cout statement is: 98 b. Incorrect. The expression tolower('B') evaluates to 'b', and the expression static_cast<int>('b') evaluates to 98. Therefore, the output of the cout statement is: 98 c. Incorrect. The expression tolower('B') evaluates to 'b', and the expression static_cast<int>('b') evaluates to 98. Therefore, the output of the cout statement is: 98 d. Correct. The expression tolower('B') evaluates to 'b', and the expression static_cast<int>('b') evaluates to 98. Therefore, the output of the cout statement is: 98

POINTS: 1 REFERENCES: 350 – Predefined Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.01 - Learn about standard (predefined) functions and discover how to use them in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:05 AM 15. The output of the statement: cout << pow(3.0, 2.0) + 5 << endl; is ____. a. 11.0 b. 12.0 c. 13.0 d. 14.0 ANSWER: FEEDBACK:

d a. Incorrect. The expression pow(3.0, 2.0) + 5 evaluates to 3.02.0 + 5 = 14.0. Therefore, the output of the cout statement is: 14.0 b. Incorrect. The expression pow(3.0, 2.0) + 5 evaluates to 3.02.0 + 5 = 14.0. Therefore, the output of the cout statement is: 14.0 c. Incorrect. The expression pow(3.0, 2.0) + 5 evaluates to 3.02.0 + 5 = 14.0. Therefore, the output of the cout statement is: 14.0 d. Correct. The expression pow(3.0, 2.0) + 5 evaluates to 3.02.0 + 5 = 14.0. Therefore, the output of the cout statement is: 14.0

POINTS: 1 REFERENCES: 350 – Predefined Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.01 - Learn about standard (predefined) functions and discover how to use them in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:07 AM 16. The output of the statement: Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 6 cout << pow(2.0, pow(3.0, 1.0)) << endl; is ____. a. 6.0 b. 7.0 c. 8.0 d. 9.0 ANSWER: FEEDBACK:

c a. Incorrect. The expression pow(2.0, pow(3.0, 1.0))evaluates to pow(2.0, 3.01.0) = pow(2.0, 3.0) = 2.03.0 = 8.0. Therefore, the output of the cout statement is: 8.0 b. Incorrect. The expression pow(2.0, pow(3.0, 1.0))evaluates to pow(2.0, 3.01.0) = pow(2.0, 3.0) = 2.03.0 = 8.0. Therefore, the output of the cout statement is: 8.0 c. Correct. The expression pow(2.0, pow(3.0, 1.0))evaluates to pow(2.0, 3.01.0) = pow(2.0, 3.0) = 2.03.0 = 8.0. Therefore, the output of the cout statement is: 8.0 d. Incorrect. The expression pow(2.0, pow(3.0, 1.0))evaluates to pow(2.0, 3.01.0) = pow(2.0, 3.0) = 2.03.0 = 8.0. Therefore, the output of the cout statement is: 8.0

POINTS: 1 REFERENCES: 350 – Predefined Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.01 - Learn about standard (predefined) functions and discover how to use them in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:08 AM 17. Functions that do not have a return type are called ____ functions. a. zero b. null c. void d. empty ANSWER: c FEEDBACK: a. Incorrect. Functions that do not have a return type are called void functions. Zero is not a function return type in C++. b. Incorrect. Functions that do not have a return type are called void functions. Null is not a function return type in C++. c. Correct. A function that does not have a return type is called a void function. d. Incorrect. Functions that do not have a return type are called void functions. Empty is not a function return type in C++. POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 353 – User-Defined Functions Multiple Choice False

Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 6 LEARNING OBJECTIVES: PDDS.MALI.06.02 - Learn about user-defined functions DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:09 AM 18. The heading of a function is also called a ____. a. title b. function signature c. function head d. function header ANSWER: d FEEDBACK: a. Incorrect. The heading of a function is also called a function header. b. Incorrect. The heading of a function is also called a function header. c. Incorrect. The heading of a function is also called a function header. d. Correct. The heading of a function is also called a function header. POINTS: 1 REFERENCES: 354 – Value-Returning Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.03 - Examine value-returning functions, including actual and formal parameters DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 8:57 PM 19. A variable or expression listed in a call to a function is called a(n) ____. a. formal parameter b. actual parameter c. data type d. type of the function ANSWER: b FEEDBACK: a. Incorrect. A variable or expression listed in a call to a function is called an actual parameter. A variable declared in a function heading is called a formal parameter. b. Correct. A variable or expression listed in a call to a function is called an actual parameter. c. Incorrect. A variable or expression listed in a call to a function is called an actual parameter. d. Incorrect. A variable or expression listed in a call to a function is called an actual parameter.

POINTS: 1 REFERENCES: 354 – Value-Returning Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.03 - Examine value-returning functions, including actual and formal parameters DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 9:02 PM 20. A variable listed in a function header is known as a(n) ____ parameter. a. actual b. local Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 6 c. formal ANSWER: FEEDBACK:

d. function c a. Incorrect. A variable listed in a function header is known as a formal parameter. A variable or an expression in a function call is called an actual parameter. b. Incorrect A variable listed in a function header is known as a formal parameter. A variable declared in a function body is called a local variable. c. Correct. A variable listed in a function header is known as a formal parameter.

d. Incorrect. A variable listed in a function header is known as a formal parameter. POINTS: 1 REFERENCES: 354 – Value-Returning Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.03 - Examine value-returning functions, including actual and formal parameters DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 9:06 PM 21. Given the following function: int next(int x) { return (x + 1); } what is the output of the following statement? cout << next(next(5)) << endl; a. 5 b. 6 c. 7 d. 8 ANSWER: FEEDBACK:

c

POINTS: REFERENCES: QUESTION TYPE:

1 360 – Syntax: return Statement Multiple Choice

a. Incorrect. The value returned by the function next is one more than the value of its formal parameter. Therefore, next(next(5)) = next(6) = 7. So the output of the cout statement is: 7 b. Incorrect. The value returned by the function next is one more than the value of its formal parameter. Therefore, next(next(5)) = next(6) = 7. So the output of the cout statement is: 7 c. Correct. The value returned by the function next is one more than the value of its formal parameter. Therefore, next(next(5)) = next(6) = 7. So the output of the cout statement is: 7 d. Incorrect. The value returned by the function next is one more than the value of its formal parameter. Therefore, next(next(5)) = next(6) = 7. So the output of the cout statement is: 7

Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 6 HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.04 - Explore how to construct and use a value-returning, user-defined function in a program DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:11 AM 22. Which of the following statement about function prototypes and function headers is true? a. PParameter names must be listed in the function prototype, but not necessarily in the function header. b. Function prototypes end with a semicolon, but function headers do not. c. Function headers should come before function prototypes. d. Function headers end with a semicolon, but function prototypes do not. ANSWER: b FEEDBACK: a. Incorrect. Function prototypes end with a semicolon, but function headers do not. Parameter names must be listed in the function header, but not necessarily in the function prototype. Parameter names must be listed in both the prototype and the header. b. Correct. Function prototypes end with a semicolon, but function headers do not.

c. Incorrect. Function prototypes should come before function headers. Function prototypes end with a semicolon, but function headers do not. d. Incorrect. Function prototypes end with a semicolon, but function headers do not.

POINTS: 1 REFERENCES: 361 – Function Prototype QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 9:15 PM 23. Given the following function prototype: int test(float, char); which of the following statements is valid? a. cout << test(12, &); b. cout << test("12.0", "&"); c. int u = test(5.0, '*'); d. cout << test("12", "&"); ANSWER: FEEDBACK:

c a. Incorrect. In the function call test(12, &), actual parameter & does not match with its corresponding formal parameter type, which is char. & must be enclosed in single quotes. b. Incorrect. In the function call test("12.0", "&"), both actual parameters do not match with their corresponding formal parameters type. "12.0" is string while its corresponding formal type is float; "&" is a string while its corresponding formal parameter type is char.

Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 6 c. Correct. In the function call test(5.0, '*'), both actual parameters match with their corresponding formal parameters type. d. Incorrect. In the function call test("12", "&"), both actual parameters do not match with their corresponding formal parameters type. "12" is string while its corresponding formal type is float; "&" is a string while its corresponding formal parameter type is char. POINTS: 1 REFERENCES: 361 – Syntax: Function Prototype QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:12 AM 24. A function prototype is ____. a. a definition, but not a declaration b. a declaration and a definition c. a declaration, but not a definition d. a comment line ANSWER: c FEEDBACK: a. Incorrect. A function prototype is a declaration, but not a definition. b. Incorrect. A function prototype is a declaration, but not a definition. c. Correct. A function prototype is a declaration, but not a definition. d. Incorrect. A function prototype is a declaration, but not a definition. In a program, a comment line is used to explain the source code; In a computer program, a comment line is used to explain the source code.

POINTS: 1 REFERENCES: 361 – Function Prototype QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 9:33 PM 25. Given the following function prototype: double tryMe(double, double); which of the following statements is valid? Assume that all variables are properly declared. a. cin >> tryMe(x); b. cout << tryMe(2.0, 3.0); c. cout << tryMe(tryMe(double, double), double); d. cout << tryMe(tryMe(float, float), float); ANSWER: FEEDBACK:

b a. Incorrect. The function tryMe has two formal parameters, while the function call tryMe(x) has only one parameter. Therefore, the function call tryMe(x) is

Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 6 invalid and will cause syntax error. b. Correct. This statement is valid. The function call tryMe(2.0, 3.0) has two actual parameters and they match with their corresponding formal parameters type. c. Incorrect. The function call tryMe(double, double) is invalid. In a function call, an actual parameter must be a variable or an expression and must match the type of its corresponding formal parameter. In the function call tryMe(double, double), double is data type, not a variable or an expression. d. Incorrect. The function call tryMe(float, float) is invalid. In a function call, an actual parameter must be a variable or an expression and must match the type of its corresponding formal parameter. In the function call tryMe(float, float), float is data type, not a variable or an expression. POINTS: 1 REFERENCES: 361-362 – Syntax: Function Prototype QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:13 AM 26. Given the function prototype: double testAlpha(int u, char v, double t); which of the following statements is legal? a. cout << testAlpha(5, 'A', 2); b. cout << testAlpha( int 5, char 'A', int 2); c. cout << testAlpha("5.0", 'A', "2.0"); d. cout << testAlpha(5.0, "65", 2.0); ANSWER: FEEDBACK:

a

POINTS:

1

a. Correct. This statement is valid. In the function call testAlpha(5, 'A', 2), the actual parameters matches with the types of their corresponding formal parameters. b. Incorrect. This statement is invalid. In a function call, only actual parameters are specified not their data type. c. Incorrect. This statement is invalid. In the function call testAlpha("5.0", 'A', "2.0"), "5.0" is a string while its corresponding formal parameter is of type int; "2.0" is a string while its corresponding formal parameter is of type double. d. Incorrect. This statement is invalid. In the function call testAlpha(5.0, "65", 2.0), 5.0 is a decimal number while its corresponding formal parameter is of type int; "65" is a string while its corresponding formal parameter is of type char.

Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 6 REFERENCES: 361-362 – Syntax: Function Prototype QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:14 AM 27. Given the function prototype: float test(int, int, int); which of the following statements is legal? a. cout << test(7, test(14, 23)); b. cout << test(test(7, 14), 23); c. cout << test(14, 23); d. cout << test(7, 14, 23); ANSWER: FEEDBACK:

d a. Incorrect. This statement is invalid. The function test has three formal parameters of type int. The function call test(14, 23) is invalid because this function call has only two actual parameters. Note that the function call test(7, test(14, 23)) also has only two actual parameters. b. Incorrect. This statement is invalid. The function test has three formal parameters of type int. The function call test(7, 14) is invalid because this function call has only two actual parameters. Note that the function call test(test(7, 14), 23) also has only two actual parameters. c. Incorrect. This statement is invalid. The function test has three formal parameters of type int. The function call test(14, 23) is invalid because this function call has only two actual parameters. d. Correct. This statement is valid. The function test has three formal parameters of type int. The function call test(7, 14, 23) has three actual parameters and their type matches with the types of their corresponding formal parameters.

POINTS: 1 REFERENCES: 361-362 – Syntax: Function Prototype QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:15 AM 28. Which of the following function prototypes is valid? a. int funcTest(int x, int y, float z){} b. funcTest(int x, int y, float){}; c. int funcTest(int, int y, float z) d. int funcTest(int, int, float); ANSWER:

d

Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 6 FEEDBACK:

a. Incorrect. In a function prototype, the function heading ends with a semicolon and does not have the function definition (body). In int funcTest(int x, int y, float z){}, the prototype does not end with a semicolon. Moreover, {} specifies the body of the function . b. Incorrect. In a function prototype, the function heading ends with a semicolon and does not have the function definition (body). In funcTest(int x, int y, float z){};, the function has no type, and {} specifies the body of the function . c. Incorrect. In a function prototype, the function heading ends with a semicolon and does not have the function definition (body). In int funcTest(int, int y, float z), the heading does not end with a semicolon. d. Correct. This is a valid function prototype. A valid function prototype must contain function data type, name of the function, the parameter list, and it should be ended with a semicolon.

POINTS: 1 REFERENCES: 361-362 – Syntax: Function Prototype QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:17 AM 29. Which of the following function prototypes is valid? a. int funcExp(int x, float v); b. funcExp(int x, float v){}; c. funcExp(void); d. int funcExp(x); ANSWER: FEEDBACK:

a a. Correct. This is a valid function prototype. A valid function prototype must contain function data type, name of the function, the parameter list, and it should be ended with a semicolon. b. Incorrect. In a function prototype, the function heading ends with a semicolon and does not have the function definition (body). In funcExp(int x, float v){};, the function funcExp does not have a type. Moreover, {} specifies the body of the function . c. Incorrect. In a function prototype, the function heading ends with a semicolon and does not have the function definition (body). In funcExp(void);, the function funcExp does not have a type. Moreover, a formal parameter cannot be of type void. d. Incorrect. This is an invalid statement. In the function prototype, the data type of the formal parameter x is not specified.

POINTS: REFERENCES: QUESTION TYPE:

1 361-362 – Syntax: Function Prototype Multiple Choice

Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 6 HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:18 AM 30. Given the following function prototype: int myFunc(int, int); which of the following statements is valid? Assume that all variables are properly declared. a. cin >> myFunc(y); b. cout << myFunc(myFunc(7, 8), 15); c. cin >> myFunc("2", "3"); d. cout << myFunc(myFunc(7), 15); ANSWER: FEEDBACK:

b a. Incorrect. The function myFunc has two formal parameters of type int. The function call myFunc(y) has only one actual parameter. So the function call myFunc(y)is invalid. b. Correct. This statement is valid. c. Incorrect. The function myFunc has two formal parameters of type int. In the function call myFunc("2", "3"), both actual parameters are of type string, not of type int. So the function call myFunc("2", "3")is invalid. d. Incorrect. The function myFunc has two formal parameters of type int. The function call myFunc(7) has only one actual parameter. So the function call myFunc(7)is invalid.

POINTS: 1 REFERENCES: 361-362 – Syntax: Function Prototype QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:19 AM 31. The statement: return 8, 10; returns the value ____. a. 8 b. 10 c. 18 d. 80 ANSWER: FEEDBACK:

b a. Incorrect. If a return statement has more than one expression, it returns only the value of the last expression. Therefore, this return statement returns 10. b. Correct. If a return statement has more than one expression, it returns only the value of the last expression. Therefore, this return statement returns 10. c. Incorrect. If a return statement has more than one expression, it returns only the value of the last expression. Therefore, this return statement returns 10. d. Incorrect. If a return statement has more than one expression, it returns only

Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 6 the value of the last expression. Therefore, this return statement returns 10. POINTS: 1 REFERENCES: 363 – Value-Returning Functions: Some Peculiarities QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:21 AM 32. The statement: return 37, y, 2 * 3; returns the value ____. a. 2 b. 3 c. y d. 6 ANSWER: FEEDBACK:

d a. Incorrect. If a return statement has more than one expression, it returns only the value of the last expression. Therefore, this return statement evaluates 2 * 3, which is 6, and returns 6. b. Incorrect. If a return statement has more than one expression, it returns only the value of the last expression. Therefore, this return statement evaluates 2 * 3, which is 6, and returns 6. c. Incorrect. If a return statement has more than one expression, it returns only the value of the last expression. Therefore, this return statement evaluates 2 * 3, which is 6, and returns 6. d. Correct. If a return statement has more than one expression, it returns only the value of the last expression. Therefore, this return statement evaluates 2 * 3, which is 6, and returns 6.

POINTS: 1 REFERENCES: 363 – Value-Returning Functions: Some Peculiarities QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:22 AM 33. The statement: return 2 * 3 + 1, 1 + 5; returns the value ____. a. 2 b. 3 c. 6 d. 7 ANSWER: FEEDBACK:

c a. Incorrect. If a return statement has more than one expression, it returns only the value of the last expression. Therefore, this return statement evaluates 1 + 5, which is 6, and returns 6. b. Incorrect. If a return statement has more than one expression, it returns only the value of the last expression. Therefore, this return statement evaluates 1 + 5, which is 6, and returns 6.

Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 6 c. Correct. If a return statement has more than one expression, it returns only the value of the last expression. Therefore, this return statement evaluates 1 + 5, which is 6, and returns 6. d. Incorrect. If a return statement has more than one expression, it returns only the value of the last expression. Therefore, this return statement evaluates 1 + 5, which is 6, and returns 6. POINTS: 1 REFERENCES: 363 – Value-Returning Functions: Some Peculiarities QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:24 AM 34. Given the following function: int strange(int x, int y) { if (x > y) return x + y; else return x – y; } what is the output of the following statement? cout << strange(4, 5) << endl; a. -1 b. 1 c. 9 d. 20 ANSWER: FEEDBACK:

a

POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 363 – Value-Returning Functions: Some Peculiarities Multiple Choice False

a. Correct. In the function call strange(4, 5), the value of x is 4 and the value of y is 5. Therefore, the expression x < y fails and the else part executes, which returns x - y, that is, the value -1. b. Incorrect. In the function call strange(4, 5), the value of x is 4 and the value of y is 5. Therefore, the expression x < y fails and the else part executes, which returns x - y, that is, the value -1. c. Incorrect. In the function call strange(4, 5), the value of x is 4 and the value of y is 5. Therefore, the expression x < y fails and the else part executes, which returns x - y, that is, the value -1. d. Incorrect. In the function call strange(4, 5), the value of x is 4 and the value of y is 5. Therefore, the expression x < y fails and the else part executes, which returns x - y, that is, the value -1.

Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 6 LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 5/11/2020 5:20 PM 35. What value is returned by the following return statement? int x = 5; return x + 1; a. 0 b. 5 c. 6 d. 7 ANSWER: FEEDBACK:

c a. Incorrect. The value of x is 5 and when the statement return x + 1; is executed, it returns the value 6. b. Incorrect. The value of x is 5 and when the statement return x + 1; is executed, it returns the value 6. c. Correct. The value of x is 5 and when the statement return x + 1; is executed, it returns the value 6. d. Incorrect. The value of x is 5 and when the statement return x + 1; is executed, it returns the value 6.

POINTS: 1 REFERENCES: 363 – Value-Returning Functions: Some Peculiarities QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.06.05 - Learn about function prototypes DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/13/2020 4:26 AM 36. When you attach & after the dataType in the formal parameter list of a function, the variable following that dataType becomes a(n) ____________________ parameter. ANSWER: reference POINTS: 1 REFERENCES: 380 – Void Functions QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.06.07 - Discover the difference between value and reference parameters DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 10:51 PM 37. ____________________ parameters are useful in three situations: • When the value of the actual parameter needs to be changed • When you want to return more than one value from a function • When passing the address would save memory space and time relative to copying a large amount of data Copyright Cengage Learning. Powered by Cognero.

Page 19


Name:

Class:

Date:

Chapter 6 ANSWER:

Reference reference POINTS: 1 REFERENCES: 386 – Reference Variables as Parameters QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.06.08 - Explore reference parameters and value-returning functions DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 10:55 PM 38. Stream variables (for example, ifstream and ofstream) should be passed by ____________________ to a function. ANSWER: reference POINTS: 1 REFERENCES: 390 – Value and Reference Parameters and Memory Allocation QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.06.08 - Explore reference parameters and value-returning functions DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 10:56 PM 39. If a function needs to return more than one value, as a rule of good programming style, you should change it to a(n) ____________________ function and use the appropriate reference parameters to return the values. ANSWER: void POINTS: 1 REFERENCES: 399 – Value and Reference Parameters and Memory Allocation QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.06.08 - Explore reference parameters and value-returning functions DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 10:57 PM 40. A function ____________________ is a function that is not fully coded. ANSWER: stub POINTS: 1 REFERENCES: 414 – Debugging: Using Drivers and Stubs QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.06.12 - Learn how to debug programs using drivers and stubs Copyright Cengage Learning. Powered by Cognero.

Page 20


Name:

Class:

Date:

Chapter 6 DATE CREATED: DATE MODIFIED:

10/5/2016 1:39 PM 3/3/2020 10:58 PM

41. The ____________________ of a function consists of the function name and its formal parameter list. ANSWER: signature POINTS: 1 REFERENCES: 416 – Function Overloading: An Introduction QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.06.13 - Learn function overloading DATE CREATED: 10/5/2016 1:39 PM DATE MODIFIED: 3/3/2020 11:00 PM

Copyright Cengage Learning. Powered by Cognero.

Page 21


Name:

Class:

Date:

Chapter 7 1. The following is a legal C++ enumeration type: enum colorType {BLUE, GREEN, PINK, YELLOW, RED}; a. True b. False ANSWER: True FEEDBACK: Correct The enumeration type colorType is valid. The general syntax to define an enumeration type is: enum typeName {value1, value2, ...};, where value1, value2, ... are C++ identifiers. Incorrect The enumeration type colorType is valid. The general syntax to define an

enumeration type is: enum typeName {value1, value2, ...};, where value1, value2, ... are C++ identifiers. POINTS: 1 REFERENCES: 469 – Enumeration Type QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.01 - Learn how to create your own simple data type—called the enumeration type DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/13/2020 4:21 AM 2. The following is a valid C++ enumeration type: enum places {1ST, 2ND, 3RD, 4TH};. a. True b. False ANSWER: False FEEDBACK: Correct Value belonging to an enumeration type are identifiers. Because 1st, 2nd, 3rd, and 4th are not valid C++ identifiers, the enumeration type places is not valid. Recall that a C++ identifier consists of letters, digits, and the underscore character and must begin with a letter or underscore. Incorrect Value belonging to an enumeration type are identifiers. Because 1st, 2nd, 3rd, and 4th are not valid C++ identifiers, the enumeration type places is not valid. Recall that a C++ identifier consists of letters, digits, and the underscore character and must begin with a letter or underscore. POINTS: 1 REFERENCES: 469 – Enumeration Type QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.01 - Learn how to create your own simple data type—called the enumeration type DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/13/2020 4:22 AM 3. No arithmetic operations are allowed on the enumeration type. Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 7 a. True b. False ANSWER: FEEDBACK:

True Correct The arithmetic operations are not allowed on the enumeration type. Incorrect The arithmetic operations are not allowed on the enumeration type.

POINTS: 1 REFERENCES: 471 – Operations on Enumeration Types QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.02 - Explore how the assignment statement, and arithmetic and relational operators work with enum types DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 4:32 AM 4. A function cannot return the value of an enumeration type. a. True b. False ANSWER: False FEEDBACK: Correct A function can return a value of the enumeration type. Incorrect Correct.

POINTS: 1 REFERENCES: 475 – Functions and Enumeration Types QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.06 Explore how to write functions to process enum types DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/4/2020 8:42 PM 5. An enumeration type can be passed as a parameter to a function only by value. a. True b. False ANSWER: False FEEDBACK: Correct The enumeration type can be passed as a parameter to a function either by value or by reference. Incorrect The enumeration type can be passed as a parameter to a function either by value or by reference.

POINTS: 1 REFERENCES: 475 – Functions and Enumeration Types QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.06 Explore how to write functions to process enum types Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 7 DATE CREATED: DATE MODIFIED:

10/5/2016 1:40 PM 3/4/2020 8:44 PM

6. An anonymous type can be passed as a parameter to a function. a. True b. False ANSWER: False FEEDBACK: Correct Because there is no name associated with an anonymous type, you cannot pass an anonymous type as a parameter to a function. Incorrect Because there is no name associated with an anonymous type, you cannot pass an anonymous type as a parameter to a function.

POINTS: 1 REFERENCES: 477 – Anonymous Data Types QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.08 - Become familiar with anonymous types DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/4/2020 8:46 PM 7. The following statement creates an anonymous type: enum {1ST, 2ND, 3RD, 4TH} places; a. True b. False ANSWER: False FEEDBACK: Correct Because the enumerators (values) 1st, 2nd, 3rd, and 4th are not valid C++ identifiers, this anonymous is not valid. Recall that a C++ identifier consists of letters, digits, and the underscore character and must begin with a letter or underscore. Incorrect Because the enumerators (values) 1st, 2nd, 3rd, and 4th are not valid C++ identifiers, this anonymous is not valid. Recall that a C++ identifier consists of letters, digits, and the underscore character and must begin with a letter or underscore. POINTS: 1 REFERENCES: 477 – Anonymous Data Types QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.08 - Become familiar with anonymous types DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/13/2020 4:25 AM 8. In C++, namespace is a reserved word. a. True b. False Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 7 ANSWER: FEEDBACK:

True In C++, namespace is a reserved word. Incorrect In C++, namespace is a reserved word. Correct

POINTS: 1 REFERENCES: 488 – Namespaces QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.10 - Learn about the namespace mechanism DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/13/2020 4:27 AM 9. The general syntax for accessing a namespace member is: namespace_name->identifier. a. True b. False ANSWER: False FEEDBACK: Correct The general syntax for accessing a namespace member is: namespace_name::identifier Incorrect The general syntax for accessing a namespace member is:

namespace_name::identifier POINTS: 1 REFERENCES: 488 – Namespaces QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.10 - Learn about the namespace mechanism DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/13/2020 4:28 AM 10. In C++, [] is called the array subscript operator. a. True b. False ANSWER: True FEEDBACK: Correct In C++, the square bracket [] is referred to as the array subscript operator. Incorrect In C++, the square bracket [] is referred to as the array subscript operator.

POINTS: 1 REFERENCES: 494 – string Type QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.11 - Explore the string data type, and learn how to use string functions to manipulate strings DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/13/2020 4:29 AM Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 7 11. Suppose that you have the following declaration. enum cars {FORD, GM, TOYOTA, HONDA}; cars domesticCars = FORD; The statement: domesticCars = static_cast<cars>(domesticCars + 1); sets the value of domesticCars to ____. a. FORD c. TOYOTA ANSWER: FEEDBACK:

b. GM d. HONDA b a. Incorrect. The statement domesticCars = static_cast<cars>(domesticCars + 1); advances the value of domesticCars to the next value in the list {FORD, GM, TOYOTA, HONDA}. Because the value of domesticCars is FORD and the next value in the list is GM, the previous statement assigns GM to domesticCars. b. Correct. The statement domesticCars = static_cast<cars>(domesticCars + 1); advances the value of domesticCars to the next value in the list {FORD, GM, TOYOTA, HONDA}. Because the value of domesticCars is FORD and the next value in the list is GM, the previous statement assigns GM to domesticCars. c. Incorrect. The statement domesticCars = static_cast<cars>(domesticCars + 1); advances the value of domesticCars to the next value in the list {FORD, GM, TOYOTA, HONDA}. Because the value of domesticCars is FORD and the next value in the list is GM, the previous statement assigns GM to domesticCars. d. Incorrect. The statement domesticCars = static_cast<cars>(domesticCars + 1); advances the value of domesticCars to the next value in the list {FORD, GM, TOYOTA, HONDA}. Because the value of domesticCars is FORD and the next value in the list is GM, the previous statement assigns GM to domesticCars.

POINTS: 1 REFERENCES: 468-470 – Enumeration Types QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.01 - Learn how to create your own simple data type—called the enumeration type DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 4:35 AM 12. Consider the declaration: enum sports {BASKETBALL, FOOTBALL, HOCKEY, BASEBALL, SOCCER}; Which of the following statements is true? Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 7 a. SOCCER-- = BASEBALL b. BASEBALL++ = SOCCER c. HOCKEY + FOOTBALL < SOCCER d. FOOTBALL <= SOCCER ANSWER: d FEEDBACK: a. Incorrect. The increment and decrement operators are not allowed in enumeration type. So, SOCCER-- = BASEBALL is an invalid statement. b. Incorrect. The increment and decrement operators are not allowed in enumeration type. So, BASEBALL++ = SOCCER is an invalid statement. c. Incorrect. The arithmetic operators are not allowed in enumeration type. So, HOCKEY+ FOOTBALL < SOCCER is an invalid statement. d. Correct. The relational operators can be used with the enumeration type because an enumeration is an ordered set of values. So, FOOTBALL <= SOCCER is a valid statement. POINTS: 1 REFERENCES: 471 – Relational Operators QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.02 - Explore how the assignment statement, and arithmetic and relational operators work with enum types DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/13/2020 4:35 AM 13. What is the output of the following code? enum courses {ALGEBRA, BASIC, PASCAL, PHILOSOPHY, ANALYSIS}; courses registered; registered = ALGEBRA; cout << registered << endl; a. ALGEBRA c. 1 ANSWER: FEEDBACK:

POINTS:

b. 0 d. "ALGEBRA" b a. Incorrect. Because ALGEBRA is the first value in the list, it is assigned the value 0. Also, the value of registered is ALGEBRA. Therefore, the statement cout << registered << endl; outputs: 0 b. Correct. Because ALGEBRA is the first value in the list, it is assigned the value 0. Also, the value of registered is ALGEBRA. Therefore, the statement cout << registered << endl; outputs: 0 c. Incorrect. Because ALGEBRA is the first value in the list, it is assigned the value 0. Also, the value of registered is ALGEBRA. Therefore, the statement cout << registered << endl; outputs: 0 d. Incorrect. Because ALGEBRA is the first value in the list, it is assigned the value 0. Also, the value of registered is ALGEBRA. Therefore, the statement cout << registered << endl; outputs: 0 1

Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 7 REFERENCES: 474 – Input/ Output of Enumeration Types QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.05 - Learn how to output data stored in an enum types DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/13/2020 4:37 AM 14. Which of the following statements declares the studentGrade variable? a. enum studentGrade {A, B, C, D, F}; b. enum int {A, B, C, D, F} studentGrade; c. enum studentGrade {A, B, C, D, F} grades; d. enum grades {A, B, C, D, F} studentGrade; ANSWER: FEEDBACK:

d a. Incorrect. The statement enum studentGrade {A, B, C, D, F}; only defines the enum type studentGrade. It does not declare the variable studentGrade. b. Incorrect. Because int is a reserved word in C++, it cannot be used as a userdefined identifier. Therefore, the statement enum int {A, B, C, D, F} studentGrade; is invalid. c. Incorrect. The statement enum studentGrade {A, B, C, D, F} grades; defines the enum type studentGrade and declares the variable grades of type studentGrade. It does not declare the variable studentGrade. d. Correct. The statement enum grades {A, B, C, D, F} studentGrade; defines the enum type grades and also declares the variable studentGrade of type grades.

POINTS: 1 REFERENCES: 476 – Declaring Variables When Defining the Enumeration Type QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.07 - Learn how to declare variables when defining the enumeration type DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/13/2020 4:39 AM 15. Which of the following statements creates an anonymous type? a. enum grades {A, B, C, D, F}; b. enum grades {}; c. enum {}; d. enum {A, B, C, D, F} grades; ANSWER: FEEDBACK:

d a. Incorrect. The statement enum grades {A, B, C, D, F}; defines the enum type grades. It is not an anonymous type. b. Incorrect. The statement enum grades {}; is illegal because the list {} is

Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 7 empty. If you specify value(s) in the list {}, then the new statement will define the enum type grades. It still will not be an anonymous type. c. Incorrect. The statement enum {}; is illegal because the list {} is empty. Moreover, the enum type has no name and/or no variable is declared in the enum statement. d. Correct. A data type wherein you directly specify values in the variable declaration with no type name is called an anonymous type. Therefore, the statement enum {A, B, C, D, F} grades; defines an anonymous type and declares the variable grades. POINTS: 1 REFERENCES: 477 – Anonymous Data Types QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.08 - Become familiar with anonymous types DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/13/2020 4:42 AM 16. In C++, you can create aliases to a previously defined data type by using the ____ statement. a. typedef b. using c. namespace d. alias ANSWER: FEEDBACK:

a a. Correct. Using the typedef statement, one can create synonyms or aliases to a previously defined data type. b. Incorrect. In C++, the using is a keyword It is used to simplify the accessing of a namespace member. c. Incorrect. In C++, namespace is a reserved word in C++. It is used to solve this problem of overlapping global identifier. d. Incorrect. In C++, there is no alias statement.

POINTS: 1 REFERENCES: 477 – typedef Statement QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.09 Become familiar with the typedef statement DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 2:46 AM 17. In C++, ____ is a reserved word. a. deftype b. typedef c. typecc d. alias ANSWER: FEEDBACK:

b a. Incorrect. The deftype is not a keyword in the C++. b. Correct. In C++, typedef is a reserved word. Using the typedef statement,

Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 7 one can create synonyms or aliases to a previously defined data type. c. Incorrect. The typecc is not a keyword in the C++. d. Incorrect. The alias is not a keyword in the C++. POINTS: 1 REFERENCES: 477 – typedef Statement QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.09 Become familiar with the typedef statement DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 2:47 AM 18. Which of the following is a valid C++ statement? a. typedef integer; b. typedef int; c. typedef int integer; d. typedef integer int; ANSWER: FEEDBACK:

c a. Incorrect. The general syntax of a typedef statement is: typedef existingTypeName newTypeName; Therefore, typedef integer; is not valid because an existing type name is not specified. b. Incorrect. The general syntax of a typedef statement is: typedef existingTypeName newTypeName; Therefore, typedef int; is not valid because new type name is not specified. c. Correct. The general syntax of a typedef statement is: typedef existingTypeName newTypeName; Therefore, typedef int integer; is valid. This statement defines integer to be an alias to the data type int. d. Incorrect. The general syntax of a typedef statement is: typedef existingTypeName newTypeName; Therefore, typedef integer int; is not valid because integer is not a predefined data type and int is a reserved word and cannot be redefined.

POINTS: 1 REFERENCES: 478 – typedef Statement QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.09 Become familiar with the typedef statement DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 2:49 AM 19. In C++, ____ is called the scope resolution operator. a. . b. ? c. : d. :: ANSWER: FEEDBACK:

d a. Incorrect. In C++, . is a class member access operator.

Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 7 b. Incorrect. In C++, ? is not a defined operator. It is used as part of the ternary operator?:. c. Incorrect. In C++, : symbol is used to create class inheritance. d. Correct. The scope of the namespace member is local to the namespace. One can access a namespace member outside the namespace by ::which means scope resolution operator. POINTS: 1 REFERENCES: 488 – Namespaces QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.10 - Learn about the namespace mechanism DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 2:50 AM 20. The scope of a namespace member is local to the ____. a. function b. block c. file d. namespace ANSWER: d FEEDBACK: a. Incorrect. The scope of a namespace member is local to the namespace. b. Incorrect. The scope of a namespace member is local to the namespace. c. Incorrect. The scope of a namespace member is local to the namespace. d. Correct. The scope of a namespace member is local to the namespace. POINTS: 1 REFERENCES: 488 – Namespaces QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.10 - Learn about the namespace mechanism DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 2:51 AM 21. Given the following code namespace globalType { void printResult(); } which of the following statements is needed to access printResult? a. globalType.printResult(); b. globalType.printResult; c. globalType::printResult(); d. globalType:printResult(); ANSWER:

c

Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 7 FEEDBACK:

a. Incorrect. The function printResult is member of the namespace globalType. A member of a namespace is accessed using the scope resolution operator, ::, not the dot (.) operator. b. Incorrect. The function printResult is member of the namespace globalType. A member of a namespace is accessed using the scope resolution operator, ::, not the dot (.) operator. Moreover, the function printResult must be called using the empty parentheses (). c. Correct. The function printResult is member of the namespace globalType. A member of a namespace is accessed using the scope resolution operator, ::. d. Incorrect. The function printResult is member of the namespace globalType. A member of a namespace is accessed using the scope resolution operator, ::, not :.

POINTS: 1 REFERENCES: 488 – Namespaces QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.10 - Learn about the namespace mechanism DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 2:55 AM 22. Which of the following statements is used to simplify the accessing of all globalType namespace members? a. using globalType; b. using namespace globalType:all; c. using namespace globalType::all; d. using namespace globalType; ANSWER: FEEDBACK:

d a. Incorrect. The syntax to simplify the accessing of all namespace members is: using namespace namespace_name; The statement using globalType; does not contain the reserved word namespace. b. Incorrect. The syntax to simplify the accessing of all namespace members is: using namespace namespace_name; The statement using namespace globalType:all; is illegal because it contains :all. c. Incorrect. The syntax to simplify the accessing of all namespace members is: using namespace namespace_name; The statement using namespace globalType::all; is illegal because it contains ::all. d. Correct. The syntax to simplify the accessing of all namespace members is: using namespace namespace_name; Therefore, the statement using namespace globalType; is correct.

POINTS: REFERENCES:

1 488-489 – Namespaces

Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 7 QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.10 - Learn about the namespace mechanism DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 3:02 AM 23. The identifiers in the system-provided header files such as iostream, cmath, and iomanip are defined in the namespace ____. a. cctype b. stdl c. std d. stdlib ANSWER: FEEDBACK:

c a. Incorrect. cctype is not a namespace. It is a header file in C++. b. Incorrect. stdl is not a namespace. c. Correct. The identifiers in the system-provided heard files such as iostream, cmath, and iomanip are defined in the namespace std. d. Incorrect. stdlib is not a namespace. In C++, the stdlib is the general purpose standard library header file.

POINTS: 1 REFERENCES: 492 – Namespaces QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.10 - Learn about the namespace mechanism DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 3:05 AM 24. Before using the data type string, the program must include the header file ____. a. enum b. iostream c. string d. std ANSWER: FEEDBACK:

c

POINTS:

1

a. Incorrect. The data type string is defined in the header file string. Therefore, before using the data type string, the program must include the header file string. The keyword enum is used to create user -defined simple data types. b. Incorrect. The data type string is defined in the header file string. Therefore, before using the data type string, the program must include the header file string. The header file iostream defines the standard input/output stream objects. c. Correct. A program must include the string header file before using the string datatype. d. Incorrect. The data type string is defined in the header file string. Therefore, before using the data type string, the program must include the header file string. In C++, std is a namespace, not a header file.

Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 7 REFERENCES: 492 – string Type QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.11 - Explore the string data type, and learn how to use string functions to manipulate strings DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 3:08 AM 25. Suppose str = "xyzw";. After the statement str[2] = 'Y'; The value of str is "____". a. xyzw b. xYzw c. xyYw d. xzYw ANSWER: FEEDBACK:

c a. Incorrect. In a string, the index of the first character is 0, the index (position) of the second character is 1, and so on. Therefore, the statement str[2] = 'Y'; replaces the character at index 2, that is, the third character of str with 'Y'. After the statement str[2] = 'Y'; the value of str is "xyYw". b. Incorrect. In a string, the index of the first character is 0, the index (position) of the second character is 1, and so on. Therefore, the statement str[2] = 'Y'; replaces the character at index 2, that is, the third character of str with 'Y'. After the statement str[2] = 'Y'; the value of str is "xyYw". c. Correct. In a string, the index of the first character is 0, the index (position) of the second character is 1, and so on. Therefore, the statement str[2] = 'Y'; replaces the character at index 2, that is, the third character of str with 'Y'. After the statement str[2] = 'Y'; the value of str is "xyYw". d. Incorrect. In a string, the index of the first character is 0, the index (position) of the second character is 1, and so on. Therefore, the statement str[2] = 'Y'; replaces the character at index 2, that is, the third character of str with 'Y'. After the statement str[2] = 'Y'; the value of str is "xyYw".

POINTS: 1 REFERENCES: 493 – string Type QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.11 - Explore the string data type, and learn how to use string functions to manipulate strings DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 5/11/2020 5:23 PM 26. Suppose that str1, str2, and str3 are string variables. After the following statements execute, the value of str3 is "____". str1 = "abc"; str2 = "xyz"; str3 = str1 + '-' + str2; a. abc b. xyz c. abc-xyz d. xyz-abc Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 7 ANSWER: FEEDBACK:

c a. Incorrect. The expression str1 + "-" + str2 concatenates str1 with ' ' followed by str2. Therefore, the value of str3 is: "abc-xyz" b. Incorrect. The expression str1 + "-" + str2 concatenates str1 with ' ' followed by str2. Therefore, the value of str3 is: "abc-xyz" c. Correct. The expression str1 + "-" + str2 concatenates str1 with ' ' followed by str2. Therefore, the value of str3 is: "abc-xyz" d. Incorrect. The expression str1 + "-" + str2 concatenates str1 with ' ' followed by str2. Therefore, the value of str3 is: "abc-xyz"

POINTS: 1 REFERENCES: 493 – string Type QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.11 - Explore the string data type, and learn how to use string functions to manipulate strings DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 3:11 AM 27. The data type string has a named constant, ____, associated with it. a. string::size b. string::size_type string::pos c. d. string::npos ANSWER: FEEDBACK:

d a. Incorrect. There is no named constant size in the data type string. b. Incorrect. There is no named constant size_type in the data type string. string::size_type is a data type defined in string type. c. Incorrect. There is no named constant pos in the data type string. d. Correct. string::npos is a named constant associated with the string data type.

POINTS: 1 REFERENCES: 496 – Additional string operations QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.11 - Explore the string data type, and learn how to use string functions to manipulate strings DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 3:13 AM 28. Suppose str = "ABCDEFGHI". The output of the statement cout << str.length() << endl; is ____. a. 7 c. 9

b. 8 d. 10

Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 7 ANSWER: FEEDBACK:

c a. Incorrect. The length method returns the string value. Here, the str contains "ABCDEFGHI", so the total length of the str is 9. b. Incorrect. The length method returns the string value. Here, the str contains "ABCDEFGHI", so the total length of the str is 9. c. Correct. The length method returns the string value. Here, the str contains "ABCDEFGHI", so the total length of the str is 9. d. Incorrect. The length method returns the string value. Here, the str contains "ABCDEFGHI", so the total length of the str is 9.

POINTS: 1 REFERENCES: 498 – Additional string operations QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.11 - Explore the string data type, and learn how to use string functions to manipulate strings DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 3:14 AM 29. The length of the string "Hello There. " is ____. a. 11 b. 12 c. 13 d. 14 ANSWER: c FEEDBACK: a. Incorrect. The length of the string "Hello There. " is 13 because the length of a string is the number of characters including whitespaces, if any, in it. This string has a space after o and another space after . (period). b. Incorrect. The length of the string "Hello There. " is 13 because the length of a string is the number of characters including whitespaces, if any, in it. This string has a space after o and another space after . (period). c. Correct. The length of the string "Hello There. " is 13 because the length of a string is the number of characters including whitespaces, if any, in it. This string has a space after o and another space after . (period). d. Incorrect. The length of the string "Hello There. " is 13 because the length of a string is the number of characters including whitespaces, if any, in it. This string has a space after o and another space after . (period). POINTS: 1 REFERENCES: 497-498 – Additional string operations QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.11 - Explore the string data type, and learn how to use string functions to manipulate strings DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 4:44 AM

Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 7 30. Consider the following statements: string str = "ABCDEFD"; string::size_type position; After the statement position = str.find('D'); executes, the value of position is ____. a. 3 b. 4 c. 6 d. 7 ANSWER: FEEDBACK:

a a. Correct. The expression str.find('D') returns the index of the first occurrence of 'D' in str. Now, str = "ABCDEFD", and so the first occurrence of 'D' is the fourth character in str. Therefore, the index of the first occurrence of 'D' in str is 3 because the index of the first character in str is 0. Thus, after the statement position = str.find('D'); executes, the value of position is 3. b. Incorrect. The expression str.find('D') returns the index of the first occurrence of 'D' in str. Now, str = "ABCDEFD", and so the first occurrence of 'D' is the fourth character in str. Therefore, the index of the first occurrence of 'D' in str is 3 because the index of the first character in str is 0. Thus, after the statement position = str.find('D'); executes, the value of position is 3. c. Incorrect. The expression str.find('D') returns the index of the first occurrence of 'D' in str. Now, str = "ABCDEFD", and so the first occurrence of 'D' is the fourth character in str. Therefore, the index of the first occurrence of 'D' in str is 3 because the index of the first character in str is 0. Thus, after the statement position = str.find('D'); executes, the value of position is 3. d. Incorrect. The expression str.find('D') returns the index of the first occurrence of 'D' in str. Now, str = "ABCDEFD", and so the first occurrence of 'D' is the fourth character in str. Therefore, the index of the first occurrence of 'D' in str is 3 because the index of the first character in str is 0. Thus, after the statement position = str.find('D'); executes, the value of position is 3.

POINTS: 1 REFERENCES: 500 – Additional string operations QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.11 - Explore the string data type, and learn how to use string functions to manipulate strings DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 3:18 AM 31. Considering the statement string str = "Gone with the wind";, the output of the statement cout << str.find("the") << endl; is ____. a. 9 b. 10 c. 11 d. 12 Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 7 ANSWER: FEEDBACK:

b a. Incorrect. The expression str.find("the") returns the index of the first occurrence of "the" in str. Now, str = "Gone with the wind ", and so the index of the first occurrence of "the" in str is 10 because the index of the first character in str is 0. Therefore, the cout statement outputs: 10 b. Correct. The expression str.find("the") returns the index of the first occurrence of "the" in str. Now, str = "Gone with the wind ", and so the index of the first occurrence of "the" in str is 10 because the index of the first character in str is 0. Therefore, the cout statement outputs: 10 c. Incorrect. The expression str.find("the") returns the index of the first occurrence of "the" in str. Now, str = "Gone with the wind ", and so the index of the first occurrence of "the" in str is 10 because the index of the first character in str is 0. Therefore, the cout statement outputs: 10 d. Incorrect. The expression str.find("the") returns the index of the first occurrence of "the" in str. Now, str = "Gone with the wind ", and so the index of the first occurrence of "the" in str is 10 because the index of the first character in str is 0. Therefore, the cout statement outputs: 10

POINTS: 1 REFERENCES: 500 – Additional string operations QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.11 - Explore the string data type, and learn how to use string functions to manipulate strings DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 3:20 AM 32. Consider the following statements: string str1 = "ABCDEFGHIJKLM"; string str2; After the statement str2 = str1.substr(1,4); executes, the value of str2 is ____. a. "ABCD" b. "BCDE" c. "BCD" d. "CDE" ANSWER: b FEEDBACK: a. Incorrect. The expression str1.substr(1,4) returns the substring of length 4 starting at index 1 in str1, which is "BCDE". Therefore, the value of str2 is "BCDE". b. Correct. The expression str1.substr(1,4) returns the substring of length 4 starting at index 1 in str1, which is "BCDE". Therefore, the value of str2 is "BCDE". c. Incorrect. The expression str1.substr(1,4) returns the substring of length 4 starting at index 1 in str1, which is "BCDE". Therefore, the value of str2 is "BCDE". d. Incorrect. The expression str1.substr(1,4) returns the substring of length 4 starting at index 1 in str1, which is "BCDE". Therefore, the value of str2 is Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 7 "BCDE". POINTS: 1 REFERENCES: 503-504 – Additional string operations QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.11 - Explore the string data type, and learn how to use string functions to manipulate strings DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 3:25 AM 33. The string function ____ function is used to interchange the contents of two string variables. a. iterator b. traverse c. swap d. change ANSWER: FEEDBACK:

c a. Incorrect. iterator is not a string function. b. Incorrect. traverse is not a string function. c. Correct. The string function swap function is used to interchange the contents of two string variables. d. Incorrect. change is not a string function.

POINTS: 1 REFERENCES: 505 – Additional string operations QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.11 - Explore the string data type, and learn how to use string functions to manipulate strings DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 3:26 AM 34. Consider the following statements: string str1 = "Gone with the wind"; string str2; After the statement str2 = str1.substr(5,4); executes, the value of str2 is "____". a. "Gone" b. "with" c. "the" d. "wind" ANSWER: FEEDBACK:

b a. Incorrect. The expression str1.substr(5,4) returns the substring of length 4 starting at index 5 in str1, which is "with". Therefore, the value of str2 is "with". Recall that the index of the first character in a string is 0. b. Correct. The expression str1.substr(5,4) returns the substring of length 4 starting at index 5 in str1, which is "with". Therefore, the value of str2 is "with". Recall that the index of the first character in a string is 0. c. Incorrect. The expression str1.substr(5,4) returns the substring of length

Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 7 4 starting at index 5 in str1, which is "with". Therefore, the value of str2 is "with". Recall that the index of the first character in a string is 0. d. Incorrect. The expression str1.substr(5,4) returns the substring of length 4 starting at index 5 in str1, which is "with". Therefore, the value of str2 is "with". Recall that the index of the first character in a string is 0. POINTS: 1 REFERENCES: 503-504 – Additional string operations QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.07.11 - Explore the string data type, and learn how to use string functions to manipulate strings DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 3:29 AM 35. The values in the domain of an enumeration type are called ____________________. ANSWER: enumerators POINTS: 1 REFERENCES: 469 – Enumeration Types QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.07.01 - Learn how to create your own simple data type—called the enumeration type DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/4/2020 11:47 PM 36. A data type wherein you directly specify values in the variable declaration with no type name is called a(n) ____________________type. ANSWER: anonymous POINTS: 1 REFERENCES: 477 – Anonymous Data Types QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.07.08 - Become familiar with anonymous types DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/4/2020 11:49 PM 37. In ANSI/ISO Standard C++, the ____________________ mechanism was designed to solve the problem of overlapping global identifiers. namespace ANSWER: POINTS: 1 REFERENCES: 487 – Namespaces Copyright Cengage Learning. Powered by Cognero.

Page 19


Name:

Class:

Date:

Chapter 7 QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.07.10 - Learn about the namespace mechanism DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/4/2020 11:50 PM 38. If a global identifier in a program has the same name as one of the global identifiers in the header file, the compiler generates a(n) ____________________ error. ANSWER: syntax POINTS: 1 REFERENCES: 487 – Namespaces QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.07.10 - Learn about the namespace mechanism DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/4/2020 11:52 PM 39. Suppose that str and strVar are string variables. The string expression strVar.____________________ inserts all the characters of str at index pos into strVar. insert(pos, str); ANSWER: POINTS: 1 REFERENCES: 497 – Additional string operations QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.07.11 - Explore the string data type, and learn how to use string functions to manipulate strings DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/4/2020 11:56 PM 40. Suppose that str and strVar are string variables. The string expression strVar.____________________, starting at index pos, replaces the next n characters of strVar with all the characters of str. strVar.replace(pos, n, str); ANSWER: POINTS: 1 REFERENCES: 497 – Additional string operations QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.07.11 - Explore the string data type, and learn how to use string functions to manipulate strings DATE CREATED: 10/5/2016 1:40 PM Copyright Cengage Learning. Powered by Cognero.

Page 20


Name:

Class:

Date:

Chapter 7 DATE MODIFIED:

3/4/2020 11:58 PM

Copyright Cengage Learning. Powered by Cognero.

Page 21


Name:

Class:

Date:

Chapter 8 1. All components of an array are of the same data type. a. True b. False ANSWER: True FEEDBACK: Correct An array is a collection of a fixed number of components all of the same data type. Incorrect An array is a collection of a fixed number of components all of the same data type.

POINTS: 1 REFERENCES: 523–Arrays QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.01 Learn the reasons for arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 1:41 AM 2. The array index can be any integer less than the array size. a. True b. False ANSWER: False FEEDBACK: Correct An array index is any expression whose value is a nonnegative integer. Incorrect An array index is any expression whose value is a nonnegative integer.

POINTS: 1 REFERENCES: 525–Accessing Array Components QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.02 Explore how to declare and manipulate data into arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 12:20 AM 3. The statement int list[25]; declares list to be an array of 26 components, since the array index starts at 0. a. True b. False ANSWER: False FEEDBACK: Correct The statement int list[25]; declares an array list of 25 components. The components are list[0], list[1], . . . , list[24]. Incorrect The statement int list[25]; declares an array list of 25 components. The

components are list[0], list[1], . . . , list[24]. POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 525–Accessing Array Components True / False False

Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 8 LEARNING OBJECTIVES: PDDS.MALI.08.02 Explore how to declare and manipulate data into arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 12:21 AM 4. Given the declaration int list[20]; the statement list[12] = list[5] + list[7]; updates the content of the 12thcomponent of the array list. a. True b. False ANSWER: False FEEDBACK: Correct Because the index of the first component of an array is 0, list[12] is the 13th component of the array list. Therefore, the statement list[12] = list[5] + list[7]; updates the content of the 13th component of the array list. Incorrect Because the index of the first component of an array is 0, list[12] is the 13th component of the array list. Therefore, the statement list[12] = list[5] + list[7]; updates the content of the 13th component of the array list. POINTS: 1 REFERENCES: 526–Accessing Array Components QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.02 Explore how to declare and manipulate data into arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 5/11/2020 5:31 PM 5. Suppose list is a one-dimensional array of size 25, wherein each component is of type int. Further, suppose that sum is an int variable. The following for loop correctly finds the sum of the elements of list. sum = 0; for (int i = 0; i < 25; i++) sum = sum + list; a. True b. False ANSWER: False FEEDBACK: Correct The value of the variable list is the base address of the array. Therefore, the statement sum = sum + list; is invalid. To correctly find the sum of the elements of list, replace this statement with sum = sum + list[i];. Note that sum is correctly initialized to 0 and the for loop variable i correctly ranges from 0 to 24. Incorrect The value of the variable list is the base address of the array. Therefore, the statement sum = sum + list; is invalid. To correctly find the sum of the elements of list, replace this statement with sum = sum + list[i];. Note Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 8 that sum is correctly initialized to 0 and the for loop variable i correctly ranges from 0 to 24. POINTS: 1 REFERENCES: 528–Processing One-Dimensional Arrays QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.02 Explore how to declare and manipulate data into arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 12:23 AM 6. If an array index goes out of bounds, the program always terminates in an error. a. True b. False ANSWER: False FEEDBACK: Correct C++ does not check whether the array index value is within range—that is, between 0 and ARRAY_SIZE - 1. If the index goes out of bounds and the program tries to access the component specified by the index, then whatever memory location is indicated by the index that location is accessed. Incorrect C++ does not check whether the array index value is within range—that is, between 0 and ARRAY_SIZE - 1. If the index goes out of bounds and the program tries to access the component specified by the index, then whatever memory location is indicated by the index that location is accessed. POINTS: 1 REFERENCES: 531–Array Index Out of Bounds QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.03 Understand the meaning of "array index out of bounds" DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 1:52 AM 7. Arrays can be passed as parameters to a function by value, but it is faster to pass them by reference. a. True b. False ANSWER: False FEEDBACK: Correct In C++, arrays are passed by reference only. Incorrect In C++, arrays are passed by reference only.

POINTS: 1 REFERENCES: 534–Arrays as Parameters to Functions QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.06 Discover how to pass an array as a parameter to a function Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 8 DATE CREATED: DATE MODIFIED:

10/5/2016 1:40 PM 3/4/2020 11:06 PM

8. When you pass an array as a parameter, the base address of the actual array is passed to the formal parameter. a. True b. False ANSWER: True FEEDBACK: Correct When you pass an array as a parameter, the base address of the actual array is passed to the formal parameter. Incorrect When you pass an array as a parameter, the base address of the actual array is passed to the formal parameter.

POINTS: 1 REFERENCES: 539–Base Address of an Array and Array in Computer Memory QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.06 Discover how to pass an array as a parameter to a function DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 12:27 AM 9. The one place where C++ allows aggregate operations on arrays is the input and output of C-strings. a. True b. False ANSWER: True FEEDBACK: Correct The one place where C++ allows aggregate operations on arrays is the input and output of C-strings. Incorrect The one place where C++ allows aggregate operations on arrays is the input and output of C-strings. POINTS: 1 REFERENCES: 556, 558–Reading and Writing Strings QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.13 Discover how to input data into – and output data from – a C-string DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 12:36 AM 10. In a two-dimensional array, the elements are arranged in a table form. a. True b. False ANSWER: True FEEDBACK: Correct In a two-dimensional array, the array elements are arranged in rows and columns in a tabular form. Incorrect In a two-dimensional array, the array elements are arranged in rows and columns Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 8 in a tabular form

POINTS: 1 REFERENCES: 575–Multidimensional Arrays QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.16 Learn about multidimensional arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/4/2020 11:15 PM 11. Which of the following statements declares alpha to be a one-dimensional array of 25 components of the type int? a. int alpha[25]; b. int array alpha[25]; c. int alpha[2][5]; d. int array alpha[25][25]; ANSWER: FEEDBACK:

a a. Correct. The statement int alpha[25]; declares the alpha to be a onedimensional of 25 components of the type int. b. Incorrect. The statement int array alpha[25]; is illegal in C++. The syntax to declare a one-dimensional array is dataType arrayName[intExp];. The correct statement is: int alpha[25]; c. Incorrect. The statement to declare a one-dimensional array alpha of 25 components is: int alpha[25];. The statement int alpha[2][5]; declares alpha to be a two-dimensional array of 10 components of type int. d. Incorrect. The statement to declare a one-dimensional array alpha of 25 components is: int alpha[25];. The statement int alpha[25][55]; declares alpha to be a two-dimensional array of 625 components of type int.

POINTS: 1 REFERENCES: 524–Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.02 Explore how to declare and manipulate data into arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 12:45 AM 12. Assume you have the following declaration char nameList[100];. Which of the following ranges is valid for the index of the array nameList? a. 0 through 99 b. 0 through 100 c. 1 through 100 d. 1 through 101 ANSWER: a FEEDBACK: a. Correct. The valid range for the index of the array nameList is 0 through 99. b. Incorrect. The valid range for the index of the array nameList is 0 through 99. c. Incorrect. The valid range for the index of the array nameList is 0 through 99. d. Incorrect. The valid range for the index of the array nameList is 0 through 99. Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 8 POINTS: 1 REFERENCES: 525–Accessing Array Components QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.02 Explore how to declare and manipulate data into arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 12:46 AM 13. Assume you have the following declaration int beta[50];. Which of the following is a valid element of beta? a. beta['2'] b. beta['50'] c. beta[0] d. beta[50] ANSWER: c FEEDBACK: a. Incorrect. The valid index range for beta is 0 through 49, and the index of an array must be a nonnegative integer. The ASCII value of '2' is 50. Therefore, the expression '2' evaluates to 50, and so beta['2'] refers to beta[50], which does not exist. beta[0] is a valid element of beta. b. Incorrect. The valid index range for beta is 0 through 49, and the index of an array must be a nonnegative integer. '50' cannot be evaluated to a nonnegative integer. Therefore, beta['50'] is invalid. beta[0] is a valid element of beta. c. Correct. The valid index range for beta is 0 through 49Thus, beta[0] is a valid element. d. Incorrect. The valid index range for beta is 0 through 49. beta[50] refers to the 51st component of beta, which does not exist. beta[0] is a valid element of beta. POINTS: 1 REFERENCES: 525–Accessing Array Components QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.02 Explore how to declare and manipulate data into arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 5/11/2020 5:32 PM 14. Assume you have the following declaration double salesData[1000];. Which of the following ranges is valid for the index of the array salesData? a. 0 through 999 b. 0 through 1000 c. 1 through 1001 d. 1 through 1000 ANSWER: a FEEDBACK: a. Correct. The valid range for the index of the array salesData is 0 through 999. b. Incorrect. The valid range for the index of the array salesData is 0 through 999. Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 8 c. Incorrect. The valid range for the index of the array salesData is 0 through 999. d. Incorrect. The valid range for the index of the array salesData is 0 through 999. POINTS: 1 REFERENCES: 525–Accessing Array Components QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.02 Explore how to declare and manipulate data into arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 3:35 AM 15. Suppose that sales is an array of 50 components of type double. Which of the following correctly initializes the array sales? a. for (int j = 1; j <= 49; j++) sales[j] = 0; b. for (int j = 1; j <= 50; j++) sales[j] = 0; c. for (int j = 0; j <= 49; j++) sales[j] = 0.0; d. for (int j = 0; j <= 48; j++) sales[j] = 0.0; ANSWER: FEEDBACK:

c a. Incorrect. The valid index range for sales is 0 to 49. Because j is initialized to 1, sales[0] will not be initialized. b. Incorrect. The valid index range for sales is 0 to 49. Because j is initialized to 1, sales[0] will not be initialized. Moreover sales[50] does not exist. c. Correct. The valid index range for sales is 0 to 49. Therefore, this for loop correctly initializes the array sales. d. Incorrect. The valid index range for sales is 0 to 49. In this for loop j ranges from 0 to 48. Therefore, sales[49] will not be initialized.

POINTS: 1 REFERENCES: 528–Processing One-Dimensional Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.02 Explore how to declare and manipulate data into arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:02 AM 16. Suppose that list is an array of 10 components of type int. Which of the following codes correctly outputs all the elements of list? Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 8 a. for (int j = 1; j < 10; j++) cout << list[j] << " "; cout << endl; b. for (int j = 0; j <= 9; j++) cout << list[j] << " "; cout << endl; c. for (int j = 1; j < 11; j++) cout << list[j] << " "; cout << endl; d. for (int j = 1; j <= 10; j++) cout << list[j] << " "; cout << endl; ANSWER: FEEDBACK:

b a. Incorrect. In this for loop the array index variable j ranges from 1 to 9. So this loop will not output list[0]. b. Correct. In this for loop the array index variable j ranges from 0 to 9. So this loop correctly outputs all the elements of list. c. Incorrect. In this for loop the array index variable j ranges from 1 to 10. So this loop will not output list[0]. Also this for loop will output list[10], which is not an element of list. d. Incorrect. In this for loop the array index variable j ranges from 1 to 10. So this loop will not output list[0]. Also this for loop will output list[10], which is not an element of list.

POINTS: 1 REFERENCES: 528–Processing One-Dimensional Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.02 Explore how to declare and manipulate data into arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:05 AM 17. What is the output of the following C++ code? int list[5] = {0, 5, 10, 15, 20}; int j; for (j = 0; j < 5; j++) cout << list[j] << " "; cout << endl; a. 0 1 2 3 4 c. 0 5 10 15 20

b. 0 5 10 15 d. 5 10 15 20

Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 8 ANSWER: FEEDBACK:

c a. Incorrect. The statement int list[5] = {0, 5, 10, 15, 20}; declares list to be an array of five components and also initializes list[0] = 0, list[1] = 5, list[2] = 10, list[3] = 15, and list[4] = 20. In the for loop, the array index variable j ranges from 0 to 4 and outputs list[0], list[1], list[2], list[3], and list[4] with a space between the numbers. Therefore, the output is: 0 5 10 15 20 b. Incorrect. The statement int list[5] = {0, 5, 10, 15, 20}; declares list to be an array of five components and also initializes list[0] = 0, list[1] = 5, list[2] = 10, list[3] = 15, and list[4] = 20. In the for loop, the array index variable j ranges from 0 to 4 and outputs list[0], list[1], list[2], list[3], and list[4] with a space between the numbers. Therefore, the output is: 0 5 10 15 20 c. Correct. The statement int list[5] = {0, 5, 10, 15, 20}; declares list to be an array of five components and also initializes list[0] = 0, list[1] = 5, list[2] = 10, list[3] = 15, and list[4] = 20. In the for loop, the array index variable j ranges from 0 to 4 and outputs list[0], list[1], list[2], list[3], and list[4] with a space between the numbers. Therefore, the output is: 0 5 10 15 20 d. Incorrect. The statement int list[5] = {0, 5, 10, 15, 20}; declares list to be an array of five components and also initializes list[0] = 0, list[1] = 5, list[2] = 10, list[3] = 15, and list[4] = 20. In the for loop, the array index variable j ranges from 0 to 4 and outputs list[0], list[1], list[2], list[3], and list[4] with a space between the numbers. Therefore, the output is: 0 5 10 15 20

POINTS: 1 REFERENCES: 528–Processing One-Dimensional Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.02 Explore how to declare and manipulate data into arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:07 AM 18. What is the value of alpha[2] after the following code executes? int alpha[5]; int j; for (j = 0; j < 5; j++) alpha[j] = 2 * j + 1; a. 1 c. 5 ANSWER:

b. 4 d. 6 c

Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 8 FEEDBACK:

a. Incorrect. The value of alpha[2] is computed as alpha[2] = 2*2+1 = 4+1 = 5. b. Incorrect. The value of alpha[2] is computed as alpha[2] = 2*2+1 = 4+1 = 5. c. Correct. The value of alpha[2] is computed as alpha[2] = 2*2+1 = 4+1 = 5. d. Incorrect. The value of alpha[2] is computed as alpha[2] = 2*2+1 = 4+1 = 5.

POINTS: 1 REFERENCES: 528–Processing One-Dimensional Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.02 Explore how to declare and manipulate data into arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:08 AM 19. What is the output of the following C++ code? int alpha[5] = {2, 4, 6, 8, 10}; int j; for (j = 4; j >= 0; j--) cout << alpha[j] << " "; cout << endl; a. 2 4 6 8 10 c. 8 6 4 2 0 ANSWER: FEEDBACK:

b. 4 3 2 1 0 d. 10 8 6 4 2 d a. Incorrect. The statement int list[5] = {2, 4, 6, 8, 10}; declares list to be an array of five components and also initializes list[0] = 2, list[1] = 4, list[2] = 6, list[3] = 8, and list[4] = 10. In the for loop, the array index variable j is initialized to 4. After each iteration of the for loop j is decremented by 1, and so it ranges from 4 to 0 and outputs the list elements in the order list[4], list[3], list[2], list[1], and list[0] with a space between the numbers. Therefore, the output is: 10 8 6 4 2 b. Incorrect. The statement int list[5] = {2, 4, 6, 8, 10}; declares list to be an array of five components and also initializes list[0] = 2, list[1] = 4, list[2] = 6, list[3] = 8, and list[4] = 10. In the for loop, the array index variable j is initialized to 4. After each iteration of the for loop j is decremented by 1, and so it ranges from 4 to 0 and outputs the list elements in the order list[4], list[3], list[2], list[1], and list[0] with a space between the numbers. Therefore, the output is: 10 8 6 4 2

Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 8 c. Incorrect. The statement int list[5] = {2, 4, 6, 8, 10}; declares list to be an array of five components and also initializes list[0] = 2, list[1] = 4, list[2] = 6, list[3] = 8, and list[4] = 10. In the for loop, the array index variable j is initialized to 4. After each iteration of the for loop j is decremented by 1, and so it ranges from 4 to 0 and outputs the list elements in the order list[4], list[3], list[2], list[1], and list[0] with a space between the numbers. Therefore, the output is: 10 8 6 4 2 d. Correct. The statement int list[5] = {2, 4, 6, 8, 10}; declares list to be an array of five components and also initializes list[0] = 2, list[1] = 4, list[2] = 6, list[3] = 8, and list[4] = 10. In the for loop, the array index variable j is initialized to 4. After each iteration of the for loop j is decremented by 1, and so it ranges from 4 to 0 and outputs the list elements in the order list[4], list[3], list[2], list[1], and list[0] with a space between the numbers. Therefore, the output is: 10 8 6 4 2 POINTS: 1 REFERENCES: 528–Processing One-Dimensional Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.02 Explore how to declare and manipulate data into arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 6/12/2020 3:54 PM 20. What is the output of the following C++ code? int list[5] = {0, 5, 10, 15, 20}; int j; for (j = 1; j <= 5; j++) cout << list[j] << " "; cout << endl; a. 0 5 10 15 20 b. 5 10 15 20 0 c. 5 10 15 20 20 d. Code results in index out-of-bounds ANSWER: d FEEDBACK: a. Incorrect. list is an array of 5 components and the components are list[0], list[1], list[2], list[3], and list[4]. In the for loop, the array index variable j is initialized to 1 and ranges from 1 to 5. When j = 5, list[5] does not exist, and so the index is out-of-bounds. b. Incorrect. list is an array of 5 components and the components are list[0], list[1], list[2], list[3], and list[4]. In the for loop, the array index variable j is initialized to 1 and ranges from 1 to 5. When j = 5, list[5] does not exist, and so the index is out-of-bounds. Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 8 c. Incorrect. list is an array of 5 components and the components are list[0], list[1], list[2], list[3], and list[4]. In the for loop, the array index variable j is initialized to 1 and ranges from 1 to 5. When j = 5, list[5] does not exist, and so the index is out-of-bounds. d. Correct. list is an array of 5 components and the components are list[0], list[1], list[2], list[3], and list[4]. In the for loop, the array index variable j is initialized to 1 and ranges from 1 to 5. When j = 5, list[5] does not exist, and so the index is out-of-bounds. POINTS: 1 REFERENCES: 531-532–Processing One-Dimensional Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.02 Explore how to declare and manipulate data into arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:12 AM 21. Suppose that gamma is an array of 50 components of type int and j is an int variable. Which of the following for loops sets the index of gamma out of bounds? a. for (j = 0; j <= 49; j++) cout << gamma[j] << " "; b. for (j = 1; j < 50; j++) cout << gamma[j] << " "; c. for (j = 0; j <= 50; j++) cout << gamma[j] << " "; d. for (j = 0; j <= 48; j++) cout << gamma[j] << " "; ANSWER: c FEEDBACK: a. Incorrect. The components of gamma are gamma[0], gamma[1], ..., gamma[49]. An array index j is valid for gamma if 0 <= j <= 49. In this for loop, the array index variable j ranges from 0 to 49, and so this loop will not set the index of gamma out of bounds. b. Incorrect. The components of gamma are gamma[0], gamma[1], ..., gamma[49]. An array index j is valid for gamma if 0 <= j <= 49. In this for loop, the array index variable j ranges from 1 to 49, and so this loop will not set the index of gamma out of bounds. c. Correct. The components of gamma are gamma[0], gamma[1], ..., gamma[49]. An array index j is valid for gamma if 0 <= j <= 49. In this for loop, the array index variable j ranges from 0 to 50, and so when j = 50, the index of gamma is out-of-bounds. d. Incorrect. The components of gamma are gamma[0], gamma[1], ..., gamma[49]. An array index j is valid for gamma if 0 <= j <= 49. In this for loop, the array index variable j ranges from 0 to 48, and so this loop will not set the index of gamma out of bounds. POINTS:

1

Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 8 REFERENCES: 531-532–Array Index Out of Bounds QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.03 Understand the meaning of "array index out of bounds" DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:14 AM 22. Consider the following declaration: int alpha[5] = {3, 5, 7, 9, 11};. Which of the following is equivalent to this statement? a. int alpha[] = {3, 5, 7, 9, 11}; b. int alpha[] = {3 5 7 9 11}; c. int alpha[5] = [3, 5, 7, 9, 11]; d. int alpha[] = (3, 5, 7, 9, 11); ANSWER: FEEDBACK:

a a. Correct. The array declaration int alpha[] = {3, 5, 7, 9, 11}; is equivalent to the array declaration int alpha[5] = {3, 5, 7, 9, 11}; b. Incorrect. The array declaration int alpha[] = {3 5 7 9 11}; is illegal. The numbers 3 5 7 9 11 in the braces must be separated by commas. The array declaration int alpha[] = {3, 5, 7, 9, 11}; is equivalent to the array declaration int alpha[5] = {3, 5, 7, 9, 11};. c. Incorrect. The array declaration int alpha[5] = [3, 5, 7, 9, 11]; is illegal. The numbers 3, 5, 7, 9, 11 must be enclosed in braces. The array declaration int alpha[] = {3, 5, 7, 9, 11}; is equivalent to the array declaration int alpha[5] = {3, 5, 7, 9, 11};. d. Incorrect. The array declaration int alpha[] = (3, 5, 7, 9, 11); is illegal. The numbers 3, 5, 7, 9, 11 must be enclosed in braces. The array declaration int alpha[] = {3, 5, 7, 9, 11}; is equivalent to the array declaration int alpha[5] = {3, 5, 7, 9, 11};.

POINTS: 1 REFERENCES: 532–Array Initialization during Declaration QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.04 Learn how to declare and initialize arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:16 AM 23. In C++, the null character is represented as ____. a. '\0' b. "\0" c. '0' d. "0" ANSWER: FEEDBACK:

a a. Correct. In C++, '\0' represents the null character.

Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 8 b. Incorrect. In C++, '\0' represents the null character. c. Incorrect. In C++, '\0' represents the null character. d. Incorrect. In C++, '\0' represents the null character. POINTS: 1 REFERENCES: 553–C-Strings (Character Arrays) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.11 Learn about C-strings DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:18 AM 24. Which of the following correctly declares name to be a character array and stores "William" in it? a. char name[6] = "William"; b. char name[7] = "William"; c. char name[8] = "William"; d. char name[8] = 'William'; ANSWER: FEEDBACK:

c a. Incorrect. C-strings in C++ are null terminated. The length of the string "William" is 7, and so you need a char array of size 8 to store "William". b. Incorrect. C-strings in C++ are null terminated. The length of the string "William" is 7, and so you need a char array of size 8 to store "William". c. Correct. C-strings in C++ are null terminated. The length of the string "William" is 7, and so you need a char array of size 8 to store "William". d. Incorrect. C-strings in C++ are null terminated. The length of the string "William" is 7, and so you need a char array of size 8 to store "William".

POINTS: 1 REFERENCES: 554–C-Strings (Character Arrays) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.11 Learn about C-strings DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:19 AM 25. Consider the following declaration: char str[15];. Which of the following statements stores "Blue Sky" into str? a. str = "Blue Sky"; b. str[15] = "Blue Sky"; c. strcpy(str, "Blue Sky"); d. strcpy("Blue Sky"); ANSWER:

c

Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 8 FEEDBACK:

a. Incorrect. Aggregate operations such as assignment and comparison are not allowed in arrays. Therefore, the assignment statement str = "Blue Sky"; is illegal. The correct statement is: strcpy(str, "Blue Sky"); b. Incorrect. str[15] refers to the 15th component of str, which is of type char. A string cannot be stores in a variable of type char. Therefore, the statement str[15] = "Blue Sky"; is illegal. The correct statement is: strcpy(str, "Blue Sky"); c. Correct. The statement strcpy(str, "Blue Sky"); uses the C-string function strcpy to store "Blue Sky" into str, which is correct. d. Incorrect. The statement strcpy("Blue Sky"); is an illegal call to the Cstring function strcpy. The function strcpy has two parameters. The correct statement is: strcpy(str, "Blue Sky");

POINTS: 1 REFERENCES: 554–C-Strings (Character Arrays) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.12 Examine the use of string functions to process C-strings DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:21 AM 26. Consider the following declaration: char charArray[51]; char discard; Assume that the input is: Hello There! How are you? What is the value of discard after the following statements execute? cin.get(charArray, 51); cin.get(discard); a. ' '(Space) b. '!' c. '\n' ANSWER: FEEDBACK:

d. '\0' c a. Incorrect. The statement cin.get(charArray, 51); stores the next 50 characters, or all characters until the newline character '\n' is found, into charArray. So, the reading will stop just before the newline character '\n'. Therefore, the statement cin.get(discard); will store the newline character '\n' into discard. The value of discard is: '\n' b. Incorrect. The statement cin.get(charArray, 51); stores the next 50 characters, or all characters until the newline character '\n' is found, into charArray. So, the reading will stop just before the newline character '\n'. Therefore, the statement cin.get(discard); will store the newline character '\n' into discard. The value of discard is: '\n'

Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 8 c. Correct. The statement cin.get(charArray, 51); stores the next 50 characters, or all characters until the newline character '\n' is found, into charArray. So, the reading will stop just before the newline character'\n'. Therefore, the statement cin.get(discard); will store the newline character ''\n' into discard. The value of discard is: '\n' d. Incorrect. The statement cin.get(charArray, 51); stores the next 50 characters, or all characters until the newline character '\n' is found, into charArray. So, the reading will stop just before the newline character '\n'. Therefore, the statement cin.get(discard); will store the newline character '\n' into discard. The value of discard is: '\n' POINTS: 1 REFERENCES: 557–String Input QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.13 Discover how to input data into – and output data from – a C-string DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:32 AM 27. Consider the following statement: double alpha[10][5];. The number of components of alpha is ____. a. 15 b. 50 c. 100 d. 150 ANSWER: b FEEDBACK: a. Incorrect. In the given two-dimensional array double alpha[10][5];, there are 10 rows and 5 columns. Thus, there are 10*5=50 components in the array. b. Correct. In the given two-dimensional array double alpha[10][5];, there are 10 rows and 5 columns. Thus, there are 10*5=50 components in the array. c. Incorrect. In the given two-dimensional array double alpha[10][5];, there are 10 rows and 5 columns. Thus, there are 10*5=50 components in the array. d. Incorrect. In the given two-dimensional array double alpha[10][5];, there are 10 rows and 5 columns. Thus, there are 10*5=50 components in the array. POINTS: 1 REFERENCES: 562–Two- and Multidimensional Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.15 Discover how to manipulate data in a two-dimensional array DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:33 AM 28. Consider the statement int list[10][8];. Which of the following is true about list? a. list has 10 rows and 8 columns. b. list has 8 rows and 10 columns. Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 8 c. list has a total of 18 components. d. list has a total of 108 components. ANSWER: a FEEDBACK: a. Correct. The two-dimensional array list has 10 rows and 8 columns. b. Incorrect. The two-dimensional array list has 10 rows and 8 columns. c. Incorrect. The two-dimensional array list has 10 rows and 8 columns. d. Incorrect. The two-dimensional array list has 10 rows and 8 columns. POINTS: 1 REFERENCES: 562–Two- and Multidimensional Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.15 Discover how to manipulate data in a two-dimensional array DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:35 AM 29. Consider the following statement: int alpha[25][10];. Which of the following statements is true about alpha? a. Rows of alpha are numbered 0...24 and columns are numbered 0...9. b. Rows of alpha are numbered 0...24 and columns are numbered 1...10. c. Rows of alpha are numbered 1...24 and columns are numbered 0...9. d. Rows of alpha are numbered 1...25 and columns are numbered 1...10. ANSWER: FEEDBACK:

a a. Correct. The two-dimensional array int alpha[25][10]; has 25 rows numbered from 0...24 and 10 columns numbered from 0...9. b. Incorrect. The two-dimensional array int alpha[25][10]; has 25 rows numbered from 0...24 and 10 columns numbered from 0...9. c. Incorrect. The two-dimensional array int alpha[25][10]; has 25 rows numbered from 0...24 and 10 columns numbered from 0...9. d. Incorrect. The two-dimensional array int alpha[25][10]; has 25 rows numbered from 0...24 and 10 columns numbered from 0...9.

POINTS: 1 REFERENCES: 562–Two- and Multidimensional Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.15 Discover how to manipulate data in a two-dimensional array DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 4:20 AM 30. Which of the following correctly declares and initializes alpha to be an array of four rows and three columns with the component type int? Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 8 a. int alpha[4][3] = {{0,1,2} {1,2,3} {2,3,4} {3,4,5}}; b. int alpha[4][3] = {0,1,2; 1,2,3; 2,3,4; 3,4,5}; c. int alpha[4][3] = {0,1,2: 1,2,3: 2,3,4: 3,4,5}; d. int alpha[4][3] = {{0,1,2}, {1,2,3}, {2,3,4}, {3,4,5}}; ANSWER: d FEEDBACK: a. Incorrect. To initializing a two dimensional array, during declaration, the elements of each row are all enclosed within a set of curly braces and separated by commas and also the set of all rows is enclosed within curly braces. In the given initialization, rows are not separated by commas. Thus, it does not declare and initialize alpha correctly. b. Incorrect. To initializing a two dimensional array, during declaration, the elements of each row are all enclosed within a set of curly braces and separated by commas and also the set of all rows is enclosed within curly braces. In the given initialization, rows are not enclosed within a set of curly braces and not separated by commas. Thus, it does not declare and initialize alpha correctly. c. Incorrect. To initializing a two dimensional array, during declaration, the elements of each row are all enclosed within a set of curly braces and separated by commas and also the set of all rows is enclosed within curly braces. In the given initialization, rows are not enclosed within a set of curly braces and not separated by commas. Thus, it does not declare and initialize alpha correctly. d. Correct. To initializing a two dimensional array, during declaration, the elements of each row are all enclosed within a set of curly braces and separated by commas and also the set of all rows is enclosed within curly braces. Thus, given statement declares and initializes alpha correctly. POINTS: 1 REFERENCES: 564–Two-Dimensional Array Initialization during Declaration QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.15 Discover how to manipulate data in a two-dimensional array DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:40 AM 31. After the following statements execute, what are the contents of matrix? int matrix[3][2]; int j, k; for (j = 0; j < 3; j++) for (k = 0; k < 2; k++) matrix[j][k] = j + k; a. 0 0 1 1 2 2 c. 0 1

b. 0 1 2 3 4 5 d. 1 1

Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 8 1 2

2 2

2 3

3 3

ANSWER: FEEDBACK:

c a. Incorrect. matrix is an array of 3 rows and 2 columns. The element in the jth row and kth column of matrix, matrix[j][k], is set to j + k, i.e., matrix[j][k] = j + k. For example, matrix[0][0] = 0 + 0 = 0, matrix[0][1] = 0 + 1 = 1, and matrix[2][1] = 2 + 1 = 3. Therefore, the contents of matrix are: 0 1 1 2 2 3 b. Incorrect. matrix is an array of 3 rows and 2 columns. The element in the jth row and kth column of matrix, matrix[j][k], is set to j + k, i.e., matrix[j][k] = j + k. For example, matrix[0][0] = 0 + 0 = 0, matrix[0][1] = 0 + 1 = 1, and matrix[2][1] = 2 + 1 = 3. Therefore, the contents of matrix are: 0 1 1 2 2 3 c. Correct. matrix is an array of 3 rows and 2 columns. The element in the jth row and kth column of matrix, matrix[j][k], is set to j + k, i.e., matrix[j][k] = j + k. For example, matrix[0][0] = 0 + 0 = 0, matrix[0][1] = 0 + 1 = 1, and matrix[2][1] = 2 + 1 = 3. Therefore, the contents of matrix are: 0 1 1 2 2 3 d. Incorrect. matrix is an array of 3 rows and 2 columns. The element in the jth row and kth column of matrix, matrix[j][k], is set to j + k, i.e., matrix[j][k] = j + k. For example, matrix[0][0] = 0 + 0 = 0, matrix[0][1] = 0 + 1 = 1, and matrix[2][1] = 2 + 1 = 3. Therefore, the contents of matrix are: 0 1 1 2 2 3

POINTS: 1 REFERENCES: 568–Sum by Row QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.15 Discover how to manipulate data in a two-dimensional array DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:47 AM 32. Given the following declaration: Copyright Cengage Learning. Powered by Cognero.

Page 19


Name:

Class:

Date:

Chapter 8 int j; int sum; double sales[10][7]; which of the following correctly finds the sum of the elements of the fifth row of sale? a. sum = 0; for(j = 0; j < 7; j++) sum = sum + sales[5][j]; b. sum = 0; for(j = 0; j < 7; j++) sum = sum + sales[4][j]; c. sum = 0; for(j = 0; j < 10; j++) sum = sum + sales[5][j]; d. sum = 0; for(j = 0; j < 10; j++) sum = sum + sales[4][j]; ANSWER: b FEEDBACK: a. Incorrect. sales is a two-dimensional array of 10 rows and 7 columns. The rows are numbered from 0 to 9 and the columns are numbered 0 to 6. The elements of the fifth row are sales[4][j], where j = 0 to 6. In this for loop sales[5][j] refers to the element of the sixth row. So this code finds the sum of the elements of the sixth row, not the sum of the elements of the fifth row. b. Correct. sales is a two-dimensional array of 10 rows and 7 columns. The rows are numbered from 0 to 9 and the columns are numbered 0 to 6. The elements of the fifth row are sales[4][j], where j = 0 to 6. Therefore, this code correctly finds the sum of the elements of the fifth row. c. Incorrect. sales is a two-dimensional array of 10 rows and 7 columns. The rows are numbered from 0 to 9 and the columns are numbered 0 to 6. The elements of the fifth row are sales[4][j], where j = 0 to 6. In this for loop sales[5][j] refers to the element of the sixth row. Moreover, j ranges from 0 to 9, and so this code will result in array index out-of-bounds. Therefore, this code does not correctly find the sum of the elements of the fifth row. d. Incorrect. sales is a two-dimensional array of 10 rows and 7 columns. The rows are numbered from 0 to 9 and the columns are numbered 0 to 6. The elements of the fifth row are sales[4][j], where j = 0 to 6. However, in this for loop j ranges from 0 to 9, resulting in array index out-of-bounds. Therefore, this code does not correctly find the sum of the elements of the fifth row. POINTS: 1 REFERENCES: 568–Sum by Row QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.15 Discover how to manipulate data in a two-dimensional array DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:48 AM Copyright Cengage Learning. Powered by Cognero.

Page 20


Name:

Class:

Date:

Chapter 8 33. Given the following declaration: int j; int sum; double sales[10][7]; which of the following correctly finds the sum of the elements of the fourth column of sales? a. sum = 0; for(j = 0; j < 7; j++) sum = sum + sales[j][3]; b. sum = 0; for(j = 0; j < 7; j++) sum = sum + sales[j][4]; c. sum = 0; for(j = 0; j < 10; j++) sum = sum + sales[j][4]; d. sum = 0; for(j = 0; j < 10; j++) sum = sum + sales[j][3]; ANSWER: d FEEDBACK: a. Incorrect. sales is a two-dimensional array of 10 rows and 7 columns. The rows are numbered 0 to 9 and the columns are numbered 0 to 6. Each column has 10 elements. The elements of the fourth column are sales[j][3], where j = 0 to 9. In this for loop sale[j][3] refers to the elements of the fourth column. However, because in the for loop j = 0 to 6, only first seven elements of the fourth column are added. Therefore, this code does not correctly find the sum of the elements of the fourth column of sales. b. Incorrect. sales is a two-dimensional array of 10 rows and 7 columns. The rows are numbered 0 to 9 and the columns are numbered 0 to 6. The elements of the fourth column are sales[j][3], where j = 0 to 9. In this code, sales[j][4] refers to the element of the fifth column of sales not the fourth column. Moreover, j ranges from 0 to 6. Therefore, this code does not correctly find the sum of the elements of the fourth column of sales. c. Incorrect. sales is a two-dimensional array of 10 rows and 7 columns. The rows are numbered 0 to 9 and the columns are numbered 0 to 6. The elements of the fourth column are sales[j][3], where j = 0 to 9. In this code, sales[j][4] refers to the element of the fifth column of sales not the fourth column. Therefore, this code does not correctly find the sum of the elements of the fourth column of sales. d. Correct. sales is a two-dimensional array of 10 rows and 7 columns. The rows are numbered 0 to 9 and the columns are numbered 0 to 6. The elements of the fourth column are sales[j][3], where j = 0 to 9. Therefore, this code correctly finds the sum of the elements of the fourth column of sales. POINTS: REFERENCES:

1 569–Sum by Column

Copyright Cengage Learning. Powered by Cognero.

Page 21


Name:

Class:

Date:

Chapter 8 QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.15 Discover how to manipulate data in a two-dimensional array DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:50 AM 34. In row order form, the ____. a. first row is stored first b. first row is stored last c. first column is stored first d. first column is stored last ANSWER: a FEEDBACK: a. Correct. In row order form, the first row is stored first, followed by the second row, followed by the third row, and so on. b. Incorrect. In row order form, the first row is stored first, followed by the second row, followed by the third row, and so on. c. Incorrect. In row order form, the first row is stored first, followed by the second row, followed by the third row, and so on. d. Incorrect. In row order form, the first row is stored first, followed by the second row, followed by the third row, and so on.

POINTS: 1 REFERENCES: 570–Passing Two-Dimensional Arrays as Parameters to Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.08.15 Discover how to manipulate data in a two-dimensional array DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/5/2020 1:23 AM 35. A collection of a fixed number of elements (called components) arranged in n dimensions (n >= 1) is called a(n) ____. a. matrix b. vector c. n-dimensional array d. parallel array ANSWER: c FEEDBACK: a. Incorrect. An n-dimensional array is a collection of a fixed number of components arranged in n-dimensions. b. Incorrect. An n-dimensional array is a collection of a fixed number of components arranged in n-dimensions. c. Correct. An n-dimensional array is a collection of a fixed number of components arranged in n-dimensions. d. Incorrect. An n-dimensional array is a collection of a fixed number of components arranged in n-dimensions. POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 575–Multidimensional Arrays Multiple Choice False

Copyright Cengage Learning. Powered by Cognero.

Page 22


Name:

Class:

Date:

Chapter 8 LEARNING OBJECTIVES: PDDS.MALI.08.16 Learn about multidimensional arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/14/2020 2:57 AM 36. In a(n) ____________________ data type, each data item is a collection of other data items. ANSWER: structured POINTS: 1 REFERENCES: 522 QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.08.01 Learn the reasons for arrays DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/5/2020 1:33 AM 37. The word ____________________ is used before the array declaration in a function heading to prevent the function from modifying the array. const ANSWER: POINTS: 1 REFERENCES: 535–Arrays as Parameters to Functions QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.08.06 Discover how to pass an array as a parameter to a function DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/5/2020 1:34 AM 38. The ____________________ of an array is the address (that is, the memory location) of the first array component. ANSWER: base address POINTS: 1 REFERENCES: 537–Base Address of an Array and Array in Computer Memory QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.08.06 Discover how to pass an array as a parameter to a function DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/5/2020 1:35 AM 39. For a list of length n, the ____________________ sort makes exactly (n(n - 1))/2 key comparisons and 3(n 1) item assignments. Copyright Cengage Learning. Powered by Cognero.

Page 23


Name:

Class:

Date:

Chapter 8 ANSWER: selection POINTS: 1 REFERENCES: 551–Searching an Array for a Specific Item QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.08.07 Learn how to search an array DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/5/2020 1:37 AM 40. The form of the for loop shown below is called a(n) ____________________ for loop. for (dataType identifier : arrayName) statements ANSWER: range-based POINTS: 1 REFERENCES: 551-552–Auto Declaration and Range-Based For Loops QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.08.10 Learn about range-based for loops DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/5/2020 1:39 AM

Copyright Cengage Learning. Powered by Cognero.

Page 24


Name:

Class:

Date:

Chapter 9 1. You can declare struct variables when you define a struct. a. True b. False ANSWER: True FEEDBACK: Correct struct variables can be declared when defining a struct. Incorrect struct variables can be declared when defining a struct.

POINTS: 1 REFERENCES: 614 – Records (structs) QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.01 Learn about records (structs) DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 11:39 PM 2. In structs, you access a component by using the struct name together with the relative position of the component. a. True b. False ANSWER: False FEEDBACK: Correct In structs, you can access a component by using the struct variable name together with the member name; these names are separated by the dot (period) operator. Incorrect In structs, you can access a component by using the struct variable name together with the member name; these names are separated by the dot (period) operator. POINTS: 1 REFERENCES: 614 – Accessing struct Members QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.02 Examine various operations on a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 11:28 PM 3. To access a structure member (component), you use the struct variable name together with the member name; these names are separated by the dot (period) operator. a. True b. False ANSWER: True FEEDBACK: Correct Use the struct variable name together with the member name to access a structure member; these names are separated by a dot (period). Incorrect Use the struct variable name together with the member name to access a Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 9 structure member; these names are separated by a dot (period). POINTS: 1 REFERENCES: 614 – Accessing struct Members QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.02 Examine various operations on a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 11:30 PM 4. You can use an assignment statement to copy the contents of one struct variable into another struct variable of the same type. a. True b. False ANSWER: True FEEDBACK: Correct One can assign the value of one struct variable to another struct variable of the same type by using an assignment statement. Incorrect One can assign the value of one struct variable to another struct variable of the same type by using an assignment statement. POINTS: 1 REFERENCES: 617 – Assignment QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.02 Examine various operations on a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 12:10 AM 5. Relational operations can be used on struct variables. a. True b. False ANSWER: False FEEDBACK: Correct You cannot use relational operators on struct variables. Incorrect You cannot use relational operators on struct variables.

POINTS: 1 REFERENCES: 618 – Comparison (Relational operators) QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.02 Examine various operations on a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 12:21 AM Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 9 6. Data in a struct variable must be read one member at a time. a. True b. False ANSWER: True FEEDBACK: Correct A struct variable does not allow aggregate input/output operations. Data in a struct variable must be read one member at a time. Incorrect A struct variable does not allow aggregate input/ output operations. Data in a

struct variable must be read one member at a time. POINTS: 1 REFERENCES: 618 – Input/ Output QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.03 Explore ways to manipulate data using a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/16/2020 11:42 PM 7. A function can return a value of the type array. a. True b. False ANSWER: False FEEDBACK: Correct The arrays are passed by reference only, and a function cannot return a value of the type array. Incorrect The arrays are passed by reference only, and a function cannot return a value of the type array.

POINTS: 1 REFERENCES: 619 – struct Variables and Functions QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.04 Learn about the relationship between a struct and functions DATE CREATED: DATE MODIFIED:

10/5/2016 1:40 PM 3/16/2020 11:44 PM

8. A function can return a value of the type struct. a. True b. False ANSWER: True FEEDBACK: Correct A function can return a value of type struct. Incorrect A function can return a value of type struct.

POINTS: REFERENCES:

1 619 – struct Variables and Functions

Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 9 QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.04 Learn about the relationship between a struct and functions DATE CREATED: DATE MODIFIED:

10/5/2016 1:40 PM 3/16/2020 10:40 PM

9. Aggregate input/output operations are allowed on a struct variable. a. True b. False ANSWER: False FEEDBACK: Correct No aggregate input/output operations are allowed on a struct variable. Data in struct variable must be read one member at a time. Similarly, the contents of a struct variable must be written one member at a time. Incorrect No aggregate input/output operations are allowed on a struct variable. Data in struct variable must be read one member at a time. Similarly, the contents of a struct variable must be written one member at a time. POINTS: 1 REFERENCES: 618 – Input/Output QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.03 Explore ways to manipulate data using a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 12:02 AM 10. A struct is typically a ____ data structure. a. simple b. homogenous c. heterogeneous d. multi ANSWER: c FEEDBACK: a. Incorrect. There is no data structure called simple. b. Incorrect. All members of a struct need not be of the same data type. Therefore, a struct is not a homogenous data structure. Typically, it is a heterogeneous data structure. c. Correct. All members of a struct need not be of the same data type. Therefore, typically, it is a heterogeneous data structure. d. Incorrect. There is no data structure called multi. POINTS: 1 REFERENCES: 612 – Records (structs) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.01 Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 9 Learn about records (structs) DATE CREATED: DATE MODIFIED:

10/5/2016 1:40 PM 3/16/2020 11:45 PM

11. The components of a struct are called the ____ of the struct. a. variables b. identifiers c. elements d. members ANSWER: d FEEDBACK: a. Incorrect. The components of a struct are called the members of the struct. b. Incorrect. The components of a struct are called the members of the struct. c. Incorrect. The components of a struct are called the members of the struct. d. Correct. The components of a struct are called the members of the struct. POINTS: 1 REFERENCES: 612 – Records (structs) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.01 Learn about records (structs) DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 12:06 AM 12. Which of the following struct definitions is correct in C++? a. struct studentType { int ID; }; b. struct studentType { string name; int ID; double gpa; } c. int struct studentType { int ID; } d. struct studentType { ID; }; ANSWER: FEEDBACK:

a a. Correct. The syntax to define a struct is struct struct_name {datatype1 identifier1; datatype2 identifier2;…};.

Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 9 Therefore, this definition of the struct studentType is correct. b. Incorrect. In this definition, ; (semicolon) is missing after } (brace). c. Incorrect. A struct has no type. Therefore, the word int before struct (in the first line) is illegal. Moreover, ; (semicolon) is missing after } (in the fourth line). d. Incorrect. The data type of the variable (identifier) ID is missing. POINTS: 1 REFERENCES: 612 – Records (structs) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.01 Learn about records (structs) DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 12:07 AM 13. Consider the following struct definition: struct rectangleData { double length; double width; double area; double perimeter; }; Which of the following variable declarations is correct? a. rectangle rectangleData; b. struct rectangleData(); c. rectangleData myRectangle; d. rectangleData rectangle.length; ANSWER: FEEDBACK:

c

POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 613 – Records (structs) Multiple Choice False

a. Incorrect. The syntax to declare a variable is dataType identifier;. Because rectangle is not a data type, this declaration is illegal. b. Incorrect. The syntax to declare a variable is dataType identifier;. struct is not a data type and rectangleData() is not a valid C++ identifier. c. Correct. The syntax to declare a variable is dataType identifier;. Therefore, the declaration rectangleData myRectangle; is correct. d. Incorrect. The syntax to declare a variable is dataType identifier;. rectangle.length is not a valid C++ identifier.

Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 9 LEARNING OBJECTIVES: PDDS.MALI.09.01 Learn about records (structs) DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 12:07 AM 14. Typically, in a program, a struct is defined ____ in the program. a. in the main function b. before the definitions of all the functions c. after the definitions of all the functions d. in any function ANSWER: b FEEDBACK: a. Incorrect. Typically, in a program, a struct is defined before the definitions of all the functions in the program, so that the struct can be used throughout the program. b. Correct. Typically, in a program, a struct is defined before the definitions of all the functions in the program, so that the struct can be used throughout the program. c. Incorrect. Typically, in a program, a struct is defined before the definitions of all the functions in the program, so that the struct can be used throughout the program. d. Incorrect. Typically, in a program, a struct is defined before the definitions of all the functions in the program, so that the struct can be used throughout the program. POINTS: 1 REFERENCES: 614 – Records (structs) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.01 Learn about records (structs) DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 12:54 AM 15. An array name and its index are separated using ____. a. curly braces b. square brackets c. a dot d. a comma ANSWER: b FEEDBACK: a. Incorrect. An array name and its index are separated using square brackets. In C++, [] is called the array subscripting operator. Curly braces are used to create things such as blocks and function definitions. b. Correct. An array name and its index are separated using square brackets. In C++, [] is called the array subscripting operator. c. Incorrect. An array name and its index are separated using square brackets. In C++, [] is called the array subscripting operator. In C++, the operator . (dot) is used to access a struct member. Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 9 d. Incorrect. An array name and its index are separated using square brackets. In C++, [] is called the array subscripting operator. In C++, commas are used to separate items in a list such as array initialization during declaration. POINTS: 1 REFERENCES: 614 – Accessing struct Members QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.02 Examine various operations on a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 12:56 AM 16. The syntax for accessing a struct member is structVariableName____. a. .memberName b. *memberName c. [memberName] d. $memberName ANSWER: FEEDBACK:

a a. Correct. The syntax for accessing a struct member is structVariableName.memberName. b. Incorrect. The syntax for accessing a struct member is structVariableName.memberName. c. Incorrect. The syntax for accessing a struct member is structVariableName.memberName. d. Incorrect. The syntax for accessing a struct member is structVariableName.memberName.

POINTS: 1 REFERENCES: 614 – Accessing struct Members QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.02 Examine various operations on a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 12:57 AM 17. Consider the following statements: struct rectangleData { double length; double width; double area; double perimeter; }; rectangleData bigRect; Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 9 Which of the following statements correctly initializes the member length of bigRect? a. bigRect = {10}; b. bigRect.length = 10; c. length[0]= 10; d. bigRect[0]= 10 ANSWER: FEEDBACK:

b a. Incorrect. The syntax for accessing a struct member is structVariableName.memberName. Therefore, bigRect = {10}; is incorrect. The correct statement is: bigRect.length = 10; b. Correct. The syntax for accessing a struct member is structVariableName.memberName. Therefore, the statement bigRect.length = 10; to initialize the member length of bigRect is correct. c. Incorrect. The syntax for accessing a struct member is structVariableName.memberName. Therefore, length[0]= 10; is incorrect. The correct statement is: bigRect.length = 10; d. Incorrect. The syntax for accessing a struct member is structVariableName.memberName. Therefore, bigRect[0]= 10; is incorrect. The correct statement is: bigRect.length = 10;

POINTS: 1 REFERENCES: 615 – Accessing the struct Members QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.02 Examine various operations on a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 1:00 AM 18. In C++, the ____ symbol is an operator, called the member access operator. a. :(colon) b. .(dot) c. ,(comma) d. $ (dollar sign) ANSWER: b FEEDBACK: a. Incorrect. In C++, the . (dot) symbol is an operator, called the member access operator. In C++, : is used with a case label and also has other use. b. Correct. In C++, the . (dot) symbol is an operator, called the member access operator. c. Incorrect. In C++, the . (dot) symbol is an operator, called the member access operator. In C++, , is used to separate items in a list. d. Incorrect. In C++, the . (dot) symbol is an operator, called the member access operator. In C++, $ is not an operator. POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 614 – Accessing the struct Members Multiple Choice False

Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 9 LEARNING OBJECTIVES: PDDS.MALI.09.02 Examine various operations on a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 1:01 AM 19. Consider the following statements: struct rectangleData { double length; double width; double area; double perimeter; }; rectangleData bigRect; Which of the following statements is valid in C++? a. cin >> bigRect; b. cin >> bigRect.length; c. perimeter = 2 * (length + width); d. area = length * width; ANSWER: FEEDBACK:

b a. Incorrect. bigRect is a struct variable of type rectangleData. Because no aggregate input operations are allowed on a struct variable, the statement cin >> bigRect; is invalid. b. Correct. The statement cin >> bigRect.length; reads a number into the member length of bigRect. This statement is valid. c. Incorrect. The syntax for accessing a struct member is structVariableName.memberName. Therefore, the statement perimeter = 2 * (length + width); is invalid because the members perimeter, length, and width are accessed without the struct variable bigRect and the dot operator. d. Incorrect. The syntax for accessing a struct member is structVariableName.memberName. Therefore, the statement area = length * width is invalid because the members area, length, and width are accessed without the struct variable bigRect and the dot operator.

POINTS: 1 REFERENCES: 615 – Accessing struct Members QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.02 Examine various operations on a struct Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 9 DATE CREATED: DATE MODIFIED:

10/5/2016 1:40 PM 3/17/2020 1:02 AM

20. Consider the following statements: struct personalInfo { string name; int age; double height; double weight; }; struct commonInfo { string name; int age; }; personalInfo person1, person2; commonInfo person3, person4; Which of the following statements is valid in C++? a. person1 = person3; b. person2 = person1; c. person2 = person3; d. person2 = person4; ANSWER: FEEDBACK:

b a. Incorrect. The variables person1 and person3 are of different struct types. Therefore, the statement person1 = person3; is invalid. b. Correct. Because we can assign the value of one struct variable to another struct variable of the same type by using an assignment statement, the statement is person2 = person1; valid. c. Incorrect. The variables person2 and person3 are of different struct types. Therefore, the statement person2 = person3; is invalid. d. Incorrect. The variables person2 and person4 are of different struct types. Therefore, the statement person2 = person4; is invalid.

POINTS: 1 REFERENCES: 617 – Assignment QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.02 Examine various operations on a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 1:03 AM 21. Consider the following statements: Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 9 struct studentType1 { string name; int ID; double gpa; }; studentType1 student1, student2; struct studentType2 { string name; int ID; double gpa; }; studentType2 student3, student4; Which of the following statements is valid in C++? a. student2 = student3; b. student1 = student4; c. student2.ID = ID; d. student1.ID = student3.ID; ANSWER: FEEDBACK:

d a. Incorrect. The variables student2 and student3 are of different struct types. Therefore, the statement student2 = student3; is invalid. b. Incorrect. The variables student1 and student4 are of different struct types. Therefore, the statement student1 = student4; is invalid. c. Incorrect. In the statement student2.ID = ID;, the variable ID (after the = sign) is accessed without its struct variable name. Therefore, this statement is invalid. d. Correct. In the statement student1.ID = student3.ID;, student1.ID and student3.ID are both int variables. Therefore, this statement is valid.

POINTS: 1 REFERENCES: 618 – Assignment QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.02 Examine various operations on a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/15/2020 10:33 PM 22. You can assign the value of one struct variable to another struct variable of ____ type. a. a simple data b. the same Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 9 c. an array ANSWER: FEEDBACK:

d. any b a. Incorrect. You can assign the value of one struct variable to another struct variable of the same type. A struct variable is not of a simple data type. b. Correct. You can assign the value of one struct variable to another struct variable of the same type. c. Incorrect. You can assign the value of one struct variable to another struct variable of the same type. A struct variable and an array variable are of different types. d. Incorrect. You can assign the value of one struct variable to another struct variable of the same type.

POINTS: 1 REFERENCES: 617 – Assignment QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.02 Examine various operations on a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/15/2020 9:29 PM 23. To compare struct variables, you compare them ____. a. by reference b. by value c. index-wise d. member-wise ANSWER: d FEEDBACK: a. Incorrect. To compare struct variables, you compare them by member-wise. b. Incorrect. To compare struct variables, you compare them by member-wise. c. Incorrect. To compare struct variables, you compare them by member-wise. d. Correct. To compare struct variables, you compare them by member-wise. POINTS: 1 REFERENCES: 618 – Comparison (Relational Operators) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.02 Examine various operations on a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/15/2020 9:30 PM 24. Consider the following statements: struct rectangleData { double length; double width; Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 9 double area; double perimeter; }; rectangleData bigRect; rectangleData smallRect; Which of the following expression is valid in C++? a. if (bigRect == smallRect) b. if (bigRect != smallRect) c. if (bigRect.length == width) d. if (bigRect.length == smallRect.width) ANSWER: FEEDBACK:

d a. Incorrect. There are no aggregate relational operators on struct variables. struct variables are compared member-wise. Therefore, the expression is bigRect == smallRect is invalid. b. Incorrect. There are no aggregate relational operators on struct variables. struct variables are compared member-wise. Therefore, the expression is bigRect != smallRect is invalid. c. Incorrect. In the given code, width is a member of the struct rectangleData. In the expression bigRect.length == width, width is accessed without its associated struct variable. Therefore, the expression bigRect.length == width is invalid. d. Correct. Both bigRect.length and smallRect.width are double variable, and so these can be compared. Therefore, the expression bigRect.length == smallRect.width is valid.

POINTS: 1 REFERENCES: 618 – Comparison (Relational Operators) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.02 Examine various operations on a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/15/2020 9:38 PM 25. Consider the following statements. struct circleData { double radius; double area; double circumference; }; circleData circle; Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 9 Which of the following statements is valid in C++? a. cin >> circle.radius; circle.area = 3.14 * radius * radius; b. cin >> circle.radius; circle.area = 3.14 * circle.radius * radius; c. cin >> circle; d. cin >> circle.radius; ANSWER: FEEDBACK:

d a. Incorrect. In the given code, radius is a member of the struct circleType. Therefore, it must be accessed using its associated struct variable and the dot operator. In the expression 3.14 * radius * radius, radius is accessed without its associated struct variable name. Therefore, the given statements are invalid. b. Incorrect. In the given code, radius is a member of the struct circleType. Therefore, it must be accessed using its associated struct variable and the dot operator. In the expression 3.14 * circle.radius * radius, radius (the second occurrence), is accessed without its associated struct variable name. Therefore, the given statements are invalid. c. Incorrect. Because no aggregate input operations are allowed on a struct variable, the statement cin >> circle; is invalid. d. Correct. The given statement cin >> circle.radius; is valid and it is used to read value for the member radius.

POINTS: 1 REFERENCES: 619 – struct Variables and Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.04 Learn about the relationship between a struct and functions DATE CREATED: DATE MODIFIED:

10/5/2016 1:40 PM 3/17/2020 12:28 AM

26. Consider the following statements: struct rectangleData { double length; double width; double area; double perimeter; }; rectangleData bigRect; Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 9 Which of the following statements is valid in C++? a. cin >> bigRect.length >> width; b. cout << bigRect.length; c. cout << bigRect; d. cout << length; ANSWER: FEEDBACK:

b a. Incorrect. In the given code, width is a member of the struct rectangleData. Therefore, it must be accessed using its associated struct variable and the dot operator. In the cin statement, width is accessed without its associated struct variable name. Therefore, the cin statement is invalid. b. Correct. The cout statement outputs the value of the member length of bigRect. This statement is valid. c. Incorrect. There are no aggregate output operations on struct variables. Therefore, the statement cout << bigRect; is invalid. d. Incorrect. In the given code, length is a member of the struct rectangleData. Therefore, it must be accessed using its associated struct variable and the dot operator. In the cout statement, length is accessed without its associated struct variable name. Therefore, the cout statement is invalid.

POINTS: 1 REFERENCES: 619 – struct Variables and Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.04 Learn about the relationship between a struct and functions DATE CREATED: DATE MODIFIED:

10/5/2016 1:40 PM 3/17/2020 12:29 AM

27. A struct variable can be passed as a parameter ____. a. only by const b. only by reference c. only by value d. either by value or by reference ANSWER: d FEEDBACK: a. Incorrect. A struct variable can be passed as a parameter either by value or by reference. There is no term passed only by const. b. Incorrect. A struct variable can be passed as a parameter either by value or by reference. c. Incorrect. A struct variable can be passed as a parameter either by value or by reference. d. Correct. A struct variable can be passed as a parameter either by value or by reference. POINTS: REFERENCES: QUESTION TYPE:

1 619 – struct Variables and Functions Multiple Choice

Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 9 HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.04 Learn about the relationship between a struct and functions DATE CREATED: DATE MODIFIED:

10/5/2016 1:40 PM 3/15/2020 9:46 PM

28. Which of the following aggregate operations can be executed on array variables? a. Arithmetic b. Assignment c. Function returning a value d. Parameter passing by reference ANSWER: d FEEDBACK: a. Incorrect. There are no aggregate arithmetic operations on array variables. b. Incorrect. There is no aggregate assignment operation on array variables. c. Incorrect. A function cannot return a value of type array. d. Correct. In C++, as parameters arrays are passed only by reference. POINTS: 1 REFERENCES: 620 – Arrays versus structs QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.05 Examine the difference between arrays and structs DATE CREATED: DATE MODIFIED:

10/5/2016 1:40 PM 3/5/2020 3:28 AM

29. Which of the following is an allowable aggregate operation on struct variables? a. Arithmetic b. Assignment c. Input/output d. Comparison ANSWER: b FEEDBACK: a. Incorrect. There are no aggregate arithmetic operations on struct variables. b. Correct. Using the assignment operator, a value of a struct variable can be assigned to a struct variable of the same type. Therefore, assignment is an allowable aggregate operation on struct variables. c. Incorrect. There are no aggregate input/output operations on struct variables. d. Incorrect. There are no aggregate comparison (relational) operations on struct variables. POINTS: 1 REFERENCES: 620 – Arrays versus structs QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.05 Examine the difference between arrays and structs

Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 9 DATE CREATED: DATE MODIFIED:

10/5/2016 1:40 PM 3/17/2020 12:30 AM

30. A list has two items associated with it: ____. a. the length and the references b. the values and the references c. the indexes and the length d. the values and the length ANSWER: d FEEDBACK: a. Incorrect. A list has two items associated with it: the values (that is, elements) and the length. b. Incorrect. A list has two items associated with it: the values (that is, elements) and the length. c. Incorrect. A list has two items associated with it: the values (that is, elements) and the length. d. Correct. A list has two items associated with it: the values (that is, elements) and the length.

POINTS: 1 REFERENCES: 620 – Arrays in structs QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.06 Discover how arrays are used in a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/5/2020 3:33 AM 31. Consider the following function prototype: int seqSearch(const listType& list, int searchItem); The formal parameter _____ cannot modify the corresponding actual parameter. a. seqSearch b. listType c. list d. searchItem ANSWER: FEEDBACK:

c a. Incorrect. seqSearch is a function name not a formal parameter. b. Incorrect. listType is a data type not a formal parameter. c. Correct. The formal parameter list cannot modify the corresponding actual parameter because it is declared with the reserved word const. d. Incorrect. The formal parameter searchItem can modify the corresponding actual parameter because it is declared without the reserved word const.

POINTS: 1 REFERENCES: 622 – Arrays in structs QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.06 Discover how arrays are used in a struct DATE CREATED: 10/5/2016 1:40 PM Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 9 DATE MODIFIED:

3/17/2020 12:31 AM

32. Consider the following statements: struct supplierType { string name; int supplierID; }; struct applianceType { supplierType supplier; string modelNo; double cost; }; applianceType applianceList[25]; Which of the following best describes applianceList? a. It is a multidimensional array. b. It is a struct. c. It is an array of structs. d. It is a struct of arrays. ANSWER: FEEDBACK:

c a. Incorrect. applianceList is an array of size 25 wherein each component is of type applianceType, which is a struct. Therefore, applianceList is an array of structs. b. Incorrect. applianceList is an array of size 25 wherein each component is of type applianceType, which is a struct. Therefore, applianceList is an array of structs. c. Correct. applianceList is an array of size 25 wherein each component is of type applianceType, which is a struct. Therefore, applianceList is an array of structs. d. Incorrect. applianceList is an array of size 25 wherein each component is of type applianceType, which is a struct. Therefore, applianceList is an array of structs.

POINTS: 1 REFERENCES: 623 – structs in Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.07 Learn how to create an array of struct items DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/17/2020 1:07 AM Copyright Cengage Learning. Powered by Cognero.

Page 19


Name:

Class:

Date:

Chapter 9 33. Consider the following statements: struct supplierType { string name; int supplierID; }; struct applianceType { supplierType supplier; string modelNo; double cost; }; applianceType applianceList[25]; Which of the following statements correctly initialize the cost of each applianceList element to 0? a. applianceList.cost = 0; b. applianceList.cost[25] = 0; c. for (int j = 1; j < 25; j++) applianceList.cost[j] = 0; d. for (int j = 0; j < 25; j++) applianceList.cost[j] = 0; ANSWER: d FEEDBACK: a. Incorrect. applianceList is an array of 25 components, wherein each component is of type applianceType, which is a struct. Also, cost is a member of each component of the array applianceList, not a member of the array variable applianceList, and there is no aggregate assignment operation on array. Therefore, the statement, applianceList.cost = 0; is illegal. b. Incorrect. The expression, applianceList[25].cost refers to the member cost of applianceList[25]. However, the valid index range for applianceType is 0 to 24. Therefore, applianceList[25] will result in array index out-of-bounds. c. Incorrect. In the for loop, j is initialized to 1. Therefore, this for loop will not initialize the member cost of applianceList[0]. d. Correct. In the for loop j is initialized to 0 and ranges from 0 to 24. The expression applianceList[j].cost refers to the memeber cost of applianceList[j]. This for loop correctly initializes the cost of each applianceList element to 0. POINTS: 1 REFERENCES: 624 – structs in Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.07 Learn how to create an array of struct items DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/15/2020 10:44 PM Copyright Cengage Learning. Powered by Cognero.

Page 20


Name:

Class:

Date:

Chapter 9 34. Consider the following statements: struct supplierType { string name; int supplierID; }; struct paintType { supplierType supplier; string color; string paintID; }; paintType paint; What is the data type of paint.supplier? a. string b. paintType c. supplierType d. struct ANSWER: FEEDBACK:

c a. Incorrect. paint is a struct variable of type paintType. supplier is a member of paint, and supplier is of type supplierType, which is a struct. Therefore, paint.supplier is of type supplierType. b. Incorrect. paint is a struct variable of type paintType. supplier is a member of paint, and supplier is of type supplierType, which is a struct. Therefore, paint.supplier is of type supplierType. c. Correct. paint is a struct variable of type paintType. supplier is a member of paint, and supplier is of type supplierType, which is a struct. Therefore, paint.supplier is of type supplierType. d. Incorrect. paint is a struct variable of type paintType. supplier is a member of paint, and supplier is of type supplierType, which is a struct. Therefore, paint.supplier is of type supplierType.

POINTS: 1 REFERENCES: 626 – structs within a struct QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.09.08 Learn how to create structs within a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/15/2020 10:01 PM 35. A struct is a(n) ____________________, not a declaration. ANSWER: definition Copyright Cengage Learning. Powered by Cognero.

Page 21


Name:

Class:

Date:

Chapter 9 POINTS: 1 REFERENCES: 613 – Records (structs) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.09.01 Learn about records (structs) DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/5/2020 8:44 PM 36. The following statement defines a struct houseType with a total of ____________________ member(s). struct houseType { string style; int numOfBedrooms; int numOfBathrooms; int numOfCarsGarage; int yearBuilt; }; ANSWER: 5 five POINTS: 1 REFERENCES: 613 – Records (structs) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.09.01 Learn about records (structs) DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/5/2020 8:46 PM 37. Memory is allocated for struct variables only when you ____________________ them. ANSWER: declare POINTS: 1 REFERENCES: 613 – Records (structs) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.09.01 Learn about records (structs) DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/15/2020 10:05 PM 38. Arrays are passed by ____________________ only. Copyright Cengage Learning. Powered by Cognero.

Page 22


Name:

Class:

Date:

Chapter 9 ANSWER: reference POINTS: 1 REFERENCES: 619 – struct Variables and Functions QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.09.04 Learn about the relationship between a struct and functions DATE CREATED: DATE MODIFIED:

10/5/2016 1:40 PM 3/5/2020 8:55 PM

39. Consider the following struct definition: const int ARRAY_SIZE = 1000; struct listType { int listElem[ARRAY_SIZE]; int listLength; }; The statement that declares intList to be a struct variable of type listType is ____________________. listType intList; ANSWER: POINTS: 1 REFERENCES: 620 – Arrays in structs QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.09.06 Discover how arrays are used in a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/15/2020 10:03 PM 40. If a variable is passed by ____________________, then when the formal parameter changes, the actual parameter also changes. ANSWER: reference POINTS: 1 REFERENCES: 622 – Arrays in structs QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.09.06 Discover how arrays are used in a struct DATE CREATED: 10/5/2016 1:40 PM DATE MODIFIED: 3/5/2020 9:16 PM Copyright Cengage Learning. Powered by Cognero.

Page 23


Name:

Class:

Date:

Chapter 9

Copyright Cengage Learning. Powered by Cognero.

Page 24


Name:

Class:

Date:

Chapter 10 1. A class is an example of a structured data type. a. True b. False ANSWER: True FEEDBACK: Correct In C++, a class is a structured data types. Incorrect In C++, a class is a structured data types.

POINTS: 1 REFERENCES: 652– QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.01 - Learn about classes DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/9/2020 9:15 PM 2. In C++, class is a reserved word and it defines only a data type. a. True b. False ANSWER: True FEEDBACK: Correct In C++, class is a reserved word and it defines only a data type. Incorrect In C++, class is a reserved word and it defines only a data type.

POINTS: 1 REFERENCES: 653–Classes QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.01 - Learn about classes DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/15/2020 11:24 PM 3. If the heading of a member function of a class ends with the word const, then the function member cannot modify the private member variables, but it can modify the public member variables. a. True b. False ANSWER: False FEEDBACK: Correct The word const at the end of a class member function's heading specifies that that the member function cannot modify the public or private member variables of a variable (object) of that class. Incorrect The word const at the end of a class member function's heading specifies that that the member function cannot modify the public or private member variables of a variable (object) of that class. POINTS: REFERENCES: QUESTION TYPE:

1 655 – Classes True / False

Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 10 HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.02 - Learn about private, protected, and public members of a class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/15/2020 11:25 PM 4. In C++ terminology, a class object is the same as a class instance. a. True b. False ANSWER: True FEEDBACK: Correct In C++, a class variable is known as a class instance or class object. Incorrect In C++, a class variable is known as a class instance or class object.

POINTS: 1 REFERENCES: 656 – Variable (Object) Declaration QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/15/2020 11:26 PM 5. Given this declaration: class myClass { public: void print(); //Output the value of x; MyClass(); private: int x; }; myClass myObject; The following statement is legal. myObject.x = 10; a. True b. False ANSWER: FEEDBACK:

False Correct

myObject is a myClass object and it cannot directly access its private members. Therefore, because x is a private member of myObject, the expression myObject.x is illegal, and hence the statement myObject.x = 10; is illegal.

Incorrect myObject is a myClass object and it cannot directly access its private members.

Therefore, because x is a private member of myObject, the expression myObject.x is illegal, and hence the statement myObject.x = 10; is illegal. POINTS: REFERENCES:

1 657 – Accessing Class Members

Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 10 QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 10:19 PM 6. If a class object is declared in the definition of a member function of that class, then the object can access both the public and private members of the class. a. True b. False ANSWER: True FEEDBACK: Correct If a class object is declared in the definition of a member function of that class, then the object can access both the public and private members of the class. Incorrect If a class object is declared in the definition of a member function of that class, then the object can access both the public and private members of the class. POINTS: 1 REFERENCES: 657 – Accessing Class Members QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/15/2020 11:29 PM 7. If an object is created in a user program, then the object can access both the public and private members of the class. a. True b. False ANSWER: False FEEDBACK: Correct When an object is created in a user program, then the object can access only the public members. Incorrect When an object is created in a user program, then the object can access only the public members. POINTS: 1 REFERENCES: 657 – Accessing Class Members QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/15/2020 11:29 PM 8. You can use built-in arithmetic operators to perform arithmetic operations on class objects. a. True b. False Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 10 ANSWER: FEEDBACK:

False Correct

A program cannot use built-in arithmetic operators to do arithmetic operations on class objects. Incorrect A program cannot use built-in arithmetic operators to do arithmetic operations on class objects.

POINTS: 1 REFERENCES: 659 – Built-in Operations on Classes QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/9/2020 9:55 PM 9. As parameters to a function, class objects can be passed by reference only. a. True b. False ANSWER: False FEEDBACK: Correct As parameters to a function, a class object can be passed either by reference or by value. Incorrect As parameters to a function, a class object can be passed either by reference or by value.

POINTS: 1 REFERENCES: 660 – Functions and Classes QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/9/2020 9:57 PM 10. The public members of a class must be declared before the private members. a. True b. False ANSWER: False FEEDBACK: Correct In C++, there is no fixed order to declare private and public members. Incorrect In C++, there is no fixed order to declare private and public members.

POINTS: 1 REFERENCES: 670 – Order of Public and Private Members of a Class QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.02 - Learn about private, protected, and public members of a class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/15/2020 11:31 PM Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 10 11. The components of a class are called the ____ of the class. a. elements b. members c. objects d. properties ANSWER: b FEEDBACK: a. Incorrect. The components of a class are called the members of the class. b. Correct. The components of a class are called the members of the class. c. Incorrect. The components of a class are called the members of the class. d. The components of a class are called the members of the class. POINTS: 1 REFERENCES: 652 – Classes QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.01 - Learn about classes DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/9/2020 10:06 PM 12. Which of the following class definitions is correct in C++? a. class studentType { public: void setData(string, double, int); private: string name; }; b. class studentType { public: void setData(string, double, int); void print() const; private: string name; double gpa; } c. class studentType { public void setData(string, double, int); private string name; }; d. studentType class { public: void setData(string, double, int); private: string name; }; Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 10 ANSWER: FEEDBACK:

a a. Correct. Following the syntax to define a class, this class definition is correct. b. Incorrect. Recall the syntax to define a class and/or review it in the text. This class definition is incorrect because, in the ninth line, the semicolon, ;, is missing after }. c. Incorrect. Recall the syntax to define a class and/or review it in the text. This class definition is incorrect because, in the third and fourth lines, the colon, :, is missing after the member access specifiers public and private. d. Incorrect. Recall the syntax to define a class and/or review it in the text. This class definition is incorrect because the first line does not begin with the keyword class. The first line should be: class studentType

POINTS: 1 REFERENCES: 654 – Classes QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.01 - Learn about classes DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 3:39 AM 13. If a member of a class is ____, you cannot access it outside the class. a. public b. automatic c. private d. static ANSWER: FEEDBACK:

c a. Incorrect. When a member of a class is private, a programr cannot access the member outside the class. b. Incorrect. When a member of a class is private, a program cannot access the member outside the class. c. Correct. When a member of a class is private, a program cannot access the member outside the class. d. Incorrect. When a member of a class is private, a program cannot access the member outside the class.

POINTS: 1 REFERENCES: 654–Classes QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.02 - Learn about private, protected, and public members of a class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/15/2020 11:34 PM 14. A class and its members can be described graphically using a notation known as the ____ notation. a. OON b. OOD c. UML d. OOP Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 10 ANSWER: FEEDBACK:

c a. Incorrect. A class and its members can be described graphically using a notation known as the UML notation. There is no term OON in C++. b. Incorrect. A class and its members can be described graphically using a notation known as the UML notation. OOD stands for object oriented design. c. Correct. A class and its members can be described graphically using a notation known as the UML notation. d. Incorrect. A class and its members can be described graphically using a notation known as the UML notation. OOP stands for object oriented programming.

POINTS: 1 REFERENCES: 656 – Unified Modeling Language Class Diagrams QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.02 - Learn about private, protected, and public members of a class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/9/2020 10:17 PM clockType -hr: int -min: int -sec: int +setTime(int, int, int): void +getTime(int&, int&, int&) const: void +printTime() const: void +incrementSeconds(): int +incrementMinutes(): int +incrementHours(): int +equalTime(const clockType&) const: bool 15. The word ____ at the end of several the member functions in the accompanying figure class clockType specifies that these functions cannot modify the member variables of a clockType object. a. static b. const c. automatic d. private ANSWER: FEEDBACK:

b a. Incorrect. The word const at the end of a member function's heading in the class clockType specifies that these functions cannot modify the member variables of a clockType object. b. Correct. The word const at the end of a member function's heading in the class clockType specifies that these functions cannot modify the member variables of a clockType object. c. Incorrect. The word const at the end of a member function's heading in the class clockType specifies that these functions cannot modify the member variables of a clockType object. d. Incorrect. The word const at the end of a member function's heading in the class clockType specifies that these functions cannot modify the member variables of a clockType object.

Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 10 POINTS: 1 REFERENCES: 655 – Classes QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: clockType definition LEARNING OBJECTIVES: PDDS.MALI.10.02 - Learn about private, protected, and public members of a class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/15/2020 11:37 PM 16. Consider the UML class diagram shown in the accompanying figure. Which of the following is the name of the class? a. clock b. clockType c. Type d. +clockType ANSWER: FEEDBACK:

b a. Incorrect. The clockType is the class name in the UML class diagram. b. Correct. The clockType is the class name in the UML class diagram. c. Incorrect. The clockType is the class name in the UML class diagram. d. Incorrect. The clockType is the class name in the UML class diagram.

POINTS: 1 REFERENCES: 656 – Unified Modeling Language Class Diagrams QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: clockType definition LEARNING OBJECTIVES: PDDS.MALI.10.02 - Learn about private, protected, and public members of a class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/15/2020 11:37 PM 17. Consider the UML class diagram shown in the accompanying figure. According to the UML class diagram, how many private members are in the class? a. none b. zero c. two d. three ANSWER: d FEEDBACK: a. Incorrect. In a UML class diagram, the symbol - before a member name specifies that the member is a private member. Thus, there are three private members in the UML class diagram. b. Correct. In a UML class diagram, the symbol - before a member name specifies that the member is a private member. Thus, there are three private members in the UML class diagram. c. Incorrect. In a UML class diagram, the symbol - before a member name specifies that the member is a private member. Thus, there are three private members in the UML class diagram. d. Incorrect. In a UML class diagram, the symbol - before a member name specifies that the member is a private member. Thus, there are three private members in the UML class diagram. Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 10 POINTS: 1 REFERENCES: 656 – Unified Modeling Language Class Diagrams QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: clockType definition LEARNING OBJECTIVES: PDDS.MALI.10.02 - Learn about private, protected, and public members of a class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 10:28 PM 18. A ____ sign in front of a member name on a UML diagram indicates that this member is a public member. a. + b. c. # d. $ ANSWER: a FEEDBACK: a. Correct.In a UML diagram, the + sign in front of the member name specifies that the member is a public member. b. Incorrect. In a UML diagram, the + sign in front of the member name specifies that the member is a public member. c. Incorrect. In a UML diagram, the + sign in front of the member name specifies that the member is a public member. d. Incorrect. In a UML diagram, the + sign in front of the member name specifies that the member is a public member. POINTS: 1 REFERENCES: 656 – Unified Modeling Language Class Diagrams QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.02 - Learn about private, protected, and public members of a class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/15/2020 11:39 PM 19. A ____ sign in front of a member name on a UML diagram indicates that this member is a protected member. a. + b. c. # d. $ ANSWER: FEEDBACK:

c

POINTS:

1

a. Incorrect. In a UML diagram, the # sign in front of the member name specifies that the member is a protected member. b. Incorrect. In a UML diagram, the # sign in front of the member name specifies that the member is a protected member. c. Correct. In a UML diagram, the # sign in front of the member name specifies that the member is a protected member. d. Incorrect. In a UML diagram, the # sign in front of the member name specifies that the member is a protected member.

Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 10 REFERENCES: 656 – Unified Modeling Language Class Diagrams QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.02 - Learn about private, protected, and public members of a class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 10:29 PM class rectangleType { public: void setLengthWidth(double x, double y); //Postcondition: length = x; width = y; void print() const; //Output length and width; double area(); //Calculate and return the area of the rectangle; double perimeter(); //Calculate and return the parameter; rectangleType(); //Postcondition: length = 0; width = 0; rectangleType(double x, double y); //Postcondition: length = x; width = y; private: double length; double width; }; 20. Consider the accompanying class definition. Which of the following variable declarations is correct? a. rectangle rectangleType; b. class rectangleType rectangle; c. rectangleType rectangle; d. rectangle rectangleType.area; ANSWER: FEEDBACK:

c a. Incorrect. The syntax to declare a variable is dataType identifier;. Because rectangle is not a data type; and rectangleType is a user-define data type and it cannot be used as a variable name, the statement rectangle rectangleType; is an invalid variable declaration. The correct statement is: rectangleType rectangle; b. Incorrect. The syntax to declare a variable is dataType identifier;. Because class is not a data type, the statement class rectangleType rectangle; is an invalid variable declaration. The correct statement is: rectangleType rectangle; c. Correct. The syntax to declare a variable is dataType identifier;. The statement rectangleType rectangle;, is a correct variable declaration. d. Incorrect. The syntax to declare a variable is dataType identifier;. Because rectangle is not a data type and rectangleType.area is an

Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 10 invalid identifier, the statement rectangle rectangleType.area; is an invalid variable declaration. The correct statement is: rectangleType rectangle; POINTS: 1 REFERENCES: 657 – Variable (Object) Declaration QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: rectangleType class LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 10:30 PM 21. Consider the accompanying class definition, and the declaration: rectangleType bigRect; Which of the following statements correctly uses the function print? a. rectangleType.print(); b. rectangleType::print(); bigRect.print(); c. d. bigRect::print(); ANSWER: FEEDBACK:

c a. Incorrect. The general syntax for an object to access a class member is classObjectName.memberName. rectangleType is not an object. The statement bigRect.print();correctly uses the function print b. Incorrect. The general syntax for an object to access a class member is classObjectName.memberName. rectangleType is not an object and :: is the scope resolution operator, not the member access operator. The statement bigRect.print();correctly uses the function print c. Correct. The general syntax for an object to access a class member is classObjectName.memberName. Thus, the statement bigRect.print();correctly uses the function print d. Incorrect. The general syntax for an object to access a class member is classObjectName.memberName. :: is the scope resolution operator, not the member access operator. The statement bigRect.print();correctly uses the function print

POINTS: 1 REFERENCES: 657–Variable (Object) Declaration QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: rectangleType class LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/15/2020 11:55 PM 22. Consider the accompanying class definition, and the object declaration: Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 10 rectangleType bigRect(14,10); Which of the following statements is correct? a. bigRect.setLengthWidth(); b. bigRect.setLengthWidth(3.0, 2.0); c. bigRect.length = 2.0; d. bigRect.length = bigRect.width; ANSWER: FEEDBACK:

b a. Incorrect. The function setLengthWidth has two formal parameters of type double. Therefore, it must be called with two actual parameters. The correct statement is: bigRect.setLengthWidth(3.0, 2.0); b. Correct. The function setLengthWidth has two formal parameters of type double. Therefore, it must be called with two actual parameters. Therefore, the statement bigRect.setLengthWidth(3.0, 2.0); is correct. c. Incorrect. Because length is a private member of the object bigRect, it cannot be directly accessed by bigRect. The correct statement is: bigRect.setLengthWidth(3.0, 2.0); d. Incorrect. Because length and width are private members of the object bigRect, they cannot be directly accessed by bigRect. The correct statement is: bigRect.setLengthWidth(3.0, 2.0);

POINTS: 1 REFERENCES: 658–Accessing Class Members QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: rectangleType class LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 12:51 AM 23. In C++, the ____ is called the member access operator. a. . b. , :: c. d. # ANSWER: FEEDBACK:

a a. Correct. In C++, the member access operator is represented using the dot symbol.

b. Incorrect. In C++, the member access operator is represented using the dot symbol. c. Incorrect. In C++, the member access operator is represented using the dot symbol. d. Incorrect. In C++, the member access operator is represented using the dot symbol.

POINTS: REFERENCES: QUESTION TYPE:

1 657 – Accessing Class Members Multiple Choice

Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 10 HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/9/2020 11:26 PM 24. If a class object is ____, then it is created each time the control reaches its declaration, and destroyed when the control exits the surrounding block. a. static b. automatic c. private d. public ANSWER: b FEEDBACK: a. Incorrect. An automatic object is created every time the control reaches its declaration, and destroyed when the control exists the block. b. Correct. An automatic object is created every time the control reaches its declaration, and destroyed when the control exists the block. c. Incorrect. An automatic object is created every time the control reaches its declaration, and destroyed when the control exists the block. d. Incorrect. An automatic object is created every time the control reaches its declaration, and destroyed when the control exists the block.

POINTS: 1 REFERENCES: 660 – Class Scope QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 1:00 AM 25. If a class object is ____,then it can be created once, when the control reaches its declaration, and destroyed when the program terminates. a. static b. automatic c. local d. public ANSWER: a FEEDBACK: a. Correct.A static object is created once, when the control reaches its declaration, and destroyed when the program ends. b. Incorrect. A static object is created once, when the control reaches its declaration, and destroyed when the program ends. c. Incorrect. A static object is created once, when the control reaches its declaration, and destroyed when the program ends. d. Incorrect. A static object is created once, when the control reaches its declaration, and destroyed when the program ends.

POINTS: 1 REFERENCES: 660 – Class Scope QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 10 DATE MODIFIED:

3/9/2020 11:33 PM

26. In C++, you can pass a variable by reference and still prevent the function from changing its value by using the keyword ____ in the corresponding formal parameter's declaration. a. automatic b. private c. static d. const ANSWER: FEEDBACK:

d a. Incorrect. In C++, one can pass a variable by reference and can still prevent the function from altering its value by using the keyword const in the corresponding formal parameter's declaration. b. Incorrect. In C++, one can pass a variable by reference and can still prevent the function from altering its value by using the keyword const in the corresponding formal parameter's declaration. c. Incorrect. In C++, one can pass a variable by reference and can still prevent the function from altering its value by using the keyword const in the corresponding formal parameter's declaration. d. Correct.In C++, one can pass a variable by reference and can still prevent the function from altering its value by using the keyword const in the corresponding formal parameter's declaration.

POINTS: 1 REFERENCES: 660 – Reference Parameters and Class Objects (Variables) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/15/2020 11:59 PM 27. In C++, the scope resolution operator is ____. a. : b. :: c. $ d. . ANSWER: FEEDBACK:

b a. Incorrect. In C++, the operator :: is called the scope resolution operator. b. Correct. In C++, the operator :: is called the scope resolution operator. c. Incorrect. In C++, the operator :: is called the scope resolution operator. d. Incorrect. . In C++, the operator :: is called the scope resolution operator.

POINTS: 1 REFERENCES: 662 – Implementation of Member Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 12:00 AM Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 10 28. A member function of a class that only accesses the value(s) of the data member(s) is called a(n) ____ function. a. accessor b. mutator c. constructor d. destructor ANSWER: a FEEDBACK: a. <p>Correct. A member function of a class that can only access and cannot modify the values of the member variables is called an accessor function.</p> b. <p>Incorrect. A member function of a class that can only access and cannot modify the values of the member variables is called an accessor function.</p> c. <p>Incorrect. A member function of a class that can only access and cannot modify the values of the member variables is called an accessor function.</p> d. <p>Incorrect. A member function of a class that can only access and cannot modify the values of the member variables is called an accessor function.</p>

POINTS: 1 REFERENCES: 666 – Accessor and Mutator Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.04 - Become aware of accessor and mutator functions DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 5/11/2020 5:36 PM 29. To guarantee that the member variables of a class object are initialized, you use ____. a. accessors b. mutators c. constructors d. destructor ANSWER: c FEEDBACK: a. Incorrect. A constructor executes automatically when a class object is declared. Therefore, to guarantee the initialization of data members of a class object, you use constructors in a class. b. Incorrect. A constructor executes automatically when a class object is declared. Therefore, to guarantee the initialization of data members of a class object, you use constructors in a class. c. Correct. A constructor executes automatically when a class object is declared. Therefore, to guarantee the initialization of data members of a class object, you use constructors in a class. d. Incorrect. A constructor executes automatically when a class object is declared. Therefore, to guarantee the initialization of data members of a class object, you use constructors in a class.

POINTS: 1 REFERENCES: 671 – Constructors QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.05 - Examine constructors and destructors DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 1:05 AM class secretType { Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 10 public: static int count; static int z; secretType(); secretType(int a); void print(); static void incrementY(); private: int x; static int y; }; secretType::secretType() { x = 1; } secretType::secretType(int a) { x = a; } void secretType::print() { cout << "x = " << x << ", y = " << y << "z = " << z << ", count = " << count << endl; } static void secretType::incrementY() { y++; } 30. Consider the accompanying class and member functions definitions. How many constructors are present in the class definition? a. none b. one c. two d. three ANSWER: c FEEDBACK: a. Incorrect. The constructors in the class are secretType(); and secretType(int a);. Thus, there are two constructors. b. Incorrect. The constructors in the class are secretType(); and secretType(int a);. Thus, there are two constructors. c. Correct. The constructors in the class are secretType(); and secretType(int a);. Thus, there are two constructors. d. Incorrect. The constructors in the class are secretType(); and secretType(int a);. Thus, there are two constructors. Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 10 POINTS: 1 REFERENCES: 672 – Constructors QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: secretType class LEARNING OBJECTIVES: PDDS.MALI.10.05 - Examine constructors and destructors DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 12:09 AM 31. How many destructors can a class have? a. no explicit destructors b. one c. two d. any number ANSWER: b FEEDBACK: a. Incorrect. A class can have only one destructor. b. Correct. A class can have only one destructor. c. Incorrect. A class can have only one destructor. d. Incorrect. A class can have only one destructor. POINTS: 1 REFERENCES: 681 – Destructors QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.05 - Examine constructors and destructors DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/9/2020 11:53 PM 32. The name of a destructor in a class is the character ____ followed by the name of the class. a. . b. :: c. # d. ~ ANSWER: FEEDBACK:

d a. Incorrect. The name of a destructor in a class is the character ~ followed by the name of the class. b. Incorrect. The name of a destructor in a class is the character ~ followed by the name of the class. c. Incorrect. The name of a destructor in a class is the character ~ followed by the name of the class. d. Incorrect. The name of a destructor in a class is the character ~ followed by the name of the class.

POINTS: 1 REFERENCES: 681 – Destructors QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.05 - Examine constructors and destructors Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 10 DATE CREATED: DATE MODIFIED:

10/5/2016 1:41 PM 3/16/2020 12:13 AM

33. What does ADT stand for? a. abstract definition type c. abstract data type ANSWER: c FEEDBACK:

b. asynchronous data transfer d. alternative definition type a. Incorrect. ADT stands for abstract data type. b. Incorrect. ADT stands forabstract data type. c. Correct. ADT stands for abstract data type. d. Incorrect. ADT stands for abstract data type.

POINTS: 1 REFERENCES: 682 – Data Abstraction, Classes, and Abstract Data Types QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.06 - Learn about the abstract data type (ADT) DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/9/2020 11:58 PM 34. Which of the following is true about classes and structs? a. By default, all members of a struct are public and all members of a class are private. b. A struct variable is passed by value only, and a class variable is passed by reference only. c. An assignment operator is allowed on class variables, but not on struct variables. d. You cannot use the member access specifier private in a struct. ANSWER: a FEEDBACK: a. Correct. By default, all members of a struct are public and all members of a class are private. b. Incorrect. By default, all members of a struct are public and all members of a class are private. A struct or a class variable can be passed by value or by reference. c. Incorrect. By default, all members of a struct are public and all members of a class are private. The assignment operator is allowed both on class variables and struct variables. d. Incorrect. By default, all members of a struct are public and all members of a class are private. You can use the member access specifier private in a struct. POINTS: 1 REFERENCES: 685 – A struct versus a class QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.08 - Become aware of the differences between a struct and a class DATE CREATED: 10/5/2016 1:41 PM Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 10 DATE MODIFIED:

3/16/2020 12:19 AM

35. If a function of a class is static, it is declared in the class definition using the keyword static in its ____. a. return type b. parameters c. heading d. main function ANSWER: c FEEDBACK: a. Incorrect. If a function of a class is static, it is declared in the class definition using the keyword static in its heading. b. Incorrect. If a function of a class is static, it is declared in the class definition using the keyword static in its heading. c. Correct. If a function of a class is static, it is declared in the class definition using the keyword static in its heading. d. Incorrect. If a function of a class is static, it is declared in the class definition using the keyword static in its heading. POINTS: 1 REFERENCES: 701 – Static Members of a Class QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.10.11 - Learn about the static members of a class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 1:21 AM 36. The definition of a(n) _________ member function of a class is placed in the implementations file of the class. ANSWER: inline POINTS: 1 REFERENCES: 700 – Executable Code QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.10.10 - Become aware of inline functions of a class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 12:06 AM 37. If a class object is passed by ____________________, the contents of the member variables of the actual parameter are copied into the corresponding member variables of the formal parameter. ANSWER: value POINTS: 1 REFERENCES: 660 – Functions and Classes QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM Copyright Cengage Learning. Powered by Cognero.

Page 19


Name:

Class:

Date:

Chapter 10 DATE MODIFIED:

3/10/2020 12:08 AM

38. Non-static member variables of a class are called the ____________________ variables of the class. ANSWER: instance POINTS: 1 REFERENCES: 666 – Implementation of Member Functions QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 12:10 AM 39. A program or software that uses and manipulates the objects of a class is called a(n) ____________________ of that class. ANSWER: client POINTS: 1 REFERENCES: 666 – Implementation of Member Functions QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 12:11 AM 40. A(n) ____________________ function of a class changes the values of the member variable(s) of the class. ANSWER: mutator POINTS: 1 REFERENCES: 666 – Implementation of Member Functions QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.10.03 - Explore how classes are implemented DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 12:12 AM 41. A(n) ____________________ contains the definitions of the functions to implement the operations of an object. ANSWER: implementation file POINTS: 1 REFERENCES: 686 – Information Hiding QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic Copyright Cengage Learning. Powered by Cognero.

Page 20


Name:

Class:

Date:

Chapter 10 LEARNING OBJECTIVES: PDDS.MALI.10.09 - Learn about information hiding DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 12:14 AM 42. The header file is also known as the ____________________ file. ANSWER: interface POINTS: 1 REFERENCES: 686 – Information Hiding QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.10.09 - Learn about information hiding DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 1:12 AM 43. A(n) ____________________ is a statement specifying the condition(s) that must be true before the function is called. ANSWER: precondition POINTS: 1 REFERENCES: 687 – Information Hiding QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.10.09 - Learn about information hiding DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 12:23 AM

Copyright Cengage Learning. Powered by Cognero.

Page 21


Name:

Class:

Date:

Chapter 11 1. In multiple inheritance, the derived class has more than one base class. a. True b. False ANSWER: True FEEDBACK: Correct When a derived class is inherited from one or more base classes, it is called multiple inheritance. Incorrect When a derived class is inherited from one or more base classes, it is called multiple inheritance.

POINTS: 1 REFERENCES: 745–Inheritance QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.02 - Learn about derived and base classes DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 9:46 PM 2. The private members of a base class can be directly accessed by a derived class. a. True b. False ANSWER: False FEEDBACK: Correct The private members of a base class remain private to the base class and cannot be directly accessed in the derived class. Incorrect The private members of a base class remain private to the base class and cannot be directly accessed in the derived class. POINTS: 1 REFERENCES: 746 – Inheritance QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.02 - Learn about derived and base classes DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 1:01 AM 3. A derived class cannot directly access public members of a base class. a. True b. False ANSWER: False FEEDBACK: Correct A derived class can directly access public members of a base class. Incorrect A derived class can directly access public members of a base class.

POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 746 – Inheritance True / False False

Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 11 LEARNING OBJECTIVES: PDDS.MALI.11.02 - Learn about derived and base classes DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 1:02 AM 4. If the derived class does not override a public member function of the base class, then in the definition of a member function of the derived class, you may specify a call to that public member function by using the name of the function and the appropriate parameter list. a. True b. False ANSWER: True FEEDBACK: Correct When the derived class does not override a public member function of the base class, then in the definition of a member function of the derived class you can specify a call to that member function by using the function name and the appropriate parameter list. Incorrect When the derived class does not override a public member function of the baseclass, then in the definition of a member function of the derived class you can specify a call to that member function by using the function name and the appropriate parameter list. POINTS: 1 REFERENCES: 751 – Redefining (Overriding) Member Functions of the Base Class QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.03 - Explore how to redefine the member functions of a base class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 1:03 AM 5. The constructors of a derived class can (directly) initialize only the (public data) members inherited from the base class of the derived class. a. True b. False ANSWER: True FEEDBACK: Correct The constructor of a derived class can directly initialize only the public (data) members inherited from the base class. Incorrect The constructor of a derived class can directly initialize only the public (data) members inherited from the base class. POINTS: 1 REFERENCES: 754 – Constructors of Derived and Base Classes QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.04 - Examine how the constructors of base and derived classes work DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 1:03 AM 6. A call to the base class’s constructor is specified in the heading of the definition of a derived class constructor. Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 11 a. True b. False ANSWER: FEEDBACK:

True Correct

A call to the constructor of a base class is specified in the heading of the definition of a derived class' constructor. Incorrect A call to the constructor of a base class is specified in the heading of the definition of a derived class' constructor.

POINTS: 1 REFERENCES: 754 – Constructors of Derived and Base Classes QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.04 - Examine how the constructors of base and derived classes work DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 10:10 PM 7. The class io is the base class of the C++ stream classes istream and ostream. a. True b. False ANSWER: False FEEDBACK: Correct The C++ stream classes istream and ostream are derived from the class ios. Therefore, the class ios is the base class of these stream classes. Incorrect The C++ stream classes istream and ostream are derived from the class ios. Therefore, the class ios is the base class of these stream classes. POINTS: 1 REFERENCES: 768 – C++ Stream Classes QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.07 - Become aware of stream classes hierarchy DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 1:04 AM 8. A derived class can directly access the protected members of the base class. a. True b. False ANSWER: True FEEDBACK: Correct A derived class can directly access the protected members of the base class. Incorrect A derived class can directly access the protected members of the base class.

POINTS: 1 REFERENCES: 769 – Protected Members of a Class QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.08 - Explore three types of inheritance: public, protected, and private Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 11 DATE CREATED: DATE MODIFIED:

10/5/2016 1:41 PM 3/16/2020 1:05 AM

9. In protected inheritance, public and protected members of the base class become the protected members of the derived class. a. True b. False ANSWER: True FEEDBACK: Correct In protected inheritance, public and protected members of the base class become the protected members of the derived class. Incorrect In protected inheritance, public and protected members of the base class

become the protected members of the derived class. POINTS: 1 REFERENCES: 770 – Inheritance as Public, Protected, or Private QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.08 - Explore three types of inheritance: public, protected, and private DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 5/11/2020 5:37 PM 10. If inheritance is private, all members of the base class, including private members, become private members of the derived class. a. True b. False ANSWER: False FEEDBACK: Correct In private inheritance, all public and protected members of the base class are private members of the derived class; however, private members of the base class are hidden in the derived class and can be accessed in the derived class through the public or protected members of the base class. Incorrect In private inheritance, all public and protected members of the base class

are private members of the derived class; however, private members of the base class are hidden in the derived class and can be accessed in the derived class through the public or protected members of the base class. POINTS: 1 REFERENCES: 770 – Inheritance as Public, Protected, or Private QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.08 - Explore three types of inheritance: public, protected, and private DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 5/11/2020 5:39 PM 11. Inheritance is an example of a(n) ____ relationship. a. is-a b. has-a Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 11 c. handshaking ANSWER: FEEDBACK:

d. had-a a a. Correct. Inheritance is a type of is-a relationship. b. Incorrect. Inheritance is a type of is-a relationship. c. Incorrect. Inheritance is a type of is-a relationship. d. Incorrect. Inheritance is a type of is-a relationship.

POINTS: 1 REFERENCES: 744 – Inheritance QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.01 - Learn about inheritance DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 10:27 PM 12. Classes can create new classes from existing classes. This important feature ____. a. encourages code reuse b. aids the separation of data and operations c. provides public access to the internal state of an object d. results in more software complexity ANSWER: a FEEDBACK: a. Correct. In C++, the Inheritance feature encourages code reuse. b. Incorrect. In C++, the Inheritance feature encourages code reuse. c. Incorrect. In C++, the Inheritance feature encourages code reuse. d. Incorrect. In C++, the Inheritance feature encourages code reuse. POINTS: 1 REFERENCES: 744 – Inheritance QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.01 - Learn about inheritance DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 10:30 PM 13. ____ is a “has-a” relationship. a. Inheritance b. Encapsulation c. Composition d. Polymorphism ANSWER: c FEEDBACK: a. Incorrect. Composition is a type of has-a relationship. b. Incorrect. Composition is a type of has-a relationship. c. Correct. Composition is a type of has-a relationship. d. Incorrect. Composition is a type of has-a relationship. POINTS: REFERENCES:

1 744 –

Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 11 QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.01 - Learn about inheritance DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 10:32 PM 14. The new classes that we create from existing classes are called ____ classes. a. sibling b. base c. derived d. parent ANSWER: c FEEDBACK: a. Incorrect. The new classes that we create from existing classes are called derived classes.

b. Incorrect. The new classes that we create from existing classes are called derived classes. c. Correct. The new classes that we create from existing classes are called derived classes. d. Incorrect. The new classes that we create from existing classes are called derived classes.

POINTS: 1 REFERENCES: 745 – Inheritance QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.02 - Learn about derived and base classes DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 10:34 PM 15. Existing classes, from which you create new classes, are called ____ classes. a. child b. base c. sibling d. derived ANSWER: b FEEDBACK: a. Incorrect. Base classes are existing classes from which new classes are created. b. Correct. Base classes are existing classes from which new classes are created. c. Incorrect. Base classes are existing classes from which new classes are created. d. Incorrect. Base classes are existing classes from which new classes are created. POINTS: 1 REFERENCES: 745 – Inheritance QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.02 - Learn about derived and base classes DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 10:37 PM 16. Suppose that bClass is a class. Which of the following statements correctly derives the class dClass from bClass? Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 11 a. class dClass:: public bClass { //classMembersList }; b. class dClass: private bClass { //classMembersList }; c. class dClass:: protected bClass { //classMembersList }; d. class bClass: public dClass { //classMembersList }; ANSWER: b FEEDBACK: a. Incorrect. Recall and/or review the syntax of a derived class in the text. The correct statements to derive dClass from bClass is: class dClass: private bClass { //classMembersList }; b. Correct. Following the syntax of a derived class, these statements correctly derive dClass from bClass. c. Incorrect. Recall and/or review the syntax of a derived class in the text. The correct statements to derive dClass from bClass is: class dClass: private bClass { //classMembersList }; d. Incorrect. Recall and/or review the syntax of a derived class in the text. The correct statements to derive dClass from bClass is: class dClass: private bClass { //classMembersList }; POINTS: 1 REFERENCES: 746 – Inheritance QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.02 - Learn about derived and base classes DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 10:04 PM 17. Consider the following class definition: Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 11 class dClass: bClass { //class members list }; The class dClass is derived from the class bClass using the ____ type of inheritance. a. public b. private c. protected d. static ANSWER: FEEDBACK:

b a. Incorrect. The first line, class dClass: bClass, does not contain any member access specifier, public, protected or private. Therefore, dClass is derived from bClass using private inheritance. b. Correct. The first line, class dClass: bClass, does not contain any member access specifier, public, protected or private. Therefore, dClass is derived from bClass using private inheritance. c. Incorrect. The first line, class dClass: bClass, does not contain any member access specifier, public, protected or private. Therefore, dClass is derived from bClass using private inheritance. d. Incorrect. The first line, class dClass: bClass, does not contain any member access specifier, public, protected or private. Therefore, dClass is derived from bClass using private inheritance.

POINTS: 1 REFERENCES: 746 – Inheritance QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.02 - Learn about derived and base classes DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 1:18 AM 18. Which of the following is a valid definition of the derived class bClass? a. class aClass: public bClass { //... }; b. class bClass: public aClass { //... }; c. class aClass::bClass { //... }; d. class bClass::aClass { Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 11 //... } ANSWER: FEEDBACK:

b a. Incorrect. Recall and/or review the syntax of a derived class in the text. The correct statements to derive bClass from aClass is: class bClass: public aClass { //... }; b. Correct. Following the syntax of a derived class, these statements correctly derive bClass from aClass. c. Incorrect. Recall and/or review the syntax of a derived class in the text. The correct statements to derive bClass from aClass is: class bClass: public aClass { //... }; d. Incorrect. Recall and/or review the syntax of a derived class in the text. The correct statements to derive bClass from aClass is: class bClass: public aClass { //... };

POINTS: 1 REFERENCES: 746 – Inheritance QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.02 - Learn about derived and base classes DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 10:05 PM 19. Which of the following is true about inheritance? a. All public member functions of the base class become the public member functions of the derived class. b. All public member variables of the base class become the public member variables of the derived class. c. All public members of the base class become the public members of the derived class. d. The public member variables of the base class become the public or private member variables of the derived class. ANSWER: d FEEDBACK: a. Incorrect. The public member variables of the base class become public or private member variables of the derived class. b. Incorrect. The public member variables of the baseclass become public or private member variables of the derived class. c. Incorrect. The public member variables of the baseclass become public or private member variables of the derived class. Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 11 d. Correct. The public member variables of the baseclass become public or private member variables of the derived class. POINTS: 1 REFERENCES: 746 – Inheritance QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.02 - Learn about derived and base classes DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 1:21 AM 20. Which of the following class definitions inherits the public members of the class aClass as the public members of the class bClass? a. class aClass: public bClass { //... }; b. class bClass: public aClass { //... }; c. class bClass: aClass { //... }; d. class aClass: bClass { //... }; ANSWER: FEEDBACK:

b a. Incorrect. Recall and/or review the syntax of a derived class in the text. The class definition that inherits the public members of the class aClass as the public members of the class bClass is: class bClass: public aClass { //... }; b. Correct. Following the syntax of a derived class, these statements correctly inherits the public members of the class aClass as the public members of the class bClass c. Incorrect. Recall and/or review the syntax of a derived class in the text. The class definition that inherits the public members of the class aClass as the public members of the class bClass is: class bClass: public aClass { //... };

Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 11 d. Incorrect. Recall and/or review the syntax of a derived class in the text. The class definition that inherits the public members of the class aClass as the public members of the class bClass is: class bClass: public aClass { //... }; POINTS: 1 REFERENCES: 746 – Inheritance QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.02 - Learn about derived and base classes DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 10:06 PM 21. Which of the following is true about a derived class? a. A derived class can directly access any member variable of the base class. b. A derived class can redefine any public member function of the base class. c. A derived class can have at most one base class. d. A derived class can redefine any member function of the base class. ANSWER: b FEEDBACK: a. Incorrect. Any public member function of the base class can be redefined by a derived class. b. Correct. Any public member function of the base class can be redefined by a derived class. c. Incorrect. Any public member function of the base class can be redefined by a derived class. d. Incorrect. Any public member function of the base class can be redefined by a derived class. POINTS: 1 REFERENCES: 747 – Inheritance QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.02 - Learn about derived and base classes DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 1:27 AM 22. To ____ a public member function of a base class in the derived class, the corresponding function in the derived class must have the same name, number, and types of parameters. a. redefine b. overload c. rename d. reuse ANSWER: a FEEDBACK: a. Correct. For redefining a public member function of a parent class in the child Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 11 class, the corresponding function in the child class must has the same name, number, and type of parameters. b. Incorrect. For redefining a public member function of a parent class in the child class, the corresponding function in the child class must has the same name, number, and type of parameters. c. Incorrect. For redefining a public member function of a parent class in the child class, the corresponding function in the child class must has the same name, number, and type of parameters. d. Incorrect. For redefining a public member function of a parent class in the child class, the corresponding function in the child class must has the same name, number, and type of parameters. POINTS: 1 REFERENCES: 747 – Redefining (Overriding) Member Functions of the Base Class QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.03 - Explore how to redefine the member functions of a base class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 1:28 AM 23. If the corresponding functions in the base class and the derived class have the same name but different sets of parameters, then this function is ____ in the derived class. a. reused b. redefined c. overloaded d. overridden ANSWER: c FEEDBACK: a. Incorrect. A function is said to be an overloaded function in the derived class when the corresponding functions in the parent class and the child class have the same name but different sets of parameters. b. Incorrect. A function is said to be an overloaded function in the derived class when the corresponding functions in the parent class and the child class have the same name but different sets of parameters. c. Correct. A function is said to be an overloaded function in the derived class when the corresponding functions in the parent class and the child class have the same name but different sets of parameters. d. Incorrect. A function is said to be an overloaded function in the derived class when the corresponding functions in the parent class and the child class have the same name but different sets of parameters.

POINTS: 1 REFERENCES: 747 – Redefining (Overriding) Member Functions of the Base Class QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.03 - Explore how to redefine the member functions of a base class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/10/2020 11:37 PM 24. Consider the following class definitions: Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 11 class bClass { public: void setX(int); void print() const; private: int x; }; class dClass: public bClass { public: void setXY(int, int); void print() const; private: int y; }; Which of the following function definition correctly redefines the member function print of bClass in the derived class dClass? a. void dClass::print() const { dClass:print(); cout << " " << y << endl; } b. void dClass::print() const { cout << x << " " << y << endl; } c. void bClass::print() const { cout << x << " " << y << endl; } d. void dClass::print() const { bClass::print(); cout << "y = " << y << endl; } ANSWER: FEEDBACK:

d a. Incorrect. To redefine a public member function of a base class in the derived class, the corresponding function in the derived class must have the same name, number, and types of parameters. Also, because x is a private member of bClass, it cannot be directly accessed in dClass. Therefore, to print the value of x, the function print of bClass must be called. The correct function definition is:void dClass::print() const { bClass::print(); cout << "y = " << y << endl;

Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 11 } b. Incorrect. To redefine a public member function of a base class in the derived class, the corresponding function in the derived class must have the same name, number, and types of parameters. Also, because x is a private member of bClass, it cannot be directly accessed in dClass. Therefore, to print the value of x, the function print of bClass must be called. The correct function definition is: void dClass::print() const { bClass::print(); cout << "y = " << y << endl; } c. Incorrect. To redefine a public member function of a base class in the derived class, the corresponding function in the derived class must have the same name, number, and types of parameters. Also, because x is a private member of bClass, it cannot be directly accessed in dClass. Therefore, to print the value of x, the function print of bClass must be called. The correct function definition is: void dClass::print() const { bClass::print(); cout << "y = " << y << endl; } d. Correct. To redefine a public member function of a base class in the derived class, the corresponding function in the derived class must have the same name, number, and types of parameters. Also, because x is a private member of bClass, it cannot be directly accessed in dClass. Therefore, to print the value of x, the function print of bClass must be called. The correct function definition is: void dClass::print() const { bClass::print(); cout << "y = " << y << endl; } POINTS: 1 REFERENCES: 747 – Redefining (Overriding) Member Functions of the Base Class QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.03 - Explore how to redefine the member functions of a base class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 10:11 PM 25. If the derived class classD overrides the public member function baseFunc of the base class classB, then to specify a call to baseFunc in classD, you use the statement ____. a. classD:: baseFunc(); b. classB::baseFunc(); Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 11 c. classD.baseFunc(); d. classB.baseFunc(); ANSWER: b FEEDBACK: a. Incorrect. To override a public member function of a base class you use the name of the base class, followed by the scope resolution operator, ::, followed by the function name with the appropriate parameter list. Therefore, the correct statement is: classB::baseFunc(); b. Correct. To override a public member function of a base class you use the name of the base class, followed by the scope resolution operator, ::, followed by the function name with the appropriate parameter list. Therefore, the correct statement is: classB::baseFunc(); c. Incorrect. To override a public member function of a base class you use the name of the base class, followed by the scope resolution operator, ::, followed by the function name with the appropriate parameter list. Therefore, the correct statement is: classB::baseFunc(); d. Incorrect. To override a public member function of a base class you use the name of the base class, followed by the scope resolution operator, ::, followed by the function name with the appropriate parameter list. Therefore, the correct statement is: classB::baseFunc(); POINTS: 1 REFERENCES: 751 – Redefining (Overriding) Member Functions of the Base Class QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.03 - Explore how to redefine the member functions of a base class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 1:39 AM 26. Which of the following statements about inheritance is true if memberAccessSpecifier is protected? a. The private members of the base class become protected members of the derived class. b. The derived class can directly access any member of the base class. c. The public members of the base class become protected members of the derived class. d. The protected members of the base class become private members of the derived class. ANSWER: c FEEDBACK: a. Incorrect. The public members of the base class become protected members of the derived class. b. Correct. The public members of the baseclass become protected members of the derivedclass. c. Incorrect. The public members of the baseclass become protected members of the derivedclass. d. Incorrect. The public members of the base class become protected members of the derivedclass. POINTS: REFERENCES: QUESTION TYPE:

1 770 – Inheritance as Public, Protected, or Private Multiple Choice

Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 11 HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.08 - Explore three types of inheritance: public, protected, and private DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 5/11/2020 5:40 PM 27. Consider the following class definitions: class bClass { public: void setX(int a); //Postcondition: x = a; void print() const; private: int x; }; class dClass: public bClass { public: void setXY(int a, int b); //Postcondition: x = a; y = b; void print() const; private: int y; }; Which of the following correctly sets the values of x and y? a. void dClass::setXY(int a, int b) { bClass::setX(a); y = b; } b. void dClass::setXY(int a, int b) { x = a; y = b; } c. void dClass::setXY(int a, int b) { x = bClass::setX(a); y = bClass::setY(b); } d. void dClass::setXY(int a, int b) { x = bClass.setX(a); b = y; } Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 11 ANSWER: FEEDBACK:

a a. Correct. The class dClass is derived from the class bClass and x is a private member of bClass. Therefore, x cannot be directly accessed in dClass. To assign a value to x, in dClass, you must use the function setX of bClass. Therefore, the correct function definition is: void dClass::setXY(int a, int b) { bClass::setX(a); y = b; } = b. Incorrect. The class dClass is derived from the class bClass and x is a private member of bClass. Therefore, x cannot be directly accessed in dClass. To assign a value to x, in dClass, you must use the function setX of bClass. Therefore, the correct function definition is: void dClass::setXY(int a, int b) { bClass::setX(a); y = b; } c. Incorrect. The class dClass is derived from the class bClass and x is a private member of bClass. Therefore, x cannot be directly accessed in dClass. To assign a value to x, in dClass, you must use the function setX of bClass. Therefore, the correct function definition is: void dClass::setXY(int a, int b) { bClass::setX(a); y = b; } d. Incorrect. The class dClass is derived from the class bClass and x is a private member of bClass. Therefore, x cannot be directly accessed in dClass. To assign a value to x, in dClass, you must use the function setX of bClass. Therefore, the correct function definition is: void dClass::setXY(int a, int b) { bClass::setX(a); y = b; }

POINTS: 1 REFERENCES: 771-772 – Inheritance as Public, Protected, or Private QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.08 - Explore three types of inheritance: public, protected, and private DATE CREATED: 10/5/2016 1:41 PM Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 11 DATE MODIFIED:

5/11/2020 5:41 PM

28. Consider the following class definitions: class bClass { public: void set(double a, double b); //Postcondition: x = a; y = b; void print() const; bClass(); //Postcondition: x = 0; y = 0; bClass(double a, double b); //Postcondition: x = a; y = b; private: double x; double y; }; class dClass: public bClass { public: void set(double a, double b, double c); //Postcondition: x = a; y = b; z = c; void print() const; dClass(); //Postcondition: x = 0; y = 0; z = 0 ; dClass(double a, double b, double c); //Postcondition: x = a; y = b; z = c; private: double z; }; Which of the following dClass constructor definitions is valid in C++? a. dClass::dClass(double a, double b, double c) : bClass() { x = a; y = b; z = c; } b. dClass::dClass(double a, double c) { x = a; z = c; } Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 11 c. dClass::dClass(double a, double b) : bClass() { x = a; y = b; } d. dClass::dClass(double a, double b, double c) : bClass(a, b) { z = c; } ANSWER: FEEDBACK:

d a. Incorrect. Both x and y are private members of bClass, and so they cannot be directly accessed in dClass. To initialize x and y in dClass, a call to the bClass constructor is specified in the heading of a constructor of dClass with appropriate parameters. The correct definition is: dClass::dClass(double a, double b, double c) : bClass(a, b) { z = c; } b. Incorrect. Both x and y are private members of bClass, and so they cannot be directly accessed in dClass. To initialize x and y in dClass, a call to the bClass constructor is specified in the heading of a constructor of dClass with appropriate parameters. The correct definition is: dClass::dClass(double a, double b, double c) : bClass(a, b) { z = c; } c. Incorrect. Both x and y are private members of bClass, and so they cannot be directly accessed in dClass. To initialize x and y in dClass, a call to the bClass constructor is specified in the heading of a constructor of dClass with appropriate parameters. The correct definition is: dClass::dClass(double a, double b, double c) : bClass(a, b) { z = c; } d. Correct. Both x and y are private members of bClass, and so they cannot be directly accessed in dClass. To initialize x and y in dClass, a call to the bClass constructor is specified in the heading of a constructor of dClass with appropriate parameters. The correct definition is: dClass::dClass(double a, double b, double c) : bClass(a, b) {

Copyright Cengage Learning. Powered by Cognero.

Page 19


Name:

Class:

Date:

Chapter 11 z = c; } POINTS: 1 REFERENCES: 770-771 – Redefining (Overriding) Member Functions of the Base Class QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.03 - Explore how to redefine the member functions of a base class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 1:47 AM 29. What is the output of the following program? #include <iostream> using namespace std; class bClass { public: void print() const; bClass(int a = 0, int b = 0); //Postcondition: x = a; y = b; private: int x; int y; }; class dClass: public bClass { public: void print() const; dClass(int a = 0, int b = 0, int c = 0); //Postcondition: x = a; y = b; z = c; private: int z; }; int main() { bClass bObject(2, 3); dClass dObject(3, 5, 8); bObject.print(); cout<<endl; dObject.print(); cout<<endl; return 0 ; Copyright Cengage Learning. Powered by Cognero.

Page 20


Name:

Class:

Date:

Chapter 11 } void bClass::print() const { cout<< x << " " << y <<endl; } bClass::bClass(int a, int b) { x = a; y = b; } void dClass::print() const { bClass:print(); cout<< " " << z <<endl; } dClass::dClass(int a, int b, int c) : bClass(a, b) { z = c; } a. 2 3 2 3 c. 3 5 8 3 5 8 ANSWER: FEEDBACK:

b. 2 3 3 5 8 d. 5 8 3 5 8 b a. Incorrect. The statement bClass bObject(2, 3); sets the value of data members x and y of bObject to 2 and 3, respectively. The statement dClass dObject(3, 5, 8); sets the value of data members x, y and z of dObject to 3, 5 and 8, respectively. The statement bObject.print(); outputs the value of x and y of bObject, and the statement dObject.print(); outputs the value of x, y and z of dObject. Therefore, the correct output is: 2 3 3 5 8 b. Correct. The statement bClass bObject(2, 3); sets the value of data members x and y of bObject to 2 and 3, respectively. The statement dClass dObject(3, 5, 8); sets the value of data members x, y and z of dObject to 3, 5 and 8, respectively. The statement bObject.print(); outputs the value of x and y of bObject, and the statement dObject.print(); outputs the value of x, y and z of dObject. Therefore, the correct output is: 2 3 3 5 8

Copyright Cengage Learning. Powered by Cognero.

Page 21


Name:

Class:

Date:

Chapter 11 c. Incorrect. The statement bClass bObject(2, 3); sets the value of data members x and y of bObject to 2 and 3, respectively. The statement dClass dObject(3, 5, 8); sets the value of data members x, y and z of dObject to 3, 5 and 8, respectively. The statement bObject.print(); outputs the value of x and y of bObject, and the statement dObject.print(); outputs the value of x, y and z of dObject. Therefore, the correct output is: 2 3 3 5 8 d. Incorrect. The statement bClass bObject(2, 3); sets the value of data members x and y of bObject to 2 and 3, respectively. The statement dClass dObject(3, 5, 8); sets the value of data members x, y and z of dObject to 3, 5 and 8, respectively. The statement bObject.print(); outputs the value of x and y of bObject, and the statement dObject.print(); outputs the value of x, y and z of dObject. Therefore, the correct output is: 2 3 3 5 8 POINTS: 1 REFERENCES: 772-773 – Inheritance as public, protected, or private QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.08 - Explore three types of inheritance: public, protected, and private DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 1:49 AM 30. ____ is the ability to combine data, and operations on that data, in a single unit. a. Inheritance b. Encapsulation c. Polymorphism d. Composition ANSWER: b FEEDBACK: a. Incorrect. In C++, the encapsulation is used to combine data and operations on that data in a single unit. b. Correct. In C++, the encapsulation is used to combine data and operations on that data in a single unit. c. Incorrect. In C++, the encapsulation is used to combine data and operations on that data in a single unit. d. Incorrect. In C++, the encapsulation is used to combine data and operations on that data in a single unit.

POINTS: 1 REFERENCES: 779 – Object-Oriented Design (OOD) and Object-Oriented Programming (OOP) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.10 - Become familiar with the three basic principles of object-oriented design DATE CREATED: 10/5/2016 1:41 PM Copyright Cengage Learning. Powered by Cognero.

Page 22


Name:

Class:

Date:

Chapter 11 DATE MODIFIED:

3/11/2020 12:58 AM

31. In ____ the same expression is used to denote different operations. a. Inheritance b. Encapsulation c. Polymorphism d. Composition ANSWER: c FEEDBACK: a. Incorrect. In polymorphism, the same expression is used to denote different operations. b. Incorrect. In polymorphism, the same expression is used to denote different operations. c. Correct. In polymorphism, the same expression is used to denote different operations. d. Incorrect. In polymorphism, the same expression is used to denote different operations.

POINTS: 1 REFERENCES: 779 – Object-Oriented Design (OOD) and Object-Oriented Programming (OOP) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.10 - Become familiar with the three basic principles of object-oriented design DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/11/2020 1:00 AM 32. OOP implements ____. a. UML b. IPE c. EIP d. OOD ANSWER: d FEEDBACK:

a. Incorrect. Object Oriented Design (OOD) is implemented by Object Oriented Programming (OOP). b. Incorrect. Object Oriented Design (OOD) isimplemented by Object Oriented Programming (OOP). c. Incorrect. Object Oriented Design (OOD) isimplemented by Object Oriented Programming (OOP). d. Correct. Object Oriented Design (OOD) isimplemented by Object Oriented Programming (OOP).

POINTS: 1 REFERENCES: 779 – Object-Oriented Design (OOD) and Object-Oriented Programming (OOP) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.10 - Become familiar with the three basic principles of object-oriented design DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/11/2020 1:01 AM 33. C++ provides ____ functions as a means to implement polymorphism in an inheritance hierarchy, which allows the Copyright Cengage Learning. Powered by Cognero.

Page 23


Name:

Class:

Date:

Chapter 11 run-time selection of appropriate member functions. a. redefined b. overridden c. virtual d. overloaded ANSWER: c FEEDBACK: a. Incorrect. In C++, virtual functions implement polymorphism in an inheritance hierarchy, which allows the run-time selection of appropriate member functions. b. Incorrect. In C++, virtual functions implement polymorphism in an inheritance hierarchy, which allows the run-time selection of appropriate member functions. c. Correct. In C++, virtual functions implement polymorphism in an inheritance hierarchy, which allows the run-time selection of appropriate member functions. d. Incorrect. In C++, virtual functions implement polymorphism in an inheritance hierarchy, which allows the run-time selection of appropriate member functions.

POINTS: 1 REFERENCES: 780 – Object-Oriented Design (OOD) and Object-Oriented Programming (OOP) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.10 - Become familiar with the three basic principles of object-oriented design DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/11/2020 1:03 AM 34. The ____ members of an object form its internal state. a. private b. protected c. public d. static ANSWER: FEEDBACK:

a a. Correct. The internal state of an object is formed by its private members. b. Incorrect. The internal state of an object is formed by its private members. c. Incorrect. The internal state of an object is formed by its private members. d. Incorrect. The internal state of an object is formed by its private members.

POINTS: 1 REFERENCES: 780 – Object-Oriented Design (OOD) and Object-Oriented Programming (OOP) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.10 - Become familiar with the three basic principles of object-oriented design DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 10:14 PM 35. The ____ members of an object form its external state. a. private b. public c. protected d. static ANSWER: FEEDBACK:

b a. Incorrect. The external state of an object is formed by its public members.

Copyright Cengage Learning. Powered by Cognero.

Page 24


Name:

Class:

Date:

Chapter 11 b. Correct. The external state of an object is formed by its public members. c. Incorrect. The external state of an object is formed by its public members. d. Incorrect. The external state of an object is formed by its public members. POINTS: 1 REFERENCES: 780 – Object-Oriented Design (OOD) and Object-Oriented Programming (OOP) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PDDS.MALI.11.10 - Become familiar with the three basic principles of object-oriented design DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/16/2020 10:15 PM 36. The constructor of a derived class cannot directly access the ____________________ member variables of the base class. private ANSWER: POINTS: 1 REFERENCES: 747 – Inheritance QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.11.04 - Examine how the constructors of base and derived classes work DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/11/2020 1:10 AM 37. The preprocessor directive ____________________ is used to prevent multiple inclusions of a header file in a program. #ifndef ANSWER: POINTS: 1 REFERENCES: 765 – Multiple Inclusions of a Header File QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.11.06 - Learn how to construct the header file of a derived class DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/11/2020 1:11 AM 38. If inheritance is public, all protected members of the base class are ____________________ members of the derived class. protected ANSWER: POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 769 – Inheritance as public, protected, or private Completion False

Copyright Cengage Learning. Powered by Cognero.

Page 25


Name:

Class:

Date:

Chapter 11 STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.11.08 - Explore three types of inheritance: public, protected, and private DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/11/2020 1:13 AM 39. In ____________________ (aggregation), one or more members of a class are objects of another class type. ANSWER: composition POINTS: 1 REFERENCES: 773 – Composition (Aggregation) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.11.09 - Learn about composition (aggregation) DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/11/2020 1:14 AM 40. In OOD, a program is a collection of interacting ____________________; in structured programming, a program is a collection of interacting functions. ANSWER: objects POINTS: 1 REFERENCES: 779 – Object-Oriented Design (OOD) and Object-Oriented Programming (OOP) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.11.10 - Become familiar with the three basic principles of object-oriented design DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/11/2020 1:15 AM 41. C++ provides ____________________ functions as a means to implement polymorphism in an inheritance hierarchy. ANSWER: virtual POINTS: 1 REFERENCES: 780 – Object-Oriented Design (OOD) and Object-Oriented Programming (OOP) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PDDS.MALI.11.10 - Become familiar with the three basic principles of object-oriented design DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/11/2020 1:17 AM

Copyright Cengage Learning. Powered by Cognero.

Page 26


Name:

Class:

Date:

Chapter 12 1. A pointer variable is a variable whose content is a memory address. a. True b. False ANSWER: True FEEDBACK: Correct The content of a pointer variable is a memory address. Incorrect The content of a pointer variable is a memory address.

POINTS: 1 REFERENCES: 818 – Pointer Data Type and Pointer Variables QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.01 - Learn about the pointer data type and pointer variables DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 1:43 AM 2. In C++, pointer variables are declared using the reserved word pointer. a. True b. False ANSWER: False FEEDBACK: Correct The general syntax for declaring a pointer variable is: dataType *identifier Incorrect The general syntax for declaring a pointer variable is: dataType *identifier POINTS: 1 REFERENCES: 818 – Declaring Pointer Variables QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.02 - Explore how to declare and manipulate pointer variables DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 1:51 AM 3. In the statement int* p, q; p and q are pointer variables. a. True b. False ANSWER: False FEEDBACK: Correct

In the given declaration, p is a pointer variable and q is an int variable. To declare both p and q to be pointer variables, the statement should be: int *p, *q.

Incorrect In the given declaration, p is a pointer variable and q is an intvariable. To

declare both p and q to be pointer variables, the statement should be: Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 12 int *p, *q. POINTS: 1 REFERENCES: 819 – Declaring Pointer Variables QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.02 - Explore how to declare and manipulate pointer variables DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 1:54 AM 4. The dereferencing operator is also known as the indirection operator and refers to the object to which its operand points. a. True b. False ANSWER: True FEEDBACK: Correct When used as a unary operator, *, is referred to as the dereferencing operator or indirection operator. It refers to the object to which its operand (that is, the pointer) points. Incorrect When used as a unary operator, *, is referred to as the dereferencing operator or indirection operator. It refers to the object to which its operand (that is, the pointer) points. POINTS: 1 REFERENCES: 821 – Dereferencing Operator (*) QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.03 - Learn about the address of the operator and the dereferencing operator DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 1:57 AM 5. In C++, the dot operator has a lower precedence than the dereferencing operator. a. True b. False ANSWER: False FEEDBACK: Correct The dereferencing operator has a lower precedence than the dot operator. Incorrect The dereferencing operator has a lower precedence than the dot operator.

POINTS: 1 REFERENCES: 826 – Classes, Structs, and Pointer Variables QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.04 - Learn how pointers work with classes and structs DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 2:01 AM Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 12 6. In C++, the member access operator arrow is >>. a. True b. False ANSWER: False FEEDBACK: Correct In C++, the member access operator arrow is ->. Incorrect In C++, the member access operator arrow is ->.

POINTS: 1 REFERENCES: 827 – Classes, Structs, and Pointer Variables QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.04 - Learn how pointers work with classes and structs DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 2:05 AM 7. Variables that are created during program execution are called static variables. a. True b. False ANSWER: False FEEDBACK: Correct Variables that are created during program execution are called dynamic variables. Incorrect Variables that are created during program execution are called dynamic variables.

POINTS: 1 REFERENCES: 830 – Dynamic Variables QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.05 - Discover dynamic variables DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 4/10/2020 10:12 AM 8. Given the declaration int *p; The statement p = new int[50]; dynamically allocates an array of 50 components of type int and p contains the base address of the array. a. True b. False ANSWER: True FEEDBACK: Correct The statement p = new int[50]; allocates memory for an array of fifty elements of int type and stores the base address of the array in p. Incorrect The statement p = new int[50]; allocates memory for an array of fifty

elements of inttype and stores the base address of the array in p. Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 12 POINTS: 1 REFERENCES: 831 – Operator new QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.06 - Explore how to use the new and delete operators to manipulate dynamic variables DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 2:56 AM 9. A memory leak is an unused memory space that cannot be allocated. a. True b. False ANSWER: True FEEDBACK: Correct An unused memory space that cannot be allocated is called a memory leak. Incorrect An unused memory space that cannot be allocated is called a memory leak.

POINTS: 1 REFERENCES: 832 – Operator delete QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.06 - Explore how to use the new and delete operators to manipulate dynamic variables DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 3:01 AM 10. If p is a pointer variable, the statement p = p + 1; is valid in C++. a. True b. False ANSWER: True FEEDBACK: Correct In C++, if p is a pointer variable, then the statement p = p + 1; is valid as the statement increments the value of p by the size of the memory allocated for its data type.For example, if p is a pointer of type int, then the statement p = p + 1 increments the value of p by 4 bytes because p is a pointer of type int and the size of the memory allocated for an int variable is 4 bytes. Incorrect In C++, if p is a pointer variable, then the statement p = p + 1; is valid as the

statement increments the value of p by the size of the memory allocated for its data type. For example, if p is a pointer of type int, then the statement p = p + 1 increments the value of p by 4 bytes because p is a pointer of type int and the size of the memory allocated for an int variable is 4 bytes. POINTS: 1 REFERENCES: 836 – Operations on Pointer Variables QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.07 - Learn about pointer arithmetic Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 12 DATE CREATED: DATE MODIFIED:

10/5/2016 1:41 PM 4/10/2020 10:32 AM

11. In C++, you declare a pointer variable by using the symbol ____ . a. * b. & c. # d. @ ANSWER: FEEDBACK:

a a. Correct. In C++, the symbol * is used between the data type and the variable name to declare a pointer. b. Incorrect. In C++, you declare a pointer variable by using the symbol *. In C++, the symbol & is called the address of operator, and it returns the address of its operand. c. Incorrect. In C++, you declare a pointer variable by using the symbol *. In C++, # is not a defined operator. In a C++ program, the symbol # is used with preprocessor directive commands, such as the command to include a header file. d. Incorrect. In C++, you declare a pointer variable by using the symbol *. In C++, the symbol @ is not defined.

POINTS: 1 REFERENCES: 818 – Declaring Pointer Variables QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.02 - Explore how to declare and manipulate pointer variables DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 11:24 PM 12. The code int *p; declares p to be a(n) ____ variable. a. new b. num c. pointer d. address ANSWER: c FEEDBACK: a. Incorrect. In C++, the symbol * is used between the data type and the variable name to declare a pointer variable. Thus, the given statement declares p to be a pointer variable. b. Incorrect. In C++, the symbol * is used between the data type and the variable name to declare a pointer variable. Thus, the given statement declares p to be a pointer variable. c. Correct. In C++, the symbol * is used between the data type and the variable name to declare a pointer variable. Thus, the given statement declares p to be a pointer variable. d. Incorrect. In C++, the symbol * is used between the data type and the variable name to declare a pointer variable. Thus, the given statement declares p to be a pointer variable.

POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 819 – Declaring Pointer Variables Multiple Choice False

Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 12 LEARNING OBJECTIVES: PAPD.MALI.12.02 - Explore how to declare and manipulate pointer variables DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 3:06 AM 13. In C++, ____ is called the address of operator. a. & b. * c. # d. -> ANSWER: FEEDBACK:

a a. Correct. In C++, the & is called the address of operator. b. Incorrect. In C++, & is called the address of operator. In C++, the symbol * is called the dereferencing operator. c. Incorrect. In C++, & is called the address of operator. In a C++ program, # is used with preprocessor directive commands, such as the command to include a header file. d. Incorrect. In C++, & is called the address of operator. In C++, -> is called the member access operator arrow.

POINTS: 1 REFERENCES: 820 – Address of Operator (&) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.03 - Learn about the address of the operator and the dereferencing operator DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 3:15 AM 14. What is the value of x after the following statements execute? int x = 25; int *p; p = &x; *p = 46; a. nullptr c. 25 ANSWER: FEEDBACK:

b. 0 d. 46 d a. Incorrect. In the given code, p is a pointer variable of type int and x is an int variable initialized to 25. After the execution of the statement p = &x;, p points to the memory location of x. The statement *p = 46; stores 46 into the memory location to which p points, that is, into x. Therefore, after the execution of the last statement, the value of x is 46. b. Incorrect. In the given code, p is a pointer variable of type int and x is an int variable initialized to 25. After the execution of the statement p = &x;, p points to the memory location of x. The statement *p = 46; stores 46 into the memory location to which p points, that is, into x. Therefore, after the execution of the last statement, the value of x is 46. c. Incorrect. In the given code, p is a pointer variable of type int and x is an int

Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 12 variable initialized to 25. After the execution of the statement p = &x;, p points to the memory location of x. The statement *p = 46; stores 46 into the memory location to which p points, that is, into x. Therefore, after the execution of the last statement, the value of x is 46. d. Correct. In the given code, p is a pointer variable of type int and x is an int variable initialized to 25. After the execution of the statement p = &x;, p points to the memory location of x. The statement *p = 46; stores 46 into the memory location to which p points, that is, into x. Therefore, after the execution of the last statement, the value of x is 46. POINTS: 1 REFERENCES: 822 – Dereferencing Operator (*) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.03 - Learn about the address of the operator and the dereferencing operator DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 3:18 AM 15. What is the output of the following statements? int x = 33; int *q; q = &x; cout << *q << endl; a. nullptr c. 3 ANSWER: FEEDBACK:

b. 0 d. 33 d a. Incorrect. In the given code, q is a pointer variable of type int and x is an int variable initialized to 33. After the execution of the statement q = &x;, q points to the memory location of x. The expression *q refers to the memory location to which q points, that is, the memory location x. The cout statement output the value of *q, which is 33. Therefore, the output is: 33 b. Incorrect. In the given code, q is a pointer variable of type int and x is an int variable initialized to 33. After the execution of the statement q = &x;, q points to the memory location of x. The expression *q refers to the memory location to which q points, that is, the memory location x. The cout statement output the value of *q, which is 33. Therefore, the output is: 33 c. Incorrect. In the given code, q is a pointer variable of type int and x is an int variable initialized to 33. After the execution of the statement q = &x;, q points to the memory location of x. The expression *q refers to the memory location to which q points, that is, the memory location x. The cout statement output the value of *q, which is 33. Therefore, the output is: 33 d. Correct. In the given code, q is a pointer variable of type int and x is an int variable initialized to 33. After the execution of the statement q = &x;, q points to the memory location of x. The expression *q refers to the memory location to which q points, that is, the memory location x. The cout statement output the value of *q, which is 33. Therefore, the output is: 33

POINTS:

1

Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 12 REFERENCES: 822 – Dereferencing Operator (*) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.03 - Learn about the address of the operator and the dereferencing operator DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 3:20 AM 16. What is the output of the following code? int *p; int x; x = 76; p = &x; *p = 43; cout << x << ", " << *p << endl; a. 76, 76 c. 43, 76 ANSWER: FEEDBACK:

b. 76, 43 d. 43, 43 d a. Incorrect. In the given code, p is a pointer variable of type int and x is an int variable. After the execution of the statement p = &x;, p points to the memory location of x, and so *p and x refers to the same memory location. The statement *p = 43; stores 43 into the memory location to which p points, that is, into x. Therefore, the output is: 43, 43 b. Incorrect. In the given code, p is a pointer variable of type int and x is an int variable. After the execution of the statement p = &x;, p points to the memory location of x, and so *p and x refers to the same memory location. The statement *p = 43; stores 43 into the memory location to which p points, that is, into x. Therefore, the output is: 43, 43 c. Incorrect. In the given code, p is a pointer variable of type int and x is an int variable. After the execution of the statement p = &x;, p points to the memory location of x, and so *p and x refers to the same memory location. The statement *p = 43; stores 43 into the memory location to which p points, that is, into x. Therefore, the output is: 43, 43 d. Correct. In the given code, p is a pointer variable of type int and x is an int variable. After the execution of the statement p = &x;, p points to the memory location of x, and so *p and x refers to the same memory location. The statement *p = 43; stores 43 into the memory location to which p points, that is, into x. Therefore, the output is: 43, 43

POINTS: 1 REFERENCES: 822 – Dereferencing Operator (*) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.03 - Learn about the address of the operator and the dereferencing operator DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 3:24 AM Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 12 17. What is the output of the following code? int *p; int x; x = 12; p = &x; cout << x << ", "; *p = 81; cout << *p << endl; a. 12, 12 c. 81, 12 ANSWER: FEEDBACK:

b. 12, 81 d. 81, 81 b a. Incorrect. In the given code, p is a pointer variable of type int and x is an int variable. The third statement stores 12 into x. After the execution of the fourth statement ,p = &x;, p points to the memory location of x, and so *p and x refers to the same memory location. The fifth statement outputs the value of x, which is 12. The sixth statement *p = 81; stores 81 into the memory location to which p points, that is, into x. The seventh statement outputs the value of *p, which is 81. Therefore, the output is: 12, 81 b. Correct. In the given code, p is a pointer variable of type int and x is an int variable. The third statement stores 12 into x. After the execution of the fourth statement ,p = &x;, p points to the memory location of x, and so *p and x refers to the same memory location. The fifth statement outputs the value of x, which is 12. The sixth statement *p = 81; stores 81 into the memory location to which p points, that is, into x. The seventh statement outputs the value of *p, which is 81. Therefore, the output is: 12, 81 c. Incorrect. In the given code, p is a pointer variable of type int and x is an int variable. The third statement stores 12 into x. After the execution of the fourth statement ,p = &x;, p points to the memory location of x, and so *p and x refers to the same memory location. The fifth statement outputs the value of x, which is 12. The sixth statement *p = 81; stores 81 into the memory location to which p points, that is, into x. The seventh statement outputs the value of *p, which is 81. Therefore, the output is: 12, 81 d. Incorrect. In the given code, p is a pointer variable of type int and x is an int variable. The third statement stores 12 into x. After the execution of the fourth statement ,p = &x;, p points to the memory location of x, and so *p and x refers to the same memory location. The fifth statement outputs the value of x, which is 12. The sixth statement *p = 81; stores 81 into the memory location to which p points, that is, into x. The seventh statement outputs the value of *p, which is 81. Therefore, the output is: 12, 81

POINTS: 1 REFERENCES: 822 – Dereferencing Operator (*) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.03 - Learn about the address of the operator and the dereferencing operator Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 12 DATE CREATED: DATE MODIFIED:

10/5/2016 1:41 PM 3/17/2020 3:26 AM

18. Which of the following can be used to initialize a pointer variable? a. 1 b. nullptr c. "0" d. '0' ANSWER: FEEDBACK:

b a. Incorrect. In C++, you can use nullptr to initialize a pointer variable. b. Correct. In C++, you can use nullptr to initialize a pointer variable. c. Incorrect. In C++, you can use nullptr to initialize a pointer variable. d. Incorrect. In C++, you can use nullptr to initialize a pointer variable.

POINTS: 1 REFERENCES: 829 – Initializing Pointer Variables QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.04 - Learn how pointers work with classes and structs DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 3:28 AM 19. The C++ operator ____ is used to create dynamic variables. a. dynamic b. new c. virtual d. dereferencing ANSWER: FEEDBACK:

b a. Incorrect. In C++, there is no term called dynamic operator. b. Correct. In C++, the operator new is used for creating a dynamic variable. c. Incorrect. In C++, there is no term called virtual operator. d. Incorrect. In C++, the operator new is used for creating a dynamic variable. In C++, the dereferencing operator, *, is used to refer to the object to which its operand points.

POINTS: 1 REFERENCES: 830 – Dynamic Variables QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.05 - Discover dynamic variables DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 3:31 AM 20. The C++ operator ____ is used to destroy dynamic variables. a. destroy b. delete c. * d. ~ ANSWER: FEEDBACK:

b a. Incorrect. In C++, there is no term called destroy operator.

Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 12 b. Correct. In C++, the operator delete is used to destroy dynamic variables. c. Incorrect. In C++, the operator delete is used to destroy dynamic variables. In C++, * as a unary operator is called the dereferencing operator, as a binary operator it is the multiplication arithmetic operator, and it is also used to declare pointer variables. d. Incorrect. In C++, the operator delete is used to destroy dynamic variables. In C++, the symbol ~ is used to declare a destructor. POINTS: 1 REFERENCES: 833 – Operator delete QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.06 - Explore how to use the new and delete operators to manipulate dynamic variables DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 3:33 AM 21. Which of the following operations is allowed on pointer variables? a. exp b. % c. == d. / ANSWER: FEEDBACK:

c a. Incorrect. The relational operator, ==, is allowed on pointer variables. In C++, exp is not an operation. b. Incorrect. The relational operator, ==, is allowed on pointer variables. The modulus operator, %, is not allowed on pointer variables. c. Correct. The relational operator, ==, is allowed on pointer variables. d. Incorrect. The relational operator, ==, is allowed on pointer variables. The division operator, /, is not allowed on pointer variables.

POINTS: 1 REFERENCES: 836 – Operations on Pointer Variables QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.07 - Learn about pointer arithmetic DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 3:36 AM 22. Which of the following arithmetic operations is allowed on pointer variables? a. Increment b. Modulus c. Multiplication d. Division ANSWER: a FEEDBACK: a. Correct. The increment operator, ++, is allowed on pointer variables. b. Incorrect. The increment operator, ++, is allowed on pointer variables. The modulus operator, %, is not allowed on pointer variables. Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 12 c. Incorrect. The increment operator, ++, is allowed on pointer variables. The multiplication operator, *, is not allowed on pointer variables. d. Incorrect. The increment operator, ++, is allowed on pointer variables. The division operator, /, is not allowed on pointer variables. POINTS: 1 REFERENCES: 836 – Operations on Pointer Variables QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.07 - Learn about pointer arithmetic DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 3:38 AM 23. Given the statement double *p;, the statement p++; will increment the value of p by ____ byte(s). a. one b. two c. four d. eight ANSWER: d FEEDBACK: a. Incorrect. The increment operator increments the value of a pointer variable by the size of the data type to which it is pointing. Because p is pointer variable of type double, the statement p++; increments the value of p by eight bytes. b. Incorrect. The increment operator increments the value of a pointer variable by the size of the data type to which it is pointing. Because p is pointer variable of type double, the statement p++; increments the value of p by eight bytes. c. Incorrect. The increment operator increments the value of a pointer variable by the size of the data type to which it is pointing. Because p is pointer variable of type double, the statement p++; increments the value of p by eight bytes. d. Correct. The increment operator increments the value of a pointer variable by the size of the data type to which it is pointing. Because p is pointer variable of type double, the statement p++; increments the value of p by eight bytes. POINTS: 1 REFERENCES: 836 – Operations on Pointer Variables QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.07 - Learn about pointer arithmetic DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 4:22 AM 24. Given the declaration int *a;, the statement a = new int[50]; dynamically allocates an array of 50 components of the type ____. a. int b. int* c. pointer d. address ANSWER: FEEDBACK:

a a. Correct. The statement a = new int[50]; allocates memory for an array of fifty elements of int type and stores the base address of the array in p.

Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 12 b. Incorrect. The statement a = new int[50]; allocates memory for an array of fifty elements of int type and stores the base address of the array in p. There is no name associated with pointer data types, and int* is not a data type in C++. c. Incorrect. The statement a = new int[50]; allocates memory for an array of fifty elements of int type and stores the base address of the array in p. There is no name associated with pointer data types, and pointer is not a data type in C++. d. Incorrect. The statement a = new int[50]; allocates memory for an array of fifty elements of int type and stores the base address of the array in p. There is no name associated with pointer data types, and address is not a data type in C++. POINTS: 1 REFERENCES: 837 – Dynamic Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.08 - Learn how to work with dynamic arrays DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 4:26 AM 25. An array created during the execution of a program is called a(n) ____ array. a. list b. static c. execution d. dynamic ANSWER: d FEEDBACK: a. Incorrect. In C++, arrays created during the execution of the program are called dynamic arrays. In C++, a list is a collection of data of same data type. b. Incorrect. In C++, arrays created during the execution of the program are called dynamic arrays. In C++, a static array has fixed size at compile time. c. Incorrect. In C++, arrays created during the execution of the program are called dynamic arrays. In C++, there is no term called execution array. d. Correct. In C++, arrays created during the execution of the program are called dynamic arrays. POINTS: 1 REFERENCES: 837 – Dynamic Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.08 - Learn how to work with dynamic arrays DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 4:28 AM 26. In a ____ copy, two or more pointers of the same type point to the same memory. a. static b. shallow c. dynamic d. deep ANSWER: b Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 12 FEEDBACK:

a. Incorrect. In C++, there is no term called static copy. b. Correct. In a shallow copy, two or more pointers of the same type point to the same memory. c. Incorrect. In C++, there is no term called dynamic copy. d. Incorrect. In a shallow copy, two or more pointers of the same type point to the same memory. In deep copy, two or more pointers of the same type each point to its own copy of the data.

POINTS: 1 REFERENCES: 847 – Shallow versus Deep Copy and Pointers QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.11 - Become familiar with the shallow and deep copies of data DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 4:31 AM 27. In a ____ copy, two or more pointers of the same type have their own data. a. shallow b. deep c. static d. dynamic ANSWER: b FEEDBACK: a. Incorrect. In a deep copy, two or more pointers of the same type have their own data. In shallow copy, two or more pointers of the same type point to the same memory. b. Correct. In deep copy, two or more pointer of the same type each point to its own copy of the data. c. Incorrect. In a deep copy, two or more pointers of the same type have their own data. In C++, there is no term called static copy. d. Incorrect. In a deep copy, two or more pointers of the same type have their own data. In C++, there is no term called dynamic copy. POINTS: 1 REFERENCES: 847 – Shallow versus Deep Copy and Pointers QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.11 - Become familiar with the shallow and deep copies of data DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 4:35 AM 28. If a class has a(n) ____, it automatically executes whenever an object of that class goes out of scope. a. constructor b. destructor c. pointer d. copy constructor ANSWER: b FEEDBACK: a. Incorrect. If a class has a destructor, it automatically executes whenever an object of that class goes out of scope. A constructor is used to initialize objects. Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 12 b. Correct. If a class has a destructor, it automatically executes whenever an object of that class goes out of scope. c. Incorrect. If a class has a destructor, it automatically executes whenever an object of that class goes out of scope. In C++, a pointer stores a memory address. d. Incorrect. If a class has a destructor, it automatically executes whenever an object of that class goes out of scope. A copy constructor executes when an object is declared and initialized by using the value of another object and when an object is passed by value as a parameter. POINTS: 1 REFERENCES: 849 – Destructor QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.12 - Discover the peculiarities of classes with pointer member variables DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 4:38 AM 29. Consider the following statement: ptrMemberVarType objectThree(objectOne); The values of the member variables of objectOne are being copied into the corresponding member variables of objectThree. This initialization is called the ____. a. default member-wise assignment b. default assignment c. default member-wise initialization d. default initialization ANSWER: c FEEDBACK: a. Incorrect. This initialization is called the default member-wise initialization. b. Incorrect. This initialization is called the default member-wise initialization. c. Correct. This initialization is called the default member-wise initialization. d. Incorrect. This initialization is called the default member-wise initialization. POINTS: 1 REFERENCES: 851 – Copy Constructor QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.12 - Discover the peculiarities of classes with pointer member variables DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 11:57 PM 30. The ____ constructor is executed when an object is declared and initialized by using the value of another object of the same type. a. default b. copy c. struct d. class ANSWER: b FEEDBACK: a. Incorrect. The copy constructor is executed when an object is declared and initialized by using the value of another object of the same type. The default Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 12 constructor does not have parameters. b. Correct. When an object is declared and initialized by using the value of another object of the same type, the copy constructor is automatically executed. c. Incorrect. The copy constructor is executed when an object is declared and initialized by using the value of another object of the same type. In C++, there is no term called struct constructor. d. Incorrect. The copy constructor is executed when an object is declared and initialized by using the value of another object of the same type. POINTS: 1 REFERENCES: 853 – Copy Constructor QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.12 - Discover the peculiarities of classes with pointer member variables DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 11:59 PM 31. Which of the following is the correct heading of the copy constructor to be included in the definition of the class rulerType? a. rulerType(int inches, int centimeters); b. rulerType(); c. rulerType(const rulerType& myRuler); d. copy rulerType(int inches, int centimeters); ANSWER: FEEDBACK:

c a. Incorrect. The general syntax to include the copy constructor in the definition of a class is: className(const className& otherObject); Therefore, the correct heading is: rulerType(const rulerType& myRuler); b. Incorrect. The general syntax to include the copy constructor in the definition of a class is: className(const className& otherObject); Therefore, the correct heading is: rulerType(const rulerType& myRuler); c. Correct. The general syntax to include the copy constructor in the definition of a class is: className(const className& otherObject); Therefore, the correct heading is: rulerType(const rulerType& myRuler) d. Incorrect. The general syntax to include the copy constructor in the definition of a class is: className(const className& otherObject); Therefore, the correct heading is: rulerType(const rulerType& myRuler);

POINTS: REFERENCES:

1 854 – Copy Constructor

Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 12 QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.12 - Discover the peculiarities of classes with pointer member variables DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 10:05 PM 32. In C++, virtual functions are declared using the reserved word ____. a. virtual b. private public c. d. struct ANSWER: FEEDBACK:

a a. Correct. In C++, virtual functions are declared using the reserved word virtual. b. Incorrect. In C++, virtual functions are declared using the reserved word virtual. The reserved private is a member access specifier. c. Incorrect. In C++, virtual functions are declared using the reserved word virtual. The reserved public is a member access specifier. d. Incorrect. In C++, virtual functions are declared using the reserved word virtual. A struct is collection of a fixed number of components in which the components may be of different types.

POINTS: 1 REFERENCES: 861 – Inheritance, Pointers, and Virtual Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.13 - Learn about virtual functions DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 10:10 PM 33. In ____ binding, the necessary code to call a specific function is generated by the compiler. a. static b. dynamic c. scope d. virtual ANSWER: a FEEDBACK: a. Correct. In the early or static binding, the compiler produces the code for calling a specific function. b. Incorrect. In the early or static binding, the compiler produces the code for calling a specific function. In late or dynamic binding, the compiler does not produce the code for calling a specific function. c. Incorrect. In the early or static binding, the compiler produces the code for calling a specific function. In C++, there is no term scope binding. d. Incorrect. In the early or static binding, the compiler produces the code for calling a specific function. In C++, there is no term virtual binding. POINTS:

1

Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 12 REFERENCES: 860 – Inheritance, Pointers, and Virtual Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.13 - Learn about virtual functions DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/18/2020 12:05 AM 34. Run-time binding is also known as ____ binding. a. static b. scope c. dynamic d. virtual ANSWER: c FEEDBACK: a. Incorrect. Run-time binding is also known as dynamic binding. Static binding is also called early binding or compile-time binding. b. Incorrect. Run-time binding is also known as dynamic binding. In C++, there is no term scope binding. c. Correct. The dynamic binding is also called run-time or late binding. d. Incorrect. Run-time binding is also known as dynamic binding. In C++, there is no term scope binding. POINTS: 1 REFERENCES: 861 – Inheritance, Pointers, and Virtual Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.13 - Learn about virtual functions DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 10:20 PM 35. The ____ operator can be used to return the address of a private data member of a class. a. dereferencing b. destructor c. address of d. member access ANSWER: c FEEDBACK: a. Incorrect. The address of operator can be used to return the address of a private data member of a class. The dereferencing operator refers to the object to which its pointer points. b. Incorrect. The address of operator can be used to return the address of a private data member of a class. The destructor is a member function of a class which executes automatically when an object of that class goes out-o scope. c. Correct. In order to return the address of a private data member of a class, the address of operator is used. d. Incorrect. The address of operator can be used to return the address of a private data member of a class. The member access operator is used to access the members of a class. POINTS: REFERENCES:

1 874 – Address of Operator and Classes

Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 12 QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.12.15 - Examine the relationship between the address of operator and classes DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 10:25 PM 36. Consider the following declaration of a struct: struct studentType { char name[26]; double gpa; int sID; char grade; }; studentType student; studentType *studentPtr; The statement (*studentPtr).gpa = 2.5; is equivalent to ___________________ = 2.5;. studentPtr->gpa ANSWER: POINTS: 1 REFERENCES: 827 – Classes, Structs, and Pointer Variables QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.12.04 - Learn how pointers work with classes and structs DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 10:28 PM 37. Consider the following statements: void pointerParameters(int* &p, double *q) { . . . } In the function pointerParameters, the parameter p is a(n) ____________________ parameter. ANSWER: reference POINTS: 1 REFERENCES: 842 – Functions and Pointers QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.12.10 - Explore how pointers work with functions as parameters and functions as return values Copyright Cengage Learning. Powered by Cognero.

Page 19


Name:

Class:

Date:

Chapter 12 DATE CREATED: DATE MODIFIED:

10/5/2016 1:41 PM 3/17/2020 10:31 PM

38. Consider the following statements: void pointerParameters(int* &p, double *q) { . . . } In the function pointerParameters, the parameter q is a(n) ____________________ parameter. ANSWER: value POINTS: 1 REFERENCES: 842 – Functions and Pointers QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.12.10 - Explore how pointers work with functions as parameters and functions as return values DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 10:35 PM 39. The statement that declares board to be an array of six pointers wherein each pointer is of type int is: int ____________________; *board[6] ANSWER: POINTS: 1 REFERENCES: 842 – Dynamic Two-Dimensional Arrays QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.12.10 - Explore how pointers work with functions as parameters and functions as return values DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 10:38 PM 40. The copy constructor automatically executes when, as a parameter, an object is passed by ____________________. ANSWER: value POINTS: 1 REFERENCES: 853 – Copy Constructor QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.12.12 - Discover the peculiarities of classes with pointer member variables Copyright Cengage Learning. Powered by Cognero.

Page 20


Name:

Class:

Date:

Chapter 12 DATE CREATED: DATE MODIFIED:

10/5/2016 1:41 PM 3/17/2020 11:13 PM

41. The binding of virtual functions occurs at program ____________________ time. ANSWER: execution run POINTS: 1 REFERENCES: 861 QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 10/5/2016 1:41 PM 42. The ____________________ of a base class automatically makes the destructor of a derived class virtual. ANSWER: virtual destructor POINTS: 1 REFERENCES: 865 – Classes and Virtual Destructors QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.12.12 - Discover the peculiarities of classes with pointer member variables DATE CREATED: 10/5/2016 1:41 PM DATE MODIFIED: 3/17/2020 11:14 PM 43. Consider the following statements: class shape { public: virtual void draw() = 0; virtual void move(double x, double y) = 0; . . . }; The code above is an example of a(n) ____________________ class definition. ANSWER: abstract POINTS: 1 REFERENCES: 867 – Abstract Classes and Pure Virtual Functions QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.12.14 - Become aware of abstract classes Copyright Cengage Learning. Powered by Cognero.

Page 21


Name:

Class:

Date:

Chapter 12 DATE CREATED: DATE MODIFIED:

10/5/2016 1:42 PM 3/17/2020 11:16 PM

Copyright Cengage Learning. Powered by Cognero.

Page 22


Name:

Class:

Date:

Chapter 13 1. In C++, >> is used as a stream extraction operator and as a right shift operator. a. True b. False ANSWER: True FEEDBACK: Correct In C++, >> is used as a stream extraction operator and as a right shift operator. Incorrect In C++, >> is used as a stream extraction operator and as a right shift operator.

POINTS: 1 REFERENCES: 895 – Operator Overloading QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.01 - Learn about overloading DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 12:30 AM 2. The return type of an operator functions is void. a. True b. False ANSWER: False FEEDBACK: Correct The result of an operation is a value. Therefore, an operator function is a valuereturning function. Incorrect The result of an operation is a value. Therefore, an operator function is a valuereturning function. POINTS: 1 REFERENCES: 896 – Syntax for Operator Functions QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.01 - Learn about overloading DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 12:31 AM 3. Operators can be overloaded either for objects of the user-defined types, or for a combination of objects of the userdefined type and objects of the built-in type. a. True b. False ANSWER: True FEEDBACK: Correct Operators can be overloaded either for objects of the user-defined types, or for a combination of objects of the user-defined type and objects of the built-in type. Incorrect Operators can be overloaded either for objects of the user-defined types, or for a combination of objects of the user-defined type and objects of the built-in type. POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 896 – Overloading an Operator: Some Restrictions True / False False

Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 13 LEARNING OBJECTIVES: PAPD.MALI.13.02 - Become familiar with the restrictions on operator overloading DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 12:33 AM 4. In C++, operator is a reserved word. a. True b. False ANSWER: True FEEDBACK: Correct In C++, operator is a reserved word. Incorrect In C++, operator is a reserved word.

POINTS: 1 REFERENCES: 896 – Syntax for Operator Functions QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.01 - Learn about overloading DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 12:35 AM 5. A friend function of a class does not have access to the private data members of the class. a. True b. False ANSWER: False FEEDBACK: Correct A friend function of a class has access to the private data members of the class. Incorrect A friend function of a class has access to the private data members of the

class. POINTS: 1 REFERENCES: 904 – Friend Functions of Classes QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.04 - Learn about friend functions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 12:39 AM 6. The declaration of a friend function cannot be placed within the private part of the class. a. True b. False ANSWER: False FEEDBACK: Correct Because a friend function is not a member of a class, its declaration can be placed within the private part of the class. Incorrect Because a friend function is not a member of a class, its declaration can be

placed within the private part of the class. Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 13 POINTS: 1 REFERENCES: 904 – Friend Functions of Classes QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.04 - Learn about friend functions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 12:41 AM 7. When writing the definition of a friend function, the name of the class and the scope resolution operator precede the name of the friend function in the function heading. a. True b. False ANSWER: False FEEDBACK: Correct When writing the definition of a friend function, the name of the class and the scope resolution operator do not precede the name of the friend function in the function heading because it is not a member function of the class. Incorrect When writing the definition of a friend function, the name of the class and the scope resolution operator do not precede the name of the friend function in the function heading because it is not a member function of the class. POINTS: 1 REFERENCES: 905– Friend Functions of Classes QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.04 - Learn about friend functions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 12:42 AM 8. Most operator functions can either be member functions or nonmember functions of a class. a. True b. False ANSWER: True FEEDBACK: Correct In C++, most of the operator functions can be either member functions or nonmember functions which mean friend functions of the class. Incorrect In C++, most of the operator functions can be either member functions or nonmember functions which mean friend functions of the class. POINTS: 1 REFERENCES: 907 – Operator Functions as Member Functions and Nonmember Functions QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.05 - Learn how to overload operators as members and nonmembers of a class DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 12:45 AM Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 13 9. Both parameters of the function to overload the operator << are reference parameters. a. True b. False ANSWER: True FEEDBACK: Correct Both parameters of the function to overload the operator << are reference parameters. Incorrect Both parameters of the function to overload the operator << are reference parameters. POINTS: 1 REFERENCES: 917 – Overloading the Stream Insertion (<<) and Extraction (>>) Operators QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 12:47 AM 10. The associativity of the assignment operator = is from right to left. a. True b. False ANSWER: True FEEDBACK: Correct The associativity of the assignment operator = is from right to left. Incorrect The associativity of the assignment operator = is from right to left.

POINTS: 1 REFERENCES: 923 – Overloading the Assignment Operator (=) QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 12:49 AM 11. The name of the function to overload the operator <= is ____. a. overload<= b. <=new c. operator<= d. <=operator ANSWER: FEEDBACK:

c a. Incorrect. The name of the function that overloads an operator is the reserved word operator followed by the operator to be overloaded. Therefore, the name of the function to overload the operator <= is: operator<= b. Incorrect. The name of the function that overloads an operator is the reserved word operator followed by the operator to be overloaded. Therefore, the name of the function to overload the operator <= is: operator<= c. Correct. The name of the function that overloads an operator is the reserved word operator followed by the operator to be overloaded. Therefore, the name of

Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 13 the function to overload the operator <= is: operator<= d. Incorrect. The name of the function that overloads an operator is the reserved word operator followed by the operator to be overloaded. Therefore, the name of the function to overload the operator <= is: operator<= POINTS: 1 REFERENCES: 895 – Operator Overloading QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.01 - Learn about overloading DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 1:06 AM 12. Every object of a class maintains a (hidden) pointer to itself, and the name of this pointer is ____. a. self b. object c. it d. this ANSWER: FEEDBACK:

d a. Incorrect. Every object of a class maintains a (hidden) pointer to itself, and the name of this pointer is this. b. Incorrect. Every object of a class maintains a (hidden) pointer to itself, and the name of this pointer is this. c. Incorrect. Every object of a class maintains a (hidden) pointer to itself, and the name of this pointer is this. d. Correct. Every object of a class maintains a (hidden) pointer to itself, and the name of this pointer is this.

POINTS: 1 REFERENCES: 899 – Pointer this QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.03 - Examine the pointer this DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 1:09 AM 13. When an object invokes a member function, the member function references the pointer ____ of the object. a. object b. it c. this d. address ANSWER: c FEEDBACK: a. Incorrect. When an object invokes a member function, the member function references the pointer this of the object. b. Incorrect. When an object invokes a member function, the member function references the pointer this of the object. c. Correct. When an object invokes a member function, the member function references the pointer this of the object. d. Incorrect. When an object invokes a member function, the member function Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 13 references the pointer this of the object. POINTS: 1 REFERENCES: 899 – Pointer this QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.03 - Examine the pointer this DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 1:11 AM 14. A(n) ____ function is a nonmember function of a class that has access to all members of the class. a. access b. protected c. friend d. void ANSWER: FEEDBACK:

c a. Incorrect. A friend function is a nonmember function of a class that has access to all members of the class. b. Incorrect. A friend function is a nonmember function of a class that has access to all members of the class. c. Correct. A friend function is a nonmember function of a class that has access to all members of the class. d. Incorrect. A friend function is a nonmember function of a class that has access to all members of the class. The reserved word void is used in a function heading to specify that the function does not have a return type.

POINTS: 1 REFERENCES: 904 – Friend Functions of Classes QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.04 - Learn about friend functions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 1:15 AM 15. The function that overloads the ____ operator for a class must be declared as a member of the class. a. :: b. * c. -> d. + ANSWER: FEEDBACK:

c

POINTS:

1

a. Incorrect. The function that overloads any of the operators (), [], ->, or = for a class must be declared as a member of the class. b. Incorrect. The function that overloads any of the operators (), [], ->, or = for a class must be declared as a member of the class. c. Correct. The function that overloads any of the operators (), [], ->, or = for a class must be declared as a member of the class. d. Incorrect. The function that overloads any of the operators (), [], ->, or = for a class must be declared as a member of the class.

Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 13 REFERENCES: 907 – Operator Functions as Member Functions and Nonmember Functions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.05 - Learn how to overload operators as members and nonmembers of a class DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 1:20 AM 16. The general form of the function to overload a binary arithmetic or relational operator as a member function of a class is: returnType operator#(____ className&) const; in which # stands for the binary arithmetic or relational operator to be overloaded. a. class b. const * c. d. & ANSWER: FEEDBACK:

b a. Incorrect. The general form of such functions is: returnType operator#(const className&) const; b. Correct. The general form of such functions is: returnType operator#(const className&) const; c. Incorrect. The general form of such functions is: returnType operator#(const className&) const; d. Incorrect. The general form of such functions is: returnType operator#(const className&) const;

POINTS: 1 REFERENCES: 910 – Overloading Binary Operators QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 1:31 AM 17. Which of the following function prototypes overloads the operator != for the class rectangleType? a. bool operator!=(rectangle&) const; b. bool operator!=(const rectangleType&) const; c. int operator!=(const rectangleType) const; d. int operator!=(rectangle&) const; ANSWER: FEEDBACK:

b a. Incorrect. The function prototype that overloads the operator != for the class rectangleType is: bool operator!=(const rectangleType&) const; b. Correct. The function prototype that overloads the operator != for the class rectangleType is: bool operator!=(const rectangleType&) const; c. Incorrect. The function prototype that overloads the operator != for the class

Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 13 rectangleType is: bool operator!=(const rectangleType&) const; d. Incorrect. The function prototype that overloads the operator != for the class rectangleType is: bool operator!=(const rectangleType&) const; POINTS: 1 REFERENCES: 912 – Overloading Binary Operators QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 1:33 AM 18. The return type of the function operator == is ____. a. int b. bool c. char d. void ANSWER: FEEDBACK:

b a. Incorrect. Because == is a relational operator and its value is true or false, the return type of the function operator == is bool. b. Correct. Because == is a relational operator and its value is true or false, the return type of the function operator == is bool. c. Incorrect. Because == is a relational operator and its value is true or false, the return type of the function operator == is bool. d. Incorrect. Because == is a relational operator and its value is true or false, the return type of the function operator == is bool.

POINTS: 1 REFERENCES: 912 – Overloading Binary Operators QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:09 AM 19. To include the operator function operator+ as a nonmember function of the class rectangleType, its prototype in the definition of rectangleType is: ____ rectangleType operator+(const rectangleType&, const rectangleType&); a. bool b. int c. double d. friend ANSWER: d FEEDBACK: a. Incorrect. A friend function is a nonmember function of a class. Therefore, following the syntax of such functions, the required function prototype is: friend rectangleType operator+(const rectangleType&, const rectangleType&);

Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 13 b. Incorrect. A friend function is a nonmember function of a class. Therefore, following the syntax of such functions, the required function prototype is:

friend rectangleType operator+(const rectangleType&, const rectangleType&);

c. Incorrect. A friend function is a nonmember function of a class. Therefore, following the syntax of such functions, the required function prototype is: friend rectangleType operator+(const rectangleType&, const rectangleType&);

d. Correct. A friend function is a nonmember function of a class. Therefore, following the syntax of such functions, the required function prototype is:

friend rectangleType operator+(const rectangleType&, const rectangleType&);

POINTS: 1 REFERENCES: 915 – Overloading Binary Operators QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:13 AM 20. The general syntax to overload the stream extraction operator >> for a class is ____. a. istream& operator>>(istream&, className&); b. const istream& operator>>(istream&, className&); c. friend operator>>(istream&, className&); d. friend istream& operator>>(istream&, className&); ANSWER: FEEDBACK:

d a. The general syntax to overload the stream extraction operator >> for a class is: friend istream& operator >> (istream&, className&); b. Incorrect. The general syntax to overload the stream extraction operator >> for a class is: friend istream& operator >> (istream&, className&); c. Incorrect. The general syntax to overload the stream extraction operator >> for a class is: friend istream& operator >> (istream&, className&); d. Correct. The general syntax to overload the stream extraction operator >> for a class is: friend istream& operator >> (istream&, className&);

POINTS: 1 REFERENCES: 918 – Overloading the Stream Insertion (<<) and Extraction (>>) Operators QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:15 AM Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 13 21. The return type of the function to overload the operator >> must be a reference to a(n) ____ object. a. iostream b. ostream c. stream d. istream ANSWER: FEEDBACK:

d a. Incorrect. The return type of the function to overload the operator >> must be a reference to an istream object. In C++, the iostream is a header file which provides functions to perform basic input and output operations in a program. b. Incorrect. The return type of the function to overload the operator >> must be a reference to an istream object. The ostream is the return type of a function to overload the operator <<. c. Incorrect. The return type of the function to overload the operator >> must be a reference to an istream object. The stream is not a (data) type. d. Correct. The return type of the function to overload the operator >> must be a reference to an istream object.

POINTS: 1 REFERENCES: 918 – Overloading the Stream Insertion (<<) and Extraction (>>) Operators QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:18 AM 22. Which of the following is a built-in operation on classes? a. increment b. assignment c. decrement d. relational operators ANSWER: b FEEDBACK: a. Incorrect. The assignment operator (=) is the one of the built-in operations on classes. The increment operation is not a built-in operation on classes. b. Correct. The assignment operator (=) is the one of the built-in operations on classes. The = causes a member-wise copy of member variables of the class. c. Incorrect. The assignment operator (=) is the one of the built-in operations on classes. The decrement operation is not a built-in operation on classes. d. Incorrect. The assignment operator (=) is the one of the built-in operations on classes. The relational operator is not a built-in operation on classes. POINTS: 1 REFERENCES: 921 – Overloading the Assignment Operator (=) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:20 AM 23. The general syntax for the function prototype to overload the assignment operator = for a class is ____. a. friend className& operator=(const className&); Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 13 b. className& operator=(className&); c. string className& operator=(className&); d. const className& operator=(const className&); ANSWER: d FEEDBACK: a. Incorrect. To overload the assignment operator = for a class, the operator function operator= must be a member of that class. The general syntax for the function prototype to overload the assignment operator = for a class is: const className& operator=(const className&); b. Incorrect. To overload the assignment operator = for a class, the operator function operator= must be a member of that class. The general syntax for the function prototype to overload the assignment operator = for a class is: const className& operator=(const className&); c. Incorrect. To overload the assignment operator = for a class, the operator function operator= must be a member of that class. The general syntax for the function prototype to overload the assignment operator = for a class is: const className& operator=(const className&); d. Correct. To overload the assignment operator = for a class, the operator function operator= must be a member of that class. The general syntax for the function prototype to overload the assignment operator = for a class is: const className& operator=(const className&); POINTS: 1 REFERENCES: 922 – Overloading the Assignment Operator (=) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:22 AM 24. To overload the pre-increment (++) operator as a member of a class the operator++ function requires ____ parameter(s). a. no b. one c. two d. three ANSWER: a FEEDBACK: a. Correct. A member function of a class has direct access to the data members of the class. The pre-increment operator increments the value of its operand (variable) by 1. Therefore, the pre-increment operator++ function as a member function of a class does not have any parameters. b. Incorrect. A member function of a class has direct access to the data members of the class. The pre-increment operator increments the value of its operand (variable) by 1. Therefore, the pre-increment operator++ function as a member function of a class does not have any parameters. c. Incorrect. A member function of a class has direct access to the data members of the class. The pre-increment operator increments the value of its operand (variable) by 1. Therefore, the pre-increment operator++ function as a member function of a class does not have any parameters. Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 13 d. Incorrect. A member function of a class has direct access to the data members of the class. The pre-increment operator increments the value of its operand (variable) by 1. Therefore, the pre-increment operator++ function as a member function of a class does not have any parameters. POINTS: 1 REFERENCES: 930 – Overloading Unary Operators QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:26 AM 25. Which of the following is the general syntax of the function prototype to overload the pre-increment operator ++ as a member function? a. className operator++(); b. className operator++(int); c. friend className operator++(); d. friend className operator++(int); ANSWER: FEEDBACK:

a a. Correct. The general syntax of the function prototype to overload the preincrement operator++ as a member function: is className operator ++(); b. Incorrect. The general syntax of the function prototype to overload the preincrement operator++ as a member function is className operator ++(); c. Incorrect. The general syntax of the function prototype to overload the preincrement operator++ as a member function is: className operator ++(); d. Incorrect. The general syntax of the function prototype to overload the preincrement operator++ as a member function is: className operator ++();

POINTS: 1 REFERENCES: 930 – Overloading Unary Operators QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:28 AM 26. Which of the following is the general syntax of the function prototype to overload the pre-increment operator as a nonmember function? a. className operator++(); b. friend className operator++(); c. className operator++(int); Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 13 d. friend className operator++(className&); ANSWER: d FEEDBACK: a. Incorrect. The general syntax of the function prototype to overload the preincrement operator as a nonmember function is: friend className operator ++(className&);. b. Incorrect. The general syntax of the function prototype to overload the preincrement operator as a nonmember function is: friend className operator ++(className&);. c. Incorrect. The general syntax of the function prototype to overload the preincrement operator as a nonmember function is: friend className operator ++(className&);. d. Correct. The general syntax of the function prototype to overload the preincrement operator as a nonmember function is: friend className operator ++(className&);. POINTS: 1 REFERENCES: 931 – Overloading Unary Operators QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:30 AM 27. Which of the following is the general syntax of the function prototype to overload the post-increment operator as a member function? a. className operator++(); b. friend className operator++(); c. className operator++(int); d. friend className operator++(int); ANSWER: FEEDBACK:

c

POINTS: REFERENCES: QUESTION TYPE:

1 932 – Overloading Unary Operators Multiple Choice

a. Incorrect. The general syntax of the function prototype to overload the postincrement operator as a member function is: className operator ++(int);. b. Incorrect. The general syntax of the function prototype to overload the postincrement operator as a member function is: className operator ++(int);. c. Correct. The general syntax of the function prototype to overload the postincrement operator as a member function is: className operator ++(int);. d. Incorrect. The general syntax of the function prototype to overload the postincrement operator as a member function is: className operator ++(int);.

Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 13 HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:32 AM 28. When the post-increment operator is overloaded as a nonmember function of the class, the operator function has ____ parameter(s). a. no b. one c. two d. three ANSWER: c FEEDBACK: a. Incorrect. When the post-increment operator is overloaded as a nonmember function of the class, the operator function operator++ has two parameters. b. Incorrect. When the post-increment operator is overloaded as a nonmember function of the class, the operator function operator++ has two parameters. c. Correct. When the post-increment operator is overloaded as a nonmember function of the class, the operator function operator++ has two parameters. d. Incorrect. When the post-increment operator is overloaded as a nonmember function of the class, the operator function operator++ has two parameters. POINTS: 1 REFERENCES: 933 – Overloading Unary Operators QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.0 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:35 AM 29. If you overload the binary arithmetic operator + as a member function, how many objects must be passed as parameters? a. none b. one c. two d. three ANSWER: b FEEDBACK: a. Incorrect. Only one object must be passed as a parameter if you overload the binary arithmetic operator + as a member function. b. Correct. Only one object must be passed as a parameter if you overload the binary arithmetic operator + as a member function. c. Incorrect. Only one object must be passed as a parameter if you overload the binary arithmetic operator + as a member function. d. Incorrect. Only one object must be passed as a parameter if you overload the binary arithmetic operator + as a member function. POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 934 – Overloading Unary Operators Multiple Choice False

Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 13 LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:39 AM 30. Which of the following is the syntax to declare the operator function operator[] as a member function of a class for nonconstant arrays? a. Type& []operator(int index); b. Type operator[](int index); c. Type& operator[](int index); d. Type [](int index); ANSWER: FEEDBACK:

c a. Incorrect. The syntax to declare the operator function operator [] as a member function of a class for non-constant arrays is: Type& operator[] (int index);. b. Incorrect. The syntax to declare the operator function operator [] as a member function of a class for non-constant arrays is: Type& operator[] (int index);. c. Correct. The syntax to declare the operator function operator [] as a member function of a class for non-constant arrays is: Type& operator[] (int index);. d. Incorrect. The syntax to declare the operator function operator [] as a member function of a class for non-constant arrays is: Type& operator[] (int index);.

POINTS: 1 REFERENCES: 950 – Overloading the Array Index (Subscript) Operator ([]) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:42 AM 31. Which of the following is the syntax to declare the operator function operator[] as a member function of a class for constant arrays? a. const Type& []operator(int index) const; b. const Type& operator[](int index) const; c. const Type& operator[](int index); d. const Type [](int index) const; ANSWER: FEEDBACK:

b a. Incorrect. The syntax to declare the operator function operator [] as a member function of a class for constant arrays is: const Type& operator[] (int index) const;. b. Correct. The syntax to declare the operator function operator [] as a member function of a class for constant arrays is: const Type& operator[] (int index) const;.

Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 13 c. Incorrect. The syntax to declare the operator function operator [] as a member function of a class for constant arrays is: const Type& operator[] (int index) const;. d. Incorrect. The syntax to declare the operator function operator [] as a member function of a class for constant arrays is: const Type& operator[] (int index) const;. POINTS: 1 REFERENCES: 950 – Overloading the Array Index (Subscript) Operator ([]) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:44 AM 32. Using a class template, you can write a single code segment for a set of related ____. a. classes b. functions c. operators d. constructors ANSWER: a FEEDBACK: a. Correct. Class templates are used to write a single code segment for a set of related classes. b. Incorrect. Class templates are used to write a single code segment for a set of related classes. c. Incorrect. Class templates are used to write a single code segment for a set of related classes. d. Incorrect. Class templates are used to write a single code segment for a set of related classes. Constructors are functions of a class that are called automatically when objects of the class are created. POINTS: 1 REFERENCES: 961 – Class Templates QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.08 - Learn about templates DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:47 AM 33. Class templates are called ____ types. a. polymorphic b. structured c. member d. parameterized ANSWER: d FEEDBACK: a. Incorrect. Class templates are used to write a single code segment for a set of related classes and are called parameterized types. b. Incorrect. Class templates are used to write a single code segment for a set of related classes and are called parameterized types. Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 13 c. Incorrect. Class templates are used to write a single code segment for a set of related classes and are called parameterized types. d. Correct. Class templates are used to write a single code segment for a set of related classes and are called parameterized types. POINTS: 1 REFERENCES: 961 – Class Templates QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.08 - Learn about templates DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:49 AM 34. Suppose cType is a class template, which can take int as a parameter. The statement: ____ declares x to be an object of type cType, and the data type passed to the class cType is int. a. cType<int> x; b. cType int x; c. cType int = x; d. cType int :: x; ANSWER: FEEDBACK:

a a. Correct. The statement cType<int> x; declares x to be an object of type cType, and the data type passed to the class cType is int. b. Incorrect. The statement cType<int> x; declares x to be an object of type cType, and the data type passed to the class cType is int. c. Incorrect. The statement cType<int> x; declares x to be an object of type cType, and the data type passed to the class cType is int. d. Incorrect. The statement cType<int> x; declares x to be an object of type cType, and the data type passed to the class cType is int.

POINTS: 1 REFERENCES: 963 – Class Templates QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.08 - Learn about templates DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:52 AM 35. Suppose cType is a class template, and func is a member function of cType. When writing the definition of func, its heading is: ____. a. template <class Type> funcType cType<Type> == func(parameters) b. template <class Type> funcType cType<Type> c. template <class Type> funcType cType<Type>::func(parameters) d. template <class Type> funcType cType<Type>func(parameters; ANSWER:

c

Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 13 FEEDBACK:

a. Incorrect. The function members of a class template are considered function templates. Therefore, when writing the definition of func, its heading is: template <class Type> funcType cType<Type>::func(parameters) b. Incorrect. The function members of a class template are considered function templates. Therefore, when writing the definition of func, its heading is: template <class Type> funcType cType<Type>::func(parameters) c. Correct. The function members of a class template are considered function templates. Therefore, when writing the definition of func, its heading is: template <class Type> funcType cType<Type>::func(parameters) d. Incorrect. The function members of a class template are considered function templates. Therefore, when writing the definition of func, its heading is: template <class Type> funcType cType<Type>::func(parameters)

POINTS: 1 REFERENCES: 963 – Class Templates QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.13.08 - Learn about templates DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:55 AM 36. With the exception of the ____________________ operator and the member selection operator, operators must be overloaded to be used on class objects. ANSWER: assignment POINTS: 1 REFERENCES: 896 – Why Operator Overloading Is Needed QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.13.01 - Learn about overloading DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 2:56 AM 37. Any function that overloads an operator is called a(n) ____________________ function. ANSWER: operator POINTS: 1 REFERENCES: 895 – Operator Overloading QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.13.01 - Learn about overloading Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 13 DATE CREATED: DATE MODIFIED:

10/5/2016 1:42 PM 3/18/2020 2:58 AM

38. The operators that cannot be overloaded are ., .*, ::, ?:, and ____________________. sizeof ANSWER: POINTS: 1 REFERENCES: 896 – Overloading an Operator: Some Restrictions QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.13.02 - Become familiar with the restrictions on operator overloading DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 3:00 AM 39. The only built-in operations on classes are assignment (=) and ____________________. ANSWER: member selection POINTS: 1 REFERENCES: 896 – Overloading an Operator: Some Restrictions QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.13.02 - Become familiar with the restrictions on operator overloading DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 3:07 AM 40. The ____________________ operator causes a member-wise copy of the member variables of the class. ANSWER: assignment POINTS: 1 REFERENCES: 921 – Overloading the Assignment Operator (=) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/18/2020 3:14 AM 41. A(n) ____________________ constructor converts its argument to an object of the constructor’s class. ANSWER: conversion POINTS: 1 REFERENCES: 956 – Overloading the Array Index (Subscript) Operator ([]) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.13.06 - Discover how to overload various operators Copyright Cengage Learning. Powered by Cognero.

Page 19


Name:

Class:

Date:

Chapter 13 DATE CREATED: DATE MODIFIED:

10/5/2016 1:42 PM 3/18/2020 3:01 AM

Copyright Cengage Learning. Powered by Cognero.

Page 20


Name:

Class:

Date:

Chapter 14 1. An exception is an occurrence of an undesirable situation that can be detected during program compilation. a. True b. False ANSWER: False FEEDBACK: Correct An exception is an occurrence of an undesirable situation that can be detected during program execution. Incorrect An exception is an occurrence of an undesirable situation that can be detected during program execution. POINTS: 1 REFERENCES: 992 QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.01 - Learn what an exception is DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/31/2020 4:56 AM 2. One of the typical ways of dealing with exceptions is to use an if statement. a. True b. False ANSWER: True FEEDBACK: Correct To deal with an exception, a typical way is to use an if statement. Incorrect To deal with an exception, a typical way is to use an if statement.

POINTS: 1 REFERENCES: 992 QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.01 - Learn what an exception is DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/31/2020 5:02 AM 3. The heading of a try block can contain ellipses in place of a parameter. a. True b. False ANSWER: False FEEDBACK: Correct The heading of a try block does not contain any parameters or ellipses. Ellipses are used in a catch block heading to specify that the catch block can catch at type of exception. Incorrect The heading of a try block does not contain any parameters or ellipses. Ellipses are used in a catch block heading to specify that the catch block can catch at type of exception. POINTS: REFERENCES:

1 996 – try/catch Block

Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 14 QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.03 - Learn how a try/catch block is used to handle exceptions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/31/2020 5:07 AM 4. The exception handing code in a catch block specifies the type of exception it can catch. a. True b. False ANSWER: False FEEDBACK: Correct The catch block parameter specifies the type of exception it can catch. Incorrect The catch block parameter specifies the type of exception it can catch.

POINTS: 1 REFERENCES: 996 – try/catch Block QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.03 - Learn how a try/catch block is used to handle exceptions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/31/2020 5:10 AM 5. If no exception is thrown in a try block, all catch blocks associated with that try block are ignored. a. True b. False ANSWER: True FEEDBACK: Correct All catch blocks associated with the try block are ignored when there is no exception thrown in the try block. Incorrect All catch blocks associated with the try block are ignored when there is no exception thrown in the try block. POINTS: 1 REFERENCES: 996 – try/catch Block QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.03 - Learn how a try/catch block is used to handle exceptions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 3/31/2020 5:11 AM 6. An object that is being thrown cannot be an anonymous object. a. True b. False ANSWER: False FEEDBACK: Correct The object that is being thrown can be either an anonymous object or a specific object. Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 14 Incorrect The object that is being thrown can be either an anonymous object or a specific

object. POINTS: 1 REFERENCES: 996 – try/catch Block QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.04 - Learn how to throw an exception DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 6:11 AM 7. The order of the catch blocks does not affect the program. a. True b. False ANSWER: False FEEDBACK: Correct If an exception is thrown in a try block, the remaining statements in that try block are ignored. The program searches the catch blocks in the order they appear after the try block and looks for an appropriate exception handler. If the type of thrown exception matches the parameter type in one of the catch blocks, the code of that catch block executes, and the remaining catch blocks after this catch blocks are ignored. The catch block that has an ellipsis (three dots) is designed to catch any type of exception. Therefore, if we put this catch block first, then this catch block can catch all types of exceptions. Incorrect If an exception is thrown in a try block, the remaining statements in that try

block are ignored. The program searches the catch blocks in the order they appear after the try block and looks for an appropriate exception handler. If the type of thrown exception matches the parameter type in one of the catch blocks, the code of that catch block executes, and the remaining catch blocks after this catch block are ignored. The catch block that has an ellipsis (three dots) is designed to catch any type of exception. Therefore, if we put this catch block first, then this catch block can catch all types of exceptions. POINTS: 1 REFERENCES: 996 – try/catch Block QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.03 - Learn how a try/catch block is used to handle exceptions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 8:38 AM 8. If the catch block with ellipses (in the heading) is needed, then it should be the first catch block in a sequence of try/catch blocks. a. True b. False ANSWER: False Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 14 FEEDBACK:

Correct

If the catch block with ellipses in the heading is required, then it must be the last catch block in the sequence of the try/catch blocks.

Incorrect If the catch block with ellipses in the heading is required, then it must be the last

catch block in the sequence of the try/catch blocks. POINTS: 1 REFERENCES: 996 – try/catch Block QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.03 - Learn how a try/catch block is used to handle exceptions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 6:31 AM 9. C++ provides all the exception classes you will ever need. a. True b. False ANSWER: False FEEDBACK: Correct C++ does not offer all exception classes that a programmer requires. Incorrect C++ does not offer all exception classes that a programmer requires.

POINTS: 1 REFERENCES: 1007 – Creating Your Own Exception Classes QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.06 - Learn how to create your own exception classes DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/2/2020 6:35 AM 10. In C++, any class can be considered an exception class. a. True b. False ANSWER: True FEEDBACK: Correct Any class in C++ can be treated as an exception class. Incorrect Any class in C++ can be treated as an exception class.

POINTS: 1 REFERENCES: 1007 – Creating Your Own Exception Classes QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.06 - Learn how to create your own exception classes DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 6:36 AM 11. A(n) ____ is an occurrence of an undesirable situation that can be detected during program execution. a. crash b. exception Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 14 c. misfire ANSWER: FEEDBACK:

d. bug b a. Incorrect. An exception is an occurrence of an undesirable situation that can be detected during program execution. A crash occurs when a program stops functioning properly and exits. b. Correct. The occurrence of the undesirable situation during the execution of the program is defined as an exception. c. Incorrect. An exception is an occurrence of an undesirable situation that can be detected during program execution. There is no term misfire in C++. A misfire is not a definite term to refer the occurrence of the undesirable situation during the program execution. d. Incorrect. An exception is an occurrence of an undesirable situation that can be detected during program execution. Typically, a bug is a coding error in the computer program.

POINTS: 1 REFERENCES: 992 QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.01 - Learn what an exception is DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 8:40 AM 12. The function ____ can check whether an expression meets the required conditions; if the conditions are not met, it terminates the program. a. check b. look c. assert d. what ANSWER: FEEDBACK:

c a. Incorrect. The function assert can check whether an expression meets the required conditions; if the conditions are not met, it terminates the program. There is no function called check in C++. b. Incorrect. The function assert can check whether an expression meets the required conditions; if the conditions are not met, it terminates the program. There is no function called look in C++. c. Correct. The function assert can check whether an expression meets the required conditions; if the conditions are not met, it terminates the program. d. Incorrect. The function assert can check whether an expression meets the required conditions; if the conditions are not met, it terminates the program. The function what returns a string having an appropriate message.

POINTS: 1 REFERENCES: 992 – Handling Exceptions within a Program QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.02 - Learn how to handle exceptions within a program DATE CREATED: 10/5/2016 1:42 PM Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 14 DATE MODIFIED:

4/2/2020 6:16 AM

13. When division by zero occurs and this problem is not addressed, the program crashes with an error message that is ____ dependent. a. code b. computer c. platform d. IDE ANSWER: d FEEDBACK: a. Incorrect. When an exception occurs and it is not addressed, the program code crashes with an error message and the message is code independent. b. Incorrect. When an exception occurs and it is not addressed, the program code crashes with an error message and the message is computer independent. c. Incorrect. When an exception occurs and it is not addressed, the program code crashes with an error message and the message is platform independent. d. Correct. When an exception occurs and it is not addressed, the program code crashes with an error message and the message is IDE dependent. POINTS: 1 REFERENCES: 992 – Handling Exceptions within a Program QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.02 - Learn how to handle exceptions within a program DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 6:48 AM 14. To use the assert function in your program, you should include the statement ____. a. #include <assert> b. #include <cassert> c. #include <iostream> d. #include <exception> ANSWER: FEEDBACK:

b a. Incorrect. To use the assert function in your program, you should include the statement: #include <cassert> b. Correct.To use the assert function in your program, you should include the statement: #include <cassert> c. Incorrect. To use the assert function in your program, you should include the statement: #include <cassert> d. Incorrect. To use the assert function in your program, you should include the statement: #include <cassert>

POINTS: 1 REFERENCES: 992 – Handling Exceptions within a Program QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.02 - Learn how to handle exceptions within a program Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 14 DATE CREATED: DATE MODIFIED:

10/5/2016 1:42 PM 4/1/2020 6:50 AM

15. Which of the following is a valid C++ statement? a. assert(0 = divisor); b. assert(divisor != 0); c. assert(divisor 0); d. assert(divisor is 0); ANSWER: FEEDBACK:

b a. Incorrect.In C++, the statement assert(divisor != 0); is a valid statement. In C++, = is the assignment operator, not a relational operator. b. Correct. In C++, the statement assert(divisor != 0); is a valid statement. c. Incorrect. In C++, the statement assert(divisor != 0); is a valid statement. A relational operator between divisor and 0 is missing. d. Incorrect. In C++, the statement assert(divisor != 0); is a valid statement. There is no operator is in C++.

POINTS: 1 REFERENCES: 992 – Handling Exceptions within a Program QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.02 - Learn how to handle exceptions within a program DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 6:57 AM 16. The statements that may generate an exception are placed in a ____ block. a. throw b. finally c. try d. catch ANSWER: FEEDBACK:

c a. Incorrect. The statements that may generate an exception are placed in a try block. There is no block called throw in C++. b. Incorrect. The statements that may generate an exception are placed in a try block. There is no block called finally in C++. c. Correct.The statements that may generate an exception are placed in a try block. d. Incorrect. The statements that may generate an exception are placed in a try block. A catch block is used to handle an exception.

POINTS: 1 REFERENCES: 996 – try/catch Block QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.03 - Learn how a try/catch block is used to handle exceptions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/2/2020 6:19 AM 17. The try block is followed by one or more ____ blocks. Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 14 a. throw c. do ANSWER: FEEDBACK:

b. finally d. catch d a. Incorrect.The try block is followed by one or more catch blocks. There is no block called throw in C++. b. Incorrect.The try block is followed by one or more catch blocks. There is no block called finally in C++. c. Incorrect.The try block is followed by one or more catch blocks. d. Correct.The try block is followed by one or more catch blocks. There is no block called do in C++.

POINTS: 1 REFERENCES: 996 – try/catch Block QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.03 - Learn how a try/catch block is used to handle exceptions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 7:05 AM 18. Which of the followingcatch blocks is designed to catch any type of exception? a. catch(){ } b. catch(...){ } c. catch(*){ } d. catch(exception){ } ANSWER: FEEDBACK:

b a. Incorrect. A catch block that has ellipses, that is, catch(...){ }, is used for catching any type of exception. b. Correct. A catch block that has ellipses, that is, catch(...){ }, is used for catching any type of exception. c. Incorrect. A catch block that has ellipses, that is, catch(...){ }, is used for catching any type of exception. d. Incorrect. A catch block that has ellipses, that is, catch(...){ }, is used for catching any type of exception.

POINTS: 1 REFERENCES: 996 – try/catch Block QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.03 - Learn how a try/catch block is used to handle exceptions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 7:08 AM 19. A catch block can have, at most, ____ catch block parameter(s). a. zero b. one c. two d. three ANSWER: b Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 14 FEEDBACK:

a. Incorrect.A catch block can have, at most, one catch block parameter. b. Correct.A catch block can have, at most, one catch block parameter. c. Incorrect.A catch block can have, at most, one catch block parameter. d. Incorrect. A catch block can have, at most, one catch block parameter.

POINTS: 1 REFERENCES: 996 – try/catch Block QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.03 - Learn how a try/catch block is used to handle exceptions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 7:14 AM 20. Which of the following statements throws a valid exception in C++? a. throw.function(); b. throw 2; c. throws str; d. 4 throw; ANSWER: FEEDBACK:

b a. Incorrect. The general syntax to throw an exception is throw expression;.Therefore, the statement throw 2; throws a valid exception. b. Correct. The general syntax to throw an exception is throw expression;. Therefore, the statement throw 2; throws a valid exception. c. Incorrect. The general syntax to throw an exception is throw expression;. Therefore, the statement throw 2; throws a valid exception. d. Incorrect. The general syntax to throw an exception is throw expression;. Therefore, the statement throw 2; throws a valid exception.

POINTS: 1 REFERENCES: 996-998 – try/catch Block QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.04 - Learn how to throw an exception DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/2/2020 6:44 AM 21. In a sequence of try/catch blocks, the last catch block of that sequence should be ____. a. catch(...) b. catch(int x) { { //exception-handling code //exception-handling code } } c. catch(str) d. catch(exception) { { //exception-handling code //exception-handling code } } ANSWER: a FEEDBACK: a. Correct. The catch block that has an ellipsis (three dots), as it's parameter, is Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 14 designed to catch any type of exception. Therefore, in a sequence of try/catch blocks, the last catch block should be: catch(...) { //exception-handling code } b. Incorrect. The catch block that has an ellipsis (three dots), as it's parameter, is designed to catch any type of exception. Therefore, in a sequence of try/catch blocks, the last catch block should be: catch(...) { //exception-handling code } c. Incorrect. The catch block that has an ellipsis (three dots), as it's parameter, is designed to catch any type of exception. Therefore, in a sequence of try/catch blocks, the last catch block should be: catch(...) { //exception-handling code } d. Incorrect. The catch block that has an ellipsis (three dots), as it's parameter, is designed to catch any type of exception. Therefore, in a sequence of try/catch blocks, the last catch block should be: catch(...) { //exception-handling code } POINTS: 1 REFERENCES: 996-998 – try/catch Block QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.03 - Learn how a try/catch block is used to handle exceptions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 8:41 AM 22. The class ____ is the base of the classes designed to handle exceptions. a. class b. exception logic_error c. d. runtime_error ANSWER: FEEDBACK:

b a. Incorrect. The class exception is the base of the classes designed to handle exceptions. In C++, class is a reserved word and is used to create classes. b. Correct.The class exception is the base of the classes designed to handle exceptions. c. Incorrect.The class exception is the base of the classes designed to handle exceptions. The class logic_error, derived from the exception class, is designed for handling logical errors.

Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 14 d. Incorrect. The class exception is the base of the classes designed to handle exceptions. The class runtime_error, derived from the exception class, is designed for handling runtime errors. POINTS: 1 REFERENCES: 1003 – Using C++ Exception Classes QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.05 - Become familiar with C++ exception classes and how to use them in a program DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 8:50 AM 23. The function ____,of the class exception,returns a string containing an appropriate message. a. where b. what c. when d. log ANSWER: FEEDBACK:

b a. Incorrect. The function what returns a string containing an appropriate message. There is no function called where in the class exception. b. Correct.The function what, of the class exception, returns a string containing an appropriate message. c. Incorrect. The function what, of the class exception, returns a string containing an appropriate message.There is no function called when in the class exception. d. Incorrect. The function what, of the class exception, returns a string containing an appropriate message. There is no function called log in the class exception.

POINTS: 1 REFERENCES: 1003 – Using C++ Exception Classes QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.05 - Become familiar with C++ exception classes and how to use them in a program DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 8:54 AM 24. To deal with logical errors in a program, such as a string subscript out of range or an invalid argument to a function call, several classes are derived from the class ____. a. logic_error b. logic_exception c. runtime_error d. exception ANSWER: FEEDBACK:

a a. Correct. To deal with logical errors in the program code, several classes are derived from the class logic_error. b. Incorrect. To deal with logical errors in the program code, several classes are

Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 14 derived from the class logic_error. There is no definite class named logic_exception. c. Incorrect. To deal with logical errors in the program code, several classes are derived from the class logic_error. The class runtime_error is designed to deal with errors that can be detected only during program execution. d. Incorrect. To deal with logical errors in the program code, several classes are derived from the class logic_error. The class logic_error is derived from the class exception. POINTS: 1 REFERENCES: 1004 – Using C++ Exception Classes QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.05 - Become familiar with C++ exception classes and how to use them in a program DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 9:01 AM 25. The class ____ is designed to deal with illegal arguments used in a function call. a. illegal_argument b. bad_argument c. invalid_call d. invalid_argument ANSWER: FEEDBACK:

d a. Incorrect. The class invalid_argument is designed to deal with illegal arguments used in a function call. There is no class called illegal_argument in C++. b. Incorrect. The class invalid_argument is designed to deal with illegal arguments used in a function call. There is no class called bad_argument in C++. c. Incorrect. The class invalid_argument is designed to deal with illegal arguments used in a function call.There is no class called invalid_call in C++. d. Correct. The class invalid_argument is designed to deal with illegal arguments used in a function call.

POINTS: 1 REFERENCES: 1004 – Using C++ Exception Classes QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.05 - Become familiar with C++ exception classes and how to use them in a program DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 9:08 AM 26. Which of the following classes is derived from the class runtime_error? a. bad_alloc b. out_of_range c. overflow_error d. length_error Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 14 ANSWER: FEEDBACK:

c a. Incorrect.The class overflow_error is derived from the class runtime_error. If the operator new cannot allocate memory space, this operator throws a bad_alloc exception. Moreover, bad_alloc is also an exception class and it is derived from the class exception. b. Incorrect. The out_of_range class is derived from the logic_error class. c. Correct.The class overflow_error is derived from the class runtime_error. d. Incorrect. The class overflow_error is derived from the class runtime_error. The class length_error is derived from the class logic_error.

POINTS: 1 REFERENCES: 1004 – Using C++ Exception Classes QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.05 - Become familiar with C++ exception classes and how to use them in a program DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 9:13 AM 27. The class ____ is designed to deal with errors that can be detected only during program execution. a. error b. exception c. runtime_error d. logic_error ANSWER: c FEEDBACK: a. Incorrect.There is no definite class called error in C++ exception. b. Incorrect.The base class exception is used to deal with the exceptions. c. Correct. In order to deal with the runtime errors, the class runtime_error is designed. d. Incorrect. In order to deal with the logical errors, the class logic_error is constructed. POINTS: 1 REFERENCES: 1004 – Using C++ Exception Classes QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.05 - Become familiar with C++ exception classes and how to use them in a program DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 9:17 AM 28. The logic_error and runtime_error classes are defined in the header file ____. a. stdex b. stdlib c. stdexcept d. exception ANSWER:

c

Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 14 FEEDBACK:

a. Incorrect. The logic_error and runtime_error classes are defined in the header file stdexcept. There is no header file called stdex. b. Incorrect. The logic_error and runtime_error classes are defined in the header file stdexcept. c. Correct. The header file stdexcept includes the classes runtime_error and logic_error. d. Incorrect. The logic_error and runtime_error classes are defined in the header file stdexcept. There is no header file called exception.

POINTS: 1 REFERENCES: 1004 – Using C++ Exception Classes QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.05 - Become familiar with C++ exception classes and how to use them in a program DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 9:26 AM 29. Which of the following statements creates a new exception class? a. class myClass {}; b. class myClass {} implements exception; c. class myExceptionClass {} extends exception; d. class myExceptionClass {} throws exception; ANSWER: FEEDBACK:

a a. Correct. The statement class myClass {};creates a new exception class. b. Incorrect. The statement class myClass {};creates a new exception class. c. Incorrect. The statement class myClass {};creates a new exception class. d. Incorrect. The statement class myClass {};creates a new exception class.

POINTS: 1 REFERENCES: 1007 – Creating Your Own Exception Classes QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.06 - Learn how to create your own exception classes DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 9:29 AM 30. . If you want to include members in your exception class, you typically include constructors and the function ____. a. that b. this c. log d. what ANSWER: FEEDBACK:

d a. Incorrect. If you want to include members in your exception class, you typically include constructors and the function what. b. Incorrect. If you want to include members in your exception class, you typically

Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 14 include constructors and the function what. c. Incorrect. If you want to include members in your exception class, you typically include constructors and the function what. d. Correct. If you want to include members in your exception class, you typically include constructors and the function what. POINTS: 1 REFERENCES: 1009 – Creating Your Own Exception Classes QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.06 - Learn how to create your own exception classes DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/1/2020 9:31 AM 31. The general syntax to rethrow the same exception caught by a catch block is: ____ a. rethrow; b. throw; c. rethrow exception; d. throw exception; ANSWER: FEEDBACK:

b a. Incorrect. The general syntax to rethrow the same exception caught by a catch block is: throw; In C++, rethrow is not a defined term. b. Correct. The general syntax to rethrow the same exception caught by a catch block is: throw; c. Incorrect. The general syntax to rethrow the same exception caught by a catch block is: throw; In C++, rethrow is not a defined term. d. Incorrect. The general syntax to rethrow the same exception caught by a catch block is: throw;

POINTS: 1 REFERENCES: 1016 – Rethrowing and Throwing an Exception QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.07 - Discover how to throw and rethrow an exception DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/2/2020 6:31 AM 32. Suppose you have written a program that inputs data from a file. If the input file does not exist when the program executes, then which of the following options should you choose? a. Terminate the program. b. Include code in the program to recover from the exception. c. Log the error and continue. d. Include code in the header file. ANSWER: a Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 14 FEEDBACK:

a. Correct. If the input file does not exist when the program executes, then terminate the program. b. Incorrect. If the input file does not exist when the program executes, then terminate the program. c. Incorrect. If the input file does not exist when the program executes, then terminate the program. d. Incorrect. If the input file does not exist when the program executes, then terminate the program.

POINTS: 1 REFERENCES: 1020 – Terminate the Program QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.08 - Explore exception-handling techniques DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/2/2020 5:18 AM 33. Which of the following options should you choose when an exception occurs in a program that analyzes an airline's ticketing transactions? a. Terminate the program. b. Include code in the program to recover from the exception. c. Log the error and continue. d. Include code in the header file. ANSWER: c FEEDBACK: a. Incorrect. The code for an airline's ticket transactions has to run continuously since transactions are real time. Therefore, the program should log the error and continue. b. Incorrect. The code for an airline's ticket transactions has to run continuously since transactions are real time.Therefore, the program should log the error and continue. c. Correct.The code for an airline's ticket transactions has to run continuously since transactions are real time.Therefore, the program should log the error and continue. d. Incorrect. The code for an airline's ticket transactions has to run continuously since transactions are real time.Therefore, the program should log the error and continue. POINTS: 1 REFERENCES: 1022 – Log the Error and Continue QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.08 - Explore exception-handling techniques DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/2/2020 5:21 AM 34. When an exception is thrown in a function, the function-call stack is ____ so that the exception can be caught in the Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 14 next try/catch block. a. destroyed b. allocated c. unbound d. unwound ANSWER: d FEEDBACK: a. Incorrect.If an exception is thrown in a function, then the function call stack is unwound so that the exception can be caught in the next block of try/catch. b. Incorrect. If an exception is thrown in a function, then the function call stack is unwound so that the exception can be caught in the next block of try/catch. c. Incorrect.If an exception is thrown in a function, then the function call stack is unwound so that the exception can be caught in the next block of try/catch. d. Correct. If an exception is thrown in a function, then the function call stack is unwound so that the exception can be caught in the next block of try/catch. POINTS: 1 REFERENCES: 1022 – Stack Unwinding QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.09 - Explore stack unwinding DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/2/2020 5:23 AM 35. When an exception is thrown, if the program does not handle the exception, then the function ____ is called to terminate the program. a. log b. what c. terminate d. close ANSWER: FEEDBACK:

c a. Incorrect.There is no function called log in exception handling. b. Incorrect. The function what returns a string having an appropriate message. c. Correct.When the program code could not handle the exception, then the terminate function is called to end the program. d. Incorrect. There is no function called close in exception handling.

POINTS: 1 REFERENCES: 1022 – Stack Unwinding QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.14.09 - Explore stack unwinding DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/2/2020 5:26 AM 36. A(n) ____________________ block specifies the type of exception it can catch and contains an exception handler. catch ANSWER: POINTS: 1 REFERENCES: 996 – try/catch Block QUESTION TYPE: Completion Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 14 HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.14.03 - Learn how a try/catch block is used to handle exceptions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/2/2020 5:28 AM 37. The ____________________ of the catch block parameter specifies the type of exception that the catch block can catch. ANSWER: data type POINTS: 1 REFERENCES: 997 – try/catch Block QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.14.03 - Learn how a try/catch block is used to handle exceptions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/2/2020 5:29 AM 38. Throwing an exception is typically done using the ____________________ statement. throw ANSWER: POINTS: 1 REFERENCES: 997 – try/catch Block QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.14.03 - Learn how a try/catch block is used to handle exceptions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/2/2020 5:30 AM 39. In C++, throw is a(n) ____________________ word. ANSWER: reserved POINTS: 1 REFERENCES: 997 – try/catch Block QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.14.04 - Learn how to throw an exception DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/2/2020 5:31 AM 40. All derived classes of the class exception override the function ____________________ to issue their own error messages. what ANSWER: Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 14 POINTS: 1 REFERENCES: 1003 – Using C++ Exception Classes QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.14.05 - Become familiar with C++ exception classes and how to use them in a program DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/2/2020 5:32 AM 41. The class ____________________ deals with the string subscript out of range error. out_of_range ANSWER: POINTS: 1 REFERENCES: 1004 – Using C++ Exception Classes QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.14.05 - Become familiar with C++ exception classes and how to use them in a program DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/2/2020 5:33 AM 42. If the operator new cannot allocate memory space, this operator throws a(n) ____________________ exception. bad_alloc ANSWER: POINTS: 1 REFERENCES: 1004 – Using C++ Exception Classes QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.14.05 - Become familiar with C++ exception classes and how to use them in a program DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/2/2020 5:48 AM

Copyright Cengage Learning. Powered by Cognero.

Page 19


Name:

Class:

Date:

Chapter 15 1. The following is a valid recursive definition to determine the factorial of a non-negative integer. 0! = 1 1! = 1 n! = n * (n - 1)! if n > 1 a. True b. False ANSWER: True FEEDBACK: Correct Recursion is the process of solving a problem by reducing it to smaller versions of itself. If n =0 or n = 1, then n!=1. If n > 1, then n = n * (n - 1)!, that is, n! defined into smaller version of itself. So it is a valid recursive definition. Incorrect Recursion is the process of solving a problem by reducing it to smaller versionsof itself. If n = 0 or n = 1, then n!=1. If n > 1, then n = n * (n - 1)!, that is, n! defined into smaller version of itself. So it is a valid recursive definition. POINTS: 1 REFERENCES: 1036 – Recursive Definitions QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.01 - Learn about recursive definitions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 7:25 AM 2. In a recursive function, the base case stops the recursion. a. True b. False ANSWER: True FEEDBACK: Correct Every recursive definition must have one (or more) base cases and the general case must eventually be reduced to a base case. Because the solution of a base case is direct, the base case stops the recursion. Incorrect Every recursive definition must have one (or more) base cases and the general case must eventually be reduced to a base case. Because the solution of a base case is direct, the base case stops the recursion. POINTS: 1 REFERENCES: 1037 – Recursive Definitions QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.02 - Explore the base case and the general case of a recursive definition DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 7:35 AM 3. With recursion, the base case must eventually be reduced to a general case. a. True b. False ANSWER: False Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 15 FEEDBACK:

Correct

Every recursive definition must have one (or more) base cases and the solution of a base case is direct. The general case must eventually be reduced to a base case. Incorrect Every recursive definition must have one (or more) base cases and the solution of a base case is direct. The general case must eventually be reduced to a base case.

POINTS: 1 REFERENCES: 1037 – Recursive Definitions QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.02 - Explore the base case and the general case of a recursive definition DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 7:36 AM 4. The following is an example of a recursive function. void print(int x) { if (x > 0) { cout<< x << " " ; print (x - 1); } } a. True b. False ANSWER: True FEEDBACK: Correct

A function that calls itself is called a recursive function. Because the function print calls itself, see the sixth line, print(x-1);, of the code, it is a recursive function. Incorrect A function that calls itself is called a recursive function. Because the function print calls itself, see the sixth line, print(x-1);, of the code, it is a recursive function.

POINTS: 1 REFERENCES: 1037 – Recursive Definitions QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.04 - Learn about recursive functions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 7:43 AM 5. Every call to a recursive function requires the system to allocate memory for its local variables and formal parameters. a. True b. False ANSWER: True FEEDBACK: Correct Every call to a recursive function has its own code and its own set of parameters and local variables. Therefore, every call to a recursive function requires the Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 15 system to allocate memory for its local variables and formal parameters. Incorrect Every call to a recursive function has its own code and its own set of parameters and local variables. Therefore, every call to a recursive function requires the system to allocate memory for its local variables and formal parameters. POINTS: 1 REFERENCES: 1038 – Recursive Definitions QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.04 - Learn about recursive functions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 7:46 AM 6. If a function is infinite recursive, then every recursive call results in another recursive call. a. True b. False ANSWER: True FEEDBACK: Correct Every recursive call of an infinite recursive function results in another recursive call. Incorrect Every recursive call of an infinite recursive function results in another recursive call. POINTS: 1 REFERENCES: 1038-1039 – Infinite Recursion QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.04 - Learn about recursive functions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 7:57 AM 7. You can use a recursive algorithm to find the largest element in an array. a. True b. False ANSWER: True FEEDBACK: Correct One can use a recursive algorithm to find the largest element in an array. Incorrect One can use a recursive algorithm to find the largest element in an array.

POINTS: 1 REFERENCES: 1039 – Problem Solving Using Recursion QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.03 - Discover what a recursive algorithm is DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 7:59 AM 8. One of the steps to design a recursive function is to determine the limiting conditions. Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 15 a. True b. False ANSWER: FEEDBACK:

True To design a recursive function, understand the problem requirements, determine the limiting conditions, identify and provide solution to each base case, and identify and provide solution in terms of smaller version of itself to each general case. Therefore, one of the steps to design a recursive function is to determine the limiting conditions. Incorrect To design a recursive function, understand the problem requirements, determine the limiting conditions, identify and provide solution to each base case, and identify and provide solution in terms of smaller version of itself to each general case. Therefore, one of the steps to design a recursive function is to determine the limiting conditions. Correct

POINTS: 1 REFERENCES: 1039 – Infinite Recursion QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.04 - Learn about recursive functions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 8:03 AM 9. A definition in which something is defined in terms of a smaller version of itself is called a(n) ____ definition. a. step-wise b. recursive c. member-wise d. iterative ANSWER: b FEEDBACK: a. Incorrect. Recursion is the process of solving a problem by reducing it to smaller versions of itself. Therefore, a definition in which something is defined in terms of a smaller version of itself is called a recursive definition. b. Correct. Recursion is the process of solving a problem by reducing it to smaller versions of itself. Therefore, a definition in which something is defined in terms of a smaller version of itself is called a recursive definition. c. Incorrect. Recursion is the process of solving a problem by reducing it to smaller versions of itself. Therefore, a definition in which something is defined in terms of a smaller version of itself is called a recursive definition. d. Incorrect. Recursion is the process of solving a problem by reducing it to smaller versions of itself. Therefore, a definition in which something is defined in terms of a smaller version of itself is called a recursive definition. An iterative control structure uses a looping structure to repeat a set of statements. POINTS: 1 REFERENCES: 1036 – Recursive Definitions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.01 - Learn about recursive definitions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 8:08 AM Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 15 10. In a recursive definition, the solution to a _____ case is direct. a. general b. base c. direct d. tail ANSWER: b FEEDBACK: a. Incorrect. In a recursive definition, the solution to abase case is direct, while a general case is defined into smaller version of itself. b. Correct. In a recursive definition, the solution to abase case is direct, while a general case is defined into smaller version of itself. c. Incorrect. In a recursive definition, the solution to abase case is direct, while a general case is defined into smaller version of itself. In direct recursion, the recursive function calls itself. d. Incorrect. In a recursive definition, the solution to a base case is direct, while a general case is defined into smaller version of itself. In tail recursion, the last statement executed is the recursive call. POINTS: 1 REFERENCES: 1036 – Recursive Definitions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.02 - Explore the base case and the general case of a recursive definition DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 8:13 AM int foo(int n) { if (n == 0) return 0; else return n + foo(n - 1); }

//Line 1 //Line 2 //Line 3 //Line 4 //Line 5 //Line 6 //Line 7

11. Consider the accompanying definition of a recursive function. Which of the statements represents the base case? a. Statements in Lines 1 to 6. b. Statements in Lines 3 and 4. c. Statements in Lines 5 and 6. d. Statements in Lines 3 to 5. ANSWER: b FEEDBACK: a. Incorrect. Statements in Lines 3 and 4 does not call the function foo, and so represent the base case. The statements in Lines 1 to 6 represent the entire recursive function. b. Correct. Statements in Lines 3 and 4 does not call the function foo, and so represent the base case. c. Incorrect. Statements in Lines 3 and 4 does not call the function foo, and so represent the base case. The statements in Lines 5 and 6 represents the general case. Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 15 d. Incorrect. Statements in Lines 3 and 4 does not call the function foo, and so represent the base case. The statement in Line 5 is part of the statement in Line 6, and so it is part of the general case. POINTS: 1 REFERENCES: 1036 –1037 – Recursive Definitions QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: foo LEARNING OBJECTIVES: PAPD.MALI.15.02 - Explore the base case and the general case of a recursive definition DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 8:17 AM 12. Consider the accompanying definition of a recursive function. Which of the statements represent the general case? a. Statements in Lines 1 to 6 b. Statements in Lines 3 and 4 c. Statements in Lines 4 to 6 d. Statements in Lines 5 and 6 ANSWER: d FEEDBACK: a. Incorrect. Statements in Lines 5 and 6 calls the function foo, and so represent the general case. The statements in Lines 1 to 6 represent the entire recursive function. b. Incorrect. Statements in Lines 5 and 6 calls the function foo, and so represent the general case. Statements in Lines 3 and 4 does not call the function foo, and so does not represent the general case. Statements in Lines 3 and 4 represents the base case. c. Incorrect. Statements in Lines 5 and 6 calls the function foo, and so represent the general case. The statement in Line 4 is part of the statement in Line 3, and so it is part of the base case. d. Correct. Statements in Lines 5 and 6 calls the function foo, and so represent the general case. POINTS: 1 REFERENCES: 1036-1037 – Recursive Definitions QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: foo LEARNING OBJECTIVES: PAPD.MALI.15.02 - Explore the base case and the general case of a recursive definition DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 8:42 AM void printNum(int num) { if (n < 0) cout << "Num is negative" << endl; else if (num == 0) Copyright Cengage Learning. Powered by Cognero.

//Line 1 //Line 2 //Line 3 //Line 4 //Line 5 Page 6


Name:

Class:

Date:

Chapter 15 cout << "Num is zero" << endl; else { cout << num << " "; printNum(num – 1); } }

//Line 6 //Line 7 //Line 8 //Line 9 //Line 10 //Line 11 //Line 12

13. Consider the accompanying definition of a recursive function. Which of the statements represent the base case? a. Statements in Lines 3 and 4 b. Statements in Lines 5 and 6 c. Statements in Lines 3 to 6 d. Statements in Lines 5 to 10 ANSWER: c FEEDBACK: a. Incorrect. The statements in Lines 3 and 4 represents a base case. The statements in Lines 5 and 6 represents another base case. The statements in Line 3 to 6 represent the base cases. b. Incorrect. The statements in Lines 5 and 6 represents a base cases. The statements in Lines 3 and 4 represents a base cases. The statements in Line 3 to 6 represent the base cases. c. Correct. The solutions in Lines 4 and 6 are direct and these statements are parts of the statements in Lines 3 and 5, respectively. Therefore, the statements in Lines 3 to 6 represent the base cases. d. Incorrect. The statements in Lines 7 to 11 represent the general case. The statemens in Lines 3 to 6 represent the base cases. POINTS: 1 REFERENCES: 1036-1037 – Recursive Definitions QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: printNum LEARNING OBJECTIVES: PAPD.MALI.15.02 - Explore the base case and the general case of a recursive definition DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 8:46 AM 14. Consider the accompanying definition of a recursive function. Which of the statements represent the general case? a. Statements in Lines 3 to 11 b. Statements in Lines 5 and 6 c. Statements in Lines 5 to 11 d. Statements in Lines 7 to 11 ANSWER: d FEEDBACK: a. Incorrect. The statements in Lines 3 to 11 represent both the base cases and the general case. b. Incorrect. The solution in Line 6 is direct and this statement is part of the statement in Line 5. Therefore, the statements in Lines 5 and 6 represent a base case. The statements in Lines 7 to 11 represent the general case. Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 15 c. Incorrect. The statements in Lines 5 and 6 represent a base case and statements in Lines 7–11 represent the general case; so it is a combination of both a base case and the general case. d. Correct. The statements in Lines 7 to 11 represent the general case. POINTS: 1 REFERENCES: 1036-1037 – Recursive Definitions QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: printNum LEARNING OBJECTIVES: PAPD.MALI.15.02 - Explore the base case and the general case of a recursive definition DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 8:49 AM int recFunc(int num) { if (num >= 10) return 10; else return num * recFunc(num + 1); } 15. Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << recFunc(8) << endl; a. 4 b. 8 c. 72 d. 720 ANSWER: FEEDBACK:

d a. Incorrect. Note that recFunc(num) = 10 if num >= 10 recFunc(num) = num * recFunc(num + 1) if num < 10, where num is an integer. The cout statement calls the recFunc with actual argument 8. Now, recFunc(8) = 8 * recFunc(9), because num = 8 < 10 recFunc(9) = 9 * recFunc(10), because num = 9 < 10 recFunc(10) = 10, because num = 10. Thus, recFunc(9)=9*recFunc(10)=9*10=90, and recFunc(8)=8*recFunc(9)=8*90=720. Therefore, the output is: 720

b. Incorrect. Note that recFunc(num) = 10 if num >= 10 recFunc(num) = num * recFunc(num + 1) if num < 10, where num is an integer. The cout statement calls the recFunc with actual argument 8. Now, recFunc(8) = 8 * recFunc(9), because num = 8 < 10 recFunc(9) = 9 * recFunc(10), because num = 9 < 10 recFunc(10) = 10, because num = 10. Thus, recFunc(9)=9*recFunc(10)=9*10=90, and recFunc(8)=8*recFunc(9)=8*90=720. Therefore, the output is: 720

c. Incorrect. Note that Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 15 recFunc(num) = 10 if num >= 10 recFunc(num) = num * recFunc(num + 1) if num < 10, where num is an integer. The cout statement calls the recFunc with actual argument 8. Now, recFunc(8) = 8 * recFunc(9), because num = 8 < 10 recFunc(9) = 9 * recFunc(10), because num = 9 < 10 recFunc(10) = 10, because num = 10. Thus, recFunc(9)=9*recFunc(10)=9*10=90, and recFunc(8)=8*recFunc(9)=8*90=720. Therefore, the output is: 720

d. Correct. Note that recFunc(num) = 10 if num >= 10 recFunc(num) = num * recFunc(num + 1) if num < 10, where num is an integer. The cout statement calls the recFunc with actual argument 8. Now, recFunc(8) = 8 * recFunc(9), because num = 8 < 10 recFunc(9) = 9 * recFunc(10), because num = 9 < 10 recFunc(10) = 10, because num = 10. Thus, recFunc(9)=9*recFunc(10)=9*10=90, and recFunc(8)=8*recFunc(9)=8*90=720. Therefore, the output is: 720

POINTS: 1 REFERENCES: 1037 – Recursive Definitions QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: recFunc LEARNING OBJECTIVES: PAPD.MALI.15.04 - Learn about recursive functions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 8:52 AM 16. Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << recFunc(10) << endl; a. 10 b. 11 c. 100 d. 110 ANSWER: FEEDBACK:

a a. Correct. Note that recFunc(num) = 10 if num >= 10 recFunc(num) = num * recFunc(num + 1) if num < 10, where num is an integer. The cout statement calls the recFunc with actual argument 10. Now, recFunc(10) = 10, because num = 10. Therefore, the output is: 10

b. Incorrect. Note that recFunc(num) = 10 if num >= 10 recFunc(num) = num * recFunc(num + 1) if num < 10, where num is an integer. The cout statement calls the recFunc with actual argument 10. Now, recFunc(10) = 10, because num = 10. Therefore, the output is: 10 Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 15 c. Incorrect. Note that recFunc(num) = 10 if num >= 10 recFunc(num) = num * recFunc(num + 1) if num < 10, where num is an integer. The cout statement calls the recFunc with actual argument 10. Now, recFunc(10) = 10, because num = 10. Therefore, the output is: 10

d. Incorrect. Note that recFunc(num) = 10 if num >= 10 recFunc(num) = num * recFunc(num + 1) if num < 10, where num is an integer. The cout statement calls the recFunc with actual argument 10. Now, recFunc(10) = 10, because num = 10. Therefore, the output is: 10

POINTS: 1 REFERENCES: 1037 – Recursive Definitions QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: recFunc LEARNING OBJECTIVES: PAPD.MALI.15.04 - Learn about recursive functions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 8:55 AM 17. Consider the following definition of the recursive function print. void print(int num) { if (num > 0) { cout << num << " "; print(num - 1); } } What is the output of the following statement? print(4); a. 0 1 2 3 4 c. 4 3 2 1 ANSWER: FEEDBACK:

b. 1 2 3 4 d. 4 3 2 1 0 c a. Incorrect. The function print is recursive and its argument, num, is an int value. If num >0, then the function print first outputs the value of num and then calls itself with argument num - 1. Therefore, print(4) first outputs 4 and then executes print(3). Similarly, print(3) first outputs 3 and then executes print(2), and so on. The recursion stops when num <= 0. Note that when num <= 0, the if statement in print fails, the recursion stops, the cout statement in print does not execute, and so the value of num is not printed. Therefore, the output is: 4 3 2 1

b. Incorrect. The function print is recursive and its argument, num, is an int value. If num >0, then the function print first outputs the value of num and then calls itself Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 15 with argument num - 1. Therefore, print(4) first outputs 4 and then executes print(3). Similarly, print(3) first outputs 3 and then executes print(2), and so on. The recursion stops when num <= 0. Note that when num <= 0, the if statement in print fails, the recursion stops, the cout statement in print does not execute, and so the value of num is not printed. Therefore, the output is: 4 3 2 1

c. Correct The function print is recursive and its argument, num, is an int value. If num >0, then the function print first outputs the value of num and then calls itself with argument num - 1. Therefore, print(4) first outputs 4 and then executes print(3). Similarly, print(3) first outputs 3 and then executes print(2), and so on. The recursion stops when num <= 0. Note that when num <= 0, the if statement in print fails, the recursion stops, the cout statement in print does not execute, and so the value of num is not printed. Therefore, the output is: 4 3 2 1

d. Incorrect. The function print is recursive and its argument, num, is an int value. If num >0, then the function print first outputs the value of num and then calls itself with argument num - 1. Therefore, print(4) first outputs 4 and then executes print(3). Similarly, print(3) first outputs 3 and then executes print(2), and so on. The recursion stops when num <= 0. Note that when num <= 0, the if statement in print fails, the recursion stops, the cout statement in print does not execute, and so the value of num is not printed. Therefore, the output is: 4 3 2 1

POINTS: 1 REFERENCES: 1037 – Recursive Definitions QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.04 - Learn about recursive functions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 8:58 AM 18. Tracing through ____ recursion is more tedious than tracing other recursive forms. a. direct b. indirect c. tail d. iterative ANSWER: b FEEDBACK: a. Incorrect. A function is called directly recursive if it calls itself. A function that calls another function and eventually results in the original function call is said to be indirectly recursive. An indirectly recursive more tedious than tracing other recursive forms. b. Correct. A function that calls another function and eventually results in the original function call is said to be indirectly recursive. An indirectly recursive more tedious than tracing other recursive forms. c. Incorrect. A recursive function in which the last statement executed is the recursive call is called a tail recursive function. A function that calls another function and eventually results in the original function call is said to be indirectly recursive. An indirectly recursive more tedious than tracing other recursive forms. d. Incorrect. A function that calls another function and eventually results in the original function call is said to be indirectly recursive. An indirectly recursive more tedious than tracing other recursive forms. Iterative recursion is not a defined term in C++. POINTS:

1

Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 15 REFERENCES: 1038 – Direct and Indirect Recursion QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.05 - Become familiar with direct and indirect recursion DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 9:02 AM 19. A function is called ____ if it calls itself. a. directly iterative b. indirectly iterative c. directly recursive d. indirectly recursive ANSWER: c FEEDBACK: a. Incorrect. In C++, directly iterative is a not a defined term. A function is called directly recursive if it calls itself b. Incorrect. In C++, indirectly iterative is not a defined term. A function is called directly recursive if it calls itself c. Correct. A function is called directly recursive if it calls itself d. Incorrect. A function is called directly recursive if it calls itself. A function that calls another function and eventually results in the original function call is said to be indirectly recursive. POINTS: 1 REFERENCES: 1038 – Direct and Indirect Recursion QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.05 - Become familiar with direct and indirect recursion DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 9:05 AM 20. A recursive function in which the last statement executed is the recursive call is called a(n) ____ recursive function. a. direct b. tail c. indefinite d. indirect ANSWER: b FEEDBACK: a. Incorrect. A recursive function in which the last statement executed is the recursive call is called a tail recursive function. In a directly recursive function, the last statement executed need not be a recursive call. b. Correct. A recursive function in which the last statement executed is the recursive call is called a tail recursive function. c. Incorrect. A recursive function in which the last statement executed is the recursive call is called a tail recursive function. In C++, the indefinite is not a defined term. d. Incorrect. A recursive function in which the last statement executed is the recursive call is called a tail recursive function. In a indirectly recursive function, the last statement executed need not be a recursive call. POINTS: REFERENCES:

1 1038 – Direct and Indirect Recursion

Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 15 QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.05 - Become familiar with direct and indirect recursion DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 9:10 AM 21. If every recursive call results in another recursive call, then the recursive function (algorithm) is said to have ____ recursion. a. unlimited b. indefinite c. infinite d. forever ANSWER: c FEEDBACK: a. Incorrect. If every recursive call results in another recursive call, then the recursive function (algorithm) is said to have infinite recursion. In C++, unlimited recursion is not a defined term. b. Incorrect. If every recursive call results in another recursive call, then the recursive function (algorithm) is said to have infinite recursion. In C++, indefinite recursion is not a defined term. c. Correct. In an infinite recursive function, every recursive call will results in another recursive call. d. Incorrect. If every recursive call results in another recursive call, then the recursive function (algorithm) is said to have infinite recursion. In C++, forever recursion is not a defined term. POINTS: 1 REFERENCES: 1038 – Infinite Recursion QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.04 - Learn about recursive functions DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 9:12 AM int mystery(int list[], int first, int last) { if (first == last) return list[first]; else return list[first] + mystery(list, first + 1, last); } 22. Consider the accompanying definition of the recursive function mystery. Given the declaration: int alpha[5] = {1, 4, 5, 8, 9}; what is the output of the following statement? cout << mystery(alpha, 0, 4) << endl; a. 1 b. 18 c. 27 d. 35 Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 15 ANSWER: FEEDBACK:

c a. Incorrect. Note that mystery(list,first,last)=list[first] if first==last mystery(list,first,last) = list[first]+mystery(list,first+1,last)if first!=last where list is an array of integers, and first and lastare int values. Now, mystery(alpha,0, 4)=alpha[0]+mystery(alpha,1,4), because 0!=4 mystery(alpha,1, 4)=alpha[1]+mystery(alpha,2,4), because 1!=4 mystery(alpha,2, 4)=alpha[2]+mystery(alpha,3,4), because 2!=4 mystery(alpha,3, 4)=alpha[3]+mystery(alpha,4,4), because 3!=4 mystery(alpha,4, 4)=alpha[4] = 9, because 4==4 Thus, mystery(alpha,3, 4)=alpha[3]+9=8+9=17, mystery(alpha,2, 4)=alpha[2]+17=5+17=22, mystery(alpha,1, 4)=alpha[1]+22 = 4 + 22 = 26, and mystery(alpha,0, 4)=alpha[0]+26=1+26 = 27. Therefore, the output is: 27

b. Incorrect. Note that mystery(list,first,last)=list[first] if first==last mystery(list,first,last) = list[first]+mystery(list,first+1,last)if first!=last where list is an array of integers, and first and lastare int values. Now, mystery(alpha,0, 4)=alpha[0]+mystery(alpha,1,4), because 0!=4 mystery(alpha,1, 4)=alpha[1]+mystery(alpha,2,4), because 1!=4 mystery(alpha,2, 4)=alpha[2]+mystery(alpha,3,4), because 2!=4 mystery(alpha,3, 4)=alpha[3]+mystery(alpha,4,4), because 3!=4 mystery(alpha,4, 4)=alpha[4] = 9, because 4==4 Thus, mystery(alpha,3, 4)=alpha[3]+9=8+9=17, mystery(alpha,2, 4)=alpha[2]+17=5+17=22, mystery(alpha,1, 4)=alpha[1]+22 = 4 + 22 = 26, and mystery(alpha,0, 4)=alpha[0]+26=1+26 = 27. Therefore, the output is: 27

c. Correct. Note that mystery(list,first,last)=list[first] if first==last mystery(list,first,last) = list[first]+mystery(list,first+1,last)if first!=last where list is an array of integers, and first and lastare int values. Now, mystery(alpha,0, 4)=alpha[0]+mystery(alpha,1,4), because 0!=4 mystery(alpha,1, 4)=alpha[1]+mystery(alpha,2,4), because 1!=4 mystery(alpha,2, 4)=alpha[2]+mystery(alpha,3,4), because 2!=4 mystery(alpha,3, 4)=alpha[3]+mystery(alpha,4,4), because 3!=4 mystery(alpha,4, 4)=alpha[4] = 9, because 4==4 Thus, mystery(alpha,3, 4)=alpha[3]+9=8+9=17, mystery(alpha,2, 4)=alpha[2]+17=5+17=22, mystery(alpha,1, 4)=alpha[1]+22 = 4 + 22 = 26, and mystery(alpha,0, 4)=alpha[0]+26=1+26 = 27. Therefore, the output is: 27

d. Incorrect. Note that mystery(list,first,last)=list[first] if first==last mystery(list,first,last) = list[first]+mystery(list,first+1,last)if first!=last where list is an array of integers, and first and lastare int values. Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 15 Now,

mystery(alpha,0, 4)=alpha[0]+mystery(alpha,1,4), because 0!=4 mystery(alpha,1, 4)=alpha[1]+mystery(alpha,2,4), because 1!=4 mystery(alpha,2, 4)=alpha[2]+mystery(alpha,3,4), because 2!=4 mystery(alpha,3, 4)=alpha[3]+mystery(alpha,4,4), because 3!=4 mystery(alpha,4, 4)=alpha[4] = 9, because 4==4 Thus, mystery(alpha,3, 4)=alpha[3]+9=8+9=17, mystery(alpha,2, 4)=alpha[2]+17=5+17=22, mystery(alpha,1, 4)=alpha[1]+22 = 4 + 22 = 26, and mystery(alpha,0, 4)=alpha[0]+26=1+26 = 27. Therefore, the output is: 27

POINTS: 1 REFERENCES: 1039-1041 – Problem Solving Using Recursion QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: mystery LEARNING OBJECTIVES: PAPD.MALI.15.06 - Explore how to use recursive functions to implement recursive algorithms DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 9:16 AM 23. Consider the following definition of the recursive function mystery. int mystery(int first, int last) { if (first > last) return 0; else if (first == last) return first; else return first + mystery(first + 1, last - 1); } What is the output of the following statement? cout << mystery(6, 10) << endl; a. 13 b. 21 c. 40 d. 42 ANSWER: b FEEDBACK: a. Incorrect. Note that mystery(first, last) = 0 if first > last; mystery(first, last) = first if first == last; mystery(first, last) = first + mystery(first + 1, last - 1) if first < last, where first and lastare int values. Now, mystery(6, 10) = 6 + mystery(7,9), because 6 < 10 mystery(7,9) = 7 + mystery(8, 8), because 7 < 9 mystery(8, 8) = 8, because 8 == 8 Thus, mystery(7, 9) = 7 + 8 = 15 and mystery(6, 10) = 6 + 15 = Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 15 21. Therefore, the output is: 21

b. Correct. Note that mystery(first, last) = 0 if first > last; mystery(first, last) = first if first == last; mystery(first, last) = first + mystery(first + 1, last - 1) if first < last, where first and lastare int values. Now, mystery(6, 10) = 6 + mystery(7,9), because 6 < 10 mystery(7,9) = 7 + mystery(8, 8), because 7 < 9 mystery(8, 8) = 8, because 8 == 8 Thus, mystery(7, 9) = 7 + 8 = 15 and mystery(6, 10) = 6 + 15 = 21. Therefore, the output is: 21

c. Incorrect. Note that mystery(first, last) = 0 if first > last; mystery(first, last) = first if first == last; mystery(first, last) = first + mystery(first + 1, last - 1) if first < last, where first and lastare int values. Now, mystery(6, 10) = 6 + mystery(7,9), because 6 < 10 mystery(7,9) = 7 + mystery(8, 8), because 7 < 9 mystery(8, 8) = 8, because 8 == 8 Thus, mystery(7, 9) = 7 + 8 = 15 and mystery(6, 10) = 6 + 15 = 21. Therefore, the output is: 21

d. Incorrect. Note that mystery(first, last) = 0 if first > last; mystery(first, last) = first if first == last; mystery(first, last) = first + mystery(first + 1, last - 1) if first < last, where first and lastare int values. Now, mystery(6, 10) = 6 + mystery(7,9), because 6 < 10 mystery(7,9) = 7 + mystery(8, 8), because 7 < 9 mystery(8, 8) = 8, because 8 == 8 Thus, mystery(7, 9) = 7 + 8 = 15 and mystery(6, 10) = 6 + 15 = 21. Therefore, the output is: 21

POINTS: 1 REFERENCES: 1043-1044 -Problem Solving Using Recursion QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.06 - Explore how to use recursive functions to implement recursive algorithms DATE CREATED: 10/5/2016 1:42 PM DATE MODIFIED: 4/3/2020 9:19 AM 24. Consider the following definition of the recursive function mystery. int mystery(int num) { Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 15 if (num <= 0) return 0; else if (num % 2 == 0) return num + mystery(num – 1); else return num * mystery(num – 1); } What is the output of the following statement? cout << mystery(5) << endl; a. 50 b. 65 c. 120 d. 180 ANSWER: FEEDBACK:

a a. Correct. Note that mystery(num) = 0 if num <= 0 mystery(num) = num + mystery(num – 1) if num is a positive even integer mystery(num) = num * mystery(num – 1) if num is a positive odd integer. Now, mystery(5) = 5 * mystery(4), because 5 is a positive odd integer; mystery(4) = 4 + mystery(3), because 4 is a positive even integer mystery(3) = 3 * mystery(2), because 3 is a positive odd integer mystery(2) = 2 + mystery(1), because 2 is a positive even integer mystery(1) = 1 * mystery(0), because 1 is a positive odd integer mystery(0) = 0. Thus, mystery(1) = 1 * 0 = 0, mystery(2) = 2 + 0 = 2, mystery(3) = 3 * 2 = 6, mystery(4) = 4 + 6 = 10, and mystery(5) = 5 * 10 = 50.Therefore, the output is: 50

b. Incorrect. Note that mystery(num) = 0 if num <= 0 mystery(num) = num + mystery(num – 1) if num is a positive even integer mystery(num) = num * mystery(num – 1) if num is a positive odd integer. Now, mystery(5) = 5 * mystery(4), because 5 is a positive odd integer; mystery(4) = 4 + mystery(3), because 4 is a positive even integer mystery(3) = 3 * mystery(2), because 3 is a positive odd integer mystery(2) = 2 + mystery(1), because 2 is a positive even integer mystery(1) = 1 * mystery(0), because 1 is a positive odd integer mystery(0) = 0. Thus, mystery(1) = 1 * 0 = 0, mystery(2) = 2 + 0 = 2, mystery(3) = 3 * 2 = 6, mystery(4) = 4 + 6 = 10, and mystery(5) = 5 * 10 = 50.Therefore, the output is: 50

c. Incorrect. Note that mystery(num) = 0 if num <= 0 mystery(num) = num + mystery(num – 1) if num is a positive even integer mystery(num) = num * mystery(num – 1) if num is a positive odd integer. Now, mystery(5) = 5 * mystery(4), because 5 is a positive odd integer; mystery(4) = 4 + mystery(3), because 4 is a positive even integer mystery(3) = 3 * mystery(2), because 3 is a positive odd integer mystery(2) = 2 + mystery(1), because 2 is a positive even integer Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 15 mystery(1) = 1 * mystery(0), because 1 is a positive odd integer mystery(0) = 0. Thus, mystery(1) = 1 * 0 = 0, mystery(2) = 2 + 0 = 2, mystery(3) = 3 * 2 = 6, mystery(4) = 4 + 6 = 10, and mystery(5) = 5 * 10 = 50.Therefore, the output is: 50

d. Incorrect. Note that mystery(num) = 0 if num <= 0 mystery(num) = num + mystery(num – 1) if num is a positive even integer mystery(num) = num * mystery(num – 1) if num is a positive odd integer. Now, mystery(5) = 5 * mystery(4), because 5 is a positive odd integer; mystery(4) = 4 + mystery(3), because 4 is a positive even integer mystery(3) = 3 * mystery(2), because 3 is a positive odd integer mystery(2) = 2 + mystery(1), because 2 is a positive even integer mystery(1) = 1 * mystery(0), because 1 is a positive odd integer mystery(0) = 0. Thus, mystery(1) = 1 * 0 = 0, mystery(2) = 2 + 0 = 2, mystery(3) = 3 * 2 = 6, mystery(4) = 4 + 6 = 10, and mystery(5) = 5 * 10 = 50.Therefore, the output is: 50

POINTS: 1 REFERENCES: 1043-1044 – Problem Solving Using Recursion QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.06 - Explore how to use recursive functions to implement recursive algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/3/2020 9:22 AM int puzzle(int start, int end) { if (start > end) return start - end; else if (start == end) return start + end; else return end * puzzle(start + 1, end - 1); } 25. Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << puzzle(5, 10) << endl; a. 720 b. 5040 c. 5760 d. 10800 ANSWER: FEEDBACK:

a a. Correct. Note that puzzle(start, end) = start - end if start > end, puzzle(start, end) = start + end if start == end, puzzle(start, end) = end * puzzle(start + 1, end - 1) if start < end.

Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 15 where start and end are int values. Now, puzzle(5,10)=10*puzzle(6,9), because 5<10. puzzle(6,9)=9*puzzle(7,8), because 6<9. puzzle(7,8)=8*puzzle(8,7), because 7<8. puzzle(8,7)=8-7=1, because 8>7. Thus, puzzle(7,8)=8*puzzle(8,7)=8*1=8, puzzle(6,9)=9*puzzle(7,8)=9*8 = 72, and puzzle(5,10)=10*puzzle(6,9) = 10*72=720. Therefore, the output is: 720

b. Incorrect. Note that puzzle(start, end) = start - end if start > end, puzzle(start, end) = start + end if start == end, puzzle(start, end) = end * puzzle(start + 1, end - 1) if start < end. where start and end are int values. Now, puzzle(5,10)=10*puzzle(6,9), because 5<10. puzzle(6,9)=9*puzzle(7,8), because 6<9. puzzle(7,8)=8*puzzle(8,7), because 7<8. puzzle(8,7)=8-7=1, because 8>7. Thus, puzzle(7,8)=8*puzzle(8,7)=8*1=8, puzzle(6,9)=9*puzzle(7,8)=9*8 = 72, and puzzle(5,10)=10*puzzle(6,9) = 10*72=720. Therefore, the output is: 720

c. Incorrect. Note that puzzle(start, end) = start - end if start > end, puzzle(start, end) = start + end if start == end, puzzle(start, end) = end * puzzle(start + 1, end - 1) if start < end. where start and end are int values. Now, puzzle(5,10)=10*puzzle(6,9), because 5<10. puzzle(6,9)=9*puzzle(7,8), because 6<9. puzzle(7,8)=8*puzzle(8,7), because 7<8. puzzle(8,7)=8-7=1, because 8>7. Thus, puzzle(7,8)=8*puzzle(8,7)=8*1=8, puzzle(6,9)=9*puzzle(7,8)=9*8 = 72, and puzzle(5,10)=10*puzzle(6,9) = 10*72=720. Therefore, the output is: 720

d. Incorrect. Note that puzzle(start, end) = start - end if start > end, puzzle(start, end) = start + end if start == end, puzzle(start, end) = end * puzzle(start + 1, end - 1) if start < end. where start and end are int values. Now, puzzle(5,10)=10*puzzle(6,9), because 5<10. puzzle(6,9)=9*puzzle(7,8), because 6<9. puzzle(7,8)=8*puzzle(8,7), because 7<8. puzzle(8,7)=8-7=1, because 8>7. Thus, puzzle(7,8)=8*puzzle(8,7)=8*1=8, puzzle(6,9)=9*puzzle(7,8)=9*8 = 72, and puzzle(5,10)=10*puzzle(6,9) = 10*72=720. Therefore, the output is: 720 Copyright Cengage Learning. Powered by Cognero.

Page 19


Name:

Class:

Date:

Chapter 15 POINTS: 1 REFERENCES: 1043-1044 – Problem Solving Using Recursion QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: puzzle LEARNING OBJECTIVES: PAPD.MALI.15.06 - Explore how to use recursive functions to implement recursive algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/3/2020 9:27 AM 26. Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << puzzle(3, 7) << endl; a. 10 b. 21 c. 42 d. 420 ANSWER: FEEDBACK:

d a. Incorrect. Note that puzzle(start, end) = start - end if start > end, puzzle(start, end) = start + end if start == end, puzzle(start, end) = end * puzzle(start + 1, end - 1) if start < end. where start and end are int values. Now, puzzle(3,7)=7*puzzle(4,6), because 3<7. puzzle(4,6)=6*puzzle(5,5), because 4<6. puzzle(5,5)=5+5=10, because 5==5. Thus, puzzle(4,6)=6*puzzle(5,5)=6*10=60, puzzle(3,7)=7*puzzle(4,6)=7*60 = 420. Therefore, the output is: 420

b. Incorrect. Note that puzzle(start, end) = start - end if start > end, puzzle(start, end) = start + end if start == end, puzzle(start, end) = end * puzzle(start + 1, end - 1) if start < end. where start and end are int values. Now, puzzle(3,7)=7*puzzle(4,6), because 3<7. puzzle(4,6)=6*puzzle(5,5), because 4<6. puzzle(5,5)=5+5=10, because 5==5. Thus, puzzle(4,6)=6*puzzle(5,5)=6*10=60, puzzle(3,7)=7*puzzle(4,6)=7*60 = 420. Therefore, the output is: 420

c. Incorrect. Note that puzzle(start, end) = start - end if start > end, puzzle(start, end) = start + end if start == end, puzzle(start, end) = end * puzzle(start + 1, end - 1) if start < end. where start and end are int values. Now, puzzle(3,7)=7*puzzle(4,6), because 3<7. puzzle(4,6)=6*puzzle(5,5), because 4<6. Copyright Cengage Learning. Powered by Cognero.

Page 20


Name:

Class:

Date:

Chapter 15 puzzle(5,5)=5+5=10, because 5==5. Thus, puzzle(4,6)=6*puzzle(5,5)=6*10=60, puzzle(3,7)=7*puzzle(4,6)=7*60 = 420. Therefore, the output is: 420

d. Correct. Note that puzzle(start, end) = start - end if start > end, puzzle(start, end) = start + end if start == end, puzzle(start, end) = end * puzzle(start + 1, end - 1) if start < end. where start and end are int values. Now, puzzle(3,7)=7*puzzle(4,6), because 3<7. puzzle(4,6)=6*puzzle(5,5), because 4<6. puzzle(5,5)=5+5=10, because 5==5. Thus, puzzle(4,6)=6*puzzle(5,5)=6*10=60, puzzle(3,7)=7*puzzle(4,6)=7*60 = 420. Therefore, the output is: 420

POINTS: 1 REFERENCES: 1043-1044 – Problem Solving Using Recursion QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: puzzle LEARNING OBJECTIVES: PAPD.MALI.15.06 - Explore how to use recursive functions to implement recursive algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/3/2020 9:31 AM 27. Which of the following function headings can be used to define a function to calculate the nth Fibonacci number? a. void rFibNum(intfirst, intsecond) b. boolrFibNum(intfirst, intsecond) c. boolrFibNum(intfirst, intsecond, int n) d. intrFibNum(intfirst, intsecond, int n) ANSWER: FEEDBACK:

d a. Incorrect. The return type of the function must be intbecause a Fibonacci number is an integer. Also, the function should have a third parameter to specify which number of the Fibonacci sequence should be computed. Therefore, the correct function heading is: intrFibNum(int first, int second, int n) b. Incorrect. The return type of the function must be int because a Fibonacci number is an integer. Also, the function should have a third parameter to specify which number of the Fibonacci sequence should be computed. Therefore, the correct function heading is: intrFibNum(int first, int second, int n) c. Incorrect. The return type of the function must be int because a Fibonacci number is an integer. Therefore, the correct function heading is: intrFibNum(int first, int second, int n) d. Correct. The function heading intrFibNum(intfirst, intsecond, int n) can be used to define a function to calculate the nth Fibonacci number.

Copyright Cengage Learning. Powered by Cognero.

Page 21


Name:

Class:

Date:

Chapter 15 POINTS: 1 REFERENCES: 1044 – Problem Solving Using Recursion QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.06 - Explore how to use recursive functions to implement recursive algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/3/2020 9:39 AM 28. How many needles are used in the Tower of Hanoi problem? a. one b. two c. three d. four ANSWER: c FEEDBACK: a. Incorrect. Three needles are used in the Tower of Hanoi problem. b. Incorrect. Three needles are used in the Tower of Hanoi problem. c. Incorrect. Three needles are used in the Tower of Hanoi problem. d. Correct. Three needles are used in the Tower of Hanoi problem. POINTS: 1 REFERENCES: 1047 – Problem Solving Using Recursion QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.06 - Explore how to use recursive functions to implement recursive algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/3/2020 9:41 AM 29. Which of the following rules should you follow to solve the Tower of Hanoi problem? a. Only two disks can be moved at a time. b. You can remove disks only from the first needle. c. The removed disk must be placed on a smaller disk. d. A smaller disk can be placed on top of a larger disk. ANSWER: d FEEDBACK: a. Incorrect. As per the Tower of Hanoi problem rules, only one disk can be moved at a time. b. Incorrect. In Tower of Hanoi problem, there is no rule that removes disk only from the first needle. c. Incorrect. As per the Tower of Hanoi problem rules, only one disk can be moved at a time, the removed disk must be placed on one of the needles and a larger disk cannot be placed on a smaller disk. d. Correct. As per the Tower of Hanoi problem rules, a larger disk cannot be placed on top of a smaller disk, buta smaller disk can be placed on top of a larger disk. POINTS: REFERENCES:

1 1047 – Problem Solving Using Recursion

Copyright Cengage Learning. Powered by Cognero.

Page 22


Name:

Class:

Date:

Chapter 15 QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.06 - Explore how to use recursive functions to implement recursive algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/3/2020 9:45 AM 30. ____ control structures use a looping structure, such as while, for, or do...while, to repeat a set of statements. a. Iterative b. Recursive c. Procedural d. Object ANSWER: a FEEDBACK: a. Correct. A looping structure, such as while, for, or do…while, is used by an iterative control structure to repeat a set of statements. b. Incorrect. In recursion, a set of statements is repeated by having the function call itself. c. Incorrect. Procedural is not a control structure in C++ programming. d. Incorrect. Object is not a control structure in C++ programming. POINTS: 1 REFERENCES: 1049-1050 – Recursion or Iteration? QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.07 - Become aware of recursion vs. iteration DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/3/2020 9:47 AM 31. Which of the following factor would best determine the solution method, iterative or recursive, for a mission control system? a. Efficiency b. Cost c. Memory space d. Computer speed ANSWER: a FEEDBACK: a. Correct. For mission control systems, efficiency is absolutely critical and, therefore, the efficiency factorwould dictate the solution method. b. Incorrect. For mission control systems, efficiency is absolutely critical and, therefore, the efficiency factor would dictate the solution method. c. Incorrect. For mission control systems, efficiency is absolutely critical and, therefore, the efficiency factor would dictate the solution method. d. Incorrect. For mission control systems, efficiency is absolutely critical and, therefore, the efficiency factor would dictate the solution method. POINTS: 1 REFERENCES: 1050 – Recursion or Iteration? QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.07 - Become aware of recursion vs. iteration Copyright Cengage Learning. Powered by Cognero.

Page 23


Name:

Class:

Date:

Chapter 15 DATE CREATED: DATE MODIFIED:

10/5/2016 1:43 PM 4/3/2020 9:51 AM

32. Which of the following solutions is easier to construct for the Tower of Hanoi problem? a. Recursive b. Iterative c. Procedural d. Step-by-step ANSWER: a FEEDBACK: a. Correct. The recursive solution is easier to construct for the Tower of Hanoi problem. b. Incorrect. The recursive solution is easier to construct for the Tower of Hanoi problem. It is difficult to construct an iterative solution for the Tower of Hanoi problem. c. Incorrect. The recursive solution is easier to construct for the Tower of Hanoi problem. d. Incorrect. The recursive solution is easier to construct for the Tower of Hanoi problem. POINTS: 1 REFERENCES: 1050 – Recursion or Iteration? QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.15.07 - Become aware of recursion vs. iteration DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/3/2020 9:55 AM 33. Consider the following recursive definition, where n is a positive integer. F(1) = 3 F(n) = F(n - 1) + 1 if n > 1 The value of F(3) is ____________________. 5 ANSWER: POINTS: 1 REFERENCES: 1039 – Problem Solving Using Recursion QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.15.06 - Explore how to use recursive functions to implement recursive algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/3/2020 9:57 AM 34. The recursive algorithm must have one or more base cases, and the general solution must eventually be reduced to a(n) ____________________. ANSWER: base case POINTS: 1 Copyright Cengage Learning. Powered by Cognero.

Page 24


Name:

Class:

Date:

Chapter 15 REFERENCES: 1037- Problem Solving Using Recursion QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.15.06 - Explore how to use recursive functions to implement recursive algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/3/2020 9:58 AM 35. Recursive algorithms are implemented using ____________________ functions. ANSWER: recursive POINTS: 1 REFERENCES: 1037 – Recursive Definitions QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.15.04 - Learn about recursive functions DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/3/2020 9:59 AM 36. Consider the following code. int fact(int num) { if (num == 0) return 1; else return num * fact(num - 1); } The function fact is an example of a(n) ____________________ recursive function. ANSWER: tail POINTS: 1 REFERENCES: 1037-1038 – Direct and Indirect Recursion QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.15.07 - Become aware of recursion vs. iteration DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 10/5/2016 1:43 PM 37. Suppose that function A calls function B, function B calls function C, function C calls function D, and function D calls function A. Then Function A is ____________________ recursive. ANSWER: indirectly POINTS: 1 Copyright Cengage Learning. Powered by Cognero.

Page 25


Name:

Class:

Date:

Chapter 15 REFERENCES: 1038 – Direct and Indirect Recursion QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.15.07 - Become aware of recursion vs. iteration DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/3/2020 10:03 AM 38. If a function A calls a function B and function B calls function A, then function A is ____________________ recursive. ANSWER: indirectly POINTS: 1 REFERENCES: 1038 – Direct and Indirect Recursion QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.15.07 - Become aware of recursion vs. iteration DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 10/5/2016 1:43 PM 39. If you execute an infinite recursive function on a computer, the function executes until the system runs out of ____________________. ANSWER: memory POINTS: 1 REFERENCES: 1038-1039 – Infinite Recursion QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.15.04 - Learn about recursive functions DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/3/2020 10:05 AM 40. The ____________________ number in a Fibonacci sequence is the sum of the second and third Fibonacci numbers. ANSWER: fourth 4th POINTS: 1 REFERENCES: 1043 – Problem Solving Using Recursion QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.15.06 - Explore how to use recursive functions to implement recursive algorithms DATE CREATED: 10/5/2016 1:43 PM Copyright Cengage Learning. Powered by Cognero.

Page 26


Name:

Class:

Date:

Chapter 15 DATE MODIFIED:

4/3/2020 10:07 AM

41. In the Tower of Hanoi problem, if needle 1 contains three disks, then the number of moves required to move all three disks from needle 1 to needle 3 is ____________________. ANSWER: 7 POINTS: 1 REFERENCES: 1049 – Tower of Hanoi: Analysis QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.15.06 - Explore how to use recursive functions to implement recursive algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 10/5/2016 1:43 PM

Copyright Cengage Learning. Powered by Cognero.

Page 27


Name:

Class:

Date:

Chapter 16 1. All of the values in a list have the same type. a. True b. False ANSWER: True FEEDBACK: Correct A list is a collection of values of the same type. Incorrect A list is a collection of values of the same type.

POINTS: 1 REFERENCES: 1070 - List Processing QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.01 - Learn about list processing and how to search a list using sequential search DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 12:48 AM 2. The size of a list is fixed and cannot be increased or decreased. a. True b. False ANSWER: False FEEDBACK: Correct The size of a list is the number of elements in the list and the size can be increased or decreased. Incorrect The size of a list is the number of elements in the list and the size can be increased or decreased. POINTS: 1 REFERENCES: 1070 - List Processing QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.01 - Learn about list processing and how to search a list using sequential search DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 1:21 AM 3. The sequential search algorithm does not assume that the list is sorted. a. True b. False ANSWER: True FEEDBACK: Correct The sequential search algorithm does not presume that the list is sorted. Incorrect The sequential search algorithm does not presume that the list is sorted.

POINTS: 1 REFERENCES: 1071 - Searching QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.01 - Learn about list processing and how to search a list using sequential Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 16 DATE CREATED: DATE MODIFIED:

search 10/5/2016 1:43 PM 4/18/2020 1:23 AM

4. In the bubble sort as given in the text, the smaller elements move toward the bottom, and the larger elements move toward the top of the list. a. True b. False ANSWER: False FEEDBACK: Correct In the bubble sort as given in the text, the larger values move toward the end of the list, and the smaller values move toward the beginning of the list. Incorrect In the bubble sort as given in the text, the larger values move toward the end of the list, and the smaller values move toward the beginning of the list. POINTS: 1 REFERENCES: 1071 - Bubble Sort QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.02 - Explore how to sort an array using the bubble sort and insertion sort algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 1:25 AM 5. On average the bubble sort makes fewer item assignments than comparisons. a. True b. False ANSWER: True FEEDBACK: Correct For a list of size n, the bubble sort makes n(n-1)/2 key comparisons and, on average, n(n-1)/4 key assignments. Therefore, on average the bubble sort makes fewer key assignments than key comparisons. Incorrect For a list of size n, the bubble sort makes n(n-1)/2 key comparisons and, on average, n(n-1)/4 key assignments. Therefore, on average the bubble sort makes fewer key assignments than key comparisons. POINTS: 1 REFERENCES: 1074-1075 - Bubble Sort QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.02 - Explore how to sort an array using the bubble sort and insertion sort algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 1:27 AM 6. The performance of bubble sort can be improved if we stop the sorting process as soon as we find that, in an iteration, no swapping of elements takes place. a. True Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 16 b. False ANSWER: FEEDBACK:

True Correct

In order to improve the performance of bubble sort, stop the sorting process ifin an iterationno swapping of elements take place. Incorrect In order to improve the performance of bubble sort, stop the sorting process if in an iteration no swapping of elements take place.

POINTS: 1 REFERENCES: 1075 - Bubble Sort QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.02 - Explore how to sort an array using the bubble sort and insertion sort algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 3:16 AM 7. The insertion sort algorithm sorts the list by moving each element to its proper place. a. True b. False ANSWER: True FEEDBACK: Correct The insertion sort algorithm sorts the list by moving each element to its proper place Incorrect The insertion sort algorithm sorts the list by moving each element to its proper place POINTS: 1 REFERENCES: 1075 - Insertion Sort QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.02 - Explore how to sort an array using the bubble sort and insertion sort algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 3:17 AM 8. During the sorting phase of insertion sort, the array containing the list is divided into two sublists, sorted and unsorted. a. True b. False ANSWER: True FEEDBACK: Correct In insertion sort, during the sorting phase the list is divided into two sublists, sorted list and unsorted list. Incorrect In insertion sort, during the sorting phase the list is divided intotwo sublists, sorted list and unsorted list. POINTS: REFERENCES: QUESTION TYPE:

1 1077 - Insertion Sort True / False

Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 16 HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.02 - Explore how to sort an array using the bubble sort and insertion sort algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 3:19 AM 9. To sort a list of 1000 elements, on average, insertion sort will makes about 250,000 item assignments. a. True b. False ANSWER: True FEEDBACK: Correct To sort a list of size n, on average, the insertion sort makes n(n-1)/4 item assignments. Therefore, if n = 1000, on average, the insertion sort makes 1000(1000-1)/4 = 250(999) = 249750 ≈ 250000 item assignments. Incorrect To sort a list of size n, on average, the insertion sort makes n(n-1)/4 item assignments. Therefore, if n = 1000, on average, the insertion sort makes 1000(1000-1)/4 = 250(999) = 249750 ≈ 250000 item assignments. POINTS: 1 REFERENCES: 1078 - Insertion Sort QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.02 - Explore how to sort an array using the bubble sort and insertion sort algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 3:20 AM 10. On a sorted list a sequential search is much faster than a binary search. a. True b. False ANSWER: False FEEDBACK: Correct On a sorted list a binary search is much faster than sequential search. Incorrect On a sorted list a binary search is much faster than sequential search.

POINTS: 1 REFERENCES: 1079 - Binary Search QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.03 - Learn how to implement the binary search algorithm DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 3:23 AM 11. The sequential search algorithm uses a(n) ____ variable to track whether the item is found. a. int b. bool c. char d. double ANSWER: b Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 16 FEEDBACK:

a. Incorrect. In sequential search algorithm, if the search element is found, then the algorithm returns true; otherwise it returns false. Thus, the sequential search algorithm uses a bool variable to track whether the item is found or not. b. Correct. In sequential search algorithm, if the search element is found, then the algorithm returns true; otherwise it returns false. Thus, the sequential search algorithm uses a bool variable to track whether the item is found or not. c. Incorrect. In sequential search algorithm, if the search element is found, then the algorithm returns true; otherwise it returns false. Thus, the sequential search algorithm uses a bool variable to track whether the item is found or not. d. Incorrect. In sequential search algorithm, if the search element is found, then the algorithm returns true; otherwise it returns false. Thus, the sequential search algorithm uses a bool variable to track whether the item is found or not.

POINTS: 1 REFERENCES: 1070 - Searching QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.01 - Learn about list processing and how to search a list using sequential search DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 3:26 AM 12. If the search item is the 900th item in the list, the sequential search makes ____ key comparisons to determine whether the search item is in the list. a. 100 b. 900 c. 9000 d. 90,000 ANSWER: b FEEDBACK: a. Incorrect. If the search item is the nth value in the list, then the sequential search makes n key comparisons to determine whether the search item is in the list or not. Here, n = 900, so the sequential search makes 900 key comparisons. b. Correct. If the search item is the nth value in the list, then the sequential search makes n key comparisons to determine whether the search item is in the list or not. Here, n = 900, so the sequential search makes 900 key comparisons. c. Incorrect. If the search item is the nth value in the list, then the sequential search makes n key comparisons to determine whether the search item is in the list or not. Here, n = 900, so the sequential search makes 900 key comparisons. d. Incorrect. If the search item is the nth value in the list, then the sequential search makes n key comparisons to determine whether the search item is in the list or not. Here, n = 900, so the sequential search makes 900 key comparisons. POINTS: 1 REFERENCES: 1071 - Searching QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.01 - Learn about list processing and how to search a list using sequential search DATE CREATED: 10/5/2016 1:43 PM Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 16 DATE MODIFIED:

4/18/2020 5:36 AM

13. In a sequential search of a list of 1000 elements, if the search item is not in the list, then ____ key comparisons will be made. a. 100 b. 1000 c. 10,000 d. 100,000 ANSWER: b FEEDBACK: a. Incorrect. If the search item is not in the list, then the sequential search compares the search item with each item in the list. Therefore, if the list has 1000 elements and the search item is not in the list, then 1000 key comparisons will be made. b. Correct. If the search item is not in the list, then the sequential search compares the search item with each item in the list. Therefore, if the list has 1000 elements and the search item is not in the list, then 1000 key comparisons will be made. c. Incorrect. If the search item is not in the list, then the sequential search compares the search item with each item in the list. Therefore, if the list has 1000 elements and the search item is not in the list, then 1000 key comparisons will be made. d. Incorrect. If the search item is not in the list, then the sequential search compares the search item with each item in the list. Therefore, if the list has 1000 elements and the search item is not in the list, then 1000 key comparisons will be made. POINTS: 1 REFERENCES: 1071 - Searching QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.01 - Learn about list processing and how to search a list using sequential search DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 3:30 AM 14. To sort a list of length n, bubble sort uses ____ iterations. a. 1 b. n - 1 c. n d. n + 1 ANSWER: b FEEDBACK: a. Incorrect. To sort a list of length n, bubble sort uses n - 1 iterations. b. Correct. To sort a list of length n, bubble sort uses n - 1 iterations. c. Incorrect. To sort a list of length n, bubble sort uses n - 1 iterations. d. Incorrect. To sort a list of length n, bubble sort uses n - 1 iterations. POINTS: 1 REFERENCES: 1071 - Bubble Sort QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.02 - Explore how to sort an array using the bubble sort and insertion sort algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 5:50 AM Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 16 15. Let L be a list of length 100 and L is to be sorted using the bubble sort algorithm. Then in each iteration of the sorting face, which of the following elements are compared first. a. L[0] and L[99] b. L[0] and L[1] c. L[1] and L[99] d. L[99] and L[100] ANSWER: b FEEDBACK: a. Incorrect. In each iteration of the sorting face, L[0] and L[1]are compared first. b. Correct. In each iteration of the sorting face, L[0] and L[1]are compared first. c. Incorrect. In each iteration of the sorting face, L[0] and L[1]are compared first. d. Incorrect. In each iteration of the sorting face, L[0] and L[1]are compared first. POINTS: 1 REFERENCES: 1071 - Bubble Sort QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.02 - Explore how to sort an array using the bubble sort and insertion sort algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 5:39 AM 16. After the second iteration of bubble sort for a list of length n, the last ____ is (are) sorted. a. element b. two elements c. three elements d. n-2 ANSWER: b FEEDBACK: a. Incorrect. After the second iteration of bubble sort for a list of length n, the last two elements are sorted. b. Correct. After the second iteration of bubble sort for a list of length n, the last two elements are sorted. c. Incorrect. After the second iteration of bubble sort for a list of length n, the last two elements are sorted. d. Incorrect. After the second iteration of bubble sort for a list of length n, the last two elements are sorted. POINTS: 1 REFERENCES: 1072 - Bubble Sort QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.02 - Explore how to sort an array using the bubble sort and insertion sort algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 3:40 AM 17. In the bubble sort algorithm, which code accomplishes swapping values in elements at positions index and index + 1? a. list[index] = list[index + 1] Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 16 list[index + 1] = list[index] b. list[index + 1] = list[index] list[index] = list[index + 1] c. list[index] = temp; list[index] = list[index + 1]; temp = list[index + 1]; d. temp = list[index]; list[index] = list[index + 1]; list[index + 1] = temp; ANSWER: FEEDBACK:

d a. Incorrect. To swap the contents of two variables, a third variable of the same type is required. Therefore, the correct code to swap list[index] and list[index + 1] is: temp = list[index]; list[index] = list[index + 1]; list[index + 1] = temp;. b. Incorrect. To swap the contents of two variables, a third variable of the same type is required. Therefore, the correct code to swap list[index] and list[index + 1] is: temp = list[index]; list[index] = list[index + 1]; list[index + 1] = temp;. c. Incorrect. To swap the contents of two variables, a third variable of the same type is required. Therefore, the correct code to swap list[index] and list[index + 1] is: temp = list[index]; list[index] = list[index + 1]; list[index + 1] = temp;. d. Correct. To swap the contents of two variables, a third variable of the same type is required. Therefore, the correct code to swap list[index] and list[index + 1] is: temp = list[index]; list[index] = list[index + 1]; list[index + 1] = temp;.

POINTS: 1 REFERENCES: 1073 - Bubble Sort QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.02 - Explore how to sort an array using the bubble sort and insertion sort algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 3:43 AM 18. For a list of length n, the bubble sort algorithm, as described in the text, makes exactly ____ key comparisons. a. n(n-1)/2 b. n(n-1)/3 c. n(n-1)/4 d. (n-1)/2 Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 16 ANSWER: FEEDBACK:

a a. Correct. For a list of length n, the bubble sort algorithm, as described in the text, makes exactly n(n-1)/2 key comparisons. b. Incorrect. For a list of length n, the bubble sort algorithm, as described in the text, makes exactly n(n-1)/2 key comparisons. c. Incorrect. For a list of length n, the bubble sort algorithm, as described in the text, makes exactly n(n-1)/2 key comparisons. d. Incorrect. For a list of length n, the bubble sort algorithm, as described in the text, makes exactly n(n-1)/2 key comparisons.

POINTS: 1 REFERENCES: 1075 - Bubble Sort QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.02 - Explore how to sort an array using the bubble sort and insertion sort algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 3:52 AM 19. Assume that n = 1000. To sort the list, bubble sort makes about ____ item assignments. a. 10,000 b. 100,000 c. 250,000 d. 500,000 ANSWER: c FEEDBACK: a. Incorrect. On average, bubble sort makes n(n-1)/4 key assignments. Therefore, to sort a list of 1000 elements, bubble sort makes 1000(10001)/4 = 250(999) = 249750 ≈ 250000 key assignments. b. Incorrect. On average, bubble sort makes n(n-1)/4 key assignments. Therefore, to sorta list of 1000 elements, bubble sort makes 1000(1000-1)/4 = 250(999) = 249750 ≈ 250000 key assignments. c. Correct. On average, bubble sort makes n(n-1)/4 key assignments. Therefore, to sorta list of 1000 elements, bubble sort makes 1000(1000-1)/4 = 250(999) = 249750 ≈ 250000 key assignments. d. Incorrect. On average, bubble sort makes n(n-1)/4 key assignments. Therefore, to sorta list of 1000 elements, bubble sort makes 1000(1000-1)/4 = 250(999) = 249750 ≈ 250000 key assignments. POINTS: 1 REFERENCES: 1075 - Bubble Sort QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.02 - Explore how to sort an array using the bubble sort and insertion sort algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 3:55 AM 20. When moving array values for insertion sort, to move list[4] into list[2], first ____. Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 16 a. move list[2] to list[3]

b. delete list[2]

c. move list[4] to list[3] d. copy list[4] into temp ANSWER: d FEEDBACK: a. Incorrect. To move list[4] into list[2], first list[4] must be copied to a temporary space. Therefore, first copy list[4] into temp. b. Incorrect. To move list[4] into list[2], first list[4] must be copied to a temporary space. Therefore, first copy list[4] into temp. c. Incorrect. To move list[4] into list[2], first list[4] must be copied to a temporary space. Therefore, first copy list[4] into temp. d. Correct. To move list[4] into list[2], first list[4] must be copied to a temporary space. Therefore, first copy list[4] into temp. POINTS: 1 REFERENCES: 1076 - Insertion Sort QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.02 - Explore how to sort an array using the bubble sort and insertion sort algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 3:56 AM 21. In the insertion sort function, the variable firstOutOfOrder is initialized to ____, assuming n is the length of the list. a. 0 b. 1 c. n - 1 d. n ANSWER: b FEEDBACK: a. Incorrect. The variable firstOutOfOrder gives the index of the first element in the unsorted portion of the list. A list of length 1 is sorted. Therefore, firstOutOfOrder is initialized to the index of the second element, which is 1, of the list. b. Correct. The variable firstOutOfOrder gives the index of the first element in the unsorted portion of the list. A list of length 1 is sorted. Therefore, firstOutOfOrder is initialized to the index of the second element, which is 1, of the list. c. Incorrect. The variable firstOutOfOrder gives the index of the first element in the unsorted portion of the list. A list of length 1 is sorted. Therefore, firstOutOfOrder is initialized to the index of the second element, which is 1, of the list. d. Incorrect. The variable firstOutOfOrder gives the index of the first element in the unsorted portion of the list. A list of length 1 is sorted. Therefore, firstOutOfOrder is initialized to the index of the second element, which is 1, of the list. POINTS: REFERENCES: QUESTION TYPE:

1 1077 - Insertion Sort Multiple Choice

Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 16 HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.02 - Explore how to sort an array using the bubble sort and insertion sort algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 3:58 AM 22. For a list of length n, insertion sort makes about ____ item assignments. a. n(n-1)/4 b. n(n-1)/2 2 c. n d. n3 ANSWER: FEEDBACK:

a a. Correct. For a list of length n, insertion sort makes about n(n-1)/4 item assignments. b. Incorrect. For a list of length n, insertion sort makes about n(n-1)/4 item assignments. c. Incorrect. For a list of length n, insertion sort makes about n(n-1)/4 item assignments. d. Incorrect. For a list of length n, insertion sort makes about n(n-1)/4 item assignments.

POINTS: 1 REFERENCES: 1078 - Insertion Sort QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.02 - Explore how to sort an array using the bubble sort and insertion sort algorithms DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 4:01 AM 23. On average, a sequential search searches ____. a. one quarter of the list b. one third of the list c. one half of the list d. the entire list ANSWER: c FEEDBACK: a. Incorrect. On average, a sequential search searches one half of the list to find whether the search item is in the list or not. b. Incorrect. On average, a sequential search searches one half of the list to find whether the search item is in the list or not. c. Correct. On average, a sequential search searches one half of the list to find whether the search item is in the list or not. d. Incorrect. On average, a sequential search searches one half of the list to find whether the search item is in the list or not. POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 1079 - Binary Search Multiple Choice False

Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 16 LEARNING OBJECTIVES: PAPD.MALI.16.03 - Learn how to implement the binary search algorithm DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 4:03 AM 24. Consider the following statement: int list[] = {4, 8, 19, 25, 34, 39, 45, 48, 66, 75, 89, 95}; When performing a binary search on list, the search element is first compared with ____. a. 4 b. 25 c. 39 d. 95 ANSWER: c FEEDBACK: a. Incorrect. The binary search compares the search item with the middle element of the list. The list contains 12 elements indexed 0 to 11. The location of the middle element is (0+11)/2 = 5 (integer division), and list[5] = 39. Therefore, the search element is first compared with 39. b. Incorrect. The binary search compares the search item with the middle element of the list. The list contains 12 elements indexed 0 to 11. The location of the middle element is (0+11)/2 = 5 (integer division), and list[5] = 39. Therefore, the search element is first compared with 39. c. Correct. The binary search compares the search item with the middle element of the list. The list contains 12 elements indexed 0 to 11. The location of the middle element is (0+11)/2 = 5 (integer division), and list[5] = 39. Therefore, the search element is first compared with 39. d. Incorrect. The binary search compares the search item with the middle element of the list. The list contains 12 elements indexed 0 to 11. The location of the middle element is (0+11)/2 = 5 (integer division), and list[5] = 39. Therefore, the search element is first compared with 39. POINTS: 1 REFERENCES: 1079 - Binary Search QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.03 - Learn how to implement the binary search algorithm DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 4:06 AM 25. Consider the following statement. int list[] = {4, 8, 19, 25, 34, 39, 45, 48, 66, 75, 89, 95}; When performing a binary search on list for 75, after the first iteration, the search is restricted to ____. a. list[0]...list[6] b. list[0]...list[7] c. list[5]...list[11] d. list[6]...list[11] ANSWER: d FEEDBACK: a. Incorrect. The binary search compares the search item with middle element of the list. The list contains 12 elements indexed 0 to 11. The location of the middle element is (0+11)/2 = 5 (integer division), and list[5] = 39. Therefore, 75 is first compared with 39. Because 75 > 39, after the first iteration, the search is restricted to list[6]...list[11]. Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 16 b. Incorrect. The binary search compares the search item with middle element of the list. The list contains 12 elements indexed 0 to 11. The location of the middle element is (0+11)/2 = 5 (integer division), and list[5] = 39. Therefore, 75 is first compared with 39. Because 75 > 39, after the first iteration, the search is restricted to list[6]...list[11]. c. Incorrect. The binary search compares the search item with middle element of the list. The list contains 12 elements indexed 0 to 11. The location of the middle element is (0+11)/2 = 5 (integer division), and list[5] = 39. Therefore, 75 is first compared with 39. Because 75 > 39, after the first iteration, the search is restricted to list[6]...list[11]. d. Correct. The binary search compares the search item with middle element of the list. The list contains 12 elements indexed 0 to 11. The location of the middle element is (0+11)/2 = 5 (integer division), and list[5] = 39. Therefore, 75 is first compared with 39. Because 75 > 39, after the first iteration, the search is restricted to list[6]...list[11]. POINTS: 1 REFERENCES: 1080 - Binary Search QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.03 - Learn how to implement the binary search algorithm DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 4:10 AM 26. The formula to find the index of the middle element of a list indexed first to last is ____. a. (mid + last)/2 b. (first + last) - 2 c. (first + last) / 2 d. (first + mid ) * 2 ANSWER: FEEDBACK:

c a. Incorrect. The formula to find the index of the middle element of a list indexed first to last is (first + last) / 2. b. Incorrect. The formula to find the index of the middle element of a list indexed first to last is (first + last) / 2. c. Correct. The formula to find the index of the middle element of a list indexed first to last is (first + last) / 2. d. Incorrect. The formula to find the index of the middle element of a list indexed first to last is (first + last) / 2.

POINTS: 1 REFERENCES: 1080 - Binary Search QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.03 - Learn how to implement the binary search algorithm DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 4:12 AM 27. In a successful search, in the last iteration, that is, the last time through the loop the binary search algorithm makes Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 16 ____ key comparison(s). a. one b. two c. n-2 d. n ANSWER: FEEDBACK:

a a. Correct. In a successful search, last time through the loop, the binary search algorithm makes one key comparison. b. Incorrect. In a successful search, last time through the loop, the binary search algorithm makes one key comparison. c. Incorrect. In a successful search, last time through the loop, the binary search algorithm makes one key comparison. d. Incorrect. In a successful search, last time through the loop, the binary search algorithm makes one key comparison.

POINTS: 1 REFERENCES: 1081 - Binary Search QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.03 - Learn how to implement the binary search algorithm DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 4:16 AM 28. Which of the following statements creates the vector object vecList of size size? a. vector[elemType] vecList(size); b. vector<elemType> vecList(size); c. vector(size) vecList<elementType> d. vector{elemType::size} vecList; ANSWER: FEEDBACK:

b a. Incorrect. The statement vector<elemType>vecList(size); creates the vector object vecList of size size. b. Correct. The statement vector<elemType>vecList(size); creates the vector object vecList of size size. c. Incorrect. The statement vector<elemType>vecList(size); creates the vector object vecList of size size. d. Incorrect. The statement vector<elemType>vecList(size); creates the vector object vecList of size size.

POINTS: 1 REFERENCES: 1083 - vector Type (class) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.04 - Become familiar with the vector type DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 4:51 AM 29. A variable declared using the vector type is called a ____. Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 16 a. vector element c. vector list ANSWER: FEEDBACK:

b. vector array d. vector container d a. Incorrect. A variable declared using the vector type is called a vector, or a vector object, or a vector container. b. Incorrect. A variable declared using the vector type is called a vector, or a vector object, or a vector container. c. Incorrect. A variable declared using the vector type is called a vector, or a vector object, or a vector container. d. Correct. A variable declared using the vector type is called a vector, or a vector object, or a vector container.

POINTS: 1 REFERENCES: 1083 - vector Type (class) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.04 - Become familiar with the vector type DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 4:53 AM 30. Suppose that index specifies the position of an element in the vector object vecList. Which of the following statements returns the element at the position index in vecList? a. vecList[index] b. vecList.get(index) c. vecList.front(index) d. vecList<index> ANSWER: FEEDBACK:

a a. Correct. The statement vecList[index] returns the element at the position index in vector vecList. b. Incorrect. The statement vecList[index] returns the element at the position index in vector vecList. c. Incorrect. The statement vecList[index] returns the element at the position index in vector vecList. d. Incorrect. The statement vecList[index] returns the element at the position index in vector vecList.

POINTS: 1 REFERENCES: 1084 - vector Type (class) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.04 - Become familiar with the vector type DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 4:57 AM 31. Which of the following statements declares intList to be an empty vector object? a. vector intList(); b. vectorintList(0); c. vector<int>intList(10); d. vector<int>intList; Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 16 ANSWER: FEEDBACK:

d a. Incorrect. The statement vector<int>intList; declares intList to be an empty vector object. The statement vector intList(); will result in a syntax error. b. Incorrect. The statement vector<int>intList; declares intList to be an empty vector object. The statement vector intList(0); will result in a syntax error. c. Incorrect. The statement vector<int>intList; declares intList to be an empty vector object. The statement declares intList to be a vector object of size 10. d. Correct. The statement vector<int>intList; declares intList to be an empty vector object.

POINTS: 1 REFERENCES: 1084 - vector Type (class) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.04 - Become familiar with the vector type DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 5:09 AM 32. Which of the following statements declares intList to be a vector of size 5 and the element to be of type int? a. vector intList[5]; b. vector<int>intList(5); c. vector<int>intList(); d. vector(int) intList[5]; ANSWER: FEEDBACK:

b a. Incorrect. The statement vector<int>intList(5); declares intList to be a vector of size 5 and the element type to be int. b. Correct. The statement vector<int>intList(5); declares intList to be a vector of size 5 and the element type to be int. c. Incorrect. The statement vector<int>intList(5); declares intList to be a vector of size 5 and the element type to be int. d. Incorrect. The statement vector<int>intList(5); declares intList to be a vector of size 5 and the element type to be int.

POINTS: 1 REFERENCES: 1085 - vector Type (class) QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.16.04 - Become familiar with the vector type DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 5:13 AM 33. The code shown represents the ____________________ search algorithm. int unknownSearch(const int list[], int listLength, int searchItem) Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 16 { int loc; bool found = false; loc = 0; while (loc < listLength && !found) if (list[loc] == searchItem) found = true; else loc++; if (found) return loc; else return -1; } ANSWER: sequential POINTS: 1 REFERENCES: 1070 - Searching QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.16.01 - Learn about list processing and how to search a list using sequential search DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 10/5/2016 1:43 PM 34. To search a list size of 1000, on average, the sequential search makes about ____________________ key comparisons. ANSWER: 500 POINTS: 1 REFERENCES: 1071 - Searching QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.16.01 - Learn about list processing and how to search a list using sequential search DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 5:15 AM 35. A(n) ____________________ search uses the “divide and conquer” technique to search the list. ANSWER: binary POINTS: 1 REFERENCES: 1079 - Binary Search QUESTION TYPE: Completion HAS VARIABLES: False Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 16 STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.16.03 - Learn how to implement the binary search algorithm DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 10/5/2016 1:43 PM 36. In order to apply a(n) ____________________ search on a list, the list must be sorted. ANSWER: binary POINTS: 1 REFERENCES: 1079 - Binary Search QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.16.03 - Learn how to implement the binary search algorithm DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 5:17 AM 37. Suppose that vecList is a vector object. The expression _______________ returns the first element of vecList. vecList.front() ANSWER: POINTS: 1 REFERENCES: 1084 - vector Type (class) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.16.04 - Become familiar with the vector type DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 5:18 AM 38. Suppose that vecList is a vector object. The statement __________________ deletes all elements of vecList. vecList.clear(); ANSWER: POINTS: 1 REFERENCES: 1084 - vector Type (class) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.16.04 - Become familiar with the vector type DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 5:20 AM 39. Suppose that vecList is a vector object. The expression _______________ returns the last element of vecList. vecList.back() ANSWER: POINTS:

1

Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 16 REFERENCES: 1084 - vector Type (class) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.16.04 - Become familiar with the vector type DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 5:21 AM 40. Suppose that vecList is a vector object and elements of vecList are of type int. The statement __________________ inserts 78 into vecList at the end. vecList.push_back(78); ANSWER: POINTS: 1 REFERENCES: 1084 - vector Type (class) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.16.04 - Become familiar with the vector type DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 5:22 AM 41. Suppose that vecList is a vector object. The statement __________________ deletes the last element of vecList. vecList.pop_back(); ANSWER: POINTS: 1 REFERENCES: 1084 - vector Type (class) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.16.04 - Become familiar with the vector type DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 5:24 AM 42. Suppose that vecList is a vector object. The expression __________________ returns true if vecList is empty and false otherwise. vecList.empty() ANSWER: POINTS: 1 REFERENCES: 1085 - vector Type (class) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.16.04 - Become familiar with the vector type DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 5:27 AM Copyright Cengage Learning. Powered by Cognero.

Page 19


Name:

Class:

Date:

Chapter 16 43. Suppose that vecList is a vector object. The expression _______________ returns the maximum number of elements that can be inserted into vecList. vecList.max_size() ANSWER: POINTS: 1 REFERENCES: 1085 - vector Type (class) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.16.04 - Become familiar with the vector type DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 5:29 AM 44. If you initially declare a vector object and do not specify its size, then in order to add elements to the vector object, you use the function ____________________. push_back ANSWER: POINTS: 1 REFERENCES: 1085 - vector Type (class) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.16.04 - Become familiar with the vector type DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 5:30 AM 45. The first element in a vector object is at location ____________________. ANSWER: 0 POINTS: 1 REFERENCES: 1085 - vector Type (class) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.16.04 - Become familiar with the vector type DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 10/5/2016 1:43 PM 46. If you want to use the class vector in your program, you must include the statement ____________________. #include <vector> ANSWER: POINTS: 1 REFERENCES: 1086 - vector Type (class) QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic Copyright Cengage Learning. Powered by Cognero.

Page 20


Name:

Class:

Date:

Chapter 16 LEARNING OBJECTIVES: PAPD.MALI.16.04 - Become familiar with the vector type DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/18/2020 5:33 AM

Copyright Cengage Learning. Powered by Cognero.

Page 21


Name:

Class:

Date:

Chapter 17 1. Linked lists allow you to overcome the fixed array size limitations during program execution. a. True b. False ANSWER: True FEEDBACK: Correct The array size must be fixed during execution, and so only a fixed number of items can be stored in an array. In a linked list, memory space to store data is allocated during program execution, and so size of a linked list is not fixed during program execution, thus, overcoming the fixed array size limitations during program execution. Incorrect The array size must be fixed during execution, and so only a fixed number of items can be stored in an array. In a linked list, memory space to store data is allocated during program execution, and so size of a linked list is not fixed during program execution, thus, overcoming the fixed array size limitations during program execution. POINTS: 1 REFERENCES: 1116 – Linked Lists QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.01 - Learn about linked lists DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 8:42 AM 2. Memory for the components of an array does not need to be contiguous. a. True b. False ANSWER: False FEEDBACK: Correct The memory for the components of an array is contiguous. Incorrect The memory for the components of an array is contiguous.

POINTS: 1 REFERENCES: 1116 – Linked Lists QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.01 - Learn about linked lists DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 8:44 AM 3. Suppose the pointer head points to the first node of a linked list. You can use the pointer head to traverse the linked list. a. True b. False ANSWER: False FEEDBACK: Correct To traverse the linked list, a pointer other than head pointer is required. Incorrect To traverse a list, a pointer other than head pointer is required. Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 17 POINTS: 1 REFERENCES: 1120 – Linked Lists: Some Properties QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.02 - Become familiar with the basic properties of linked lists DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 8:55 AM 4. To deallocate the memory occupied by the node of a linked list the operator clear is used. a. True b. False ANSWER: False FEEDBACK: Correct The operator delete is used to deallocate the memory occupied by the node of a linked list. Incorrect The operator delete is used to deallocate the memory occupied by the node of a linked list. POINTS: 1 REFERENCES: 1124 – Destroy the List QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.03 - Explore the insertion and deletion operations on linked lists DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 8:56 AM 5. In a linked list, if a new item is always inserted at the beginning or at the end of the list and the data we read is unsorted, the linked list will be unsorted. a. True b. False ANSWER: True FEEDBACK: Correct If the input data is unsorted and the new data item is always inserted at the beginning or at the end, then the linked list created will be unsorted. Incorrect If the input data is unsorted and the new data item is always inserted at the beginning or at the end, then the linked list created will be unsorted. POINTS: 1 REFERENCES: 1124 – Building a Linked List QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.04 - Discover how to build and manipulate a linked list DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 8:58 AM 6. When you build a linked list in the backward manner, a new node is always inserted at the end of the linked list. a. True Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 17 b. False ANSWER: FEEDBACK:

False Correct

If a linked list is created in the backward manner, the new node is always inserted at the beginning of the linked list. Incorrect If a linked list is created in the backward manner, the new node is always inserted at the beginning of the linked list.

POINTS: 1 REFERENCES: 1128 – Building a Linked List QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.04 - Discover how to build and manipulate a linked list DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 9:00 AM 7. It is not possible to create an ordered linked list. a. True b. False ANSWER: False FEEDBACK: Correct An ordered linked list can be created by inserting each item at its proper place in the linked list. Incorrect An ordered linked list can be created by inserting each item at its proper place in the linked list. POINTS: 1 REFERENCES: 1130 – Linked List as an ADT QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.09 - Learn how to create ordered linked lists DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 9:03 AM 8. The length of a linked list is the number of nodes in the list. a. True b. False ANSWER: True FEEDBACK: Correct The length of a linked list is the number of nodes in the list. Incorrect The length of a linked list is the number of nodes in the list.

POINTS: 1 REFERENCES: 1138 – Length of a List QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.07 - Learn how to implement the basic operations on a linked list DATE CREATED: 10/5/2016 1:43 PM Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 17 DATE MODIFIED:

4/7/2020 9:05 AM

9. A linked list is a random access data structure. a. True b. False ANSWER: False FEEDBACK: Correct A linked list is a sequential access data structure. Incorrect A linked list is a sequential access data structure.

POINTS: 1 REFERENCES: 1142 – Search the List QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.07 - Learn how to implement the basic operations on a linked list DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 9:06 AM 10. A doubly linked list can be traversed in either direction, backward or forward. a. True b. False ANSWER: True FEEDBACK: Correct A doubly linked list can be traversed either in the forward direction or in the backward direction. Incorrect A doubly linked list can be traversed either in the forward direction or in the backward direction. POINTS: 1 REFERENCES: 1164 – Doubly Linked Lists QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.10 - Learn how to construct a doubly linked list DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 9:09 AM 11. Data can be organized and processed sequentially using an array, called a(n) ____ list. a. linked b. ordered c. sequential d. ascending ANSWER: c FEEDBACK: a. Incorrect. Linked list can be organized and processed non-contiguously. b. Incorrect. Ordered list can be organized either in ascending ordered or descending order. c. Correct. Sequential list can be organized and processed contiguously using an array. d. Incorrect. An ascending list can be organized in ascending order. POINTS:

1

Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 17 REFERENCES: 1116– Linked Lists QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.01 - Learn about linked lists DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 9:11 AM 12. A linked list is a collection of components, called ____. a. elements b. nodes c. members d. pointers ANSWER: b FEEDBACK: a. Incorrect. A linked list is a collection of components called nodes. An array is a collection of components called elements. b. Correct. A linked list is a collection of components called nodes. c. Incorrect. A linked list is a collection of components called nodes. A class is a collection of components called members. d. Incorrect. A linked list is a collection of components called nodes. In C++, pointers are used to create dynamic memory space (variables). POINTS: 1 REFERENCES: 1116 – Linked Lists QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.01 - Learn about linked lists DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 9:13 AM 13. In a linked list, the address of the first node in the list is stored in a separate location, called the ____ or first. a. head b. pointer c. front d. top ANSWER: a FEEDBACK: a. Correct. In a linked list, the address of the first node in the list is stored in a separate location called the head or first. b. Incorrect. In a linked list, the address of the first node in the list is stored in a separate location called the head or first. c. Incorrect. In a linked list, the address of the first node in the list is stored in a separate location called the head or first. d. Incorrect. In a linked list, the address of the first node in the list is stored in a separate location called the head or first. POINTS: 1 REFERENCES: 1116 – Linked Lists QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.01 - Learn about linked lists Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 17 DATE CREATED: DATE MODIFIED:

10/5/2016 1:43 PM 4/7/2020 9:19 AM

14. In a linked list, the order of the nodes is determined by the address, called the ____, stored in each node. a. head b. tail c. link d. first ANSWER: c FEEDBACK: a. Incorrect. In a linked list, the order of the nodes is determined by the address, called the link, stored in each node. b. Incorrect.In a linked list, the order of the nodes is determined by the address, called the link, stored in each node. c. Correct. In a linked list, the order of the nodes is determined by the address, called the link, stored in each node. d. Incorrect. In a linked list, the order of the nodes is determined by the address, called the link, stored in each node. POINTS: 1 REFERENCES: 1116 – Linked Lists QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.01 - Learn about linked lists DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 9:22 AM 15. Every node (except of the last node) in a singly linked list contains ____. a. the next node b. no address information c. the address of the next node d. the address of the previous node ANSWER: c FEEDBACK: a. Incorrect. Every node (except of the last node) in a singly linked list contains the address of the next node. b. Incorrect. Every node (except of the last node) in a singly linked list contains the address of the next node. c. Correct. Every node in a singly linked list has the address of the next node. d. Incorrect. Every node (except of the last node) in a singly linked list contains the address of the next node. POINTS: 1 REFERENCES: 1116 – Linked Lists QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.01 - Learn about linked lists DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 9:24 AM Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 17 16. The link field of the last node of a linked list is ____. a. nullptr b. 1 c. n-1 d. n ANSWER: FEEDBACK:

a a. Correct. To make the last node points to nothing, nullptr is assigned to the link field of the last node. Therefore, The link field of the last node of a linked list is nullptr. b. Incorrect. To make the last node points to nothing, nullptr is assigned to the link field of the last node. Therefore, The link field of the last node of a linked list is nullptr. c. Incorrect. To make the last node points to nothing, nullptr is assigned to the link field of the last node. Therefore, The link field of the last node of a linked list is nullptr. d. Incorrect. To make the last node points to nothing, nullptr is assigned to the link field of the last node. Therefore, The link field of the last node of a linked list is nullptr.

POINTS: 1 REFERENCES: 1116 – Linked Lists QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.01 - Learn about linked lists DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 9:27 AM 17. Because each node of a linked list has two components, we need to declare each node as a(n) ____. a. reference and string b. int and object c. index and element d. class or struct ANSWER: d FEEDBACK: a. Incorrect. Because each node of a linked list has two components, we need to declare each node as a class or struct. b. Incorrect. Because each node of a linked list has two components, we need to declare each node as a class or struct. c. Incorrect. Because each node of a linked list has two components, we need to declare each node as a class or struct. d. Correct. Because each node of a linked list has two components, we need to declare each node as a class or struct. POINTS: 1 REFERENCES: 1117 – Linked Lists QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.01 - Learn about linked lists DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 9:44 AM Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 17 18. Each node of a (singly) linked list has two components: one to store the____ and one to store the ____. a. info, head b. link, back c. back, head d. data, link ANSWER: d FEEDBACK: a. Incorrect. Each node of a (singly) linked list has two components: one to store the data and one to store the link. b. Incorrect. Each node of a (singly) linked list has two components: one to store the data and one to store the link. c. Incorrect. Each node of a (singly) linked list has two components: one to store the data and one to store the link. d. Correct. Each node of a (singly) linked list has two components: one to store the data and one to store the link. POINTS: 1 REFERENCES: 1117 – Linked Lists QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.01 - Learn about linked lists DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 9:48 AM 19. Suppose that in a linked list, the link field of the first node points to the last node and the link field of the last node is nullptr. Then the number of nodes in the linked list is ______. a. 0 b. 1 c. 2 d. 3 ANSWER: c FEEDBACK: a. Incorrect. Then the number of nodes in the linked list is 2. If the number of nodes is 0, then the list is empty, and so there is no first node pointing to the last node or there is no last node with link field nullptr. b. Incorrect. Then the number of nodes in the linked list is 2. If the number of nodes is 1, then the link field of the first node is nullptr and so it does not point to any other node. c. Correct. Then the number of nodes in the linked list is 2. d. Incorrect. Then the number of nodes in the linked list is 2. If the number of nodes in the linked list is 3, then there is one node between the first and the last node, and so the link field of the first node points to the second node not the last node. POINTS: 1 REFERENCES: 1120 – Linked Lists: Some Properties QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.02 - Become familiar with the basic properties of linked lists DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 9:51 AM Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 17 20. What is the purpose of the following code? current = head; while (current != nullptr) { //Process current current = current->link; } a. Insertion of a node b. Selection of a node c. Traversal of a linked list d. Creation of a new list ANSWER: c FEEDBACK: a. Incorrect. The purpose of the given code is to traverse the nodes in the linked list using the while loop. b. Incorrect. The purpose of the given code is to traverse the nodes in the linked list using the while loop. c. Correct. The purpose of the given code is to traverse the nodes in the linked list using the while loop. d. Incorrect. The purpose of the given code is to traverse the nodes in the linked list using the while loop. POINTS: 1 REFERENCES: 1120 – Linked Lists: Some Properties QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.02 - Become familiar with the basic properties of linked lists DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/7/2020 9:53 AM struct nodeType { int info; nodeType *link; }; nodeType *head, *p, *q, *newNode; newNode = new nodeType; 21. Consider the accompanying code. What is the effect of the following statement? newNode->info = 50; a. Stores 50 in the info field of the newNode b. Creates a new node c. Places the node at location 50 d. Cannot be determined from this code ANSWER: a Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 17 FEEDBACK:

a. Correct. The given statement newNode->info = 50; stores the value 50 in the data field, info, of the newNode. b. Incorrect. The given statement newNode->info = 50; stores the value 50 in the data field, info, of the newNode. c. Incorrect. The given statement newNode->info = 50; stores the value 50 in the data field, info, of the newNode. d. Incorrect. The given statement newNode->info = 50; stores the value 50 in the data field, info, of the newNode.

POINTS: 1 REFERENCES: 1121 – Linked Lists: Some Properties QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: nodeType LEARNING OBJECTIVES: PAPD.MALI.17.02 - Become familiar with the basic properties of linked lists DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/8/2020 6:36 AM 22. When building a linked list in the ____ manner, a new node is always inserted at the end of the linked list. a. backward b. forward c. traversal d. random ANSWER: b FEEDBACK: a. Incorrect. When building a linked list in the forward manner, a new node is always inserted at the end of the linked list. When a linked list is constructed in the backward manner, a new node is always inserted at the beginning of the linked list. b. Correct. While constructing a linked list in the forward manner, a new node is always inserted at the end of the linked list. c. Incorrect. When building a linked list in the forward manner, a new node is always inserted at the end of the linked list. d. Incorrect. When building a linked list in the forward manner, a new node is always inserted at the end of the linked list. When a linked list is constructing in the random manner, a new node is always inserted randomly inthe linked list. POINTS: 1 REFERENCES: 1124 – Building a Linked List QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.04 - Discover how to build and manipulate a linked list DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/8/2020 6:38 AM 23. How many pointers are needed to build a linked list in a backward manner? a. One b. Two c. Three d. Four Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 17 ANSWER: FEEDBACK:

b a. Two pointers are needed to build a linked list in a backward manner. One pointer to point to the first node of the list and another pointer to create a new node. b. Two pointers are needed to build a linked list in a backward manner. One pointer to point to the first node of the list and another pointer to create a new node. c. Two pointers are needed to build a linked list in a backward manner. One pointer to point to the first node of the list and another pointer to create a new node. d. Two pointers are needed to build a linked list in a backward manner. One pointer to point to the first node of the list and another pointer to create a new node.

POINTS: 1 REFERENCES: 1129 – Linked List as an ADT QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.05 - Learn how to implement linked lists as ADTs DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/17/2020 5:45 AM 24. Which of the following is a basic operation on singly linked lists? a. Retrieve the data of an arbitrary node. b. Swap the head and the last nodes. c. Determine whether the list is nearly full. d. Make a copy of the linked list. ANSWER: d FEEDBACK: a. Incorrect. Make a copy of the linked list. b. Incorrect. Make a copy of the linked list. c. Incorrect. Make a copy of the linked list. Logically a linked list is never full. d. Correct. Make a copy of the linked list. POINTS: 1 REFERENCES: 1129 – Linked List as an ADT QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.05 - Learn how to implement linked lists as ADTs DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/8/2020 7:16 AM 25. The ____ deallocates the memory occupied by the nodes of a linked list when the linked list class object goes out of scope. a. constructor b. destructor c. head pointer d. tail pointer ANSWER: b FEEDBACK: a. Incorrect. The destructor deallocates the memory occupied by the nodes of a linked list when the linked list class object goes out of scope. A constructor is Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 17 used to initialize an object when it is create. b. Correct. The destructor deallocates the memory occupied by the nodes of a linked list when the linked list class object goes out of scope. c. Incorrect. The destructor deallocates the memory occupied by the nodes of a linked list when the linked list class object goes out of scope. The head pointer points to the first node of the linked list. d. Incorrect. The destructor deallocates the memory occupied by the nodes of a linked list when the linked list class object goes out of scope. The tail pointer points to the last node of the linked list. POINTS: 1 REFERENCES: 1140 – Destructor QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.07 - Learn how to implement the basic operations on a linked list DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/8/2020 7:25 AM 26. The steps required to insert a new item at the beginning of an unordered linked list are ____. a. 1. Create a new node. 2. Insert the node before first. 3. Increment the counter by 1. b. 1. Create a new node. 2. Store the new item in the new node. 3. Insert the node before first. 4. Increment the counter by 1. c. 1. Create a new node. 2. Store the new item in the new node. 3. Insert the node before first. d. 1. Create a new node. 2. Store the new item in the new node. 3. Insert the node before first. 4. Decrement the counter by 1. ANSWER: b FEEDBACK: a. Incorrect. The steps required to insert a new item at the beginning of an unordered linked list are: 1. Create a new node; 2. Store the new item in the new node; 3. Insert the node before first, and 4. Increment the counter by 1. b. Correct. The steps required to insert a new item at the beginning of an unordered linked list are: 1. Create a new node; 2. Store the new item in the new node; 3. Insert the node before first, and 4. Increment the counter by 1. c. Incorrect. The steps required to insert a new item at the beginning of an unordered linked list are: 1. Create a new node; 2. Store the new item in the new node; 3. Insert the node before first, and 4. Increment the counter by 1. d. Incorrect. The steps required to insert a new item at the beginning of an unordered linked list are: 1. Create a new node; 2. Store the new item in the new node; 3. Insert the node before first, and 4. Increment the counter by 1. Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 17 POINTS: 1 REFERENCES: 1143 – Insert the First Node QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.07 - Learn how to implement the basic operations on a linked list DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/8/2020 7:29 AM 27. Every node in a doubly linked list has two pointers: ____ and ____. a. top; bottom b. back; next c. current; forward d. previous; forward ANSWER: FEEDBACK:

b a. Incorrect. Every node in a doubly linked list has two pointers: back and next. b. Correct. Every node in a doubly linked list has two pointers: back and next. c. Incorrect. Every node in a doubly linked list has two pointers: back and next. d. Incorrect. Every node in a doubly linked list has two pointers: back and next.

POINTS: 1 REFERENCES: 1166 – Doubly Linked Lists QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.10 - Learn how to construct a doubly linked list DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/8/2020 7:31 AM 28. Which of the following correctly initializes a doubly linked list in the default constructor? a. head = nullptr; back = nullptr; b. head = 0; back = 0; count = 0; c. first = empty; last = empty; d. first = nullptr; last = nullptr; count = 0; ANSWER: FEEDBACK:

d a. Incorrect. In a doubly linked list, the pointer first points to the first node, the pointer last points to the last node, and the variable count stores the number of nodes in the linked list. The statements to initialize these are: first = nullptr;, last = nullptr;, and count = 0; b. Incorrect. In a doubly linked list, the pointer first points to the first node, the pointer last points to the last node, and the variable count stores the number of nodes in the linked list. The statements to initialize these are: first =

Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 17 nullptr;, last = nullptr;, and count = 0; c. Incorrect. In a doubly linked list, the pointer first points to the first node, the pointer last points to the last node, and the variable count stores the number of nodes in the linked list. The statements to initialize these are: first = nullptr;, last = nullptr;, and count = 0; d. Correct. In a doubly linked list, the pointer first points to the first node, the pointer last points to the last node, and the variable count stores the number of nodes in the linked list. The statements to initialize these are: first = nullptr;, last = nullptr;, and count = 0; POINTS: 1 REFERENCES: 1167 – Default Constructor QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.10 - Learn how to construct a doubly linked list DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/8/2020 7:35 AM template <class Type> ____ doublyLinkedList<Type>::isEmptyList() const { return (first == nullptr); } 29. Consider the accompanying statements. The function isEmptyList returns true if the list is empty; otherwise, it returns false. The missing code is ____. a. protected b. int c. void d. bool ANSWER: d FEEDBACK: a. Incorrect. The function isEmptyList returns true if the list is empty; otherwise, it returns false. Therefore, the return type of this function is bool, and so the missing code is bool. b. Incorrect. The function isEmptyList returns true if the list is empty; otherwise, it returns false. Therefore, the return type of this function is bool, and so the missing code is bool. c. Incorrect. The function isEmptyList returns true if the list is empty; otherwise, it returns false. Therefore, the return type of this function is bool, and so the missing code is bool. d. Correct. The function isEmptyList returns true if the list is empty; otherwise, it returns false. Therefore, the return type of this function is bool, and so the missing code is bool. POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 1167 – isEmptyList Multiple Choice False

Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 17 PREFACE NAME: isEmpty LEARNING OBJECTIVES: PAPD.MALI.17.10 - Learn how to construct a doubly linked list DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/8/2020 8:22 AM 30. Consider the statements above. The list is empty if the pointer first is ____. a. nullptr b. empty c. last d. next ANSWER: FEEDBACK:

a a. Correct. If first == nullptr, then the linked list is empty. b. Incorrect. If first == nullptr, then the linked list is empty. c. Incorrect. If first == nullptr, then the linked list is empty. d. Incorrect. If first == nullptr, then the linked list is empty.

POINTS: 1 REFERENCES: 1167 – isEmptyList QUESTION TYPE: Multiple Choice HAS VARIABLES: False PREFACE NAME: isEmpty LEARNING OBJECTIVES: PAPD.MALI.17.10 - Learn how to construct a doubly linked list DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/8/2020 7:43 AM 31. Consider the following code: template <class Type> int doublyLinkedList<Type>::length() const { ____ } The statement that provides the length of the linked list is ____. a. cout <<< count; b. destroy(); c. return count; d. return next; ANSWER: FEEDBACK:

c a. Incorrect. The length of a list is the number of nodes in the list, and the variable count stores the number nodes on the list. Therefore, the function length, returns the value of count, and so the missing statement is: return count; Moreover, the statement cout<<< count;will cause syntax error. b. Incorrect. The length of a list is the number of nodes in the list, and the variable count stores the number nodes on the list. Therefore, the function length, returns the value of count, and so the missing statement is: return count; c. Correct. The length of a list is the number of nodes in the list, and the variable count stores the number nodes on the list. Therefore, the function length,

Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 17 returns the value of count, and so the missing statement is: return count; d. Incorrect. The length of a list is the number of nodes in the list, and the variable count stores the number nodes on the list. Therefore, the function length, returns the value of count, and so the missing statement is: return count; POINTS: 1 REFERENCES: 1168 – Length of the List QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.10 - Learn how to construct a doubly linked list DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/8/2020 8:27 AM 32. Consider the following code which deletes all the nodes in a linked list. void doublyLinkedList<Type>::destroy() { nodeType<Type> *temp; //pointer to delete the node while (first != nullptr) { temp = first; first = first->next; ____ } last = nullptr; count = 0; } Which of the following is the missing statement? a. delete first; b. delete temp; c. destroy temp; d. clear temp; ANSWER: FEEDBACK:

b a. Incorrect. Each time through the while loop, temp points to the first node of the list, which is to be deleted. The statement delete temp; deallocates the memory space of the node pointed to which temp is pointing. Therefore, the missing statement is: delete temp; b. Correct. Each time through the while loop, temp points to the first node of the list, which is to be deleted. The statement delete temp; deallocates the memory space of the node pointed to which temp is pointing. Therefore, the missing statement is: delete temp; c. Incorrect. Each time through the while loop, temp points to the first node of the list, which is to be deleted. The statement delete temp; deallocates the memory space of the node pointed to which temp is pointing. Therefore, the missing statement is: delete temp; d. Incorrect. Each time through the while loop, temp pointes to the first node, which is to delete, of the list. The statement delete temp; deallocates the

Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 17 memory space of the node pointed to which temp is pointing. Therefore, the missing statement is: delete temp; POINTS: 1 REFERENCES: 1167 – Destroy the List QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.10 - Learn how to construct a doubly linked list DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/20/2020 11:53 AM 33. Which of the following statements appears in the insert function of a doubly linked list? a. current++; b. trailCurrent++; c. newNode++; d. count++; ANSWER: FEEDBACK:

d a. Incorrect. The pointer current is used to traverse the doubly liked list. However, the expression current++ increments the value of current by the size of the node it is pointing to, and so this expression may not necessarily make current point to the next node. The statement to advance current to the next node is: current = current->link;. After adding a new node, the value of count is incremented. Therefore, the statement count++; appears in the function insert. b. Incorrect. The pointer trailCurrent is used to traverse the linked list. The expression trailCurrent++ increments the value of trailCurrent by the size of node it is pointing to, and so this expression may not necessarily make trailCurrent point to the next node. The statement to advance trailCurrent to the next node is: trailCurrent = trailCurrent >link;. After adding a new node, the value of count is incremented. Therefore, the statement count++; appears in the function insert. c. Incorrect. The pointer newNode is used to create a new node for the doubly linked list. However, the expression newNode++ increments the value of newNode by the size of the node it is pointing to, and so it does not create a new node. After adding a new node, the value of count is incremented. Therefore, the statement count++; appears in the function insert. d. Correct. After adding a new node, the value of count is incremented. Therefore, the statement count++; appears in the function insert.

POINTS: 1 REFERENCES: 1171 – First and Last Elements QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.17.10 - Learn how to construct a doubly linked list DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/8/2020 8:28 AM 34. In a linked list, the link component of each node is a(n) ____________________. Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 17 ANSWER: pointer POINTS: 1 REFERENCES: 1117 – Linked Lists QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.17.01 - Learn about linked lists DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/8/2020 8:05 AM 35. Each node of a linked list must store the data as well as the ____________________ of the next node in the list. ANSWER: address POINTS: 1 REFERENCES: 1130 – Linked List as an ADT QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.17.05 - Learn how to implement linked lists as ADTs DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/8/2020 8:06 AM 36. In C++, the dereferencing operator is ____________________. ANSWER: * POINTS: 1 REFERENCES: 1131 – Linked List as an ADT QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.17.06 - Learn how to create linked list iterators DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/8/2020 8:07 AM 37. A(n) ____________________ is an object that produces each element of a container, such as a linked list, one element at a time. ANSWER: iterator POINTS: 1 REFERENCES: 1131 – Linked List as an ADT QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.17.06 - Learn how to create linked list iterators DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/8/2020 8:09 AM Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 17 38. The ____________________ operator advances the iterator to the next node in the linked list. ANSWER: increment ++ POINTS: 1 REFERENCES: 1131 – Linked List as an ADT QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.17.06 - Learn how to create linked list iterators DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 10/5/2016 1:43 PM 39. For classes that include pointer data members, the assignment operator must be explicitly ____________________. ANSWER: overloaded POINTS: 1 REFERENCES: 1136 – Linked List as an ADT QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.17.06 - Learn how to create linked list iterators DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 10/5/2016 1:43 PM 40. The ____________________ constructor executes when an object is declared and initialized using another object. ANSWER: copy POINTS: 1 REFERENCES: 1140 – Linked List as an ADT QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.17.06 - Learn how to create linked list iterators DATE CREATED: 10/5/2016 1:43 PM DATE MODIFIED: 4/8/2020 8:12 AM 41. A(n) ____________________ linked list is a linked list in which every node has a next pointer and a back pointer. ANSWER: doubly POINTS: 1 REFERENCES: 116 - 4 – Doubly Linked Lists QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.17.10 - Learn how to construct a doubly linked list Copyright Cengage Learning. Powered by Cognero.

Page 19


Name:

Class:

Date:

Chapter 17 DATE CREATED: DATE MODIFIED:

10/5/2016 1:43 PM 4/8/2020 8:13 AM

Copyright Cengage Learning. Powered by Cognero.

Page 20


Name:

Class:

Date:

Chapter 18 1. The bottom element of the stack is the last element added to the stack. a. True b. False ANSWER: False FEEDBACK: Correct The top element of the stack is the last element added to the stack. Incorrect The top element of the stack is the last element added to the stack.

POINTS: 1 REFERENCES: 1211– Stacks QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.01 - Learn about stacks DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 6:42 AM 2. In the array representation of a stack, stackTop indicates the number of elements in the stack. If stack is nonempty, then stackTop-1is the index of the top item of the stack. a. True b. False ANSWER: True FEEDBACK: Correct If stackTop is 0, then the stack is empty; otherwise, the stack is nonempty.If stack is nonempty, then stackTop-1 is the index of the top item of the stack. Incorrect If stackTop is 0, then the stack is empty; otherwise, the stack is nonempty. If

stack is nonempty, then stackTop-1 is the index of the top item of the stack. POINTS: 1 REFERENCES: 1216 – Implementation of Stacks as Arrays QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.03 - Learn how to implement a stack as an array DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 6:45 AM 3. If you try to add a new item to a full stack, the resulting condition is called an outflow. a. True b. False ANSWER: False FEEDBACK: Correct Adding a new item to a full stack results in overflow. Incorrect Adding a new item to a full stack results in overflow.

POINTS: 1 REFERENCES: 1220– Push QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.03 - Learn how to implement a stack as an array Copyright Cengage Learning. Powered by Cognero.

Page 1


Name:

Class:

Date:

Chapter 18 DATE CREATED: DATE MODIFIED:

10/5/2016 1:44 PM 4/10/2020 6:48 AM

4. In the linked implementation of stacks, the memory to store the stack elements is allocated statically. a. True b. False ANSWER: False FEEDBACK: Correct In the linked implementation of stacks, the memory to store the stack elements is allocated dynamically, i.e., during program execution. Incorrect In the linked implementation of stacks, the memory to store the stack elements is allocated dynamically, i.e., during program execution. POINTS: 1 REFERENCES: 1234 – Linked Implementation of Stacks QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.04 - Learn how to implement a stack as a linked list DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 6:49 AM 5. The default constructor for the linked implementation of a stack initializes the stack to an empty state when a stack object is declared. a. True b. False ANSWER: True FEEDBACK: Correct The default constructor initializes the stack to the empty state when the stack object is declared. Incorrect The default constructor initializes the stack to the empty state when the stack object is declared. POINTS: 1 REFERENCES: 1235 – Default Constructor QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.04 - Learn how to implement a stack as a linked list DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 6:53 AM 6. Postfix notation requires the use of parentheses to enforce operator precedence. a. True b. False ANSWER: False FEEDBACK: Correct In postfix notation, parentheses are omitted. Incorrect In postfix notation, parentheses are omitted.

POINTS:

1

Copyright Cengage Learning. Powered by Cognero.

Page 2


Name:

Class:

Date:

Chapter 18 REFERENCES: 1245 – Application of Stacks: Postfix Expressions Calculator QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.05 - Learn about infix, prefix, and postfix expressions, and how to use a stack to evaluate postfix expressions. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 6:55 AM 7. The infix expression (a + b) * (c - d / e) + f is equivalent to the postfix expression ab + cde /-* f + a. True b. False ANSWER: FEEDBACK:

True Correct

In postfix notation, operators appear after the operands and parentheses are not needed and therefore, omitted. The equivalent postfix expressions is: a b + c d e /-* f + Incorrect In postfix notation, operators appear after the operands and parentheses are not needed and therefore, omitted. The equivalent postfix expressions is: a b + c d e /-* f +

POINTS: 1 REFERENCES: 1246 – Application of Stacks: Postfix Expressions Calculator QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.05 - Learn about infix, prefix, and postfix expressions, and how to use a stack to evaluate postfix expressions. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 6:56 AM 8. The expression a + b is the same in both infix notation and postfix notation. a. True b. False ANSWER: False FEEDBACK: Correct The expression a + b is not the same in both infix notation and postfix notation. It is a + b in the infix notation and ab+ in the postfix notation. Incorrect The expression a + b is not the same in both infix notation and postfix notation. It is a + b in the infix notation and ab+ in the postfix notation. POINTS: REFERENCES: QUESTION TYPE: HAS VARIABLES:

1 1246 – Application of Stacks: Postfix Expressions Calculator True / False False

Copyright Cengage Learning. Powered by Cognero.

Page 3


Name:

Class:

Date:

Chapter 18 LEARNING OBJECTIVES: PAPD.MALI.18.05 - Learn about infix, prefix, and postfix expressions, and how to use a stack to evaluate postfix expressions. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 7:01 AM 9. A queue is a First In First Out data structure. a. True b. False ANSWER: True FEEDBACK: Correct A queue is a data structure in which the elements are added at one end, called the rear, and deleted from the other end, called the front; a First In First Out (FIFO) data structure. Incorrect A queue is a data structure in which the elements are added at one end, called the rear, and deleted from the other end, called the front; a First In First Out (FIFO) data structure. POINTS: 1 REFERENCES: 1259 – Queues QUESTION TYPE: True / False HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.07 - Learn about queues. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 7:10 AM 10. A(n) ____ is a list of homogenous elements in which the addition and deletion of elements occurs only at one end. a. stack b. queue c. array d. linked list ANSWER: a FEEDBACK: a. Correct. A stack is a list of homogenous elements where the addition and deletion of elements occurs only at one end(that is, top of the stack). b. Incorrect. A stack is a list of homogenous elements where the addition and deletion of elements occurs only at one end (that is, top of the stack).A queue is a data structure in which elements are added at one end, called the rear, and deleted from the other end, called the front. c. Incorrect. A stack is a list of homogenous elements where the addition and deletion of elements occurs only at one end (that is, top of the stack). In an array, you can add or delete an element at any position in the array. d. Incorrect. A stack is a list of homogenous elements where the addition and deletion of elements occurs only at one end (that is, top of the stack). POINTS: 1 REFERENCES: 1210– Stacks QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.01 - Learn about stacks DATE CREATED: 10/5/2016 1:44 PM Copyright Cengage Learning. Powered by Cognero.

Page 4


Name:

Class:

Date:

Chapter 18 DATE MODIFIED:

4/10/2020 7:15 AM

11. The addition or deletion of a stack element occurs only at one end, called the ____ of the stack. a. head b. bottom c. top d. middle ANSWER: c FEEDBACK: a. Incorrect. The addition or deletion of a stack element occurs only at one end, called the top of the stack. b. Incorrect. The addition or deletion of a stack element occurs only at one end, called the top of the stack. c. Correct. The addition or deletion of a stack element occurs only at one end, called the top of the stack. d. Incorrect. The addition or deletion of a stack element occurs only at one end, called the top of the stack. POINTS: 1 REFERENCES: 1210 – Stacks QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.01 - Learn about stacks DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 7:21 AM 12. The ____ element of the stack is the last element added to the stack. a. top b. bottom c. head d. tail ANSWER: a FEEDBACK: a. Correct. The top element of the stack is the last element added to the stack. b. Incorrect. The top element of the stack is the last element added to the stack. c. Incorrect. The top element of the stack is the last element added to the stack. d. Incorrect. The top element of the stack is the last element added to the stack. POINTS: 1 REFERENCES: 1211 – Stacks QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.01 - Learn about stacks DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 7:32 AM 13. A stack is a(n) ____ data structure. a. FIFO b. FILO c. LIFO d. LILO ANSWER: c FEEDBACK: a. Incorrect. A stack is a Last In First Out (LIFO) data structure. A queue is a First Copyright Cengage Learning. Powered by Cognero.

Page 5


Name:

Class:

Date:

Chapter 18 In First Out (FIFO) data structure. b. Incorrect. A stack is a Last In First Out (LIFO) data structure. c. Correct. A stack is a Last In First Out (LIFO) data structure. d. Incorrect. A stack is a Last In First Out (LIFO) data structure. POINTS: 1 REFERENCES: 1211 – Stacks QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.01 - Learn about stacks DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 7:38 AM 14. The operation to add an element onto the stack is called ______. a. pop b. push c. enqueue d. dequeue ANSWER: FEEDBACK:

b a. Incorrect. The operation to add an element onto the stack is called push. The operation pop removes the top element of the stack b. Correct. The operation to add an element onto the stack is called push. c. Incorrect. The operation to add an element onto the stack is called push.In the queue data structure, the operation enqueue adds an element in the queue. d. Incorrect. The operation to add an element onto the stack is called push.In the queue data structure, the operation dequeue removes an element from the queue.

POINTS: 1 REFERENCES: 1211 – Stacks QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.01 - Learn about stacks DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 7:41 AM 15. The operation to remove the top element from the stack is called ____. a. dequeue b. top c. pop d. push ANSWER: FEEDBACK:

c a. Incorrect. The operation to remove the top element from the stack is called pop. In the queue data structure, the operation dequeue removes an element from the queue. b. Incorrect. The operation to remove the top element from the stack is called pop. In the stack data structure, the operation topis used to retrieve the top element of the stack.

Copyright Cengage Learning. Powered by Cognero.

Page 6


Name:

Class:

Date:

Chapter 18 c. Correct. The operation to remove the top element from the stack is called pop. In the stack data structure, the operation popis used to remove the top element from the stack. d. Incorrect. The operation to remove the top element from the stack is called pop. In the stack data structure, the operation push adds an element onto the stack. POINTS: 1 REFERENCES: 1211 – Stacks QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.01 - Learn about stacks DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 7:44 AM 16. A stack can be implemented as either a(n) ____ or a linked structure. a. map b. struct c. queue d. array ANSWER: d FEEDBACK: a. Incorrect. A stack can be implemented as either an array or a linked structure. b. Incorrect. A stack can be implemented as either an array or a linked structure. c. Incorrect. A stack can be implemented as either an array or a linked structure. d. Correct. A stack can be implemented as either an array or a linked structure. POINTS: 1 REFERENCES: 1213 – Stack Operations QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.02 - Examine various stack operations DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 7:46 AM 17. When a stack is implemented as an array, the stack is empty if the value of stackTop is ____. a. zero b. one c. nonzero d. equal to the size of the array ANSWER: a FEEDBACK: a. Correct. The stack is empty if the value of stackTop is zero. b. Incorrect. The stack is empty if the value of stackTop is zero. If stackTopis 1, then the stack contains 1 element. c. Incorrect. The stack is empty if the value of stackTop is zero. If stackTop is nonzero, then the stack is nonempty. d. Incorrect. The stack is empty if the value of stackTop is zero. If stackTop is equal to the size of the array, then the stack is full. POINTS: REFERENCES:

1 1216 – Implementation of Stacks as Arrays

Copyright Cengage Learning. Powered by Cognero.

Page 7


Name:

Class:

Date:

Chapter 18 QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.03 - Learn how to implement a stack as an array DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 7:49 AM 18. If you try to add a new item to a full stack, the resulting condition is called a(n) ____. a. override b. overflow c. overload d. underflow ANSWER: b FEEDBACK: a. Incorrect. If you try to add a new item to a full stack, the resulting condition is called an overflow. b. Correct. If you try to add a new item to a full stack, the resulting condition is called an overflow. c. Incorrect. If you try to add a new item to a full stack, the resulting condition is called an overflow. d. Incorrect. If you try to add a new item to a full stack, the resulting condition is called an overflow. POINTS: 1 REFERENCES: 1220 – Push QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.03 - Learn how to implement a stack as an array DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 7:53 AM 19. Popping an element from an empty stack is called ____. a. overflow b. underflow c. exception d. overloading ANSWER: b FEEDBACK: a. Incorrect. Popping an element from an empty stack is called underflow. b. Correct. Popping an element from an empty stack is called underflow. c. Incorrect. Popping an element from an empty stack is called underflow. d. Incorrect. Popping an element from an empty stack is called underflow. POINTS: 1 REFERENCES: 1222 – Pop QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.03 - Learn how to implement a stack as an array DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 7:55 AM 20. What is the output of the following code? Copyright Cengage Learning. Powered by Cognero.

Page 8


Name:

Class:

Date:

Chapter 18 stackType<int> stack; int x, y; x = 4; y = 2; stack.push(6); stack.push(x); stack.push(x + 1); y = stack.top(); stack.pop(); stack.push(x + y); x = stack.top(); stack.pop(); cout << "x = " << x << endl; a. x = 4 c. x = 6 ANSWER: FEEDBACK:

b. x = 5 d. x = 9 d a. Incorrect. In this program segment, x = 4 and y = 2. The statement stack.push(6); pushes 6 into the stack. The statement stack.push(x); pushes 4(that is, value of x) into the stack. The statement stack.push(x + 1); pushes 5 (that is, 4 + 1 = 5) into the stack. The statement y = stack.top();stores the top value (that is, 5) into y. The value of y is now 5. The statement stack.pop(); pops the top element, i.e., 5 from the stack. The statement stack.push(x + y); pushes 9 (that is, 4 + 5 = 9) into the stack. The statement x = stack.top(); stores the top value (that is, 9) into x. The value of x is now 9. The statement stack.pop();pops the top element, i.e.,9 from the stack. The statement cout << "x = " << x <<endl;outputsx = 9 since the variable x contains 9. b. Incorrect. In this program segment, x = 4 and y = 2. The statement stack.push(6); pushes 6 into the stack. The statement stack.push(x); pushes 4 (that is, value of x) into the stack. The statement stack.push(x + 1); pushes 5 (that is, 4 + 1 = 5) into the stack. The statement y = stack.top(); stores the top value (that is, 5) into y. The value of y is now 5. The statement stack.pop(); pops the top element, i.e., 5 from the stack. The statement stack.push(x + y); pushes 9 (that is, 4 + 5 = 9) into the stack. The statement x = stack.top(); stores the top value (that is, 9) into x. The value of x is now 9. The statement stack.pop();pops the top element, i.e., 9 from the stack. The statement cout << "x = " << x <<endl;outputsx = 9 since the

Copyright Cengage Learning. Powered by Cognero.

Page 9


Name:

Class:

Date:

Chapter 18 variable x contains 9. c. Incorrect. In this program segment, x = 4 and y = 2. The statement stack.push(6); pushes 6 into the stack. The statement stack.push(x); pushes 4 (that is, value of x) into the stack. The statement stack.push(x + 1); pushes 5 (that is, 4 + 1 = 5) into the stack. The statement y = stack.top(); stores the top value (that is, 5) into y. The value of y is now 5. The statement stack.pop(); pops the top element, i.e., 5 from the stack. The statement stack.push(x + y); pushes 9 (that is, 4 + 5 = 9) into the stack. The statement x = stack.top(); stores the top value (that is, 9) into x. The statement stack.pop();pops the top element, i.e., 9 from the stack. The statement cout << "x = " << x <<endl;outputsx = 9 since the variable x contains 9. d. Correct. In this program segment, x = 4 and y = 2. The statement stack.push(6); pushes 6 into the stack. The statement stack.push(x); pushes 4 (that is, value of x) into the stack. The statement stack.push(x + 1); pushes 5 (that is, 4 + 1 = 5) into the stack. The statement y = stack.top(); stores the top value (that is, 5) into y. The value of y is now 5. The statement stack.pop(); pops the top element, i.e., 5 from the stack. The statement stack.push(x + y); pushes 9 (that is, 4 + 5 = 9) into the stack. The statement x = stack.top(); stores the top value (that is, 9) into x. The value of x is now 9. The statement stack.pop();the top element, i.e., out 9 from the stack. The statement cout << "x = " << x <<endl;outputsx = 9 since the variable x contains 9. POINTS: 1 REFERENCES: 1227 – Stack Header File QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.03 - Learn how to implement a stack as an array DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 8:22 AM 21. What is the output of the following code? stackType<int> stack; int x, y; x = 5; y = 3; stack.push(4); stack.push(x); Copyright Cengage Learning. Powered by Cognero.

Page 10


Name:

Class:

Date:

Chapter 18 stack.push(x + 1); y = stack.top(); stack.pop(); stack.push(x + y); x = stack.top(); stack.pop(); cout << "x = " << x << endl; cout << "y = " << y << endl; a. x = 5 b. x = 4 y = 6 y = 3 c. x = 5 d. x = 11 y = 3 y = 6 ANSWER: FEEDBACK:

d a. Incorrect. In this program segment, x = 5 and y = 3. The statement stack.push(4); pushes 4 into the stack. The statement stack.push(x); pushes 5 (that is, value of x) into the stack. The statement stack.push(x + 1); pushes 6 (that is, 5 + 1 = 6) into the stack. The statement y = stack.top(); stores the top value (that is, 6) into y. The value of y is now 6. The statement stack.pop();removes the top element, i.e, 6 from the stack. The statement stack.push(x + y); pushes 11 (that is, 5 + 6 = 11) into the stack. The statement x = stack.top(); stores the top value (that is, 11) into x. The value of x is now 11. The statement stack.pop();removes the top element, i.e, 11 from the stack. The coutstatements outputs: x = 11 y = 6 b. Incorrect. In this program segment, x = 5 and y = 3. The statement stack.push(4); pushes 4 into the stack. The statement stack.push(x); pushes 5 (that is, value of x) into the stack. The statement stack.push(x + 1); pushes 6 (that is, 5 + 1 = 6) into the stack. The statement y = stack.top(); stores the top value (that is, 6) into y. The value of y is now 6. The statement stack.pop();removes the top element, i.e, 6 from the stack. The statement stack.push(x + y); pushes 11 (that is, 5 + 6 = 11) into the stack. The statement x = stack.top(); stores the top value (that is, 11) into x. The value of x is now 11. The statement stack.pop();removes the top element, i.e, 11 from the stack. The cout statements outputs: x = 11 y = 6 c. Incorrect. In this program segment, x = 5 and y = 3. The statement stack.push(4); pushes 4 into the stack.

Copyright Cengage Learning. Powered by Cognero.

Page 11


Name:

Class:

Date:

Chapter 18 The statement stack.push(x); pushes 5 (that is, value of x) into the stack. The statement stack.push(x + 1); pushes 6 (that is, 5 + 1 = 6) into the stack. The statement y = stack.top(); stores the top value (that is, 6) into y. The value of y is now 6. The statement stack.pop();removes the top element, i.e, 6 from the stack. The statement stack.push(x + y); pushes 11 (that is, 5 + 6 = 11) into the stack. The statement x = stack.top(); stores the top value (that is, 11) into x. The value of x is now 11. The statement stack.pop(); removes the top element, i.e,11 from the stack. The cout statements outputs: x = 11 y = 6 d. Correct. In this program segment, x = 5 and y = 3. The statement stack.push(4); pushes 4 into the stack. The statement stack.push(x); pushes 5 (that is, value of x) into the stack. The statement stack.push(x + 1); pushes 6 (that is, 5 + 1 = 6) into the stack. The statement y = stack.top(); stores the top value (that is, 6) into y. The value of y is now 6. The statement stack.pop();removes the top element, i.e, 6 from the stack. The statement stack.push(x + y); pushes 11 (that is, 5 + 6 = 11) into the stack. The statement x = stack.top(); stores the top value (that is, 11) into x. The value of x is now 11. The statement stack.pop();removes the top element, i.e, 11 from the stack. The cout statements outputs: x = 11 y = 6 POINTS: 1 REFERENCES: 1227 – Stack Header File QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.03 - Learn how to implement a stack as an array DATE CREATED: 4/10/2020 8:17 AM DATE MODIFIED: 4/10/2020 8:25 AM 22. The expression (a - b) * (c + d) is equivalent to which of the following postfix expressions? a. a b c d - + * b. a b - c d + * c. a b - + c d * d. - + * a b c d ANSWER: FEEDBACK:

b a. Incorrect. Following the algorithm given in Programming Exercise 10 of this chapter, the infix expression (a - b) * (c + d) is equivalent to thepostfix expression:

Copyright Cengage Learning. Powered by Cognero.

Page 12


Name:

Class:

Date:

Chapter 18 a b - c d + * b. Correct. Following the algorithm given in Programming Exercise 10 of this chapter, the infix expression (a - b) * (c + d) is equivalent to the postfix expression: a b - c d + * c. Incorrect. Following the algorithm given in Programming Exercise 10 of this chapter, the infix expression (a - b) * (c + d) is equivalent to the postfix expression: a b - c d + * d. Incorrect. Following the algorithm given in Programming Exercise 10 of this chapter, the infix expression (a - b) * (c + d) is equivalent to the postfix expression: a b - c d + * POINTS: 1 REFERENCES: 1246 – Application of Stacks: Postfix Expressions Calculator QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.05 - Learn about infix, prefix, and postfix expressions, and how to use a stack to evaluate postfix expressions. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 8:29 AM 23. The postfix expression 5 6 + 4 * 10 5 / - = evaluates to ____. a. 10 b. 30 c. 42 d. 44 ANSWER: c FEEDBACK: a. Incorrect. A postfix expression is evaluated using the rule: Scan the expression from left to right. When an operator is found, back up to get the required number of operands, perform the operation, and continue. Therefore, the postfix expression 5 6 + 4 * 10 5 / - evaluates to 42 as follows: (The equal sign marks the end of the expression, and therefore, in the following, it is not shown.) 5 6 + 4 * 10 5 / 11 4 * 10 5 / (because 5 + 6 = 11) 44 10 5 / (because 11 * 4 = 44) 44 2 (because 10 / 5 = 2) 42 (because 44 - 2 = 42) b. Incorrect. A postfix expression is evaluated using the rule: Scan the expression from left to right. When an operator is found, back up to get the required number of operands, perform the operation, and continue. Therefore, the postfix expression 5 6 + 4 * 10 5 / - evaluates to 42 as follows: (The equal sign marks the end of the expression, and therefore, in the following, it is not shown.) 5 6 + 4 * 10 5 / 11 4 * 10 5 / (because 5 + 6 = 11) 44 10 5 / (because 11 * 4 = 44) Copyright Cengage Learning. Powered by Cognero.

Page 13


Name:

Class:

Date:

Chapter 18 44 2 (because 10 / 5 = 2) 42 (because 44 - 2 = 42) c. Correct. A postfix expression is evaluated using the rule: Scan the expression from left to right. When an operator is found, back up to get the required number of operands, perform the operation, and continue. Therefore, the postfix expression 5 6 + 4 * 10 5 / - evaluates to 42 as follows: (The equal sign marks the end of the expression, and therefore, in the following, it is not shown.) 5 6 + 4 * 10 5 / 11 4 * 10 5 / (because 5 + 6 = 11) 44 10 5 / (because 11 * 4 = 44) 44 2 (because 10 / 5 = 2) 42 (because 44 - 2 = 42) d. Incorrect. A postfix expression is evaluated using the rule: Scan the expression from left to right. When an operator is found, back up to get the required number of operands, perform the operation, and continue. Therefore, the postfix expression 5 6 + 4 * 10 5 / - evaluates to 42 as follows: (The equal sign marks the end of the expression, and therefore, in the following, it is not shown.) 5 6 + 4 * 10 5 / 11 4 * 10 5 / (because 5 + 6 = 11) 44 10 5 / (because 11 * 4 = 44) 44 2 (because 10 / 5 = 2) 42 (because 44 - 2 = 42) POINTS: 1 REFERENCES: 1246 – Application of Stacks: Postfix Expressions Calculator QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.05 - Learn about infix, prefix, and postfix expressions, and how to use a stack to evaluate postfix expressions. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 8:49 AM 24. The postfix expression 2 4 6 * + 15 - 21 7 / + = evaluates to ____. a. 4 b. 14 c. 24 d. 26 ANSWER: FEEDBACK:

b a. Incorrect. A postfix expression is evaluated using the rule: Scan the expression from left to right. When an operator is found, back up to get the required number of operands, perform the operation, and continue. Therefore, the postfix expression 2 4 6 * + 15 - 21 7 / + evaluates to 14 as follows: (The equal sign marks the end of the expression, and therefore, in the following, it is not shown.) 2 4 6 * + 15 - 21 7 / + 2 24 + 15 - 21 7 / + (because 4 * 6 = 24) 26 15 - 21 7 / + (because 2 + 24 = 26) 11 21 7 / + (because 26 - 15 = 11) 11 3 + (because 21 / 7 = 3)

Copyright Cengage Learning. Powered by Cognero.

Page 14


Name:

Class:

Date:

Chapter 18 14 (because 11 + 3 = 14) b. Correct. A postfix expression is evaluated using the rule: Scan the expression from left to right. When an operator is found, back up to get the required number of operands, perform the operation, and continue. Therefore, the postfix expression 2 4 6 * + 15 - 21 7 / + evaluates to 14 as follows: (The equal sign marks the end of the expression, and therefore, in the following, it is not shown.) 2 4 6 * + 15 - 21 7 / + 2 24 + 15 - 21 7 / + (because 4 * 6 = 24) 26 15 - 21 7 / + (because 2 + 24 = 26) 11 21 7 / + (because 26 - 15 = 11) 11 3 + (because 21 / 7 = 3) 14 (because 11 + 3 = 14) c. Incorrect. A postfix expression is evaluated using the rule: Scan the expression from left to right. When an operator is found, back up to get the required number of operands, perform the operation, and continue. Therefore, the postfix expression 2 4 6 * + 15 - 21 7 / + evaluates to 14 as follows: (The equal sign marks the end of the expression, and therefore, in the following, it is not shown.) 2 4 6 * + 15 - 21 7 / + 2 24 + 15 - 21 7 / + (because 4 * 6 = 24) 26 15 - 21 7 / + (because 2 + 24 = 26) 11 21 7 / + (because 26 - 15 = 11) 11 3 + (because 21 / 7 = 3) 14 (because 11 + 3 = 14) d. Incorrect. A postfix expression is evaluated using the rule: Scan the expression from left to right. When an operator is found, back up to get the required number of operands, perform the operation, and continue. Therefore, the postfix expression 2 4 6 * + 15 - 21 7 / + evaluates to 14 as follows: (The equal sign marks the end of the expression, and therefore, in the following, it is not shown.) 2 4 6 * + 15 - 21 7 / + 2 24 + 15 - 21 7 / + (because 4 * 6 = 24) 26 15 - 21 7 / + (because 2 + 24 = 26) 11 21 7 / + (because 26 - 15 = 11) 11 3 + (because 21 / 7 = 3) 14 (because 11 + 3 = 14) POINTS: 1 REFERENCES: 1246 – Application of Stacks: Postfix Expressions Calculator QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.05 - Learn about infix, prefix, and postfix expressions, and how to use a stack to evaluate postfix expressions. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 8:52 AM 25. In evaluating a postfix expression, when an equal sign (=) is encountered, how many elements must the stack contain Copyright Cengage Learning. Powered by Cognero.

Page 15


Name:

Class:

Date:

Chapter 18 so that no error is generated? a. none b. one c. two d. three ANSWER: b FEEDBACK:

a. Incorrect. In a postfix expression evaluation, when an equal (=) sign is encountered, the stack must contain exactly one element, so that, no error is generated. b. Correct. In a postfix expression evaluation, whenan equal (=) sign is encountered, the stack must contain exactly one element, so that, no error is generated. c. Incorrect. In a postfix expression evaluation, when an equal (=) sign is encountered, the stack must contain exactly one element, so that, no error is generated. d. Incorrect. In a postfix expression evaluation, when an equal (=) sign is encountered, the stack must contain exactly one element, so that, no error is generated.

POINTS: 1 REFERENCES: 1247 – Application of Stacks: Postfix Expressions Calculator QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.05 - Learn about infix, prefix, and postfix expressions, and how to use a stack to evaluate postfix expressions. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 8:58 AM 26. The postfix expression 3 5 + 2 ; 6 - = will generate an error, because it ____. a. contains an illegal operator b. does not have enough operands c. has too many operands d. has too many operators ANSWER: a FEEDBACK: a. Correct. The postfix expression 3 5 + 2 ; 6 - = will generate an error, because it contains the illegal operation ;. b. Incorrect. The postfix expression 3 5 + 2 ; 6 - = will generate an error, because it contains the illegal operation ;. c. Incorrect. The postfix expression 3 5 + 2 ; 6 - = will generate an error, because it contains the illegal operation ;. d. Incorrect. The postfix expression 3 5 + 2 ; 6 - = will generate an error, because it contains the illegal operation ;. POINTS: 1 REFERENCES: 1247 – Application of Stacks: Postfix Expressions Calculator QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.05 - Learn about infix, prefix, and postfix expressions, and how to use a stack to evaluate postfix expressions. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 9:01 AM Copyright Cengage Learning. Powered by Cognero.

Page 16


Name:

Class:

Date:

Chapter 18 27. The postfix expression 14 2 5 + = cannot be evaluated,, because ____. a. it contains an illegal operator b. it does not have enough operands c. it has too many operators d. it does not have enough operators ANSWER: d FEEDBACK: a. Incorrect. The postfix expression 14 2 5 + = is evaluated as: 14 2 5 + = 14 7 = (because 2 + 5 = 7) The equal sign = marks the end of the expression. There are two operands, 14 and 7, and no operation to apply of these operands. Therefore, the postfix expression 14 2 5 + = cannot be evaluated, because it does not have enough operators. b. Incorrect. The postfix expression 14 2 5 + = is evaluated as: 14 2 5 + = 14 7 = (because 2 + 5 = 7) The equal sign = marks the end of the expression. There are two operands, 14 and 7, and no operation to apply of these operands. Therefore, the postfix expression 14 2 5 + = cannot be evaluated, because it does not have enough operators. c. Incorrect. The postfix expression 14 2 5 + = is evaluated as: 14 2 5 + = 14 7 = (because 2 + 5 = 7) The equal sign = marks the end of the expression. There are two operands, 14 and 7, and no operation to apply of these operands. Therefore, the postfix expression 14 2 5 + = cannot be evaluated, because it does not have enough operators. d. Correct. The postfix expression 14 2 5 + = is evaluated as: 14 2 5 + = 14 7 = (because 2 + 5 = 7) The equal sign = marks the end of the expression. There are two operands, 14 and 7, and no operation to apply of these operands. Therefore, the postfix expression 14 2 5 + = cannot be evaluated, because it does not have enough operators. POINTS: 1 REFERENCES: 1247 – Application of Stacks: Postfix Expressions Calculator QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.05 - Learn about infix, prefix, and postfix expressions, and how to use a stack to evaluate postfix expressions. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 9:54 AM 28. A queue is a data structure in which the elements are ____. a. added to the rear and deleted from the front Copyright Cengage Learning. Powered by Cognero.

Page 17


Name:

Class:

Date:

Chapter 18 b. added to and deleted from the rear c. added to and deleted from the front d. added and deleted in the middle ANSWER: a FEEDBACK: a. Correct. In a queue, the elements are added to the rear and deleted from the front. b. Incorrect. In a queue, the elements are added to the rear and deleted from the front. c. Incorrect. In a queue, the elements are added to the rear and deleted from the front. d. Incorrect. In a queue, the elements are added to the rear and deleted from the front. POINTS: 1 REFERENCES: 1259 – Queues QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.07 - Learn about queues. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 9:06 AM 29. Which of the following is listed in the chapter as a basic operation performed on a queue? a. push b. pop c. front d. top ANSWER: FEEDBACK:

c a. Incorrect. In queue data structure, the isEmptyQueue operation checks whether the queue is empty or not. Therefore, isEmptyQueue is a basic operation performed on a queue.The push operation adds a new element to the top of the stack. b. Incorrect. In queue data structure, the isEmptyQueue operation checks whether the queue is empty or not. Therefore, isEmptyQueue is a basic operation performed on a queue. The pop operation removes the top element of the stack. c. Correct. In queue data structure, the isEmptyQueue operation checks whether the queue is empty or not. Therefore, isEmptyQueue is a basic operation performed on a queue. d. Incorrect. In queue data structure, the isEmptyQueue operation checks whether the queue is empty or not. Therefore, isEmptyQueue is a basic operation perforemd on a queue. The top operations returns the top element of a stack.

POINTS: 1 REFERENCES: 1260 – Queue Operations QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.08 - Examine various queue operations. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/20/2020 12:20 PM Copyright Cengage Learning. Powered by Cognero.

Page 18


Name:

Class:

Date:

Chapter 18 30. What is the output of the following code? queueType<int> queue; int x, y; x = 2; y = 3; queue.addQueue(x); queue.addQueue(y); x = queue.front(); queue.deleteQueue(); queue.addQueue(x + 2); queue.addQueue(x); queue.addQueue(y - 3); y = queue.front(); queue.deleteQueue(); cout << "x = " << x << endl; cout << "y = " << y << endl; a. x = 2 y = 4 c. x = 2 y = 3 ANSWER: FEEDBACK:

b. x = 4 y = 3 d. x = 3 y = 2 c a. Incorrect. In this program segment, x is initialized to 2 and y is initialized to 3, and sox = 2 and y = 3. The statement queue.addQueue(x);inserts 2(that is, the value of x) into the queue. The statement queue.addQueue(y);inserts 3 (that is, the value of y) into the queue; now the queue contains 2, 3. The statement x = queue.front(); stores 2 into x. The value of x is now 2. The statement queue.deleteQueue(); removes the front element, that is,2 from the queue; now the queue contains 3. The statement queue.addQueue(x + 2);inserts 4 (that is, 2 + 2 = 4) into the queue; now the queue contains 3, 4. The statement queue.addQueue(x); inserts 2 (that is, the value of x) into the queue; now the queue contains 3, 4, 2. The statement queue.addQueue(y - 3); inserts 0 (that is, 3 – 3 = 0) into the queue; now the queue contains 3, 4, 2, 0. The statement y = queue.front(); stores the front of the queue (that is, 3) into y. The value of y is now 3. The statement queue.deleteQueue() removes the front element, that is, 3 from the queue; now the queue contains 4, 2, 0. The cout statements output: x = 2 y = 3 b. Incorrect. In this program segment, x is initialized to 2 and y is initialized to 3,

Copyright Cengage Learning. Powered by Cognero.

Page 19


Name:

Class:

Date:

Chapter 18 and sox = 2 and y = 3. The statement queue.addQueue(x); inserts 2 (that is, the value of x) into the queue. The statement queue.addQueue(y); inserts 3 (that is, the value of y) into the queue; now the queue contains 2, 3. The statement x = queue.front(); stores 2 into x. The value of x is now 2. The statement queue.deleteQueue(); removes the front element, that is, 2 from the queue; now the queue contains 3. The statement queue.addQueue(x + 2); inserts 4 (that is, 2 + 2 = 4) into the queue; now the queue contains 3, 4. The statement queue.addQueue(x); inserts 2 (that is, the value of x) into the queue; now the queue contains 3, 4, 2. The statement queue.addQueue(y - 3); inserts 0 (that is, 3 – 3 = 0) into the queue; now the queue contains 3, 4, 2, 0. The statement y = queue.front(); stores the front of the queue (that is, 3) into y. The value of y is now 3. The statement queue.deleteQueue() removes the front element, that is, 3 from the queue; now the queue contains 4, 2, 0. The cout statements output: x = 2 y = 3 c. Correct. In this program segment,x is initialized to 2 and y is initialized to 3, and sox = 2 and y = 3. The statement queue.addQueue(x); inserts 2 (that is, the value of x) into the queue. The statement queue.addQueue(y); inserts 3 (that is, the value of y) into the queue; now the queue contains 2, 3. The statement x = queue.front(); stores 2 into x. The value of x is now 2. The statement queue.deleteQueue(); removes the front element, that is, 2 from the queue; now the queue contains 3. The statement queue.addQueue(x + 2); inserts 4 (that is, 2 + 2 = 4) into the queue; now the queue contains 3, 4. The statement queue.addQueue(x); inserts 2 (that is, the value of x) into the queue; now the queue contains 3, 4, 2. The statement queue.addQueue(y - 3); inserts 0 (that is, 3 – 3 = 0) into the queue; now the queue contains 3, 4, 2, 0. The statement y = queue.front(); stores the front of the queue (that is, 3) into y. The value of y is now 3. The statement queue.deleteQueue() removes the front element, that is, 3 from the queue; now the queue contains 4, 2, 0. The cout statements output: x = 2 y = 3 d. Incorrect. In this program segment, x is initialized to 2 and y is initialized to 3, and sox = 2 and y = 3. The statement queue.addQueue(x); inserts 2 (that is, the value of x) into Copyright Cengage Learning. Powered by Cognero.

Page 20


Name:

Class:

Date:

Chapter 18 the queue. The statement queue.addQueue(y); inserts 3 (that is, the value of y) into the queue; now the queue contains 2, 3. The statement x = queue.front(); stores 2 into x. The value of x is now 2. The statement queue.deleteQueue(); removes the front element, that is, 2 from the queue; now the queue contains 3. The statement queue.addQueue(x + 2); inserts 4 (that is, 2 + 2 = 4) into the queue; now the queue contains 3, 4. The statement queue.addQueue(x); inserts 2 (that is, the value of x) into the queue; now the queue contains 3, 4, 2. The statement queue.addQueue(y - 3); inserts 0 (that is, 3 – 3 = 0) into the queue; now the queue contains 3, 4, 2, 0. The statement y = queue.front(); stores the front of the queue (that is, 3) into y. The value of y is now 3. The statement queue.deleteQueue() removes the front element, that is, 3 from the queue; now the queue contains 4, 2, 0. The cout statements output: x = 2 y = 3 POINTS: 1 REFERENCES: 1275-1276 – Implementation of Queues as Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.09 - Learn how to implement a queue as an array. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 9:12 AM 31. What is the output of the following code? queueType<int> queue; int x, y; x = 8; y = 5; queue.addQueue(12); queue.addQueue(x); queue.addQueue(y); x = queue.front(); queue.deleteQueue(); queue.addQueue(x + 2); queue.addQueue(x); queue.addQueue(y - 3); y = queue.front(); queue.deleteQueue(); cout<< "x = " << x <<endl; cout<< "y = " << y <<endl; Copyright Cengage Learning. Powered by Cognero.

Page 21


Name:

Class:

Date:

Chapter 18 a. x = 5 y = 8 c. x = 8 y = 5

b. x = 12 y = 8 d. x = 14 y = 12

ANSWER: FEEDBACK:

b a. Incorrect. In this program segment, x is initialized to 8 and y is initialized to 5, and so x = 8 and y = 5. The statement queue.addQueue(12); inserts 12 into the queue. The statement queue.addQueue(x); inserts 8 (that is, the value of x) into the queue. The statement queue.addQueue(y); inserts 5 (that is, the value of y) into the queue; now the queue contains 12, 8, and 5 (in this order). The statement x = queue.front(); stores 12 into x. The value of x is now 12. The statement queue.deleteQueue(); removes the front element, that is, 12 from the queue; now the queue contains 8 and 5 (in this order). The statement queue.addQueue(x + 2); inserts 14 (that is, 12 + 2 = 14) into the queue; now the queue contains 8, 5,and 14 (in this order). The statement queue.addQueue(x); inserts 12 (that is, the value of x) into the queue; now the queue contains 8, 5, 14,and 12 (in this order). The statement queue.addQueue(y - 3); inserts 2 (that is, 5 – 3 = 2) into the queue; now the queue is contains 8, 5, 14, 12, and 2 (in this order). The statement y = queue.front(); stores the front of the queue (that is, 8) into y. The value of y is now 8. The statement queue.deleteQueue(); removes the front element, that is, 8 from the queue; now the queue contains 5, 14, 12, and 2 (in this order). The cout statements output: x = 12 y = 8 b. Correct. In this program segment, x is initialized to 8 and y is initialized to 5, and so x = 8 and y = 5. The statement queue.addQueue(12); inserts 12 into the queue. The statement queue.addQueue(x); inserts 8 (that is, the value of x) into the queue. The statement queue.addQueue(y); inserts 5 (that is, the value of y) into the queue; now the queue contains 12, 8, and 5 (in this order). The statement x = queue.front(); stores 12 into x. The value of x is now 12. The statement queue.deleteQueue(); removes the front element, that is, 12 from the queue; now the queue contains 8 and 5 (in this order). The statement queue.addQueue(x + 2); inserts 14 (that is, 12 + 2 = 14) into the queue; now the queue contains 8, 5,and 14 (in this order). The statement queue.addQueue(x); inserts 12 (that is, the value of x) into the queue; now the queue contains 8, 5, 14,and 12 (in this order). The statement queue.addQueue(y - 3); inserts 2 (that is, 5 – 3 = 2) into the queue; now the queue is contains 8, 5, 14, 12, and 2 (in this order). The statement y = queue.front(); stores the front of the queue (that is, 8)

Copyright Cengage Learning. Powered by Cognero.

Page 22


Name:

Class:

Date:

Chapter 18 into y. The value of y is now 8. The statement queue.deleteQueue(); removes the front element, that is, 8 from the queue; now the queue contains 5, 14, 12, and 2 (in this order). The cout statements output: x = 12 y = 8 c. Incorrect. The statement queue.addQueue(12); inserts 12 into the queue. The statement queue.addQueue(x); inserts 8 (that is, the value of x) into the queue. The statement queue.addQueue(y); inserts 5 (that is, the value of y) into the queue; now the queue contains 12, 8, and 5 (in this order). The statement x = queue.front(); stores 12 into x. The value of x is now 12. The statement queue.deleteQueue(); removes the front element, that is, 12 from the queue; now the queue contains 8 and 5 (in this order). The statement queue.addQueue(x + 2); inserts 14 (that is, 12 + 2 = 14) into the queue; now the queue contains 8, 5,and 14 (in this order). The statement queue.addQueue(x); inserts 12 (that is, the value of x) into the queue; now the queue contains 8, 5, 14,and 12 (in this order). The statement queue.addQueue(y - 3); inserts 2 (that is, 5 – 3 = 2) into the queue; now the queue is contains 8, 5, 14, 12, and 2 (in this order). The statement y = queue.front(); stores the front of the queue (that is, 8) into y. The value of y is now 8. The statement queue.deleteQueue(); removes the front element, that is, 8 from the queue; now the queue contains 5, 14, 12, and 2 (in this order). The cout statements output: x = 12 y = 8 d. Incorrect. In this program segment, x is initialized to 8 and y is initialized to 5, and so x = 8 and y = 5. The statement queue.addQueue(12); inserts 12 into the queue. The statement queue.addQueue(x); inserts 8 (that is, the value of x) into the queue. The statement queue.addQueue(y); inserts 5 (that is, the value of y) into the queue; now the queue contains 12, 8, and 5 (in this order). The statement x = queue.front(); stores 12 into x. The value of x is now 12. The statement queue.deleteQueue(); removes the front element, that is, 12 from the queue; now the queue contains 8 and 5 (in this order). The statement queue.addQueue(x + 2); inserts 14 (that is, 12 + 2 = 14) into the queue; now the queue contains 8, 5,and 14 (in this order). The statement queue.addQueue(x); inserts 12 (that is, the value of x) into the queue; now the queue contains 8, 5, 14,and 12 (in this order). The statement queue.addQueue(y - 3); inserts 2 (that is, 5 – 3 = 2) into the queue; now the queue is contains 8, 5, 14, 12, and 2 (in this order). The statement y = queue.front(); stores the front of the queue (that is, 8) into y. The value of y is now 8. Copyright Cengage Learning. Powered by Cognero.

Page 23


Name:

Class:

Date:

Chapter 18 The statement queue.deleteQueue(); removes the front element, that is, 8 from the queue; now the queue contains 5, 14, 12, and 2 (in this order). The cout statements output: x = 12 y = 8 POINTS: 1 REFERENCES: 1264-1265 – Implementation of Queues as Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.09 - Learn how to implement a queue as an array. DATE CREATED: 4/10/2020 9:14 AM DATE MODIFIED: 4/10/2020 9:19 AM 32. Consider the following code. What is in queue after the execution of the last statement? queueType<int> queue; int x, y; x = 8; y = 5; queue.addQueue(12); queue.addQueue(x); queue.addQueue(y); x = queue.front(); queue.deleteQueue(); queue.addQueue(x + 2); queue.addQueue(x); queue.addQueue(y - 3); y = queue.front(); queue.deleteQueue(); a. 5, 14, 12, and 2 (in this order) c. 2, 12, 14, and 5 (in this order) ANSWER: FEEDBACK:

b. 8, 5, 14, 12, and 2 (in this order) d. 8, 5, 14, 2, and 12 (in this order)

a a. Correct. In this program segment, x is initialized to 8 and y is initialized to 5, and so x = 8 and y = 5. The statement queue.addQueue(12); inserts 12 into the queue. The statement queue.addQueue(x); inserts 8 (that is, the value of x) into the queue. The statement queue.addQueue(y); inserts 5 (that is, the value of y) into the queue; now the queue contains 12, 8, and 5 (in this order). The statement x = queue.front(); stores 12 into x. The value of x is now 12. The statement queue.deleteQueue(); removes the front element, that is, 12 from the queue; now the queue contains 8 and 5 (in this order). The statement queue.addQueue(x + 2); inserts 14 (that is, 12 + 2 = 14) into the queue; now the queue contains 8, 5,and 14 (in this order). The statement queue.addQueue(x); inserts 12 (that is, the value of x) into

Copyright Cengage Learning. Powered by Cognero.

Page 24


Name:

Class:

Date:

Chapter 18 the queue; now the queue contains 8, 5, 14,and 12 (in this order). The statement queue.addQueue(y - 3); inserts 2 (that is, 5 – 3 = 2) into the queue; now the queue is contains 8, 5, 14, 12, and 2 (in this order). The statement y = queue.front(); stores the front of the queue (that is, 8) into y. The value of y is now 8. The statement queue.deleteQueue(); removes the front element, that is, 8 from the queue; now the queue contains 5, 14, 12, and 2 (in this order). Therefore, after the execution of the last statement queue contains 5, 14, 12, and 2 (in this order). b. Incorrect. In this program segment, x is initialized to 8 and y is initialized to 5, and so x = 8 and y = 5. The statement queue.addQueue(12); inserts 12 into the queue. The statement queue.addQueue(x); inserts 8 (that is, the value of x) into the queue. The statement queue.addQueue(y); inserts 5 (that is, the value of y) into the queue; now the queue contains 12, 8, and 5 (in this order). The statement x = queue.front(); stores 12 into x. The value of x is now 12. The statement queue.deleteQueue(); removes the front element, that is, 12 from the queue; now the queue contains 8 and 5 (in this order). The statement queue.addQueue(x + 2); inserts 14 (that is, 12 + 2 = 14) into the queue; now the queue contains 8, 5,and 14 (in this order). The statement queue.addQueue(x); inserts 12 (that is, the value of x) into the queue; now the queue contains 8, 5, 14,and 12 (in this order). The statement queue.addQueue(y - 3); inserts 2 (that is, 5 – 3 = 2) into the queue; now the queue is contains 8, 5, 14, 12, and 2 (in this order). The statement y = queue.front(); stores the front of the queue (that is, 8) into y. The value of y is now 8. The statement queue.deleteQueue(); removes the front element, that is, 8 from the queue; now the queue contains 5, 14, 12, and 2 (in this order). Therefore, after the execution of the last statement queue contains 5, 14, 12, and 2 (in this order). c. Incorrect. The statement queue.addQueue(12); inserts 12 into the queue. The statement queue.addQueue(x); inserts 8 (that is, the value of x) into the queue. The statement queue.addQueue(y); inserts 5 (that is, the value of y) into the queue; now the queue contains 12, 8, and 5 (in this order). The statement x = queue.front(); stores 12 into x. The value of x is now 12. The statement queue.deleteQueue(); removes the front element, that is, 12 from the queue; now the queue contains 8 and 5 (in this order). The statement queue.addQueue(x + 2); inserts 14 (that is, 12 + 2 = 14) into the queue; now the queue contains 8, 5,and 14 (in this order). The statement queue.addQueue(x); inserts 12 (that is, the value of x) into the queue; now the queue contains 8, 5, 14,and 12 (in this order). The statement queue.addQueue(y - 3); inserts 2 (that is, 5 – 3 = 2) into the queue; now the queue is contains 8, 5, 14, 12, and 2 (in this order). Copyright Cengage Learning. Powered by Cognero.

Page 25


Name:

Class:

Date:

Chapter 18 The statement y = queue.front(); stores the front of the queue (that is, 8) into y. The value of y is now 8. The statement queue.deleteQueue(); removes the front element, that is, 8 from the queue; now the queue contains 5, 14, 12, and 2 (in this order). Therefore, after the execution of the last statement queue contains 5, 14, 12, and 2 (in this order). d. Incorrect. In this program segment, x is initialized to 8 and y is initialized to 5, and so x = 8 and y = 5. The statement queue.addQueue(12); inserts 12 into the queue. The statement queue.addQueue(x); inserts 8 (that is, the value of x) into the queue. The statement queue.addQueue(y); inserts 5 (that is, the value of y) into the queue; now the queue contains 12, 8, and 5 (in this order). The statement x = queue.front(); stores 12 into x. The value of x is now 12. The statement queue.deleteQueue(); removes the front element, that is, 12 from the queue; now the queue contains 8 and 5 (in this order). The statement queue.addQueue(x + 2); inserts 14 (that is, 12 + 2 = 14) into the queue; now the queue contains 8, 5,and 14 (in this order). The statement queue.addQueue(x); inserts 12 (that is, the value of x) into the queue; now the queue contains 8, 5, 14,and 12 (in this order). The statement queue.addQueue(y - 3); inserts 2 (that is, 5 – 3 = 2) into the queue; now the queue is contains 8, 5, 14, 12, and 2 (in this order). The statement y = queue.front(); stores the front of the queue (that is, 8) into y. The value of y is now 8. The statement queue.deleteQueue(); removes the front element, that is, 8 from the queue; now the queue contains 5, 14, 12, and 2 (in this order). Therefore, after the execution of the last statement queue contains 5, 14, 12, and 2 (in this order). POINTS: 1 REFERENCES: 1264-1265 – Implementation of Queues as Arrays QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.09 - Learn how to implement a queue as an array. DATE CREATED: 4/10/2020 9:13 AM DATE MODIFIED: 4/10/2020 9:21 AM 33. What is the output of the following code? queueType<int> queue; int x, y; x = 2; y = 6; queue.addQueue(x); queue.addQueue(y); x = queue.front(); queue.deleteQueue(); Copyright Cengage Learning. Powered by Cognero.

Page 26


Name:

Class:

Date:

Chapter 18 queue.addQueue(x + 2); queue.addQueue(x); queue.addQueue(y - 3); while (!queue.isEmptyQueue()) { cout << queue.front() << " "; queue.deleteQueue(); } cout << endl a. 6 2 3 3 c. 6 3 3 3 ANSWER: FEEDBACK:

b. 6 2 4 2 d. 6 4 2 3 d a. Incorrect. In this program segment, x is initialized to2 and y is initialized to 6, and sox = 2 and y = 6. The statement queue.addQueue(x); inserts 2 (that is, value of x) into the queue. The statement queue.addQueue(y); inserts 6 (that is, value of y) into the queue; now the queue contains 2, 6. The statement x = queue.front(); stores 2 into x. The value of x is now 2. The statement queue.deleteQueue(); removes 2 from the queue; now the queue contains 6. The statement queue.addQueue(x + 2); inserts 4 (that is, 2 + 2 = 4) into the queue; now the queue contains 6, 4. The statement queue.addQueue(x); inserts 2 (that is, value of x) into the queue; now the queue contains 6, 4, 2. The statement queue.addQueue(y - 3); inserts 3 (that is, 6 – 3 = 3) into the queue; now the queue contains 6, 4, 2, 3. The while loop outputs the number stored in the queue, (that is, 6, 4, 2, and3). Therefore, the output of the given code is: 6 4 2 3 b. Incorrect. In this program segment, x is initialized to 2 and y is initialized to 6, and sox = 2 and y = 6. The statement queue.addQueue(x); inserts 2 (that is, value of x) into the queue. The statement queue.addQueue(y); inserts 6 (that is, value of y) into the queue; now the queue contains 2, 6. The statement x = queue.front(); stores 2 into x. The value of x is now 2. The statement queue.deleteQueue(); removes 2 from the queue; now the queue contains 6. The statement queue.addQueue(x + 2); inserts 4 (that is, 2 + 2 = 4) into the queue; now the queue contains 6, 4. The statement queue.addQueue(x); inserts 2 (that is, value of x) into the queue; now the queue contains 6, 4, 2. The statement queue.addQueue(y - 3); inserts 3 (that is, 6 – 3 = 3) into the queue; now the queue contains 6, 4, 2, 3.

Copyright Cengage Learning. Powered by Cognero.

Page 27


Name:

Class:

Date:

Chapter 18 The while loop outputs the numberstored in the queue, (that is, 6, 4, 2, , and3). Therefore, the output of the given code is: 6 4 2 3 c. Incorrect. In this program segment, x is initialized to 2 and y is initialized to 6, and sox = 2 and y = 6. The statement queue.addQueue(x); inserts 2 (that is, value of x) into the queue. The statement queue.addQueue(y); inserts 6 (that is, value of y) into the queue; now the queue contains 2, 6. The statement x = queue.front(); stores 2 into x. The value of x is now 2. The statement queue.deleteQueue(); removes 2 from the queue; now the queue contains 6. The statement queue.addQueue(x + 2); inserts 4 (that is, 2 + 2 = 4) into the queue; now the queue contains 6, 4. The statement queue.addQueue(x); inserts 2 (that is, value of x) into the queue; now the queue contains 6, 4, 2. The statement queue.addQueue(y - 3); inserts 3 (that is, 6 – 3 = 3) into the queue; now the queue contains 6, 4, 2, 3. The while loop outputs the number stored in the queue, (that is, 6, 4, 2, , and3). Therefore, the output of the given code is: 6 4 2 3 d. Correct. In this program segment, x is initialized to 2 and y is initialized to 6, and sox = 2 and y = 6. The statement queue.addQueue(x); inserts 2 (that is, value of x) into the queue. The statement queue.addQueue(y); inserts 6 (that is, value of y) into the queue; now the queue contains 2, 6. The statement x = queue.front(); stores 2 into x. The value of x is now 2. The statement queue.deleteQueue(); removes 2 from the queue; now the queue contains 6. The statement queue.addQueue(x + 2); inserts 4 (that is, 2 + 2 = 4) into the queue; now the queue contains 6, 4. The statement queue.addQueue(x); inserts 2 (that is, value of x) into the queue; now the queue contains 6, 4, 2. The statement queue.addQueue(y - 3); inserts 3 (that is, 6 – 3 = 3) into the queue; now the queue contains 6, 4, 2, 3. The whileloopoutputs the numbers stored in the queue, (that is, 6, 4, 2, , and3). Therefore, the output of the given code is:6 4 2 3 POINTS: 1 REFERENCES: 1275-1276 – Linked Implementation of Queues QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.10 - Learn how to implement a queue as a linked list. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 9:24 AM Copyright Cengage Learning. Powered by Cognero.

Page 28


Name:

Class:

Date:

Chapter 18 34. A technique in which one system models the behavior of another system is called ____. a. imitation b. recursion c. simulation d. stimulation ANSWER: c FEEDBACK: a. Incorrect. A technique in which one system models the behavior of another system is called simulation. b. Incorrect. A technique in which one system models the behavior of another system is called simulation. c. Correct. A technique in which one system models the behavior of another system is called simulation. d. Incorrect. A technique in which one system models the behavior of another system is called simulation. POINTS: 1 REFERENCES: 1277 – Application of Queues: Simulation QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.11 - Discover how to use queues to solve simulation problems. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 9:27 AM 35. To describe a queuing system, we use the term ____ for the object that provides the service. a. client b. server c. customer d. provider ANSWER: b FEEDBACK: a. Incorrect. To describe a queuing system, the term server is used for the object that provides the service. b. Correct. To describe a queuing system, the term server is used for the object that provides the service. c. Incorrect. To describe a queuing system, the term server is used for the object that provides the service. d. Correct. To describe a queuing system, the term server is used for the object that provides the service. POINTS: 1 REFERENCES: 1278 – Designing a Queuing System QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.11 - Discover how to use queues to solve simulation problems. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 9:29 AM 36. To describe a queuing system, we use the term ____ for the object receiving the service. a. receiver b. server c. customer d. provider Copyright Cengage Learning. Powered by Cognero.

Page 29


Name:

Class:

Date:

Chapter 18 ANSWER: FEEDBACK:

c a. Incorrect. To describe a queuing system, the term customer is used for the object receiving the service. b. Incorrect. To describe a queuing system, the term customer is used for the object receiving the service. c. Correct. To describe a queuing system, the term customer is used for the object receiving the service. d. Incorrect. To describe a queuing system, the term customer is used for the object receiving the service.

POINTS: 1 REFERENCES: 1278 – Designing a Queuing System QUESTION TYPE: Multiple Choice HAS VARIABLES: False LEARNING OBJECTIVES: PAPD.MALI.18.11 - Discover how to use queues to solve simulation problems. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 9:31 AM 37. The elements at the ____________________ of the stack have been the longest in the stack. ANSWER: bottom POINTS: 1 REFERENCES: 1211 – Stacks QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.18.01 - Learn about stacks DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 9:33 AM 38. An array is a(n) ____________________ access data structure. ANSWER: random POINTS: 1 REFERENCES: 1214 – Implementation of Stacks as Arrays QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.18.03 - Learn how to implement a stack as an array DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 10/5/2016 1:44 PM 39. In the array representation of a stack, the stack is initialized simply by setting stackTop to ____________________. ANSWER: 0 zero POINTS: 1 Copyright Cengage Learning. Powered by Cognero.

Page 30


Name:

Class:

Date:

Chapter 18 REFERENCES: 1217– Initialize Stack QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.18.03 - Learn how to implement a stack as an array DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 10/5/2016 1:44 PM 40. The ____________________ constructor is called when a stack object is passed as a (value) parameter to a function. ANSWER: copy POINTS: 1 REFERENCES: 1233 – Implementation of Stacks as Arrays QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.18.03 - Learn how to implement a stack as an array DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 10/5/2016 1:44 PM 41. In ____________________ notation, operators are written after the operands. ANSWER: postfix POINTS: 1 REFERENCES: 1245 – Application of Stacks: Postfix Expressions Calculator QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.18.05 - Learn about infix, prefix, and postfix expressions, and how to use a stack to evaluate postfix expressions. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 9:37 AM 42. ____________________ techniques are used when it is too expensive or dangerous to experiment with real systems. ANSWER: Simulation simulation POINTS: 1 REFERENCES: 1277 – Application of Queues: Simulation QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.18.11 - Discover how to use queues to solve simulation problems. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 9:39 AM Copyright Cengage Learning. Powered by Cognero.

Page 31


Name:

Class:

Date:

Chapter 18 43. When describing a queuing system, the term ____________________ refers to the time it takes to serve a customer. ANSWER: transaction time POINTS: 1 REFERENCES: 1278 – Designing a Queuing System QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.18.11 - Discover how to use queues to solve simulation problems. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 9:40 AM 44. In a(n) ____________________ simulation, the clock is implemented as a counter, and the passage of, say, one minute can be implemented by incrementing the counter by 1. ANSWER: time driven time-driven POINTS: 1 REFERENCES: 1278 – Designing a Queuing System QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.18.11 - Discover how to use queues to solve simulation problems. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 4/10/2020 9:41 AM 45. In a queuing system, every customer has a customer number, arrival time, ____________________ time, transaction time, and departure time. ANSWER: waiting POINTS: 1 REFERENCES: 1279 – Customer QUESTION TYPE: Completion HAS VARIABLES: False STUDENT ENTRY MODE: Basic LEARNING OBJECTIVES: PAPD.MALI.18.11 - Discover how to use queues to solve simulation problems. DATE CREATED: 10/5/2016 1:44 PM DATE MODIFIED: 10/5/2016 1:44 PM

Copyright Cengage Learning. Powered by Cognero.

Page 32


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.