C++ Coding Midterm Practice Flashcards ionicons-v5-c

logical (boolean) expression

An expression that has a value of either true or false

relational operator

A __ allows you to make comparisons in a program

nested

when one control statement is located within another, it is said to be ____

short-circuit evaluation

A process in which the computer evaluates a logical expression from left to right and stops as soon as the value of the expression is known.

Control structures

____ alter the normal flow of control

selection and repetition

Two most common control structures are: __ ___

switch

The ___ structure is sued to handle multiway selection

false

The result of a logical expression cannot be assigned to an int variable

false

In a one-way selection, if a semicolon is placed after the expression in an if statement, the expression in the if statement is always true.

false

Every if statement must have a corresponding else

true

The expression in the if statement:if (score = 30) grade = 'A';always evaluates to true

false

The expression:(ch >= 'A' && ch <= 'Z')evaluates to false if either ch <'A' or ch >= 'Z'.

false

The expression in a switch statement should evaluate to a value of the simple data type.

false

The expression !(x>0) is true only if x is a negative number

false

in C++, both ! and != are logical operators

true

The order in which statements execute in a program is called the flow of control.

false

It is a good idea to redefine cin and cout in your programs.

false

In the statement cin >> x;, x can be a variable or an expression.

false

The following statements will result in input failure if the input values are not on a separate line. (Assume that x and y are int variables.) cin >> x;cin >> y;

true

The number of input data extracted by cin and >> depends on the number of variables appearing in the cin statement.

false

The extraction operator >> skips only all leading blanks when searching for the next data in the input stream.

true

When reading data into a char variable, after skipping any leading whitespace characters, the extraction operator >> finds and stores only the next character; reading stops after a single character.

true

Entering a char value into an int variable causes serious errors, called input failure.

false

If input failure occurs in a C++ program, the program terminates immediately and displays an error message.

false

In an output statement, each occurrence of endl advances the cursor to the end of the current line on an output device.

true

You can use the function getline to read a string containing blanks.

x = 10, y = 20.7

Suppose that x is an int variable and y is a double variable and the input is:10 20.7Choose the values after the following statement executes: cin >> x >> y;.

cin >> x >> y;

Suppose that x and y are int variables. Which of the following is a valid input statement?

x = 15, ch = 'A', y = 73.2

Suppose that x is an int variable, y is a double variable and ch is a char variable and the input is:15A 73.2Choose the values after the following statement executes: Suppose that x is an int variable, y is a double variable and ch is a char variable and the input is:15A 73.2Choose the values after the following statement executes:cin >> x >> ch >> y;

alpha = 17, ch = 'A'

Suppose that alpha is an int variable and ch is a char variable and the input is:17 AWhat are the values after the following statements execute?cin >> alpha;cin >> ch;

x = 15, y = 76.3, z = 14

Suppose that x is an int variable, y is a double variable, z is an int variable, and the input is:15 76.3 14Choose the values after the following statement executes:cin >> x >> y >> z;

'C'

Suppose that ch1, ch2, and ch3 are variables of the type char and the input is:A BCChoose the value of ch3 after the following statement executes:cin >> ch1 >> ch2 >> ch3;

x = 28, y = 32, z = 0.6

Suppose that x and y are int variables, z is a double variable, and the input is:28 32.6 12Choose the values of x, y, and z after the following statement executes:cin >> x >> y >> z;

ch = '276', x = '.'

Suppose that x is an int variable, ch is a char variable, and the input is:276.Choose the values after the following statement executes:cin >> ch >> x;

This statement results in input failure

Suppose that x and y are int variables, ch is a char variable, and the input is:4 2 A 12Choose the values of x, y, and ch after the following statement executes:cin >> x >> ch >> y;

ch1 = 'A', ch2 = ' ', alpha = 18

Suppose that ch1 and ch2 are char variables, alpha is an int variable, and the input is:A 18What are the values after the following statement executes?cin.get(ch1);cin.get(ch2);cin >> alpha;

'B'

Suppose that ch1, ch2, and ch3 are variables of the type char and the input is:A BCWhat is the value of ch3 after the following statements execute?cin.get(ch1);cin.get(ch2);cin.get(ch3);

ignore

When you want to process only partial data, you can use the stream function ____ to discard a portion of the input.

300

Suppose that alpha, beta, and gamma are int variables and the input is:100 110 120200 210 220300 310 320What is the value of gamma after the following statements execute?cin >> alpha;cin.ignore(100, '\n');cin >> beta;cin.ignore(100,'\n');cin >> gamma;

W

Suppose that ch1 and ch2 are char variables and the input is:WXYZWhat is the value of ch2 after the following statements execute?cin.get(ch1);cin.putback(ch1);cin >> ch2;

X

Suppose that ch1 and ch2 are char variables and the input is:WXYZWhat is the value of ch2 after the following statements execute?cin >> ch1;ch2 = cin.peek();cin >> ch2;

member access

In C++, the dot is an operator called the ____ operator.

25.67 356.88 7623.97

Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the following statements?cout << fixed << showpoint;cout << setprecision(2);cout << x << ' ' << y << ' ' << z << endl;

55.680 476.859 23.82

Suppose that x = 55.68, y = 476.859, and z = 23.8216. What is the output of the following statements?cout << fixed << showpoint;cout << setprecision(3);cout << x << ' ' << y << ' ' << setprecision(2) << z << endl;

1565.683 85.7800 123.98

Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements?cout << fixed << showpoint;cout << setprecision(3) << x << ' ';cout << setprecision(4) << y << ' ' << setprecision(2) << z << endl;

12345678901234567890**18Happy*Sleepy

What is the output of the following statements?cout << setfill('*');cout << "12345678901234567890" << endlcout << setw(5) << "18" << setw(7) << "Happy" << setw(8) << "Sleepy" << endl;

123456789012345678901234567890####Mickey Donald*****Goofy

What is the output of the following statements?cout << "123456789012345678901234567890" << endlcout << setfill('#') << setw(10) << "Mickey" << setfill(' ') << setw(10) << "Donald" << setfill('*') << setw(10) << "Goofy" << endl;

setfill

____ is a parameterized stream manipulator.

iostream

Manipulators without parameters are part of the ____ header file.

inFile.open("progdata.dat");

Consider the following program segment.ifstream inFile; //Line 1int x, y; //Line 2... //Line 3inFile >> x >> y; //Line 4Which of the following statements at Line 3 can be used to open the file progdata.dat and input data from this file into x and y at Line 4?

outFile.open("outputData.out");

Suppose that outFile is an ofstream variable and output is to be stored in the file outputData.out. Which of the following statements opens the file outputData.out and associates outFile to the output file?

predefined orpre defined orpre-defined

C++ comes with a wealth of functions, called ____________________ functions, that are written by other programmers.

char

In the C++ statement,cin.get(u);u must be a variable of type ____________________.

peek

The function ____________________ returns the next character in the input stream; it does not remove the character from the input stream.

putback

The stream function ____________________ lets you put the last character extracted from the input stream by the get function back into the input stream.

istream

The functions get, ignore, and so on are members of the data type ____________________.

classes

C++ has a special name for the data types istream and ostream. They are called ____________________.

istream

cin is called a(n) ____________________ object.

member access

In C++, the dot is an operator called the ____________________operator.

iomanip

To use the manipulator setprecision, the program must include the header file ____________________.

cin.setf(ios::fixed);

On some compilers, the statements cin >> fixed; and cin >> scientific; might not work. In this case, you can use the statement ____________________ in place of cin >> fixed;.

setw

The manipulator ____________________ is used to output the value of an expression in a specific number of columns.

unsetf

You can disable the manipulator left by using the stream function ____________________.

cin.setf(ios::left);

On some compilers, the statements cin >> left; and cin >> right; might not work. In this case, you can use the statement ____________________ in place of cin >> left;.

iomanip

To use a parameterized stream manipulator in a program, you must include the header file ____________________.

fstream

C++ provides a header file called ____________________, which is used for file I/O.

True

The basic commands that a computer performs are input, output, storage, and performance of arithmetic and logical operations.

True

Main memory is directly connected to the CPU.

False

When the computer is turned off, everything in secondary memory is lost.

False

The devices that feed data and programs into computers are called output devices.

True

Information stored in main memory must be transfered to some other device for permanent storage.

False

The device that stores information permanently (unless the device becomes unusable or you change the information by rewriting it) is called primary storage.

False

The command that does the linking on Visuall C++ 2010 Express and Visual Studio 2010 is Make or Remake.

False

When you compile your program, the compiler identifies the logic errors and suggests how to correct them.

True

To develop a program to solve a problem, you start by analyzing the problem.

False

C++ programs have always been portable from one compiler to another.

mainframe, midsize, and micro

Several categories of computers exist, such as ____.

input, output, storage

The basic commands that a computer performs are ___, and performance of arithmetic and logical operations.

random access memory

Main memory is called ____.

CPU

The ___ is the brain of the computer and the single most expensive peice of harware in your personal computer.

memory cells

Main memory is an ordered sequence of items, called ___.

input

The devices that feed data and programs into computers are called ___ devices.

output

The devices that the computer uses to display results are called ___ devices.

main memory

When the power is switched off, everything in ___ is lost.

Application

___ progrmas perform a specific task.

operating system

The ___ monitors the overall activity of the computer and provides services.

Digital signals

___ represent information with a sequence of 0s and 1s.

byte

A sequence of eight bits is called a ____.

bit

The digit 0 or 1 is called a binary digit or ____.

gigabyte

The term GB refers to ___.

Unicode

___ consists of 65,536 characters.

compiler

A program called a ____ translates instructions written in high-level languages into machine code.

linker

A program called a ___ combines the object program with the programs from libraries.

loader

A program that loads an executable program into main memory is called a ___.

algorithm

A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time is caled an ____.

analyzing the problem

To develop a program to solve a problem, you start by ____.

structured

Dividing a problem into smaller subproblems is called ___ design.

object

An ___ consists of data and the operations on those data.

C

The programming language C++ evolved from ____.

1980s

The programming language C++ was designed by Bjarne Stroustrup at Bell Laboratories in the early ____.

operating system

The ____ monitors the overall activity of the computer and provides services such as memory management, input/output activities, and storage management.

Digital

___ signals represent information with a sequence of 0s and 1s.

applications

Word processors, spreadsheets, and games are examples of ____.

binary

A sequence of 0s and 1s is sometimes referred to as ____ code.

128

The ASCII data set consists of ___ characters.

mnemonic

Assemble language uses easy-to-remember instructions called ____.

assembler

A program called an _____ translates the assembly language instructions into machine language.

High-level

___ languages include FORTRAN, COBOL, Pascal, C, C++, and Java.

source program

The term ___ is used to describe a program that has been written in a high-level language.

preprocessor

In a C++ program, statements that begin with the symbol # are called ____ directives.

object program

The machine language verson of the high-level language program is called ____.

...

The structured design approach is also known as ____.

objects

In object-oriented design, the first step in the problem-solving process is to identify the components called ___, which form the basis of a solution, and to determine how they interact with one another.

object oriented

In ___ design, the final program is a collection of interacting objects.

class

In C++, the mechanism that allows you to combine data and operationso f the data into a single unit is called a ____.

False

In C++ reserved words are the same as predefined identifiers.

True

The maximum number of significant digits in values fo the double type is 15.

True

The maximum number of significant digits in float values is up to 6 or 7.

False

An operator that has only one operand is called a unique operator.

True

If a C++ arithmetic expression has no parentheses, operators are evaluated from left to right.

...

A mixed arithmetic expression contains all operands of the same type.

True

Suppose a = 5. After the execution of the statement ++a; the value of a is 6.

True

The escape sequence /r moves the insertion point to the beginning of the next line.

False

A comma is also called a statement terminator.

...

Suppose that sum is an int variable. The statement sum += 7; is equivalent to the statement sum = sum + 7.

syntax

The ___ rules of programming language tell you which statements are legal, or accepted by the programming language.

char

Is a reserved word in C++

program_1

Is a legal identifier.

46259

___ is a valid int value

'A'

___ is a valid char value.

double

An example of a floating point data type is ____.

four

The memory allocated for a float value is ___ bytes.

3

The value of the expression 33/10, assuming both values are integral data types is ____.

3

The value of the expression 17 % 7 is ____.

...

The expression static_cast<int?(9.9) evaluates to ___.