C++ Final Exam 1 - 4

Ace your homework & exams now with Quizwiz!

Which of the following is a preprocessor directive?

#include <iostream>

Which of the following is a common input device?

---ALL--- Keyboard Mouse Scanner Microphone 2

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

0

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

012

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? cout << "Four" << "score" << endl; cout << "and" << "seven" << endl; cout << "years" << " ago" << endl;

Fourscore andseven yearsago

Three primary activities of a program are:

Input, Processing, and Output

Which is true about the following statement?

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

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

Operators

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

Parentheses

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

Preprocessor

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

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

Punctuation

The computer's main memory is commonly known as:

RAM

True/False: The term "bit" stands for binary digit.

TRUE

Internally, the CPU consists of two parts:

The Control Unit and the Arithmetic and Logic Unit

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

The data type of the variable

An example of a secondary storage device is:

The disk drive

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

Variable

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

scope

The ____ of a variable is limited to the block in which it is declared?

scope

This statement uses the value of a variable or expression to determine where the program will branch to.

select

This manipulator is used to establish a field width for the value immediately following it.

setw

The total number of digits that appear before and after the decimal point is sometimes referred to as:

significant digits and precision

Computer programs are also known as:

software

An expression that has any value other than 0 is considered true by and if statement.

true

Both of the following if statements perform the same operation. if (sales > 10000) commissionRate = 0.15; if *sales > 1000> commissionRate = 0.15

true

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

true

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

true

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

true

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 writing long integer literals or long long integer literals in C++ 11, you can use either an uppercase or lowercase L.

true

Which statement is equivalent to the following?

x *=2;

When a relational expression is false, it has the value ________.

zero

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

#include directive

What is the modulus operator?

%

This operator represents the logical AND.

&&

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

--ALL-- None of these To fetch instructions To carry out the operations commanded by the instructions

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

1

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;

This is true!This is all folks

The purpose of a memory address is:

To identify the location of a byte in memory

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

True

True/False: A CPU really only understands instructions that are written in machine language.

True

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

cin object

This statement will pause the screen, until the [Enter] key is pressed.

cin.get()

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

cin.get(length, width, height);

This function tells the cin object to skip one or more characters in the keyboard buffer.

cin.ignore

When using the sqrt function you must include this header file.

cmath

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

Desk Checking

Input values should always be checked for:

Division by zero, if division is taking place, reasonableness, Appropriate range

True/False: Machine language is an example of a high-level language.

FALSE

True/False: Programs are commonly referred to as hardware.

FALSE

True/False: The preprocessor executes after the compiler.

FALSE

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

False

True/False: In programming, the terms "line" and "statement" always mean the same thing.

False

True/False: Pseudocode is a form of program statement that will always evaluate to "false."

False

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

Floating point data types

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

Four score and seven years ago

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 ________ is/are used to display information on the computer's screen.

cout object

To use the rand() function, you must #include this header file in your program.

cstdlib

If you intend to place a block of statements within an if statement, you must place these around the block.

curly braces {}

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

definition

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

double payCheck;

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

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 C++ language requires that you give variables names that indicate what the variables are used for.

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

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

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;

false

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

fetch

This stream manipulator forces cout to print the digits in fixed-point notation.

fixed

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

flowchart

Every complete C++ program must have a ________.

function named main

________ reads a line of input, including leading and embedded spaces, and stores it in a string object.

getline

Which statement will read an entire line of input into the following string object?

getline(cin, address);

When a program lets the user know that an invalid choice has been made, this is known as:

input validation

When a variable is assigned a number that is too large for its data type, it:

overflows

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

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

string

True/False: In C++, key words are written in all lowercase letters.

true

True/False: The CPU is the most important component in a computer because without it, the computer could not run software.

true

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

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

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

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

true

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

true

This operator is known as the logical OR operator

||

If you place a semicolon after the statement:

The compiler will interpret the semicolon as a null statement.

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

What will the following program segment display? int funny = 7, serious = 15; funny = serious %2; if (funny i=1) { funny = 0; serious = 0; } else if (funny ==2) { funny = 10; serious = 10; } else { funny = 1; serious = 1; } cout << funny << " " << serious << endl;

1 1

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

12

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

Look at the following program and answer the question that follows it.

14

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;

15

This operator is used in C++ to represent equality.

==

The programmer usually enters source code into a computer using:

A text editor

What statement best describes a variable and its primary purpose?

A variable is a named storage location in the computer's memory used for holding a piece of information.

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

Algorithm

An Integrated Development Environment typically consists of:

All of these

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

All of these are valid identifiers.

Which of the following best describes an operator?

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

This step will uncover any syntax errors in your program.

Compiling

The programming process consists of several steps, which include:

Design, Creation, Testing, and Debugging

The function, pow(x, 5.0), requires this header file.

cmath

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

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

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

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

integer and floating point

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

iostream

This manipulator causes the field to be left-justified with padding spaces printed to the right.

left

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

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?

name = "Jane";

The statement: cin >> setw(10) >> str; will read up to this many characters into str.

nine

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

none of these

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

not compile

Which statement is equivalent to the following? number +=1;

number = number + 1;

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

operating system

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

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

20

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

3 * 2

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

3dGraph

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

4

Which line in the following program will cause a compiler error? # include <iostream> using namespace std; int main() { const int MY_VAL = 77; MY_VAL = 99; cout << MY_VAL << endl; return 0; }

7

Which value can be entered to cause the following code segment to display the message: "That number is acceptable/" in number; cin >> number; if (number > 10 && number < 100) cout << "That number is acceptable.\n" else cout<<"That number is not acceptable. \n"

99

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

>>,<<

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

The ________ decodes an instruction and generates electrical signals.

Control Unit

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

Key Words

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

Associativity is either right to left or:

Left to right

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

Logic errors

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

Low-level and High-level

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

MondayTuesdayWednesday

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

Null terminator

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

RAM

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

Relational expression

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

Secondary storage

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

Semicolon

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.

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

Statement

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

String literal

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

Syntax

True/False: Software engineering is a field that encompasses designing, writing, testing, debugging, documenting, modifying, and maintaining computer programs.

TRUE

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;

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

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

The beginning of a comment

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

Variables

________ represent storage locations in the computer's memory.

Variables

Which character signifies the beginning of an escape sequence?

\

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

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

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


Related study sets

DD-Viral Structure and Replication

View Set

ELECTIC: LAZARUS - MULTIMODAL APPROACH

View Set

FD - Diesel Generator Engine Fuel Oil System

View Set

Gospel of Mark 10-12 - Bible Experience 2012

View Set

CRQ 7) In 1798 Thomas Malthus published An Essay on the Principle of Population in which he argued that population growth will inevitably outpace food production, resulting in widespread famine.

View Set

ATI fundamentals Practice Test A

View Set