COP 3014 Exam 1 Practice Questions

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

The _____ decodes an instruction and generates an electronic signal

Control Unit

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

Four score and seven years ago

This operator takes an operand and reverses its truth or falsehood:

!

Which of the following lines must be included in a program that has string variables?

#include <string>

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

#include directive

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

3*2

What is the value of number after the following statements execute? int number = 10; number += 5; number -= 2; number *= 3;

39

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

4

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

6

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

7

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

3

The ________ loop is a good choice when you do not want the loop to iterate if the condition is FALSE in the beginning.

while

The first step in writing a program is to

clearly define what the program is to do

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

closes a file

The function pow(x, y), requires which header file?

cmath

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

compilers

Which step uncovers any syntax errors in your program

compiling

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

The programming process consists of several steps, which include:

design, creation, testing, debugging

The term that refers to the programmer reading the program from the beginning and stepping through each statement is

desk checking

The ________ loop is ideal in situations where you want the loop to iterate at least once.

do-while

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

double payCheck;

In a cout statement, which of the following will advance the output position to the beginning of the next line?

endl or \n

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

false

The CPU's control unit retrieves the next instruction in a sequence of program instructions from main memory in the ________ stage.

fetch

This manipulator forces cout to print digits in fixed-point notation:

fixed

A variable, usually a bool or an int, that signals when a condition exists is known as a(n)

flag

The data type used to declare variables that can hold real numbers is

float

Every complete C++ program must have a

function named main

A debugging process where you, the programmer, pretend you are a computer and step through each statement while recording the value of each variable at each step is known as

hand-tracing

A model often used when creating a program that begins with the overall task and refines it into smaller subtasks is a(n)

hierarchy chart

A computer stores a program while it is running

in main memory

This means to increase a value:

increment

In a for statement, this expression is executed only once:

initialization

Which is not a common input device

printer

The two methods used by C++ to write computer programs are:

procedural programming and object-oriented programming

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

program

Whereas < is called a relational operator, x < y is called a(n)

relational expression

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

scope

This manipulator is used to establish a field width for the value that follows it:

setw

Character constants in C++ are always enclosed in

single quotation marks ( ' ' )

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

single, double

Computer programs are also known as

software

When a programmer saves a file the statements he or she writes to create a program, these statements are

source code

When a programmer saves to a file the statements he or she writes to create a program, these statements are

source code

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

statement

In the following statement, the characters Hello! are a(n) cout << "Hello!";

string literal

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

syntax

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

the beginning of a comment

If you place a semicolon after the statement:if (x < y)

the compiler will interpret the semicolon as a null statement

The two parts of the CPU are

the control unit and the arithmetic and logic unit

Which of the following must be included in any program that uses the cin object?

the header file iostream

Which of the following must be included in any program that uses the cout object?

the header file iostream

A variable definition defines 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

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

trialing else

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

true

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

user's name is janedoe

A(n) ________ represents a storage location in the computer's memory.

variable

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

variable definition

Which of the following is evaluated first, given the expression:

A && B || C && !D

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

233445

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; }

1

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

1 1 ... and on forever

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

12

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

12

What is the value of cube after the following code executes? double cube, side; side = 5.0; cube = pow(side, 3.0); 8.0

125.0

What is the value of x after the following code executes? int x = 0; int y = 5; int z = 4; x = x + y + z * 2;

13

Which of the following is NOT a valid C++ identifier?

1user

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

2

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

21

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";

99

The ________ is an equality (or comparison) operator.

==

A multi-line comment

All of these are true

What is the output of the following code segment if the user enters 23? int number; cout << "Enter a number: "; cin >> number; if (number > 0) cout << "Hi, there!" << endl; else cout << "Good-bye." << endl;

Hi, there!

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

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

MondayTuesdayWednesday

A volatile type of memory that is used for storage is

RAM

What will the following code display?cout << "Roses " << "are red"; cout << "and " << "violets/n" cout << "are" << "blue" << endl;

Roses are redand violets/nareblue

A statement that causes a loop to terminate early is

break

Given the if/else statement: if (a < 5) b = 12; else d = 30; Which of the following performs the same operation?

a < 5 ? b = 12 : d = 30;

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

algorithm

Which of the following best describes an operator

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

The data type of a variable whose value can be either true or false is

bool

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

key words

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

letter = 'M';

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 4using namespace std; 5 6int main() 7{ 8int hours; 9double payRate, grossPay; 10 11hours = 40; 12payRate = 20.0; 13grossPay = hours * payRate; 14cout << "My gross pay is $" << grossPay << endl; 15return 0; 16}

line 14

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

line 6

Which line in the following program will cause a compiler error? 1 #include 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 }

line 7

Data items whose values do NOT change while the program is running are

literals

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

name = "Jane";

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

nesting

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

null terminator, marks the end of the string

A computer monitor is a type of

output device


Kaugnay na mga set ng pag-aaral

Unit 10: Real Estate Finance--Lending Institution

View Set

BYS 301- Ch 8 Carbohydrate Metabolism

View Set