Full file at http://testbank360.eu/test-bank-c-1st-edition-jeffrey-childs

Chapter 1

Multiple Choice (Chapter 1)

1) In C++, a data structure is often an object that is made from a ______.

A. function

B. struct

C. variable

D. class

2) A(n) ______is often defined for a record of information.

A. array

B. struct

C. function

D. variable

3) The variables declared within a struct definition are called:

A. components

B. data members

C. characteristics

D. clients

4) When a programmer writes a definition to make a new type to be used for a declaration, the new type is called a:

A. programmer-defined type

B. client-defined type

C. struct-defined type

D. user-defined type

5) By convention, a ______includes public and private sections.

A. class

B. class function

C. struct

D. data member

6) A(n) ______is made from a class.

A. data member

B. class function

C. object

D. blueprint

7) hiding data from outside entities (the way the private section of a class hides data from the main program) describes ______.

A. encapsulation

B. maintenance

C. poor programming practice

D. invisibility

8) The ______section of a well-written class does not contain data members.

A. private

B. specification

C. specification File

D. public

9) The data member declarations of a class are found in the ______.

A. public section

B. private section

C. function definitions

D. function prototypes

10) The public section of a class is also referred to as the ______.

A. class interface

B. maintenance area

C. data member section

D. class implementation

11) ______refers to how something was put into code.

A. Design

B. Maintenance

C. Implementation

D. Specification

12) The file that contains the class definition is called the ______.

A. class implementation file

B. main program file

C. class specification file

D. client file

13) The file that contains the class function definitions is called the ______.

A. class specification file

B. header file

C. main program file

D. class implementation file

14) A file that has a .h extension is called a ______.

A. main program file

B. class specification file

C. class implementation file

D. header file

15) A ______is a person who makes use of a class when writing a program.

A. client

B. user

C. maintainer

D. class specialist

16) A ______is a program that uses a class.

A. function

B. main function

C. user program

D. client program

17) A ______is used to test a class.

A. class tester

B. testing machine

C. class interface

D. test driver

18) ______is work done on a program after it has been put into operation.

A. Class specification

B. Class implementation

C. Operation implementation

D. Maintenance

19) When a function name, like setBalance, describes what the function does, it is an example of:

A. a function prototype

B. self-documenting code

C. function implementation

D. encapsulation

20) Suppose we have a struct called Employee, we have an object declared from the struct called emp, and we have a data member of the struct called salary. To access the salary data member of emp, we would use the code:

A. emp[salary]

B. Employee.emp[salary]

C. emp( salary )

D. emp.salary

21) Suppose we have a class called Fish, an object of the Fish class called salmon, a class function called eat, and we would like to pass the string “worm” into the eat function. The line of code for doing this would look like this:

A. Fish.eat( “worm” );

B. eat( “worm” );

C. salmon.eat( “worm” );

D. Fish.salmon( eat.worm );

22) When a main program communicates with the object of a class, the first step of the communication involves:

A. a class function using its data members to prepare for the communication

B. a signal sent from the main program to a class data member

C. the call of a class function from the main program

D. the call of a client function from the main program

23) In the past, most of the work was spent on designing, coding, and testing programs, while little work is spent on maintenance; today, most of the work on a program is spent on maintenance. The main reason for this trend is because.

A. people don’t spend as much time designing as they used to

B. customers complain more often today than in the past

C. programmers are intentionally making programs buggier, so they can spend more time maintaining them – it’s job security

D. in the past, programs were small and could easily be rewritten; now, programs are humongous, and it is more cost-effective to maintain them

24) The main advantage to declaring a variable within a class definition is that:

A. you only have to declare it once

B. the object made from the class will remember the value of the variable, even when a function of the object is not executing

C. it allows you to write class functions to access the value of the variable

D. you might declare a variable that is not useful, and the client will never know

25) The main program is often called a client program because:

A. a client (computer user) uses the main program

B. a class is often a client of a main program

C. a single class can be used by many different main programs, so the class can be thought of as a service, while the main programs that use the service are clients

D. special programmers, called clientia, write them

Answers to Multiple Choice (Chapter 1)

1) D

2) B

3) B

4) D

5) A

6) C

7) A

8) D

9) B

10) A

11) C

12) C

13) D

14) A

15) A

16) D

17) D

18) D

19) B

20) D

21) C

22) C

23) D

24) B

25) C

Short Answer (Chapter 1)

1) Explain what happens when an object of a struct is assigned to another object of the same struct.

2) When using structs, explain the difference between a definition and a declaration.

3) Explain why we cannot use the data members of a struct definition without a declaration.

4) Explain what the difference is between a class and an object.

5) What is(are) the difference(s) between a class and a struct.

6) In an #include preprocessing directive, what is the difference between putting a header file in double quotes “ “ and putting a header file in angle brackets < >. Explain how the compiler handles each of these instances.

7) How does a function definition in a class implementation file differ from a function definition in a main program file?

8) How do structs compare to arrays? Explain similarities and differences.

9) Why is a class object thought of as being separate from the rest of the program?

10) Why don’t we place function definitions in the public section of a class specification file?

Essay (Chapter 1)

1) Explain why encapsulation is advantageous, and why it is a good idea for class functions, rather than main programs, to directly access data members of a class.

2) There are two ways of declaring a variable within class code. We may declare it in the private section, or we may declare it locally within a class function definition. Explain when we should use each, and why it is advantageous to use each one when it should be used.

3) Explain why we should not obtain user information or provide messages to users within class functions.

4) Explain why we should test each individual class as it is made, rather than writing a program that uses many classes and testing the whole system at one time.

Chapter 2

Multiple Choice (Chapter 2)

1) A function written to handle operations involving one or more objects is a:

A. overloaded operator function

B. operation function

C. objective function

D. class function

2) An operator acts upon:

A. variables, constants, and objects

B. variables and numbers only

C. variables, constants, and numbers only

D. numbers only

3) An operator that involves only two operands is a:

A. operand operator

B. binary operator

C. unary operator

D. ternary operator

4) Operators act upon:

A. operations

B. overloaded operator function calls

C. operands

D. additions, subtractions, multiplications, and divisions, to name a few

5) One or more classes can be made from a(n) ______.

A. object

B. blueprint

C. class template

D. class implementation file

6) ______means place an element on top of a stack.

A. Push

B. Pop

C. Peek

D. Top

7) ______means remove an element from the top of a stack.

A. Push

B. Pop

C. Peek

D. Top

8) ______means retrieve the element at the top of a stack without removing it.

A. Peek

B. Top

C. Push

D. Pop

9) LIFO stands for:

A. Lifetime Object

B. the Lipton Information Formatting Operation

C. Loadable Input Float Operator

D. Last-in, First-out

10) ______occurs when we just use something without thinking about the details of how it works.

A. Poor programming

B. Abstraction

C. Detail ignorance

D. Encapsulation

11) A(n) ______is a data type that consists of data and functions that act upon the data.

A. overloaded operator type

B. class template type

C. LIFO

D. ADT

12) The fact that a stack can consist of a stack of floats, a stack of ints, a stack of objects, a stack of strings, etc., illustrates:

A. how class templates can come in handy for data structures

B. that stacks need overloaded operator functions

C. abstraction

D. that a push or pop might not work for every situation

13) The stack and string are examples of:

A. abstract data types

B. overloaded operator functions

C. struct objects

D. Lipton Information

14) When the left operand of a binary operation is a struct object:

A. the overloaded operator function for the binary operator must be written beneath the struct definition

B. the overloaded operator function for the binary operator should be written inside the struct definition

C. an overloaded operator function cannot be written for the binary operator

D. a compiler error occurs

15) When the left operand of a binary operation is not an object, but the right operand is a struct object:

A. a compiler error occurs

B. the overloaded operator function for the binary operator must be written beneath the struct definition

C. the overloaded operator function for the binary operator should be written inside the struct definition

D. an overloaded operator function cannot be written for the binary operator

16) To tell a compiler that a class specification file contains a class template, rather than a class:

A. the phrase “CLASS TEMPLATE” must be written at the top of the file and must be in capital letters.

B. the word DataType must appear somewhere in the class

C. we can use the line of code

template <class DataType>

directly above what would otherwise be the class definition

D. we #include the class implementation file at the end of the class specification file

17) Suppose we have a class template called Stack, and we wish to make a class from the class template for a stack of strings. We also wish to declare a stack object called stk using this stack class. To do this, in the main program we would type the line of code:

A. Stack stk<string>;

B. Stack string<stk>;

C. Stack<stk> string;

D. Stack<string> stk;

18) Suppose that a client uses a struct object for the DataType of a class template, and this will require that operators (used within the class functions) are overloaded. The best way to tell a client which operators will need to have overloaded operator functions, and how the functions should be written, is to:

A. send the client a detailed email about all required overloaded operator functions

B. place comments above the class template that specify the details of the required overloaded operator functions

C. write details about the required overloaded operator functions into the client’s main program

D. You shouldn’t tell the client how to do it – you should write the overloaded operator functions yourself, and place them in another file

19) The first step involved in making a class out of a class template is:

A. the compiler substitutes the type in angle brackets for DataType throughout the class.

B. the compiler encounters the line of code:

template <class DataType>

C. the compiler encounters the declaration of an object using a class template with a data type specified in angle brackets

D. none of the above

20) Suppose you need to make two overloaded operator functions for the minus operator, placing them both in the same struct definition. You can do this as long as:

A. their parameters are of different types

B. one passes in one parameter, and the other passes in two parameters

C. the return types are different for both

D. both the return types and the parameters are of different types

21) There is only one parameter for an overloaded operator function (for a binary operator) when it is placed into a struct definition because: