CS 135 Midterm Ch. 1-4

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

This operator performs a logical NOT operation.

!

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

0 1 1 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? 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 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;

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

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;

20

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

3

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

3 * 2

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 }

6

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

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

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

==

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

>> , <<

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

Which of the following best describes an operator?

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

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 step will uncover any syntax errors in your program.

Compiling

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

Curly braces { }

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

Desk Checking

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: Programs are commonly referred to as hardware.

False

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

False

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

False

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

False

True/False: The preprocessor executes after the compiler.

False

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

Four score and seven/nyearsago

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

Fourscore andseven yearsago

Which is true about the following statement? cout << setw(4) << num4 << " ";

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

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

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

Logic errors

Which of the following is a common input device?

Mouse, Microphone, Keyboard, Scanner

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

Null terminator

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

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

Program

The computer's main memory is commonly known as:

RAM

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

RAM

Input values should always be checked for:

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

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

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.

Internally, the CPU consists of two parts:

The Control Unit and the Arithmetic and Logic Unit

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

The beginning of a comment

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

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

True

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

True

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

True

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

True

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

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: The term "bit" stands for binary digit.

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

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: You should be careful when using the equality operator to compare floating point values because of potential round-off errors.

True

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

Variables

________ represent storage locations in the computer's memory.

Variables

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

You failed the test! You passed the test!

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

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

bool

Which data type typically requires only one byte of storage?

char

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

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

cin.ignore

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

cmath

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

cmath

Relational operators allow you to ________ numbers.

compare

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

cout object

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;

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

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

fixed

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

getline

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?

if (code == 'C') cout << "This is a check\n";

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

iostream header file

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

left

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

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

nesting

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

not compile

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

overflows

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

precision and significant digits

The ________ of a variable is limited to the block in which it is declared.

scope

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

setw

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

sizeof

Computer programs are also known as:

software

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

trailing else

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

zero


Kaugnay na mga set ng pag-aaral

Financial Accounting Final Review

View Set

Chapter 12: Case Study Question #3

View Set

D'Antoni Case Studies- Lower Limb

View Set

Policy riders for disability protection

View Set

12 Venture John the Baptist 12/6/20 Gr 6

View Set

NR 224 Fundamentals Final Review

View Set

Intermediate Accounting: Chapter 12

View Set