C++ Final

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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

#include directive

This operator represents the logical AND:

&&

What is the value of donuts after the following code executes? int donuts = 10; if (donuts = 1) donuts = 0; else donuts += 2;

0

How many elements does the following array have? int bugs[1000];

1000

What is the output of the following statement? cout << 4 * (15 / (1 + 3) ) << end1;

12

Given the following C++ statements int number = 38, children = 4, cookies; cookies = number % children; What is the value of the variable cookies after the execution of the statement?

2

Given the following code segment, what is output after "result = "? int x = 1, y = 1, z = 1; y = y + z; x = x + y; cout << "result = " << (x < y ? y : x) << endl;

3

In the following C++ statement, what will be executed first according to the order of precedence? result = 6 - 3 * 2 + 7 - 10 / 2;

6

What will the following code display? int numbers[] = {99, 87, 66, 55, 101} for (int i = 1; i < 4; i++) cout << numbers[i] << endl;

87 66 55

Why is it critical that counter variables be properly initialized?

A counter variable is used to control or keep track of the number of times a loop iterates. In a loop, the counter is usually incremented or decremented. If the counter variable is not properly initialized, it will not hold the correct number.

Describe the difference between pretest loops and posttest loops.

A pretest loop tests its condition before each iteration. A post-test loop tests its condition after each iteration.

Of the following, which is a valid C++ identifier?

All of the above are valid identifiers.

Which of the following statements is not valid C++ code?

All of these are invalid (int ptr=&num1; int ptr=int *num1; float num1=*ptr2; )

Why is it critical that accumulator variables be properly initialized?

An accumulator is used to keep a running total of numbers. In a loop, a value is usually added to the current value of the accumulator. If it is not properly initialized, it will not contain the correct total.

Which of the following best describes an operator?

An operator allows you to perform operations on one or more pieces of data.

Why should you be careful not to place a statement in the body of a for loop that changes the value of the loop s counter variable?

Because the for loop has an update expression that normally changes the contents of a counter. If you have code inside that loop that also changes the counter, the loop will not be able to properly control the value of the counter.

Why are the statements in the body of a loop called conditionally executed statements

Because they are only executed when a condition is true.

Why should a program close a file when it's finished using it?

By closing a file, any unsaved data that is held in the buffer is saved to its file.

Why should you indent the statement in the body of a loop?

By indenting the statements, you make them stand out from the surrounding code. This helps you to identify at a glance the statements that are conditionally executed by a loop.

What will the following segment of code output if the value 11 is entered at the keyboard? int number; cin >> number; if (number > 0) cout << "C++"; else cout << "Soccer"; cout << " is "; cout << "fun" << endl;

C++ is fun

_______________ are used to translate each source code instruction into the appropriate machine language instruction.

Compilers

What does the following statement do? double *num2;

Declares a pointer variable named num2.

What will be the output of the following code segment after the user enters 0 at the keyboard? int x=-1; cout <<"Enter a 0 or a 1 from the keyboard: "; cin >>x; if (x) cout << "true"<<endl; else cout <<"False"<<endl;

False

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

Key Words

Mistakes that cause a running program to produce incorrect results are called:

Logic errors

What will the following code display?

MondayTuesdayWednesday

When an if statement is placed within the conditionally-executed code of another if statement, this is known as:

Nesting

A ________ is a set of instructions that the computer follows to solve a problem.

Program

The statements written by the programmer are called:

Source code

A variable declaration announces the name of a variable that will be used in a program, as well as:

The area of the code in which it will be used

In a C++ program, two slash marks ( // ) indicate:

The beginning of a comment

Which loop should you use in situations where you wish the loop to repeat until the test expression is false, but the loop should execute at least one time?

The do-while loop.

Which loop should you use when you know the number of required iterations?

The for loop.

What is the difference between the while loop and the do-while loop

The while loop is a pretest loop and the do-while loop is a post-test loop.

Which loop should you use in situations where you wish the loop to repeat until the test expression is false, and the loop should not execute if the test expression is false to begin with?

The while loop.

The purpose of a memory address is:

To identify the location of a byte in memory

Programmer-defined names of memory locations that may hold data are:

Variables

A(n) ________ is a variable that is initialized to some starting value usually zero, and then has numbers added to it in each iteration of a loop

accumulator

The __, also known as the address operator, returns the memory address of a variable

ampersand (&)

A(n) ________ search is more efficient than a(n) ________ search

binary, linear

The statement or block that is repeated is known as the_________if the loop

body

A variable whose value can be either true or false is of this data type.

bool

The _____ statement causes a loop to terminate immediately

break

The ________loop is ideal for situations that require a counter

break

Without this statement appearing in a switch construct, the program "falls through" all of the statements below the one with the matching case expression.

break

Relational operators allow you to ________ numbers.

compare

The ______ statement causes a loop to skip the remaining statements in the current iteration

continue

A(n)________is a variable that "counts" the number of times a loop repeats.

counter

The ________ is/are used to display information on the computer's screen. Question options:

cout object

Members of a class object are accessed with the

dot operator

What is the value of the following expression? true && false

false

The ______ loop is ideal for situations that require a counter.

for

An array can easily be stepped through by using a ________.

for loop

What header file do you need to include in a program that performs file operations?

fstream

Every complete C++ program must have a

function named main

What data type do you use when you want to create a file stream object that can write data to a file?

ifstream

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

implicit array sizing

To___________a value means to increase it by one, and to___________a value means to decrease it by one

increment, decrement,

A loop that does not have a way of stopping is a(n) ________ loop

infinite (or endless)

Inside the for loop's parentheses the first expression is the ______ , the second expression is the _ and the third expression is the______

initialization, test, update

The statement "int *ptr;" has the same meaning as

int* ptr;

In any program that uses the cin object, you must include the ________.

iostream header file

Each repetition of a loop is known as a(n) _______

itleration

A binary search begins with the ________ element of an array.

middle

Assume that myCar is an instance of the Car class, and that the Car class has a member function named accelerate. Which of the following is a valid call to the accelerate member function?

myCar.accelerate();

A loop that is inside another is called a(n) _____ loop

nested

What data type do you use when you want to create a file stream object that can write data from a file?

postfix

When the increment or decrement operator is placed after the operand (or to the oper and's right) the operator is being used in _ mode

postfix

A loop that evaluates its test expression after each repetition is a(n) _ loop.

posttest

When the increment or decrement operator is placed before the operand (or to the operands left)), the operator is being used in ________mode

prefix

A loop that evaluates its test expression before each repetition is a(n) _______loop

pretest

Examples of access specifiers are the keywords:

private and public

A(n) _______ is a sum of numbers that accumulates with each iteration of a loop

running total

A variable's ___________ is the part of the program that has access to the variable.

scope

Given the following declaration, where is 77 stored in the scores array? int scores[]={83, 62, 77, 97};

scores[2]

The _________ sort usually performs fewer exchanges than the ________ sort

selection, bubble

A(n) __ is required after the closing brace of a structure declaration.

semicolon

A(n) ________ is a special value that marks the end of a series of values

sentinel (-1,-99)

A two-dimensional array is like ________ put together.

several identical arrays

The advantage of a linear search is its ________.

simplicity

A character literal is enclosed in ________ quotation marks, whereas a string literal is enclosed in ________

single, double

Array elements must be _________ before a binary search can be performed

sorted

A C++ class is similar to one of these

structure

To access an array element, use the array name and the element's ________.

subscript

This is a set of rules that must be strictly followed when writing a program

syntax

The statement cout << &num1; will output

the memory address of the variable called num1.

An element of a two-dimensional array is referred to by ________ followed by ________.

the row subscript of the element, the column subscript of the element

An array can store a group of values, but the values must be

the same data type

The ______ and ______ loops will not iterate at all if their test expressions are false to start with

while and for

Which of the following expressions will determine whether x is less than or equal to y?

x <= y


Ensembles d'études connexes

10. What are the tips for writing true - false questions?

View Set

Pharm Made Easy 4.0 Hematologic System

View Set