CompSci Midterm

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

34) Which of the following is a preprocessor directive?

#include <iomanip>

These are operators that add and subtract one from their operands.

++ and --

Assume that x is an int variable. What value is assigned to x after the following assignment statement is executed? x = - 3 + 4 % 6 / 5;

-3

What is the value stored at x, given the statements: int x; x = 3 / static_cast<int> (4.5 + 6.4);

0

What will the following code display? int numbers[4] = { 99, 87 }; cout << numbers[3] << endl;

0

What will the following loop display? int x = 0; while (x < 5) { cout << x << endl; x++; }

0 1 2 3 4

What will the following loop display? int x = 0; while (x < 5) { cout << x << endl; x++; }

0 1 2 3 4

What will the following loop display? Int X=0; While (X<5) { C out << X << endl; X++; }

0 1 2 3 4 5

What will the following code display? int x = 0, y = 1, z = 2; cout << x << y << z << endl;

012

What will the following code display? int x = 0, y = 1, z = 2; cout << x << y << z << endl;

012

These are data items whose values do not change while the program is running.

Literals

What will the following program segment display? int funny = 7, serious = 15; funny = serious % 2; if (funny != 1) { funny = 0; serious = 0; } else if (funny == 2) { funny = 10; serious = 10; } else { funny = 1; serious = 1; } cout << funny << " " << serious << endl; A) 7 15 B) 0 0 C) 10 10 D) 1 1 E) None of these

1 1

What is the output of the following code segment? n = 1; for ( ; n <= 5; ) cout << n << ' '; n++;

1 1 1 ... and on forever

What is the output of the following code segment? n = 1; while (n <= 5) cout << n << ' '; n++;

1 1 1 ... and on forever

What is the output of the following code segment? n = 1; while (n <= 5) cout << n << ' '; n++;

1 1 1 forever (statements need to be bracketed)

What is the output of the following code segment? n=1; For ( ;n<=5; ) C out << n << ' '; n++;

1 1 1.. And on forever

What is the output of the following code segment? n=1; While (n <= 5) C out << n << ' '; n++;

1 1 1.. And on forever

Which line in the following program contains a call to the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }

10

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

12

What is the output of the following program? #include <iostream> using namespace std; void doSomething(int); int main() { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int num) { num = 0; cout << num << endl; }

2 0 2

What will the value of x be after the following statements execute? int x; x = 18 % 4;

2

What is the output of the following program? #include <iostream> using namespace std; void doSomething(int&); int main() { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int& num) { num = 0; cout << num << endl; }

2 0 0

Illegal Variable?

3dGraph

Which one of the following would be an illegal variable name?

3dGraph

What is the value of number after the following statements execute? int number; number = 18 % 4 + 2;

4

What will the value of x be after the following statements execute? int x; x = 18 / 4;

4

What will the value of x be after the following statements execute? int x; x = 18.0 / 4;

4

What will the following code display? int number = 6; ++number; cout << number << endl;

7

What will the following code display? int number = 6; cout << ++number << endl;

7

What will the following code display? int number = 6; number++; cout << number << endl;

7

What will the following code display? Int number= 6; ++number; C out << number << endl;

7

sequence structure

A type of program structure where the statements are executed in sequence, without branching off in another direction.

34) The default section of a switch statement performs a similar task as the ________ portion of an if/else if statement. A) conditional B) break C) trailing else D) All of these E) None of these

C

3) Which of the following best describes an operator?

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

The = operator means _____, not mathematical equality.

Assignment

The statements in the body of a While loop may never be executed, whereas the statements in the body of a Do-While loop will be executed:

At least once

The statements in the body of a while loop may never be executed, whereas the statements in the body of a do-while loop will be executed:

At least once

29) This operator performs a logical NOT operation. A) -- B) ! C) <> D) >< E) None of these

B

35) Which of the following defines a double-precision floating point variable named payCheck? A) float payCheck; B) double payCheck; C) payCheck double; D) Double payCheck;

B

43) Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 int number = 5; 7 8 if (number >= 0 && <= 100) 9 cout << "passed.\n"; 10 else 11 cout << "failed.\n"; 12 return 0; 13 } A) 6 B) 8 C) 10 D) 9

B

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

B

1) In a C++ program, two slash marks ( // ) indicate: A) The end of a statement B) The beginning of a comment C) The end of the program D) The beginning of a block of code E) None of the above

B

11) Besides decimal, two other number systems you might encounter in C++ programs are: A) Octal and Fractal B) Hexadecimal and Octal C) Unary and Quaternary D) Base 7 and Base 9 E) None of the above

B

17) What is the output of the following statement? cout << 4 * (15 / (1 + 3)) << endl; A) 15 B) 12 C) 63 D) 72 E) None of these

B

19) This is used to mark the end of a complete C++ programming statement. A) Pound Sign B) Semicolon C) Data type D) Void E) None of the above

B

21) In C++ the = operator indicates: A) equality B) assignment C) subtraction D) negation E) None of these

B

21) ________ must be included in any program that uses the cout object. A) Opening and closing braces B) The header file iostream C) Comments D) Escape sequences E) None of the above

B

22) If you use a C++ key word as an identifier, your program will: A) Execute with unpredictable results B) not compile C) understand the difference and run without problems D) Compile, link, but not execute E) None of the above

B

26) These operators connect two or more relational expressions into one, or reverse the logic of an expression. A) relational B) logical C) irrational D) negation E) None of these

B

28) A variable whose value can be either true or false is of this data type. A) binary B) bool C) T/F D) float E) None of the above

B

36) What is the value of donuts after the following code executes? int donuts = 10; if (donuts = 1) donuts = 0; else donuts += 2; A) 12 B) 10 C) 0 D) 1

C

Null terminator '\0'

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

What will the following code do? const int SIZE = 5; double x[SIZE]; for(int i = 2; i <= SIZE; i++) { x[i] = 0.0; }

Each element in the array, except the first and the last, is initialized to 0.0

The amount of memory used by the data type int is _____ the amount of memory used by the data type unsigned int.

Equal to

To allow file access in a program, you must #include this header file.

F stream

10) True/False: C++ 11 introduces an alternative way to define variables, using the template key word and an initialization value.

FALSE

2) True/False: The default section is required in a switch statement.

FALSE

3) True/False: The C++ language requires that you give variables names that indicate what the variables are used for.

FALSE

4) True/False: A variable called "average" should be declared as an integer data type because it will probably hold data that contains decimal places.

FALSE

7) True/False: The following code correctly determines whether x contains a value in the range of 0 through 100. if (x >= 0 && <= 100)

FALSE

8) True/False: If you do not follow a consistent programming style, your programs will generate compiler errors.

FALSE

True/False: Arithmetic operators that share the same precedence have right to left associativity.

FALSE

True/False: If you want to know the length of the string that is stored in a string object, you can call the object's size member function.

FALSE

True/False: In C++, it is impossible to display the number 34.789 in a field of 9 spaces with 2 decimal places of precision.

FALSE

True/False: The fixed manipulator causes a number to be displayed in scientific notation.

FALSE

True/False: The following statement will output $5.00 to the screen: cout << setprecision(5) << dollars << endl;

FALSE

True/False: When a program uses the setw manipulator, the iosetwidth header file must be included in a preprocessor directive.

FALSE

A While loop is somewhat limited, because the counter can only be incremented by one each time through the loop.

False

A variable called "average" should be declared as an integer data type because it will probably hold data that contains decimal places.

False

A while loop is somewhat limited, because the counter can only be incremented by one each time through the loop.

False

Numeric data types in C++ have unlimited ranges.

False

The C++ language requires that you give variables names that indicate what the variables are used for.

False

The condition that is tested by a While loop must be enclosed in parentheses and terminated with a semicolon.

False

The increment and decrement operators can be used in mathematical expressions; however, they cannot be used in relational expressions.

False

The scope of a variable declared in a For loop's Initialization expression always extends beyond the body of the loop.

False

The scope of a variable declared in a for loop's initialization expression always extends beyond the body of the loop.

False

To output multiple lines of text to the user, you must use more than one cout statement.

False

You do not need to pay attention to capitalization in C++, since variable names are not case sensitive.

False

You may nest While and Do-While loops, but you may not nest For loops.

False

You may not use the Break and Continue statements within the same set of nested loops.

False

You may not use the Break statement in a nested loop.

False

During which stage does the central processing unit retrieve from main memory the next instruction in the sequence of program instructions?

Fetch

These are used to declare variables that can hold real numbers.

Floating point data types

If you want a user to enter exactly 20 values, which loop would be the best to use?

For

This loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop.

For

Closing brace

For every opening brace in a C++ program, there must be a

What will the following code display? cout << "Four\n" << "score\n"; cout << "and" << "\nseven"; cout << "\nyears" << " ago" << end;

Four score and seven years ago

What will the following code display? cout << "Four\n" << "score\n"; cout << "and" << "\nseven"; cout << "\nyears" << "ago" << endl;

Four score and seven years ago

What will the following code display? cout << "Four" << "score"; cout << "and" << "seven\n"; cout << "years" << "ago" << endl;

Four score and seven yearsago

In C++ 11, if you want an integer literal to be treated as a long long int, you can append ________ at the end of the number.

LL

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

#include directive

What is the modulus operator?

%

Character constants in C++ are always enclosed in ________.

'single quotation marks'

True/False: The only difference between the get function and the >> operator is that get reads the first character typed, even if it is a space, tab, or the [Enter] key.

TRUE

True/False: When C++ is working with an operator, it strives to convert the operands to the same type.

TRUE

True/False: When the fixed manipulator is used, the value specified by the setprecision manipulator will be the number of digits to appear after the decimal point.

TRUE

This is a control structure that causes a statement or group of statements to repeat.

Loop

What will the following code display? cout << "Monday"; cout << "Tuesday"; cout << "Wednesday:;

MondayTuesdayWednesday

If you place a semicolon after the test expression in a While loop, it is assumed to be a(n):

Null statement

In memory, C++ automatically places a ________ at the end of string literals.

Null terminator

To write data to a file, you define an object of this data type.

Of stream

What is a valid C++ identifier?

Only Alphabets,Digits and Underscores are permitted. Identifier name cannot start with a digit. Key words cannot be used as a name. Upper case and lower case letters are distinct. Special Characters are not allowed. Global Identifier cannot be used as "Identifier".

A file must be ________ before data can be written to or read from it.

Opened

31) A(n) ________ is the most fundamental set of programs on a computer.

Operating System

The Do-While loop is a -blank- loop that is ideal in the situations where you always want the loop to iterate at least once.

Post-test

The Do-While loop is considered a(n) -blank- loop.

Post-test

The While loop is this type of loop.

Pre-test

When the increment operator precedes its operand, as in ++num1, the expression is on this mode.

Prefix

This operator increments the value of its operand, then uses the value in context.

Prefix increment

A statement that starts with a # is called a

Preprocessor directive

A statement that starts with a # symbol is called a:

Preprocessor directive

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

Program

32) This is a volatile type of memory, used for temporary storage.

RAM

9) The computer's main memory is commonly known as:

RAM

The computer's main memory is commonly known as

RAM

The computer's main memory is commonly known as:

RAM

boolean expression

Relational expressions are also known as _____. Value can only be true or false.

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

Semicolon

This is a special value hat marks the end of a list of values.

Sentinel

Character constants in C++ are always enclosed in _____.

Single quotation marks

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

Single, Double

38) In the process of translating a source file into an executable file, which of the following is the correct sequence?

Source code, preprocessor, modified source code, compiler, object code, linker, executable code.

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

Statement

This may be used to write information to a file.

Stream insertion operator

In programming terms, a group of characters inside a set of quotation marks is called aNo:

String literal

This is a set of rules that must be followed when constructing a program.

Syntax

1) True/False: If the sub-expression on the left side of the || operator is true, the expression on the right side will not be checked.

TRUE

1) True/False: When typing in your source code into the computer, you must be very careful since most of your C++ instructions, header files, and variable names are case sensitive.

TRUE

2) True/False: A preprocessor directive does not require a semicolon at the end.

TRUE

3) True/False: Both of the following if statements perform the same operation. if (sales > 10000) commissionRate = 0.15; if (sales > 10000) commissionRate = 0.15;

TRUE

4) True/False: You should be careful when using the equality operator to compare floating point values because of potential round-off errors.

TRUE

5) True/False: An expression that has any value other than 0 is considered true by an if statement.

TRUE

5) True/False: Escape sequences are always stored internally as a single character.

TRUE

6) True/False: Floating point constants are normally stored in memory as doubles.

TRUE

6) True/False: If the sub-expression on the left side of an && operator is false, the expression on the right side will not be checked.

TRUE

7) True/False: C++ does not have a built in data type for storing strings of characters.

TRUE

8) True/False: As a rule of style, when writing an if statement you should indent the conditionally-executed statements.

TRUE

9) True/False: When writing long integer literals or long long integer literals in C++ 11, you can use either an uppercase or lowercase L.

TRUE

True/False: The cin << statement will stop reading input when it encounters a newline character.

TRUE

What will the following code display? int number = 23; cout << "The number is " << "number" << endl;

The number is number

What will the following code display? int number = 7; cout << "The number is " << "number" << endl;

The number is number

What will the following code display? int number = 7; cout << "The number is " << "number" << endl;

The number is number

What does the term hardware refer to?

The physical components that a computer is made of

priming read

The read operation that takes place just before the loop is called a _____. It provides the first value for the loop to test.

When typing in your source code into the computer, you must be very careful since most of your C++ instructions, header files, and variable names are case sensitive.

True

A For statement contains three expressions, Initialization, test, and:

Update

You may define a -blank- in the Initialization expression of a For loop.

Variable

________ represent storage locations in the computer's memory.

Variables

_____________ represent storage locations in the computer's memory.

Variables

read position

When a file has been opened for input, the file stream object internally maintains a special value known as a _____.

Which of the following statements correctly defines a named constant named TAX_RATE that holds the value 0.075?

const double TAX_RATE = 0.075;

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

cout object

28) During which stage does the central processing unit analyze the instruction and encode it in the form of a number, and then generate an electronic signal?

decode

You must have a ________ for every variable you intend to use in a program.

definition

The programming process consists of several steps, which include:

design, creation, testing, and debugging

16) This term refers to the programmer reading the program from the beginning and stepping through each statement.

desk checking

Using C++11: What data type does the compiler determine for the variable cost in the following statement? auto cost = 14.95;

double

Which of the following defines a double-precision floating point variable named payCheck?

double payCheck;

The end of a printed line can be signaled by sending _____ to the cout object

endl

13) During which stage does the central processing unit retrieve from main memory the next instruction in the sequence of program instructions?

fetch

40) A(n) ________ is a diagram that shows the logical flow of a program.

flow chart

If you want a user to enter exactly 20 values, which loop would be the best to use?

for

Every complete C++ program must have a ________.

function named main

36) In a broad sense, the two primary categories of programming languages are:

high-low language

Look at the following function prototype. int myFunction(double); What is the data type of the funtion's return value?

int

How would you consolidate the following declaration statements into one statement? int x = 7; int y = 16; int z = 28;

int x = 7, y = 16, z = 28;

Which of the following correctly consolidates the following declaration statements into one statement? int x = 7; int y = 16; int z = 28; select one:

int x = 7, y = 16, z = 28;

The numeric data types in C++ can be broken into two general categories:

integer and floating point

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

keywords

Which of the following statements correctly assigns the character M to the variable named letter?

letter = 'M';

note

note. Precedence and Associativity of Logical operators. in order of precedence ! && ||

note

note. The do-while loop is a good choice for repeating a menu.

note

note. The do-while loop. The do-while loop is also a conditional loop. Unlike the while loop, however, do-while is a posttest loop. It is ideal in situations where you always want the loop to iterate at least once. The do-while loop is a good choice for repeating a menu.

note.

note. The while loop. a conditional loop, which means it repeats as long as a particular condition exists. It is also a pretest loop, so it is ideal in situations where yo do not want the loop to iterate if the condition is false from the beginning. For example, validating input that has been read and reading lists of data terminated by a sentinel value are good applications of the while loop.

note.

note. You should use the do-while loop when you want to make sure the loop executes at least once.

37) Which of the following is not one of the five major components of a computer system?

preprocessor

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

program

17) This is used in a program to mark the beginning or ending of a statement, or separate items in a list.

punctuation

2) At the heart of a computer is its central processing unit. The CPU's job is:

run software

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

scope

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

secondary storage

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

secondary storage

How would you consolidate the following declaration statements into one statement? short a = 1; short a = 5; short a = 7;

short a = 1, b = 5, c = 7;

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

single, double

4) An Integrated Development Environment typically consists of:

text editor-compiler-debugger

sequential access

when you work with a _____ file, you access data from the beginning of the file to the end of the file.

What will the value of x be after the following statements execute? int x = 0; int y = 5; int z = 4; x = y + z * 2;

13

Which line in the following program contains the header for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }

15 (end chapter 6)

Given the following function definition: void calc (int a, int& b) { int c; c = a + 2; a = a * 3; b = c + a; } What is the output of the following code fragment that invokes calc? (All variables are of type int) x = 1; y = 2; z = 3; calc(x, y); cout << x << " " << y << " " << z << endl;

163

How many times will the following loop display "Hello"? For (int i=1; i< 20; i++) C out << "Hello!" << endl;

19

How many times will the following loop display "Hello"? for (int i = 1; i < 20; i++) cout << "Hello!" << endl;

19

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

2

What will the value of result be after the following statement executes? result = 6 - 3 * 2 + 7 - 10 / 2 ;

2

How many times will the following loop display "Hello"? For (int i=0; i <20; i++) C out << "Hello!" << endl;

20

How many times will the following loop display "Hello"? For (int i=20; i>0; i--) C out << "Hello!" << endl;

20

How many times will the following loop display "Hello"? for (int i = 0; i < 20; i++) cout << "Hello!" << endl;

20

How many times will the following loop display "Hello"? for (int i = 20; i > 0; i--) cout << "Hello!" << endl;

20

What will the value of x be after the following statements execute? x = (19 − 3) * (2 + 3) / 4

20

How many times will the following loop display "Hello"? For (int i =0; i <= 20; i++) C out << "Hello!" << endl;

21

How many times will the following loop display "Hello"? for (int i = 0; i <= 20; i++) cout << "Hello!" << endl;

21

What will the following code display? int x = 23, y = 34, z = 45; cout << x << y << z << endl;

233445

Look at the following function prototype. int myFunction(double, double, double); How many parameter variables does this function have?

3

What is the value stored in the variable myNum after the following assignment statement executes? myNum = 23 % 5

3

What will the following code display? int x = 0; for (int count = 0; count < 3; count++) x += count; cout << x << endl;

3

What will the following code display? int x = 0; for (int count = 0; count < 3; count++) x += count; cout << x << endl;

3

What will the following code display? int x=0; For (int count=0; count < 3; count ++) X += count; C out << 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;

3 * 2

Which line in the following program contains the prototype for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }

4

What is the output of the following program? #include <iostream> using namespace std; void showDub(int); int main() { int x = 2; showDub(x); cout << x << endl; return 0; } void showDub(int num) { cout << (num * 2) << endl; }

4 2

What is the value of average after the following code executes? double average; average = 1.0 + 2.0 + 3.0 / 3.0;

4.0

What will the following code display? int number = 6; int x = 0; x = --number; cout << x << endl;

5

What will the following code display? Int number=6 Int X=0; X= --number; C out << X << endl;

5

What will the following code display? Int number= 6; Int X=0; X=number--; C out << X << endl;

6

What will the following code display? Int number=6; C out << number++ << endl;

6

What will the following code display? int number = 6; cout << number++ << endl;

6

What will the following code display? int number = 6; int x = 0; x = number--; cout << x << endl;

6

What is the output of the following program? #include <iostream> using namespace std; int getValue(int); int main() { int x = 2; cout << getValue(x) << endl; return 0; } int getValue(int num) { return num + 5; }

7

What will the following code display? Int number=6; C out << ++number << endl;

7

What will the following code display? Int number=6; Number++; C out << number << endl;

7

Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL = 77; 7 MY_VAL = 99; 8 cout << MY_VAL << endl; 9 return 0; 10 }

7

Assuming you are using a system with 1-byte characters, how many bytes of memory will the following string literal occupy? "William"

8

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

Following statement While (x++ < 10) Which operator is used first?

<

Look at the following statement. while (x++ < 10) Which operator is used first?

<

23) 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; A) C++ is fun B) Soccer is fun C) C++ D) C++fun E) Soccerfun

A

25) When a program lets the user know that an invalid choice has been made, this is known as: A) input validation B) output correction C) compiler criticism D) output validation E) None of these

A

27) The float data type is considered ________ precision, and the double data type is considered ________ precision. A) single, double B) float, double C) integer, double D) short, long E) None of the above

A

The statement: cin >> setw(10) >> str; will read up to this many characters into str. A) Nine B) Ten C) Eleven D) Eight E) None of these

A

Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL; 7 MY_VAL = 77; 8 cout << MY_VAL << endl; 9 return 0; 10 } A) 6 B) 8 C) 9 D) 7

A

Which statement is equivalent to the following? number += 1; A) number = number + 1; B) number + 1; C) number = 1; D) None of these

A

17) This statement uses the value of a variable or expression to determine where the program will branch to. A) switch B) select C) associative D) scope E) None of these

A

18) In programming terms, a group of characters inside a set of quotation marks is called a(n): A) String literal B) Variable C) Operation D) Statement E) None of the above

A

18) Without this statement appearing in a switch construct, the program "falls through" all of the statements below the one with the matching case expression. A) break B) exit C) switch D) scope E) None of these

A

2) After execution of the following code, what will be the value of input_value if the value 0 is entered at the keyboard at run time? cin >> input_value; if (input_value > 5) input_value = input_value + 5; else if (input_value > 2) input_value = input_value + 10; else input_value = input_value + 15; A) 15 B) 10 C) 25 D) 0 E) 5

A

23) What is the value of cookies after the execution of the following statements? int number = 38, children = 4, cookies; cookies = number % children; A) 2 B) 0 C) 9 D) .5 E) None of these

A

27) What will the following program display? #include <iostream> using namespace std; int main() { int a = 0, b = 2, x = 4, y = 0; cout << (a == b) << " "; cout << (a != b) << " "; cout << (b <=x) << " "; cout << (y > a) << endl; return 0; } A) 0 1 1 0 B) 0 0 1 0 C) 1 1 0 1 D) 1 0 0 1 E) None of these

A

35) What is the value of donuts after the following code executes? int donuts = 10; if (donuts != 10) donuts = 0; else donuts += 2; A) 12 B) 10 C) 0 D) 2

A

38) What is the value of the following expression? true && true A) true B) false C) -1 D) +1

A

39) What is the value of the following expression? true || true A) true B) false C) -1 D) +1

A

39) What will the following code display? cout << "Four\n" << "score\n"; cout << "and" << "\nseven"; cout << "\nyears" << " ago" << endl; A) Four score and seven years ago B) Four score and seven years ago C) Four score and seven years ago D) Four score and seven years ago

A

40) What is the value of the following expression? false || true A) true B) false C) -1 D) +1

A

44) What will the value of x be after the following statements execute? int x; x = 18.0 / 4; A) 4.5 B) 4 C) 0 D) unknown

A

50) In C++ 11, the ________ tells the compiler to determine the variable's data type from the initialization value. A) auto key word B) #include preprocessor directive C) variable's name D) dynamic_cast key word E) None of the above

A

7) These are data items whose values do not change while the program is running. A) Literals B) Variables C) Comments D) Integers E) None of the above

A

This function tells the cin object to skip one or more characters in the keyboard buffer. A) cin.ignore B) cin.jump C) cin.hop D) cin.skip; E) None of the above

A

What will the value of x be after the following statements execute? int x = 0; int y = 5; int z = 4; x = y + z * 2; A) 13 B) 18 C) 0 D) unknown

A

When converting some algebraic expressions to C++, you may need to insert ________ that do not appear in the algebraic expression. A) Parentheses B) Exponents C) Calculations D) Coercions E) None of the above

A

Which is true about the following statement? cout << setw(4) << num4 << " "; A) It allows four spaces for the value in the variable num4. B) It outputs "setw(4)" before the value in the variable num4. C) It should use setw(10) to output the value in the variable num10. D) It inputs up to four characters stored in the variable num4. E) None of these

A

text

A _____ file contains data that has been encoded as text, using a scheme such as ASCII or unicode.

binary

A _____ file contains data that has not been converted to text.

file buffer

A _____ is a small holding section of memory that file-bound data is first written to.

file stream object

A _____ is an object that is associated with a specific file and provides a way for the program to work with that file.

relational expression

A _____ is used to determine whether x is greater than y.

conditional

A _____ loop executes as long as a particular condition exists.

count controlled

A _____ loop is a loop that repeats a specific number of times.

note

A branch occurs when one part of a program causes another part to execute.

single, double

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

An Integrated Development Environment (IDE) typically consists of:

A debugger, text editor, and compiler

A loop that is inside another loop is called:

A nested loop

The While loop has two important parts: an expression that is tested for a true or false value, and:

A statement or block that is repeated as long as the expression is true.

Preprocessor directive

A statement that starts with a # is called a

What will the following program display? #include <iostream> using namespace std; int main() { int a = 0, b = 2, x = 4, y = 0; cout << (a == b) << " "; cout << (a != b) << " "; cout << (b <=x) << " "; cout << (y > a) << endl; return 0; } A) 0 1 1 0 B) 0 0 1 0 C) 1 1 0 1 D) 1 0 0 1 E) None of these

A) 0 1 1 0

What is the value of donuts after the following code executes? int donuts = 10; if (donuts != 10) donuts = 0; else donuts += 2; A) 12 B) 10 C) 0 D) 2

A) 12

After execution of the following code, what will be the value of input_value if the value 0 is entered at the keyboard at run time? cin >> input_value; if (input_value > 5) input_value = input_value + 5; else if (input_value > 2) input_value = input_value + 10; else input_value = input_value + 15; A) 15 B) 10 C) 25 D) 0 E) 5

A) 15

What will be the value of result after the following code has been executed? int a = 60; int b = 15; int result = 10; if (a = b) result *= 2; A) 10 B) 120 C) 20 D) This code will not compile

A) 20

Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL; 7 MY_VAL = 77; 8 cout << MY_VAL << endl; 9 return 0; 10 } A) 6 B) 8 C) 9 D) 7

A) 6

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

A) C++ is fun

What will the following code display? cout << "Four\n" << "score\n"; cout << "and" << "\nseven"; cout << "\nyears" << " ago" << endl; A) Four score and seven years ago B) Four score and seven years ago C) Four score and seven years ago D) Four score and seven years ago

A) Four score and seven years ago

Which is true about the following statement? cout << setw(4) << num4 << " "; A) It allows four spaces for the value in the variable num4. B) It outputs "setw(4)" before the value in the variable num4. C) It should use setw(10) to output the value in the variable num10. D) It inputs up to four characters stored in the variable num4. E) None of these

A) It allows four spaces for the value in the variable num4.

5) The purpose of a memory address is:

A) To identify the location of a byte in memory

3) 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; A) Nothing will be displayed. B) false C) x D) true

B

31) Every complete C++ program must have a ________. A) comment B) function named main C) preprocessor directive D) symbolic constant E) cout statement

B

33) Given that, x = 2, y = 1, and z = 0, what will the following cout statement display? cout << "answer = " << (x || !y && z) << endl; A) answer = 0 B) answer = 1 C) answer = 2 D) None of these

B

33) Which one of the following would be an illegal variable name? A) dayOfWeek B) 3dGraph C) _employee_num D) June1997 E) itemsorderedforthemonth

B

37) What is the value of the following expression? true && false A) true B) false C) -1 D) +1

B

37) What will the following code display? int number = 7; cout << "The number is " << "number" << endl; A) The number is 7 B) The number is number C) The number is7 D) The number is 0

B

43) What will the value of x be after the following statements execute? int x; x = 18 / 4; A) 4.5 B) 4 C) 0 D) unknown

B

48) Assume that a program has the following string object definition: string name; Which of the following statements correctly assigns a string literal to the string object? A) name = Jane; B) name = "Jane"; C) name = 'Jane'; D) name = (Jane);

B

5) If you place a semicolon after the statement: if (x < y) A) The code will not compile. B) The compiler will interpret the semicolon as a null statement. C) The if statement will always evaluate to false. D) All of the above E) None of these

B

6) When a relational expression is false, it has the value ________. A) one B) zero C) zero, one, or minus one D) less than zero E) None of these

B

6) ________ represent storage locations in the computer's memory. A) Literals B) Variables C) Comments D) Integers E) None of the above

B

8) You must have a ________ for every variable you intend to use in a program. A) purpose B) definition C) comment D) constant E) None of the above

B

9) What will the following segment of code output? Assume the user enters a grade of 90 from the keyboard. cout << "Enter a test score: "; cin >> test_score; if (test_score < 60); cout << "You failed the test!" << endl; if (test_score > 60) cout << "You passed the test!" << endl; else cout << "You need to study for the next test!"; A) You failed the test! B) You passed the test! C) You failed the test! You passed the test! D) You failed the test! You did poorly on the test! E) None of the above

B

In any program that uses the cin object, you must include the ________. A) compiler B) iostream header file C) linker D) >> and << operators E) None of the above

B

The ________ causes a program to wait until information is typed at the keyboard and the Enter key is pressed. A) Output stream B) cin object C) cout object D) Preprocessor E) None of the above

B

The function, pow(x, 5.0), requires this header file. A) cstdlib B) cmath C) cstring D) iostream E) iomanip

B

What is the value of average after the following code executes? double average; average = 1.0 + 2.0 + 3.0 / 3.0; A) 2.0 B) 4.0 C) 1.5 D) 6.0

B

What is the value stored at x, given the statements: int x; x = 3 / static_cast<int>(4.5 + 6.4); A) .3 B) 0 C) .275229 D) 3.3 E) None of these

B

When a variable is assigned a number that is too large for its data type, it: A) underflows B) overflows C) reverses polarity D) exceeds expectations E) None of the above

B

When using the sqrt function you must include this header file. A) cstdlib B) cmath C) cstring D) iostream E) iomanip

B

Which statement is equivalent to the following? x = x * 2; A) x * 2; B) x *= 2; C) x = x * x; D) None of these

B

You can use these to override the rules of operator precedence in a mathematical expression. A) [Brackets] B) (Parentheses) C) {Braces} D) The escape character \ E) None of these

B

You want the user to enter the length, width, and height from the keyboard. Which cin statement is correctly written? A) cin << length, width, height; B) cin.get(length, width, height); C) cin >> length >> width >> height; D) cin >> length, width, height; E) cin << length; width; height;

B

________ reads a line of input, including leading and embedded spaces, and stores it in a string object. A) cin.get B) getline C) cin.getline D) get E) None of these

B

What is the value stored at x, given the statements: int x; x = 3 / static_cast<int>(4.5 + 6.4); A) .3 B) 0 C) .275229 D) 3.3 E) None of these

B) 0

What is the value of average after the following code executes? double average; average = 1.0 + 2.0 + 3.0 / 3.0; A) 2.0 B) 4.0 C) 1.5 D) 6.0

B) 4.0

Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 int number = 5; 7 8 if (number >= 0 && <= 100) 9 cout << "passed.\n"; 10 else 11 cout << "failed.\n"; 12 return 0; 13 } A) 6 B) 8 C) 10 D) 9

B) 8

The following code correctly determines whether x contains a value in the range of 0 through 100 . if (x >= 0 && <= 100) A) True B) False

B) False

The statement cout << setprecision(5) << dollars << endl; will output $5.00 to the screen. A) True B) False

B) False

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; A) Nothing will be displayed B) false C) x D) true

B) False

What will the following code display? int number = 7; cout << "The number is " << "number" << endl; A) The number is 7 B) The number is number C) The number is7 D) The number is 0

B) The number is number

Given that x = 2, y = 1, and z = 0, what will the following cout statement display? cout << "answer = " << (x || !y && z) << endl; A) answer = 0 B) answer = 1 C) answer = 2 D) None of these

B) answer = 1

This statement causes a loop to terminate early.

Break

A file -blank- is a small holding section of memory that file-bound information is first written to.

Buffer

This statement will pause the screen, until the [Enter] key is pressed. A) cin; B) cin.getline(); C) cin.get(); D) cin.ignore(); E) cin.input();

C

10) When an if statement is placed within the conditionally-executed code of another if statement, this is known as: A) complexity B) overloading C) nesting D) validation E) None of these

C

12) What will the following segment of code output? score = 40; if (score > 95) cout << "Congratulations!\n"; cout << "That's a high score!\n"; cout << "This is a test question!" << endl; A) This is a test question! B) Congratulations! That's a high score! This is a test question! C) That's a high score! This is a test question! D) Congratulations! That's a high score! E) None of these

C

15) Assuming x is 5, y is 6, and z is 8, which of the following is false? 1. x == 5; 2. 7 <= (x + 2); 3. z < = 4; 4. (1 + x) != y; 5. z >= 8; 6. x >= 0; 7. x <= (y * 2) A) 3, 4, 6, 7 are false. B) Only 5 is false. C) 3 and 4 are false. D) All are false. E) None of these.

C

19) Whereas < is called a relational operator, x < y is called a(n) ________. A) Arithmetic operator B) Relative operator C) Relational expression D) Largeness test E) None of these

C

32) This control sequence is used to skip over to the next horizontal tab stop. A) \n B) \h C) \t D) \a E) \'

C

40) What will the following code display? cout << "Four " << "score "; cout << "and " << "seven/n"; cout << "years" << "ago" << endl; A) Four score and seven yearsago B) Four score and seven years ago C) Four score and seven/nyearsago D) Four score and seven yearsago

C

42) Assume that a program has the following variable definition: char letter; Which of the following statements correctly assigns the character Z to the variable? A) letter = Z; B) letter = "Z"; C) letter = 'Z'; D) letter = (Z);

C

46) Assuming you are using a system with 1-byte characters, how many bytes of memory will the following string literal occupy? "William" A) 7 B) 14 C) 8 D) 1

C

1) Relational operators allow you to ________ numbers. A) add B) multiply C) compare D) average E) None of these

C

10) The numeric data types in C++ can be broken into two general categories: A) numbers and characters B) singles and doubles C) integer and floating point D) real and unreal E) None of the above

C

11) What is the output of the following segment of code if the value 4 is input by the user when asked to enter a number? int num; int total = 0; cout << "Enter a number from 1 to 10: "; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 4: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout << total << endl; A) 0 B) 3 C) 13 D) 28 E) None of these

C

13) In memory, C++ automatically places a ________ at the end of string literals. A) Semicolon B) Quotation marks C) Null terminator D) Newline escape sequence E) None of the above

C

13) This operator represents the logical AND. A) ++ B) || C) && D) @ E) None of these

C

2) A statement that starts with a # symbol is called a: A) Comment B) Function C) Preprocessor directive D) Key word E) None of the above

C

20) Which character signifies the beginning of an escape sequence? A) // B) / C) \ D) # E) {

C

25) Character constants in C++ are always enclosed in ________. A) [brackets] B) "double quotation marks" C) 'single quotation marks' D) {braces} E) (parentheses)

C

26) These are used to declare variables that can hold real numbers. A) Integer data types B) Real data types C) Floating point data types D) Long data types E) None of the above

C

30) A variable's ________ is the part of the program that has access to the variable. A) data type B) value C) scope D) reach E) None of the above

C

31) Which statement allows you to properly check the char variable code to determine whether it is equal to a "C" and then output "This is a check" and then advance to a new line? A) if code is equal to C cout << "This is a check\n"; B) if (code = "C") cout << "This is a check" << endl; C) if (code == 'C') cout << "This is a check\n"; D) if (code == C) cout << "This is a check" << endl;

C

32) The ________ of a variable is limited to the block in which it is declared. A) precedence B) associativity C) scope D) branching ability E) None of these

C

34) Look at the following program and answer the question that follows it. 1 // This program displays my gross wages. 2 // I worked 40 hours and I make $20.00 per hour. 3 #include <iostream> 4 using namespace std; 5 6 int main() 7 { 8 int hours; 9 double payRate, grossPay; 10 11 hours = 40; 12 payRate = 20.0; 13 grossPay = hours * payRate; 14 cout << "My gross pay is $" << grossPay << endl; 15 return 0; 16 } Which line(s) in this program cause output to be displayed on the screen? A) 13 and 14 B) 8 and 9 C) 14 D) 13 E) 15

C

36) What will the following code display? cout << "Monday"; cout << "Tuesday"; cout << "Wednesday"; A) Monday Tuesday Wednesday B) Monday Tuesday Wednesday C) MondayTuesdayWednesday D) "Monday" "Tuesday" "Wednesday"

C

4) The ________ is/are used to display information on the computer's screen. A) Opening and closing braces B) Opening and closing quotation marks C) cout object D) Backslash E) None of the above

C

42) Which value can be entered to cause the following code segment to display the message: "That number is acceptable." int number; cin >> number; if (number > 10 && number < 100) cout << "That number is acceptable.\n"; else cout << "That number is not acceptable.\n"; A) 100 B) 10 C) 99 D) 0 E) All of these

C

44) Which of the following expressions will determine whether x is less than or equal to y? A) x > y B) x =< y C) x <= y D) x >= y

C

45) What will be the value of result after the following code has been executed? int a = 60; int b = 15; int result = 10; if (a = b) result *= 2; A) 10 B) 120 C) 20 D) This code will not compile.

C

45) What will the value of x be after the following statements execute? int x; x = 18 % 4; A) 0.45 B) 4 C) 2 D) unknown

C

7) This is a variable, usually a bool or an int, that signals when a condition exists. A) relational operator B) arithmetic operator C) flag D) float E) None of these

C

Associativity is either right to left or: A) Top to bottom B) Front to back C) Left to right D) Undeterminable E) None of the above

C

The ________ operator always follows the cin object, and the ________ operator follows the cout object. A) binary, unary B) conditional, binary C) >>, << D) <<, >> E) None of the above

C

This manipulator causes the field to be left-justified with padding spaces printed to the right. A) left_justify B) right C) left D) left_pad E) None of these

C

This manipulator is used to establish a field width for the value immediately following it. A) field_width B) set_field C) setw D) iomanip E) None of the above

C

This stream manipulator forces cout to print the digits in fixed-point notation. A) setprecision(2) B) setw(2) C) fixed D) setfixed(2) E) None of these

C

What is the value of number after the following statements execute? int number = 10; number += 5; number -= 2; number *= 3; A) 3 B) 30 C) 15 D) 2

C

When the final value of an expression is assigned to a variable, it will be converted to: A) The smallest C++ data type B) The largest C++ data type C) The data type of the variable D) The data type of the expression E) None of the above

C

Which statement will read an entire line of input into the following string object? string address; A) cin << address; B) cin address; C) getline(cin, address); D) cin.get(address); E) None of the above

C

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

C) 0

What is the output of the following segment of code if 4 is input by the user when asked to enter a number? int num; int total = 0; cout << "Enter a number from 1 to 10: "; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 4: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout << total << endl; A) 0 B) 3 C) 13 D) 28 E) None of these

C) 13

1 // This program displays my gross wages. 2 // I worked 40 hours and I make $20.00 per hour. 3 #include <iostream> 4 using namespace std; 5 6 int main() 7 { 8 int hours; 9 double payRate, grossPay; 10 11 hours = 40; 12 payRate = 20.0; 13 grossPay = hours * payRate; 14 cout << "My gross pay is $" << grossPay << endl; 15 return 0; 16 } Which line(s) in this program cause output to be displayed on the screen? A) 13 and 14 B) 8 and 9 C) 14 e. 15 D) 13

C) 14

Assuming x is 5, y is 6, and z is 8, which of the following is false? 1. x == 5; 2. 7 <= (x + 2); 3. z < = 4; 4. (1 + x) != y; 5. z >= 8; 6. x >= 0; 7. x <= (y * 2) A) 3, 4, 6, 7 are False B) Only 5 is False C) 3 and 4 are False D) All are False E) None of these are False

C) 3 and 4 are false

Which value can be entered to cause the following code segment to display the message "That number is acceptable." int number; cin >> number; if (number > 10 && number < 100) cout << "That number is acceptable.\n"; else cout << "That number is not acceptable.\n"; A) 100 B) 10 C) 99 D) 0 E) All of these

C) 99

What will the following code display? cout << "Four " << "score "; cout << "and " << "seven/n"; cout << "years" << "ago" << endl; A) Four score and seven yearsago B) Four score and seven years ago C) Four score and seven/nyearsago D) Four score and seven yearsago

C) Four score and seven/nyearsago

What will the following code display? cout << "Monday"; cout << "Tuesday"; cout << "Wednesday"; A) Monday Tuesday Wednesday B) Monday Tuesday Wednesday C) MondayTuesdayWednesday D) "Monday" "Tuesday" "Wednesday"

C) MondayTuesdayWednesday

What will the following segment of code output? score = 40; if (score > 95) cout << "Congratulations!\n"; cout << "That's a high score!\n"; cout << "This is a test question!" << endl; A) This is a test question! B) Congratulations! That's a high score! This is a test question! C) That's a high score! This is a test question! D) Congratulations! That's a high score! E) None of these

C) That's a high score! This is a test question!

What will the following segment of code output? You can assume the user enters a grade of 90 from the keyboard. cout << "Enter a test score: "; cin >> test_score; if (test_score < 60); cout << "You failed the test!" << endl; if (test_score > 60) cout << "You passed the test!" << endl; else cout << "You need to study for the next test!"; A) You failed the test! B) You passed the test! C) You failed the test! You passed the test! D) You failed the test! You did poorly on the test! E) None of the above

C) You failed the test! You passed the test!

Assuming dataFile is a file stream object, the statement dataFile.close ( );

Closes a file

For every opening brace in a C++ program, there must be a

Closing Brace

For every opening brace in a C++ program, there must be a:

Closing brace

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

Compilers

This statement may be used to stop a loop's current iteration and begin the next one.

Continue

The ________ decodes an instruction and generates electrical signals

Control Unit

The ________ decodes an instruction and generates electrical signals.

Control Unit

10) The ________ decodes an instruction and generates electrical signals.

Control unit

This is a variable that is regularly incremented or decremented each time a loop iterates.

Counter

The ______ is/are used to display information on the computer's screen.

Cout object

38) What will the following code display? int x = 0, y = 1, z = 2; cout << x << y << z << endl; A) 0 1 2 B) 0 1 2 C) xyz D) 012

D

4) What is assigned to the variable a given the statement below with the following assumptions: x = 10, y = 7, and z, a, and b are all int variables. a = x >= y; A) 10 B) 7 C) The string "x >= y" D) 1 E) 0

D

41) What is the output of the following code? int w = 98; int x = 99; int y = 0; int z = 1; if (x >= 99) { if (x < 99) cout << y << endl; else cout << z << endl; } else { if (x == 99) cout << x << endl; else cout << w << endl; } A) 98 B) 99 C) 0 D) 1

D

8) What is the output of the following code segment? int x = 5; if (x = 2) cout << "This is true!" << endl; else cout << "This is false!" << endl; cout << "This is all folks!" << endl; A) This is true! B) This is false! C) This is true! This is false! D) This is true! This is all folks! E) None of these

D

12) A character literal is enclosed in ________ quotation marks, whereas a string literal is enclosed in ________ quotation marks. A) double, single B) triple, double C) open, closed D) single, double E) None of the above

D

14) This operator takes an operand and reverses its truth or falsehood. A) || B) relational C) arithmetic D) ! E) None of these

D

15) What is the modulus operator? A) + B) * C) & D) % E) ||

D

16) Input values should always be checked for: A) Appropriate range B) Reasonableness C) Division by zero, if division is taking place D) All of these E) None of these

D

16) Which data type typically requires only one byte of storage? A) short B) int C) float D) char E) double

D

20) This operator is used in C++ to represent equality. A) = B) >< C) !! D) == E) None of these

D

22) If you intend to place a block of statements within an if statement, you must place these around the block. A) Parentheses ( ) B) Square brackets [ ] C) Angle brackets < > D) Curly braces { } E) None of these

D

24) What will the following program segment display? int funny = 7, serious = 15; funny = serious % 2; if (funny != 1) { funny = 0; serious = 0; } else if (funny == 2) { funny = 10; serious = 10; } else { funny = 1; serious = 1; } cout << funny << " " << serious << endl; A) 7 15 B) 0 0 C) 10 10 D) 1 1 E) None of these

D

28) This operator is known as the logical OR operator. A) -- B) // C) # D) || E) None of these

D

29) Which of the following correctly consolidates the following declaration statements into one statement? int x = 7; int y = 16; int z = 28; A) int x = 7; y = 16; z = 28; B) int x = 7 y = 16 z = 28; C) int x, y, z = 7, 16, 28 D) int x = 7, y = 16, z = 28; E) None of these will work.

D

3) For every opening brace in a C++ program, there must be a: A) String literal B) Function C) Variable D) Closing brace E) None of the above

D

30) 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; A) 0 B) 1 C) 2 D) 3 E) None of these

D

41) What will the following code display? cout << "Four" << "score" << endl; cout << "and" << "seven" << endl; cout << "years" << "ago" << endl; A) Four score and seven years ago B) Four score and seven years ago C) Fourscoreandsevenyearsago D) Fourscore andseven yearsago

D

47) The first step in using the string class is to #include the ________ header file. A) iostream B) cctype C) cmath D) string E) None of the above

D

49) In C++ 11, if you want an integer literal to be treated as a long long int, you can append ________ at the end of the number. A) L B) <INT> C) I D) LL E) None of the above

D

5) The ________ causes the contents of another file to be inserted into a program. A) Backslash B) Pound sign C) Semicolon D) #include directive E) None of the above

D

Assume that x is an int variable. What value is assigned to x after the following assignment statement is executed? x = -3 + 4 % 6 / 5; A) 0 B) 1 C) 2 D) —3 E) None of these

D

The total number of digits that appear before and after the decimal point is sometimes referred to as: A) floating points B) significant digits C) precision D) B and C E) None of these

D

To use the rand() function, you must #include this header file in your program. A) iostream B) iomanip C) iorand D) cstdlib E) None of these

D

What will the value of result be after the following statement executes? result = 6 - 3 * 2 + 7 - 10 / 2 ; A) 8 B) 6 C) 1.5 D) 2

D

When this operator is used with string operands it concatenates them, or joins them together. A) & B) * C) % D) + E) None of the above

D

Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL = 77; 7 MY_VAL = 99; 8 cout << MY_VAL << endl; 9 return 0; 10 } A) 6 B) 8 C) 9 D) 7

D

What will the following code display? int x = 0, y = 1, z = 2; cout << x << y << z << endl; A) 0 1 2 B) 0 1 2 C) xyz D) 012

D) 012

What is the output of the following code? int w = 98; int x = 99; int y = 0; int z = 1; if (x >= 99) { if (x < 99) cout << y << endl; else cout << z << endl; } else { if (x == 99) cout << x << endl; else cout << w << endl; } A) 98 B) 99 C) 0 D) 1

D) 1

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; A) 0 B) 1 C) 2 D) 3 E) None of these

D) 3

What will the following code display? cout << "Four" << "score" << endl; cout << "and" << "seven" << endl; cout << "years" << "ago" << endl; A) Four score and seven years ago B) Four score and seven years ago C) Fourscoreandsevenyearsago D) Fourscore andseven yearsago

D) Fourscore andseven yearsago

During which stage does the central processing unit analyze the instruction and encode it in the form of a number, and then generate an electronic signal?

Decode

You must have a ___________ for every variable you intend to use in a program.

Definiton

6) The programming process consists of several steps, which include:

Design, Creation, Testing, and Debugging

14) Which escape sequence causes the cursor to move to the beginning of the current line? A) \n B) \t C) \a D) \b E) \r

E

24) This function in C++ allows you to identify how many bytes of storage on your computer system an integer data value requires. A) len B) bytes C) f(x) D) int E) sizeof

E

9) Of the following, which is a valid C++ identifier? A) June1997 B) _employee_number C) ___department D) myExtraLongVariableName E) All of the above are valid identifiers.

E

What will the following code display? cout << "Four" << " score" << end; cout << "and" << " seven" << end; cout << "years" << " ago" << end;

Fourscore andseven yearsago

What will the following code display? cout << "Four" << "score" << endl; cout << "and" << "seven" << endl; cout << "years" << "ago" << endl;

Fourscore andseven yearsago

Every complete C++ Program must have a _____

Function named main

Besides decimal, two other number systems you might encounter in C++ programs are:

Hexadecimal and Octal

To read data from a file, you define an object of this data type.

If stream

The beginning of a comment

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

decision structure

In a _____, a specific action is taken only when a specific condition exists.

This means to increase a value by one.

Increment

Something within a While loop must eventually cause the condition to become false, or a(n) -blank- results

Infinite loop

In a For statement, this expression is executed only once.

Initialization

26) Three primary activities of a program are:

Input, Processing, and Output

The numeric data types in C++ can be broken into two general categories:

Integer and Floating Point

The While loop contains an expression that is tested for a true or false value, and a statement or block that is repeated as long as the expression:

Is true

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

June1997 _employee_number ___department myExtraLongVariableName All of these are valid identifiers.

&&

The _____ operator is known as the logical AND operator. it takes two expressions as operands and creates an expression that is true only when both sub-expressions are true.

||

The _____ operator is known as the logical OR operator. It takes two expressions as operands and creates an expression that is true when either of the sub-expressions are true.

cout object

The ______ is/are used to display information on the computer's screen.

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

The beginning of a comment

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

The beginning of a comment

27) An example of a secondary storage device is:

The disk drive

note

The for loop. The for loop is a pretest loop that has built-in expressions for initializing, testing, and updating. These expressions make it very convenient to use a counter variable to control the number of iterations that the loop performs. The initialization expression can initialize the counter variable to a starting value, the test expression can test the counter variable to determine whether it holds the maximum value, and the update expression can increment the counter variable. {{{The for loop is ideal in situations where the exact number of iterations is known.}}}

________ must be included in any program that uses the cout object.

The header file iostream

____________ must be included in any program that uses the cout object.

The header file iostream

At the heart of a computer is its central processing unit. The CPU's job is:

To fetch instructions, to carry out the operations commanded by the instructions, and to produce some outcome or resultant information.

The purpose of a memory address is:

To identify the location of a byte in memo

A While loop's body can contain multiple statements, as long as they are enclosed in braces.

True

A while loop's body can contain multiple statements, as long as they are enclosed in curly braces.

True

All variables in C++ must be declared before they are used within the program.

True

An Initialization expression may be omitted from the For loop if no Initialization is required.

True

An output file is a file that data is written to.

True

Enumerated data types allow a programmer to create a new, simple data type of their own.

True

If you want to stop the loop before it goes through all its iterations, the Break statement may be used.

True

It is possible to define a file stream object and open a file in one statement.

True

Multiple relational expressions cannot be placed into the test condition of a For loop.

True

The update expression of a For loop can contain more than one statement, e.g. Counter++, total+=sales

True

3dGraph

Which one of the following would be an invalid variable name?

This is a pre-test loop that is ideal in situations where you do not want the loop to iterate if the condition is false from the beginning.

While

definition

You must have a ___________ for every variable you intend to use in a program

What will be the output after the following lines of code execute? bool choice; choice = true; cout << "Your choice is " << choice

Your choice is 1

Which character signifies the beginning of an escape sequence?

\

Which escape sequence causes the cursor to move to the beginning of the next line?

\n

Which escape sequence causes the cursor to move to the beginning of the current line?

\r

This control sequence is used to skip over to the next horizontal tab stop.

\t

filename extensions

_____ are short sequences of characters that appear at the end of a filename preceded by a period.

fstream

_____ file stream. Objects of this data type can be used to open files for reading, writing, or both.

ifstream

_____ is the input file stream. You can create an object of this data type when you want to open an existing file and read data from it.

ofstream

_____ is the output file stream. You can create an object of this data type when you want to create a file and write data to it.

input validation

_____ is the process of inspecting data given to a program by the user and determining if it is valid.

Variables

_____________ represent storage locations in the computer's memory.

sentinel

a _____ is a special value that marks the end of a list of values.

An example of a secondary storage device is:

a hard disk

Legal Variable?

abc123

18) A set of well-defined steps for performing a task or solving a problem is known as a(n):

algorithm

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

algorithm

20) Internally, the CPU consists of two parts:

algorithmic unit - logic unit

In C++ 11, the ________ tells the compiler to determine the variable's data type from the initialization value.

auto key word

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

bool

Write the C++ expression for the following algebraic expression. (a^3)/(b^2 k^4)

c = pow(a, 3) / (pow(b, 2) * pow(k, 4));

Which data type typically requires only one byte of storage?

char

You want the user to enter the length, width, and height from the keyboard. Which cin statement is correctly written?

cin >> length >> width >> height;

12) ________ are used to translate each source code instruction into the appropriate machine language instruction.

compilers

15) This step will uncover any syntax errors in your program.

compliling

concept.

concept. A counter is a variable that is regularly incremented or decremented each time a loop iterates.

concept

concept. A flag is a boolean or integer variable that signals when a conditions exists.

concept

concept. A loop that is inside another loop is called a nested loop.

concept.

concept. A running total is a sum of numbers that accumulates with each iteration of a loop. The variable used to keep the running total is called an accumulator.

concept

concept. Although most repetitive algorithms can be written with any of the three types of loops, each works best in different situations.

concept.

concept. As long as the user of a program enters bad input, the program will produce bad output. Programs should filter bad output.

concept.

concept. Logical operators are effective for determining whether a number is in or out of a range. && for within a range. || for out of a range.

concept.

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

concept

concept. Relational operators allow you to compare numeric and char values and determine whether one is greater than, less than, equal to, or not equal to another.

concept.

concept. Relational operators can also be used to compare characters and string objects.

concept.

concept. The break statement causes a loop to terminate early. The continue statement causes a loop to stop its current iteration and begin the next one.

concept.

concept. The do-while loop is a posttest loop, which means its expression is tested after each iteration.

concept.

concept. The for loop is ideal for performing a known number of iterations.

concept

concept. The if statement can cause other statements to execute only under certain conditions.

concept

concept. The if statement can conditionally execute a block of statements enclosed in braces.

concept.

concept. The if/else if statement tests a series of conditions. It is often simpler to test a series of conditions with the if/else if statement than a set of nested if/else statements.

concept

concept. The if/else statement will execute one group of statements if the expression is true, or another group of statements if the expression is false.

concept.

concept. The switch statement lets the value of a variable or expression determine where the program will branch.

concept

concept. To test more than one condition, an if statement can be nested inside another if statement.

concept.

concept. When a program needs to save data for later use, it writes the data in a file. The data can then be read from the file at a later time.

concept.

concept. You can use nested if/else statements or the if/else if statement to create menu-driven programs. A menu-driven program allows the user to determine the course of action by selecting it from a list of actions.

concept.

concept. You can use the conditional operator to create short expressions that work like if/else statements.

concept.

concept. the while loop can be used to create input routines that repeat until acceptable data is entered.

Assume that a program has the following variable definition: char letter; Which of the following statements correctly assigns the character Z to the variable?

letter = 'Z';

Given the following program, which line(s) cause(s) output to be displayed on the screen? 1 // This program displays my gross wages. 2 // I worked 40 hours and I make $20.00 per hour. 3 #include <iostream> 4 using namespace std; 5 6 int main() 7 { 8 int hours; 9 double payRate, grossPay; 10 11 hours = 40; 12 payRate = 20.0; 13 grossPay = hours * payRate; 14 cout << "My gross pay is $" << grossPay << endl; 15 return 0; 16 }

line 14

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

logic errors

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

logic errors

Which one of the following would be an illegal variable name?

long

In a broad sense, the two primary categories of programming languages are

low-level and high-level

39) Which of the following is a common input device?

mouse, scanner mic, keyboard.

Assuming that a program has the following string object definition. string name; Which statement correctly assigns the string literal "Jane" to the string object?

name = "Jane";

If you use a C++ key word as an identifier, your program will:

not compile

note.

note. A count controlled loop must possess three elements. 1. It must initialize a counter variable to a starting value. 2. it must test the counter variable by comparing it to a maximum value. When the counter variable reaches its maximum value, the loop terminates. 3. It must update the counter variable during each iteration, usually by incrementing.

note.

note. A file's read position marks the location of the next byte that will be read from the file.

note.

note. You should use the for loop instead of the while or do-while loop in any situation that clearly requires an initialization, uses a false condition to stop the loop, and requires an update to occur at the end of each loop iteration.

note.

note. do-while block do { statement; statement; } while (expression);

note.

note. for loop format. for (initialization; test; update) statement;

note

note. general format of a do-while loop. do statement; while (expression);

note.

note. the do-while loop must be terminated with a semicolon.

note

note. the for loop is a count controlled loop. it is a pretest loop as well.

note.

note. the fstream header file contains all the declarations necessary for file operations.

note

note. the switch statement is a natural mechanism for building menu systems.

note.

note. this is how to check if a file opened successfully. if (inputFile.fail())

note.

note. you can both define and initialize the counter variable in the loop header.

note.

note. you can omit a for loop's initialization expression if it is defined beforehand. int num = 1; for ( ; num <= maxValue; num++) etc.

8) Characters or symbols that perform operations on one or more operands are:

operators

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

operators

Assuming outFile is a file stream object and number is a variable, which statement writes the contents of number to the file associated with outFile?

outFile << number;

1) What does the term hardware refer to?

physical components

The float data type is considered _____ precision, and the double data type is considered _____ precision.

single, double

The float data type is considered ________ precision, and the double data type is considered ________ precision.

single, double

This function in C++ allows you to identify how many bytes of storage on your computer system an integer data value requires.

sizeof

30) Computer programs are also known as:

software

19) The statements written by the programmer are called:

source code

The statements written by the programmer are called:

source code

In the process of translating a source file into an executable file, which of the following is the correct sequence?

source code, preprocessor, modified source code, compiler, object code, linker, executable code

24) This is a complete instruction that causes the computer to perform some action.

statement

Including the following namespace will allow you simplify you code.

std

14) What statement best describes a variable and its primary purpose?

store data

The first step in using the string class is to #include the ________ header file.

string

33) This is a set of rules that must be followed when constructing a program.

syntax

35) The programmer usually enters source code into a computer using:

text editor

The programmer usually enters source code into a computer using:

text editor

!

the _____ operator performs a logical NOT operation. It takes an operand and reverses its truth or falsehood. In other words, if the expression is true, the _____ operator returns false, and if the expression is false, it returns true.

Internally, the CPU consists of two parts:

the control unit and the arithmetic and log unit

posttest

the do-while loop is a _____ loop?

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

the type of data it will be used to hold

the purpose of a memory address is:

to identify the location of a byte in memory

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

type of data it will hold

Which part of the following line is ignored by the compiler? double userName = "janedoe"; // user's name is janedoe

user's name is janedoe

23) The name for a memory location that may hold data is:

variable

The name for a memory location that may hold data is:

variable

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

variables

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

variables

warning

warning. Break and continue mess with the normal conditions of loops, they should mostly be avoided.

random access

when you work with a _____ file (also known as a direct access file), you can jump directly to any piece of data in the file without reading the data before it.


Kaugnay na mga set ng pag-aaral

Python Summary Test 2 (Chapter 4-5)

View Set

Jonathan Edwards's "Sinners in the Hands of an Angry God"

View Set

Chapter 6 - Taxable Income from Business Operations

View Set

PrepU: Chapter 27 - Fundamentals

View Set

Imperialism in Africa, Imperialism in Asia, Unit 4: Imperialism

View Set

Ms Maren's Math words Quarter 1, 2021-22

View Set

Helpdesk: Choosing Software (9/26)

View Set

Infant and Child Development Exam 2 (michaelchen5)

View Set

Chapter 22 Check Your Understanding

View Set

Foundations of Nursing - Legal & Ethical Aspects of Nursing

View Set