master C++ Study Guide

Ace your homework & exams now with Quizwiz!

The ________ operator takes an operand and reverses its truth or falsehood.

!

The ________ directive causes the contents of another file to be inserted into a program.

#include

The C++ ________ operator represents logical AND

&&

1) ________ are C++ operators that change their operands by one.

++ and --

In C++ when a relational expression is false, it has the value ________.

0

The expression 5 % 2 evaluates to

1

3) What will the following code print? num = 5; cout << num++ << " "; cout << num-- << " "; cout << --num;

5 6 5

10) What does the following C++ expression evaluate to? 6 - 6 / 3 + 3

7

What value will be assigned to the variable number by the following statement? int number = 7.8;

7

Which of the following will cause the next output to begin on a new line?

A and C, but not B

Which of the following definitions will allow the variable total to hold floating-point values?

All of the above

20) In order for a C++ program to read data from a file,

All of the above are required.

2) The -- operator

All of the above are true.

3) The ++ operator

All of the above.

Which of the following keywords is/are the names of C++ data types?

All the above

4) The while loop has two important parts: a condition that is tested and a statement or block of statements that is executed

As long as the condition is true

A variable must be defined

Before it can be used

Which of the following is/are valid C++ identifiers ?

Both A and B, but not C.

12) Which of the following statements doubles the value stored in answer?

Both B and C, but not A

17) If Circle is the name of a class, which of the following statements would create a Circle object named myCircle?

Circle myCircle;

20) To use an output file in a C++ program you must

E) do B and C, but not A.

11) True/False: When an operator has two operands of different data types, C++ always converts them both to double before performing the operation.

FALSE

13) True/False: The following pair of C++ statements is legal. const double taxRate; taxRate = .05;

FALSE

14) True/False: The following C++ statement will assign 1.5 to the result variable. int result = 3.0 / 2.0;

FALSE

15) True/False: If the value of dollars is 5.0, the following statement will output 5.00 to the monitor: cout << fixed << showpoint << setprecision(4) << dollars << endl;

FALSE

17) True/False: The following statement sets the value of total to -3. total -= 3;

FALSE

24) True/False: When a C++ expression is evaluated, binary operations are performed before unary operations.

FALSE

7) True/False: In C++, the 5 basic arithmetic operators are addition (+), subtraction (-), multiplication (*), division (/), and exponentiation (^).

FALSE

10) True/False: A class must have exactly one constructor.

False

10) True/False: A constructor is a public class function that gets called whenever you want to re-initialize an object's member data.

False

12) True/False: The following pair of C++ statements will cause 3.5 to be output. double number = 7 / 2; cout << number;

False

12) True/False: You can nest a for loop inside another for loop, but cannot nest a while loop inside another while loop or a do-while loop inside another do-while loop.

False

14) True/False: Before beginning to add value to it, an accumulator should be initialized to 1.

False

14) True/False: Both function headers and function calls must list the data types of all data being passed to the function.

False

15) True/False: In C++ If you attempt to store more data in an array than it can hold, the compiler will issue an error.

False

15) True/False: Once a value has been stored in a variable it cannot be changed.

False

16) True/False: In C++ global and local numeric variables are initialized to zero by default.

False

16) True/False: The purpose of the compiler is to convert object code into source code.

False

16) When a loop is nested inside another loop, the outer loop goes through all its iterations for each iteration of the inner loop.

False

17) True/False: The only difference between C-strings and string objects is how they are declared and internally stored. They are used exactly the same way.

False

19) True/False: You may use the exit() function to return the flow of control from a function back to main() regardless of where the function was called from.

False

2) True/False: ADT stands for Algorithmic Data Type.

False

2) True/False: The amount of memory used by an array depends solely on the number of elements the array can hold.

False

2) True/False: To decrement a number means to increase its value.

False

22) True/False: The cin object lets the user enter a string that contains embedded blanks.

False

3) True/False: The size of an array is the number of elements that have data stored in them.

False

4) True/False: A class declaration creates an object.

False

4) True/False: If a C++ program contains the following array definition int score[10]; the following statement would store 100 in the first array element: score[1] = 100;

False

4) True/False: If a function has no return statement, the flow of control moves to the next function in the file when the closing brace of the function body is reached.

False

5) True/False: The following statement is a valid C++ array definition. double money[25.00];

False

7) True/False: When you make a function call, the order of the arguments you send does not matter as long as the number of arguments matches the number of parameters the function has.

False

8) True/False: A while loop is somewhat limited, because the counter can only count up, not down.

False

8) True/False: The following array definition is legal because C++ allows arrays to be implicitly sized. int grades[ ];

False

A switch statement branches to a particular block of code depending on the value of a numeric (i.e. integer or floating-point) variable or constant.

False

An array can be returned by a function as well as passed to a function.

False

If the sub-expression on the left side of an && operator is true, the expression on the right side will not be checked

False

Relational operators connect two or more relational expressions into one, or reverse the logic of an expression.

False

True/False: Arrays can be passed to functions, but individual array elements cannot be.

False

True/False: Executable code is computer code that contains no errors.

False

True/False: IDE stands for internal data engine.

False

True/False: If a variable is defined as int sum; it may be written in the program code as sum or Sum, but not SUM.

False

True/False: Most modern computers can understand and execute pseudocode.

False

True/False: The following is a legal C++ statement to define and initialize a variable.

False

True/False: The following statements both declare the variable num to be an integer.

False

True/False: The following two C++ statements perform the same operation. wages = regPay + overTime; regPay + overTime = wages;

False

17) What does the following statement do? typedef int oneDArray[20];

It makes oneDArray an alias for a data type that holds 20 integers.

Which of the following is/are valid C++ identifiers?

June_2010

________ are data items whose values cannot change while the program is running.

Literals

7) Which of the following statements will correctly carry out the operation stated in the comment to its right.

None of the above.

4) What will the following code print?

None of these

If s1 and s2 are string objects, s1 == s2 is true when ________.

None of these because one or more characters in the strings have different ASCII codes

7) ________ can be used to override the rules of operator precedence.

Parentheses

________ is used in a C++ program to mark the end of a statement, or to separate items in a list.

Punctuation

15) If Square is the name of a class, which of the following statements would create a Square object named box?

Square box;

13) Which of the following statements about named constants is/are true?

Statements A and C are true, but B is not.

The purpose of a memory address is

To identify the location of a memory cell

4) True/False: A function can have zero to many parameters and either zero or one return value(s).

True

4) True/False: The cin object can be used to input more than one value in a single statement.

True

6) True/False: A while loop is somewhat limited because the counter can only be incremented or decremented by one each time through the loop.

True

6) True/False: Each individual element of an array can be accessed by the array name and an element number, called a subscript.

True

True/False: Before a computer can execute a program written in a high level language, such as C++, it must be translated into object code.

True

True/False: C++ is a case-sensitive language.

True

True/False: If a new value is stored in a variable, it replaces whatever value was previously there.

True

True/False: Syntax involves rules that must be followed when writing a program.

True

20) Hand tracing a program is

a program debugging technique.

Even when there is no power to the computer, data can be held in

a secondary storage device.

23) The cin object must be followed by

a single stream insertion (<<) operator.

In programming terms, a group of characters inside a set of double quotation marks (" ") is called

a string literal.

12) The name of a destructor must begin with

a tilde (~).

A storage location in the computer's memory that can hold a piece of data is called

a variable.

17) A variable that keeps a running total of data values is called a(n)

accumulator

7) In a function call, in addition to the name of the function, you are required to furnish

all of the above.

High-level programming languages include

all of the above.

An operation that copies a value into a variable is called a(n) ________ operation.

assignment

10) The statements in the body of a do-while loop are executed

at least once

13) The statements in the body of a do-while loop are executed

at least once.

6) In OOP terminology, an object's member variables are often called its ________, and its member functions are sometimes referred to as its ________.

attributes, methods

4) Subscript numbering in C++

automatically begins with zero.

2) A function ________ is a statement that causes a function to execute.

call

11) A constructor must have the same name as the

class.

20) To use the sqrt() function, or other mathematical library functions, you must #include the ________ header file in your program.

cmath

Relational operators allow you to ________ numbers.

compare

The ________ coordinates the computer's operations by fetching the next instruction and using control signals to regulate the other major computer components.

control unit

At the heart of a computer is its central processing unit (CPU). Its job is to

do all of the above. [fetch instructions - carry out the operations commanded by the instructions - produce some result]

18) The ideal type of loop to use for repeating a menu is a(n) ________ loop.

do-while

16) The statement cout << setw(4) << num4 << " ";

does none of above.

7) Public members of a class object can be accessed from outside the class by using the

dot operator.

5) The bundling of an object's data and functions together is called

encapsulation.

Which of the following correctly declares an enumerated data type named student?

enum student { Bill, Tom, Mary };

19) The ________ function causes the entire program to terminate, regardless of which function or control mechanism is executing.

exit()

5) Program code that can be evaluated to a value is called a(n)

expression.

If number is an int variable, both of the following statements will print out its value: cout << number; cout << "number";

false

17) The ideal type of loop to use if you want a user to enter exactly 20 values is a(n) ________ loop.

for

16) To use stream manipulators, you should include the ________ header file.

fstream

16) Accessors are sometimes called ________ functions and mutators are sometimes called ________ functions.

get, set

A ________ variable is declared outside all functions.

global

The ________ statement executes one block of statements if a test condition is true, and another block if the condition is false

if/else

The ________ statement acts like a chain of if statements. Each performs its test, one after the other, until one of them is found to be true.

if/else if

5) If nothing within a while loop ever causes the condition to become false, a(n) ________ may occur.

infinite loop

13) In a for statement, the ________ expression is executed only once.

initialization

7) When three different objects of a class are created, they are said to be separate ________ of the class.

instances

3) In any program that uses the cin object, you must #include

iostream header file

Words with a special meaning that may be used only for their intended purpose are known as

keywords.

10) A ________ variable is defined inside the body of a function and is not accessible outside that

local

11) A sentinel is a special value that

marks the end of a list of values.

Characters or symbols that perform operations on one or more operands are

operators.

16) When more than one function has the same name they are called ________ functions.

overloaded

18) The following two arrays string deptName[3] = {"Manufacturing", "Sales", "Business Office"); double deptBudget[3] = {200000.0, 60000.0, 50000.0}; are an example of ________ arrays.

parallel

6) The ________ is used to protect important data.

private access specifier

A(n) ________ is a set of instructions that tells the computer how to solve a problem.

program

Creating a program requires many steps. Three of these are

program design, writing source code, and testing

10) A function ________ eliminates the need to place the function definition before all calls to the function.

prototype

14) A(n) ________ member function may be called by a statement in a function that is outside of the class.

public

The expression x < y is called a(n) ________ expression.

relational

10) A(n) ________ is a special value that marks the end of a list of values.

sentinel

A C++ character literal is enclosed in ______ quotation marks, whereas a string literal is enclosed in ______ quotation marks.

single, double

A ________ is a complete instruction that causes the computer to perform some action.

statement

8) By using the same ________ you can build relationships between data stored in two or more arrays.

subscript

3) To access an array element, use the array name and the element's

subscript.

The programs that control and manage the basic operations of a computer are generally referred to as

system software.

18) An overloaded function is one

that has the same name as another function.

The default section of a switch statement performs a similar task as the ________ portion of an if/else if statement

trailing else

9) True/False: When a loop is nested inside another loop, the inner loop goes through all its iterations for each iteration of the outer loop.

true

True/False: The following two statements could be used interchangeably in a C++ program.

true

What will the following expression evaluate to? !( 6 > 7 || 3 == 4)

true

18) For data validation, it is best to use a(n)

while

{}

{}

The expression 7 % 2 evaluates to

1

What will the following statement assign to variable answer if x equals 17? answer = x > 100 ? 0 : 1;

1

The expression 5 / 2 evaluates to

2

The expression 7 / 2 evaluates to

3

What value will be assigned to the variable number by the following statement? int number = 3.75;

3

13) If the scores array is defined like this: int scores[ ]= {4, 7, 4, 8, 9}; what will the following statement display? cout << scores[4];

9

The ________ operator is used in C++ to test for equality.

==

2) The ________ operator always follows the cin object, and the ________ operator follows the cout object.

>> , <<

6) Which of the following statements correctly initialize the value variable?

All of the above.

5) In a function header, in addition to the name of the function, you are required to furnish

All of these

12) In the following statement, what is 22.0? cout << sqrt(22.0);

An argument

The following C++ test checks if the variable child is in the range 3-12. if (child >= 3 && <= 12)

False

The following C++ test checks if the variable child is in the range 3-12. if (child >= 3 || child <= 12)

False

The following statement s will not print anything. x = 5; if (x < 5) cout << "Hello "; cout << "world \n";

False

The three logical operators, AND, OR, and NOT, all have the same precedence.

False

To check if a variable has a particular value, use the = relational operator, as in the statement if (s = 3) cout << "S has the value 3"

False

True/False: A while loop may have a semicolon after the test expression and before the body of the loop, but it is not required.

False

________ is an example of volatile memory, used for temporary storage while a program is running.

RAM

14) True/False: The following statement sets sum1, sum2, and sum3 all to zero. sum1 = sum2 = sum3 = 0;

TRUE

8) True/False: The following two expressions evaluate to the same thing: c + a * b c + (a * b)

TRUE

1) ________ causes a program to wait until information is typed at the keyboard and the Enter key is pressed.

The cin object

21) The ________ object causes data to be input from the keyboard.

The cin object

________ must be included in a program in order to use the cout object.

The iostream header file

18) The following 4 lines of C++ code, use strings. string firstName; // Define a string object char lastName[7]; // Define a C-string firstName = "Abraham"; // Assign a value to the string object lastName = "Lincoln"; // Assign a value to the C-string

The string object is assigned a value correctly, but the C-string is not.

1) True/False: An Abstract data type (ADT) is a programmer-defined data type that specifies the values the type can hold, the operations that can be performed on them, and how the operations will be implemented.

True

1) True/False: One reason for using functions is to break programs into a set of manageable units, or modules.

True

12) True/False: After carrying out the following two statements, sales will have been created as a one-dimensional array that can hold 20 doublevalues. typedef salesArray double[20]; salesArray sales;

True

12) True/False: When a function just needs to use a copy of an argument passed to it, the argument should normally be passed by value.

True

12) True/False: When you pass an array as an argument to a function, the function can modify the contents of the array.

True

13) True/False: Although global variables can be useful, it is considered good programming practice to restrict your use of them.

True

14) True/False: An initialization expression may be omitted from the for loop if no initialization is required.

True

14) True/False: It is possible for a function to have some parameters with default arguments and some without.

True

16) True/False: Any of the following statements can be used to initialize the integer variable num to 7; int num = 7; int num(7); int num{7};

True

18) True/False: A function with a return type of bool must return a value of either true or false.

True

2) True/False: In C++ and other object-oriented programming languages, ADTs are normally implemented as classes.

True

2) True/False: The amount of memory used by an array depends upon the array's data type and how many elements it can hold.

True

4) True/False: A class declaration provides a pattern for creating objects, but doesn't make any objects.

True

6) True/False: The block of code in the body of a while statement can contain an unlimited number of statements, provided they are enclosed in a set of braces.

True

7) True/False: An individual array element can be processed or passed to a function just like a regular C++ variable.

True

9) True/False: A constructor is a public class function that is automatically invoked (i.e., called) whenever a class object is created.

True

9) True/False: A private member function may only be called from a function that is a member of the same class.

True

9) True/False: Functions are ideal for use in menu-drive programs. When a user selects a menu item, the program can call an appropriate function to carry out the user's choice.

True

9) True/False: When an operator's operands are of different data types, such as int and double, C++ automatically converts one of them so that they are the same data type.

True

All of the relational operators are binary

True

Assuming goodData is a Boolean variable, the following two tests are logically equivalent. if (goodData == false) if (!goodData)

True

Assuming moreData is a Boolean variable, the following two tests are logically equivalent. if (moreData == true) if (moreData)

True

Characters and string objects can be compared with any of the relational operators.

True

If the sub-expression on the left side of an || operator is true, the expression on the right side will not be checked.

True

In C++ an expression that evaluates to 5, -5, or for that matter anything other than 0, is considered true by an if statement.

True

Relational expressions and logical expressions are both Boolean, which means they evaluate to true or false.

True

The rule for matching an else with an if is that an else goes with the last if statement before it that doesn't have its own else

True

The statement pass = (score >= 7) ? true : false; does exactly the same thing as the if/else statement below: if (score >= 7) pass = true; else pass = false;

True

True/False: Most of the lines in a program contain something meaningful; however, some of the lines may contain nothing at all.

True

True/False: Object-oriented programming is centered around objects that include both data and the functions that operate on them.

True

True/False: The following two statements will assign the same value to result. result = a + b * c; result = b * c + a;

True

In a C++ program, two slash marks ( // ) indicate the beginning of

a comment.

9) To step through a one-dimensional array, accessing the elements one by one, it would be most appropriate to use ________ loop.

a for loop

Every C++ program must have

a function called main.

8) A C++ member function that sets or changes the value stored in a member variable is called

a mutator.

Which of the following is an example of a secondary storage device?

all of the above

6) In a function prototype, in addition to the name of the function, you are required to furnish

all of the above.

An integrated development environment (IDE) normally includes

all of the above. [a text editor - a compiler - a debugger]

1) An array can store multiple values, but the values must be

all the same data type.

15) A C++ member function that uses, but does not change, the value of a member variable is called

an accessor.

A set of well-defined steps for performing a task or solving a problem is known as

an algorithm

17) On each iteration of the following range-based for loop for (int element : myArray) cout << element << endl; the variable element holds

an array value.

13) The elements of an array can be

any of the above.

5) A(n) ________ is information that is passed to a function, and a(n) ________ is a special variable that

argument, parameter

A ________ variable can hold only one of two values: true or false.

bool

A flag is a variable, usually of data type ________, that signals when a condition exists.

bool

hat literal(s) appear in the following C++ statement? int number = 4 + 8;

both B and C

15) The ________ statement causes a loop to terminate early.

break

If a switch statement has no ________ statements, the program "falls through" all of the statements below the one with the matching case expression.

break

8) When only a copy of an argument is passed to a function, it is said to be passed

by value.

copy of 13

copy of 13

copy of 5

copy of 5

8) A(n) ________ is a variable that is regularly incremented or decremented each time a loop iterates.

counter

The ________ is used to display information on the computer's screen.

cout object

12) A constructor that does not require that any arguments be passed to it is called a(n) ________ constructor.

default

15) A(n) ________ argument is one that is automatically passed to a parameter when the argument is left out of the function call.

default

2) A function ________ includes the statements that make up the function.

definition

You must have a(n) ________ for every variable you include in a program.

definition

20) A ________ is a program module whose purpose is to test other modules by calling them.

driver

True/False: A variable of the char data type can hold a set of characters like "January".

false

True/False: The following two statements both assign the value 5 to the variable dept. 5 = dept; dept = 5;

false

A(n) ________ is a variable, usually a bool, that signals when a condition exists

flag

19) To use files in a C++ program you must include the ________ header file.

fstream

18) Which of the following will allow an entire line of text to be read into a string object, even if it contains embedded blanks?

getline()

The bool data type

has only two values: true and false.

C++ is an example of a ________ programming language.

high-level

The ________ statement can cause other program statements to execute only under certain conditions

if

The _________ statement executes one statement, or block of statement, if condition is true and skips it, doing nothing, if the condition is false.

if

Two different variables in the same program may have the same name ________.

if they have different scope

5) The statement int grades[ ] = { 100, 90, 99, 80 }; is an example of

implicit array sizing.

1) To ________ a value means to increase it.

increment

8) When the body of a member function is defined inside a class declaration, it is called a(n) ________ function.

inline

When a program lets the user know that an invalid menu choice has been made, this is an example of ________.

input validation

Three primary activities of a typical program are

input, processing, output

3) An object is a(n) ________ of a class.

instance

13) A destructor is a member function that

is automatically called when an object is destroyed.

Mistakes that allow a program to run, but cause it to produce erroneous results are called

logic errors.

7) A(n) ________ is a variable that controls the number of times a loop iterates.

loop control variable

1) Breaking a program up into a set of manageable sized functions is called ________ programming.

modular

18) If setRadius is a Circle class function and myCircle is a Circle object, which of the following statements would set myCircle's radius to 2.5?

myCircle.setRadius(2.5);

When an if statement is placed within the conditionally-executed code of another if statement, this is known as a(n) ________.

nested if

A trailing else placed at the end of an if/else if statement provides a default action when ________ of the if conditions is/are true.

none

19) The following statement number = rand() % 5 + 10; assigns number a value in the range of

none of the above

11) A constructor may have a return type of

none of the above.

9) You can assign the contents of one array to another by using

none of the above.

A software package that includes a text editor, compiler, debugger, and assorted utilities for creating, testing, and running software is called

none of the above.

19) Which of the following statements will assign number a value from 90 - 100.

number = rand() % 11 + 90;

A class may have ________ default constructor(s) and ________ destructor(s).

only one, only one

5) When an arithmetic expression contains two or more different operators, such as * and +, the order in which the operations is done is determined by

operator precedence.

9) When converting some algebraic expressions to C++, you may need to insert ________ and ________ that do not appear in the algebraic expression.

operators, parentheses

9) When a function needs access to an original argument passed to it, for example in order to change its value, the argument needs to be

passed into a reference parameter.

11) The do-while loop is a(n) ________ loop, whereas the while loop is a(n) ________ loop.

post test, pretest

#include <iostream> is an example of a(n)

preprocessor directive.

9) The while loop is a(n) ________ loop, whereas the do-while loop is a(n) ________ loop.

pretest, post-test

5) An object typically hides its data, but allows outside code to access it through its

public member functions.

The computer's main memory is commonly known as

random-access memory (RAM).

14) The following statement for(int val : myArray) cout << val << " "; is an example of a(n)

range-based for loop.

13) When used as a parameter, a ________ variable allows a function to access and modify the original argument passed to it.

reference

5) The while loop has two important parts: a condition that is tested and a statement or block of statements that is

repeated as long as the condition is true.

17) The ________ statement causes a function to end and the flow of control to move back to the point where the function call was made.

return

3) A void function is one that

returns no value.

8) A void function is one that

returns no value.

6) Operator associativity is either left to right or

right to left

A ________ is used to mark the end of a complete C++ programming statement.

semicolon

15) The ________ stream manipulator can be used to establish a field width for the value immediately following it.

setw

The statements written by a programmer are called

source code

11) The value in ________ local variable is retained between function calls.

static

11) Which of the following expressions will evaluate to 2.5?

static_cast<double>(5)/2

20) A ________ is a dummy function that is called instead of the actual function it represents, to test that the call to and return from the function are working correctly.

stub

Internally, the central processing unit (CPU) consists of two parts:

the arithmetic and logic unit (ALU) and the control unit.

The CPU includes

the arithmetic and logic unit (ALU) and the control unit.

10) When the final value of an expression is assigned to a variable, it will be converted to

the data type of the variable.

16) If a while loop has no braces around the body of the loop

the loop body contains just one statement

C++ automatically places ________ at the end of a string literal.

the null terminator

The term hardware refers to

the physical components that make up a computer.

8) In C++, a value can be raised to a power by using

the pow

14) When a member function is defined outside of the class declaration, the function name must be qualified with the class name, followed by

the scope resolution operator (::).

10) When an array is passed to a function, it is actually ________ the array that is/are passed.

the starting memory address of

11) When an array is passed to a function, it is actually ________ the array that is passed.

the starting memory address of

15) Two or more functions may have the same name provided that

their parameter lists are different

12) A for statement contains three expressions: initialization, test, and

update

1) Unlike regular variables, arrays can hold multiple

values.

15) You may define a(n) ________ in the initialization expression of a for loop.

variable

Memory locations that can hold data are called

variables.

A variable definition always specifies the name of a variable and tells

what type of data it can hold.

3) A function other than the main function is executed

whenever it is called

17) A static local variable is one

whose value is retained between function calls.

6) A function can have ________ parameters, and it can have either zero or one return value(s).

zero to many

The programmer usually enters source code into a computer using

{ A) a preprocessor. B) a compiler. C) a linker. D) a debugger. E) none of the above. }

In the C++ statement pay = rate * hours; the * symbol is an example of

{ A) an operator. B) an operand. C) a variable separator. D) syntax. E) none of the above. }

Which of the following definitions will allow the variable average to hold floating-point values?

{ A) float average; B) double average; C) auto average = 0.0; D) All of the above E) A and B, but not C }

List five elements that are common to all programming languages.

{ }

19) True/False: A structure has member variables, like an object, but they are usually all public and accessed directly with the dot operator, instead of by calling member functions.

{}

The ________ operator is known as the logical OR operator

||


Related study sets

Chapter 4: Abraham, Our Father & the Patriarchs

View Set

Anatomy/Physiology Chapter 1: Anatomical Position

View Set