c++ chapters 1-4 (MIDTERM)

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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

False Correct When the computer is turned off, everything in the main memory is lost, but the secondary memory stores information permanently.

If the expression in an assert statement evaluates to true, the program terminates. a. True b. False

False FEEDBACK: Correct A program terminates when an expression in the statement assert evaluates to 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 FEEDBACK: Correct A secondary storage device is used to store information permanently until the device becomes unusable or someone rewrites the information stored in it.

Suppose P and Q are logical expressions. The logical expression P && Q is true if both P and Q are true. a. True b. False

True FEEDBACK: Correct As per the definition of the and operator, &&, expression1 && expression2 is true if and only if both expression1 and expression2 are true.

In C++, && has a higher precedence than ||. a. True b. False

True FEEDBACK: Correct As per the precedence of operators, the or operator || has a lesser precedence than the and operator &&.

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

True FEEDBACK: Correct Function getLine reads all characters in the line including any blanks, if any, until it reaches end of the current line.

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

True FEEDBACK: Correct Information stored in the main memory is lost when the computer is turned off, so the information should be transferred to some other device like hard disk (HD) for permanent storage.

Suppose that x is an int variable. Which of the following expressions always evaluates to true? a. (x > 0) || ( x <= 0) b. (x >= 0) || (x == 0) c. (x > 0) && ( x <= 0) d. (x > 0) && (x == 0)

a. Correct. If x is an int variable, then x = 0, x > 0, or x < 0. Thus, either x > 0 is true or x <= true. Also, true || true = true, false || true = true, and true || false = true. Therefore, (x > 0) || ( x <= 0) will always evaluate to true.

he expression static_cast<int>(9.9) evaluates to ____. a. 9 b. 10 c. 9.9 d. 9.0

a. Correct. In the evaluation of static_cast<dataTypeName>(expression), first the expression is evaluated and its value is converted to the data type specified by dataTypeName. Thus, the evaluation result is 9.

Which of the following is a legal identifier? a. program! b. program_1 c. 1program d. program 1

b. program_1

Suppose that alpha and beta are int variables. The statement alpha = --beta; is equivalent to the statement(s) ____. a. alpha = 1 - beta; b. alpha = beta - 1; c. beta = beta - 1; alpha = beta; d. alpha = beta; beta = beta - 1;

c. Correct. In the statement alpha = --beta, first beta is decremented by a value 1 and then assigned to alpha

20. You can use either a(n) ____ or a ____ to store the value of a logical expression. a. float, double b. char, string c. int, bool d. float, string

c. Correct. One can either use a bool variable or an int variable for storing the result of a logical expression.

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

member access

Assembly language uses easy-to-remember instructions called ____________________.

mnemonics

In C++, you can use a(n) ____________________ to instruct a program to mark those memory locations in which data is fixed throughout program execution.

named constant constant

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

objects

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

predefined

____________________ functions are those that have already been written and are provided as part of the system.

predefined standard

A(n) ____________________ is a sequence of zero or more characters.

string

38. A(n) ____________________ is a collection of statements, and when it is activated, or executed, it accomplishes something.

subprogram function module

The ____ rules of a programming language tell you which statements are legal, or accepted, by the programming language. a. semantic b. logical c. syntax d. grammatical

syntax

____ is a valid char value. a. "-129" b. 'A' c. "A" d. 129

b

____ is a valid int value. a. 46,259 b. 46259 c. 462.59 d. -32.00

b

When a value of one data type is automatically changed to another data type, a(n) ____________________ type coercion is said to have occurred.

implicit

The memory space for a(n) ____________________ data value is 4 bytes.

int.

The ASCII data set consists of ____________________ characters.

128

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

False FEEDBACK: Correct If input failure occurs in a C++ program, the program does not terminate immediately displaying an error message, instead program quietly continues to execute with whatever values are stored in the variables and produces incorrect results.

In C++, both ! and != are relational operators. a. True b. False

False FEEDBACK: Correct The operator != is a relational operator and the operator! is a logical operator.

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

False FEEDBACK: Correct The syntax errors in a program can be identified by a compiler while compiling the program. Also, the compiler suggests how to correct the errors

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

ANSWER: False FEEDBACK: Correct An arithmetic expression consisting of operands of different data types are usually called a mixed arithmetic expression.

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

ANSWER: False FEEDBACK: Correct An operator that consists of only one operator is known as unary operators.

A comma is also called a statement terminator

ANSWER: False FEEDBACK: Correct In C++, a semicolon is known as a statement terminator.

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

ANSWER: operating system

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

Correct Redefining cin and cout in the programs is not a good idea as its already defined and have specific meanings in C++.

Suppose that alpha and beta are int variables. The statement alpha = ++beta; is equivalent to the statement(s) ____. a. beta = beta + 1; alpha = beta; b. alpha = beta; beta = beta + 1; c. alpha = alpha + beta; d. alpha = beta + 1;

Correct. In the statement alpha = ++beta;, first beta is incremented by 1 and then the value of beta is assigned to alpha.

Suppose that alpha is an int variable and ch is a char variable. The input is: ​ 17 A ​ What are the values after the following statements execute? ​ cin >> alpha; cin >> ch; ​ a. alpha = 17, ch = ' ' b. alpha = 1, ch = 7 c. alpha = 17, ch = 'A' d. alpha = 17, ch = 'a'

Correct. The first cin statement will read 17 and store it into the variable alpha and the second cin statement will read A and store it into the variable ch.

The basic commands that a computer performs are input (get data), output (display result), storage, and performance of arithmetic and logical operations.

True FEEDBACK: Correct Reading data (input), displaying results (output), storage, and performing arithmetic and logical operations are the basic commands which are performed by a computer.

Main memory is directly connected to the CPU.

True FEEDBACK: Correct The main memory (also called random access memory) is directly connected to the central processing unit (CPU).

Suppose that ch1, ch2, and ch3 are variables of the type char. The input is: ​ A B C ​ What is the value of ch3 after the following statements execute? ​ cin.get(ch1); cin.get(ch2); cin.get(ch3); ​ a. 'A' b. 'B' c. 'C' d. '\n'

b. Correct. The function get does not skip leading whitespaces and reads the next character, including a whitespace, if any. The first statement cin.get(ch1), reads and stores 'A' into ch1, the reading stops just after A. The second statement, cin.get(ch2), reads the space after A and stores it into ch2. The third statement, cin.get(ch3), reads and stores 'A' into ch3. Therefore, after the given statements execute ch3 = 'B'.

Which of the following is a relational operator? a. = b. == c. ! d. &&

b. Correct. The operator == is a relational operator.

What does <= mean? a. less than b. greater than c. less than or equal to d. greater than or equal to

c. Correct. The less than or equal to is represented as <=.

Which of the following is a reserved word in C++? a. char b. Char c. CHAR d. character

char

In C++, the mechanism that allows you to combine data and operations on the data into a single unit is called a(n) ____________________.

class

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

classes

____________________ can be used to identify the authors of the program, give the date when the program is written or modified, give a brief explanation of the program, and explain the meaning of key statements in a program.

comments

What is the output of the following code? ​ char lastInitial = 'S'; ​ switch (lastInitial) { case 'A': cout << "section 1" <<endl; break; case 'B': cout << "section 2" <<endl; break; case 'C': cout << "section 3" <<endl; break; case 'D': cout << "section 4" <<endl; break; default: cout << "section 5" <<endl; } ​ a. section 2 b. section 3 c. section 4 d. section 5

d. Correct. The value of lastInitial is 'S' and it does not match with any case label. So the statement following the default label will be executed. Thus, the output is: section 5

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

digital

An example of a floating point data type is ____. a. int b. char c. double d. short

double

The ____________________ type is C++ 's method for allowing programmers to create their own simple data types.

enumeration

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

false FEEDBACK: Correct The manipulator endl is used to move the insertion point to the beginning of the next line.

In a C++ program, ____________________ are used to separate special symbols, reserved words, and identifiers.

whitespaces

A compound statement functions as if it was a single statement. a. True b. False

True FEEDBACK: Correct A compound statement typically acts a single statement.

n C++, the operators != and == have the same order of precedence. a. True b. False

True FEEDBACK: Correct As per the precedence of operators, the not equal to operator !=and the equal to operator == have the same order of precedence.

A control structure alters the normal sequential flow of execution in a program.

True FEEDBACK: Correct In a program, control structures alters the normal sequential flow of execution.

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

True FEEDBACK: Correct The number of input data extracted by cin and >> is based on the number of variables in the statement. If more number of inputs are given, then it just skips the additional input and take only required number of inputs

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

True FEEDBACK: Correct To solve a problem by developing a program, the problem must be analyzed first.

Suppose that x and y are int variables, ch is a char variable, and the input is: ​ 4 2 A 12 ​ Choose the values of x, y, and ch after the following statement executes: ​ cin >> x >> ch >> y; ​ a. x = 4, ch = 2, y = 12 b. x = 4, ch = A, y = 12 c. x = 4, ch = ' ', y = 2 d. This statement results in input failure

d. Correct. In the cin statement cin >> x >> ch >> y;, the first variable after the first >> is x, the second variable is ch, and the third variable is y. This input statement first read 4 and stores it into x, then reads 2 and stores it as '2' into ch. The next value in the input stream is A, which is not an integer. Therefore, trying to read and store A into y will result into input failure since y is an int variable. This statement results into input failure.

____ is a parameterized stream manipulator. a. endl b. fixed c. scientific d. setfill

d. Correct. Manipulators with parameters are called parameterized stream manipulator. Example setprecision, setw, and setfill.

Which of the operators &&, =, !, and || has the lowest precedence? a. ! b. || c. && d. =

d. Correct. The precedence of the operators &&, =, !, and || from highest to lowest is: ! (highest), && (second highest), || (third highest), = (lowest). Thus, = has the lowest precedence.

You can disable assert statements by using which of the following preprocessor command? a. #include <cassert> b. #define <assert> c. #clear NDEBUG d. #define NDEBUG

d. Correct. The preprocessor command #define NDEBUG is used to disable assert statements in a program.

Suppose that sum and num are int variables and sum = 5 and num = 10. After the statement sum += num executes, ____. a. sum = 0 b. sum = 5 c. sum = 10 d. sum = 15

d. Correct. The statement sum += num; results in adding the values of sum and num; that is, sum + num = 5 + 10 = 15, and then storing the result in sum

When you want to process only partial data, you can use the stream function ____ to discard a portion of the input. a. clear b. skip c. delete d. ignore

d. Correct. The stream function ignore is used to discard portion of the input within a line. In other words, stream function ignore processes only partial data within a line.

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

fstream

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

peek

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

preprocessor

____________________ rules determine the meaning of instructions.

semantic

A data type is called ____________________ if the variable or named constant of that type can store only one value at a time.

simple

Putting ____________________ in front of a logical expression reverses the value of that logical expression.

true

The value of the expression 7 + 8 <= 15 is ____________________.

true

Suppose that x is an int variable, y is a double variable, and ch is a char variable. The input is: ​ 15A 73.2 ​ Choose the values after the following statement executes: ​ cin >> x >> ch >> y; ​ a. x = 15, ch = 'A', y = 73.2 b. x = 15, ch = 'A', y = 73.0 c. x = 15, ch = 'a', y = 73.0 d. This statement results in an error because there is no space between 15 and A.

Correct. The extraction operators first reads and stores 15 into x and reading stops after 5. Next the extraction operator reads 'A' and stores into ch and reading stops after 'A'. Then the extraction operator reads and stores 73.2 into y. In the given input, the first integer value 15 will be stored into the variable x, the next character value 'A' will be stored into the variable ch, and the last decimal value 73.2 will be stored into the variable y.

Suppose that x is an int variable, y is a double variable, and z is an int variable. The input is: ​ 15 76.3 14 ​ Choose the values after the following statement executes: ​ cin >> x >> y >> z; ​ a. x = 15, y = 76, z = 14 b. x = 15, y = 76, z = 0 c. x = 15, y = 76.3, z = 14 d. x = 15.0, y = 76.3, z = 14.0

Correct. The first value 15 will be stored into the variable x, the second value 76.3 will be stored into the variable y, and the last value 14 will be stored into the variable z.

Suppose that x and y are int variables. Which of the following is a valid input statement? a. cin >> x >> cin >> y; b. cin >> x >> y; c. cin << x << y; d. cout << x << y;

Correct. The statement cin >> x >> y; is used to read values for the variables x and y

The result of a logical expression cannot be assigned to an int variable, but it can be assigned to a bool variable. a. True b. False

False FEEDBACK: Correct One can either use a bool variable or an int variable for storing the result of a logical expression.

The operators !, &&, and || are called relational operators. a. True b. False

False FEEDBACK: Correct The operators !, &&, and || are logical operators.

The expression (x >= 0 && x <= 100) evaluates to false if either x < 0 or x >= 100. a. True b. False

False FEEDBACK: Correct When the value of x = 100, the expression (x >= 0 && x <= 100) evaluates to true.

Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y / x > 0) ? x : y;. a. 2 b. 3 c. 4 d. 6

a. Correct. In the given conditional expression, (y / x > 0) evaluates to true, thus the result is x; that is, 2.

What is the output of the following C++ code? int x = 55;int y = 5;switch (x % 7){case 0:case 1:y++;case 2:case 3:y = y + 2;case 4:break;case 5:case 6:y = y - 3;} cout << y << endl; a. 2 b. 5 c. 8 d. 10

a. Correct. In the switch statement, the value of the expression x % 7 is 55 % 7, which evaluates to 6. Thus, the value of the x % 7 matches with the case label 6. So the statement y = y - 3 will be executed, that is, y = 5 - 3 = 2. So the output of the C++ code is: 2

Manipulators without parameters are part of the ____ header file. a. iostream b. iomanip

a. Correct. Manipulators without parameters are part of the iostream header file.

Suppose that ch1 and ch2 are char variables, and alpha is an int variable. The input is: ​ A 18 ​ What are the values after the following statement executes? ​ cin.get(ch1); cin.get(ch2); cin >> alpha; ​ a. ch1 = 'A', ch2 = ' ', alpha = 18 b. ch1 = 'A', ch2 = '1', alpha = 8 c. ch1 = 'A', ch2 = ' ', alpha = 1 d. ch1 = 'A', ch2 = '\n', alpha = 1

a. Correct. The function get does not skip leading whitespaces and reads the next character, including a whitespace, if any. The first statement cin.get(ch1), reads and stores 'A' into ch1, the reading stops just after A. The second statement, cin.get(ch2), reads the space after A and stores it into ch2. The third statement, cin >> alpha;, reads and stores 18 into alpha. Therefore, after the given statements execute, ch1 = 'A', ch2 = ' ', and alpha = 18.

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; a. 55.680 476.859 23.82 b. 55.690 476.860 23.82 c. 55.680 476.860 23.82 d. 55.680 476.859 23.821

a. Correct. The manipulator fixed is used to output numbers in a fixed decimal format, the manipulator showpoint is used to output number with the decimal point and trailing zeros, if any, and the manipulator setprecision is used to output numbers to a fixed number of decimal places. The statement, cout << setprecision(3);, sets the output of numbers to three decimal places. The third statement after outputting the values of x and y with three decimal place, uses setprecision to set the output of numbers to two decimal places. So the value of z is output with two decimal places. Since x = 55.68 has only two decimal places and the precision is three decimal places, x is printed as 55.680.

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

a. Correct. The manipulator setw is used to output the value of an expression in a specific number of columns. If the number of columns specified by setw exceeds the number of columns required by the expression, the output of the expression is rightjustified and the unused columns to the left are filled with spaces. The manipulator setfill is used to fill the unused columns with a character other than a space. The expression setfill('#') fills the unused columns with the character #. The expression setfill(' ') fills the unused columns with the space character. The expression setfill('*') fills the unused columns with the character *. "Mickey" is output in 10 columns and it requires only six columns, the left four columns are filled with #. "Donald" is output in 10 columns and it requires only six columns, the left four columns are filled with the space character. "Goofy" is output in 10 columns and it requires only five columns, the left five columns are filled with *.

Which of the operators %, =, !, and * has the highest precedence? a. ! b. * c. % d. =

a. Correct. The precedence of the operators %, =, !, and * from highest to lowest is: ! (highest), % and * (second highest), = (lowest). Note that % and * have the same level of precedence.

Suppose that x and y are int variables, and z is a double variable. The input is: ​ 28 32.6 12 ​ Choose the values of x, y, and z after the following statement executes: ​ cin >> x >> y >> z; ​ a. x = 28, y = 32, z = 0.6 b. x = 28, y = 32, z = 12.0 c. x = 28, y = 12, z = 32.6 d. x = 28, y = 12, z = 0.6

a. Correct. The statement cin >> x >> y >> z; first reads and stores 28 into x, then reads and stores 32 into y, since y is an int variable. After reading and storing 32 into y, the reading stops after 32, just before the dot. Next the value .6, which is a decimal value, will be read and stored into z since z is a double variable. After reading .6 into z, the reading stops after 6. The last input value 12 will remain into the input stream for further input, if any.

Suppose that ch1 and ch2 are char variables and the input is: ​ WXYZ ​ What is the value of ch2 after the following statements execute? ​ cin.get(ch1); cin.putback(ch1); cin >> ch2; ​ a. W b. X c. Y d. Z

a. Correct. The stream function putback lets you put the last character extracted from the input stream by the get function back into the input stream. The first statement, cin.get(ch1);, reads W and stores it into ch1. Next, the statement, cin.putback(ch1);, puts W back into the input stream. So after the execution of this statement, the reading marker is before W. Therefore, the next statement, cin >> ch2;, reads W and stores it into ch2. Therefore, after the last statement executes, ch2 = 'W'.

Consider the following program segment. ifstream inFile; //Line 1int x, y; //Line 2... //Line 3 inFile >> x >> y; //Line 4 Which 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? a. inFile.open("progdata.dat"); b. inFile(open,"progdata.dat"); c. open.inFile("progdata.dat"); d. open(inFile,"progdata.dat");

a. Correct. inFile.open("progdata.dat") is correct syntax to open the file.

. Suppose x is 5 and y is 7. Choose the value of the following expression: ​ (x != 7) && (x <= y) ​ a. false b. true c. 0 d. null

b. Correct. If x is 5 and y is 7, then (x != 7) && (x <= y) = (5 != 7) && (5 <= 7) = true && true = true.

In C++, the dot is an operator called the ____ operator. a. dot access b. member access c. data access d. member

b. Correct. In C++, dot is an operator, called member access operator

What is the output of the following C++ code? int x = 35;int y = 45;int z;if (x > y)z = x + y;elsez = y - x; cout << x << " " << y << " " << z << endl; a. 35 45 80 b. 35 45 10 c. 35 45 -10 d. 35 45 0

b. Correct. In this program segment, x = 35 and y = 45. In the if statement, the expression (x > y) = (35 > 45) = false. So the statement in the body of else, that is, z = y - x executes. Thus, z = y - x = 45 -35 = 10. Therefore, the cout statement outputs: 35 45 10

Which of the following will cause a logical error if you are attempting to compare x to 5? a. if (x == 5) b. if (x = 5) c. if (x <= 5) d. if (x >= 5)

b. Correct. Since an assignment expression (x = 5) is used inside an if statement, it will cause a logical error.

Which of the following will cause a logical error if you are attempting to compare x to 5? a. if (x == 5) b. if (x = 5) c. if (x <= 5) d. if (x >= 5)

b. Correct. Since the assignment expression (x = 5) is used in the if statement, it will cause a logical error.

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

b. Correct. The manipulator setw is used to output the value of an expression in a specific number of columns. If the number of columns specified by setw exceeds the number of columns required by the expression, the output of the expression is rightjustified and the unused columns to the left are filled with spaces. The manipulator setfill is used to fill the unused columns with a character other than a space. The statement, cout << setfill('*');, fills the unused columns with the character *. The value of 18 is output in five columns. Because it only requires two columns, the three columns to the left of 18 are filled with *. The value of "Happy" is output in 7 columns and it only requires five columns, the first two columns are filled with *. The value of "Sleepy" is output in eight columns and requires only six columns, so the left two columns are filled with *.

Suppose that ch1 and ch2 are char variables and the input is: ​ WXYZ ​ What is the value of ch2 after the following statements execute? ​ cin >> ch1; ch2 = cin.peek(); cin >> ch2; ​ a. W b. X c. Y d. Z

b. Correct. The peek function returns the next character from the input stream but does not remove the character from that stream. The firs statement, cin >> ch1;, reads and stores the character W into ch1 and the reading marker is after just before X. The next statement, ch2 = cin.peek();, reads and stores the next character X into ch2, but does not remove X from the input stream. Therefore, after the second statement executes, the reading marker is still before X. Next, the third statement, cin >> ch2;, reads and stores the next (non whitespace) character X into ch2. After the execution of the given statements, ch2 = 'X'.

For a program to use the assert function, it must include which of the following preprocessor command? a. #include <asserts> b. #include <cassert> c. #include <assertc> d. #include NDEBUG

b. Correct. To use the function assert in a program, the preprocessor command #include <cassert> must be included in the program.

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? a. outFile("outputData.out"); b. outFile.open("outputData.out"); c. open(outFile,"outputData.out"); d. open.outFile("outputData.out");

b. Correct. outFile.open("outputData.out") opens the file to store the output data.

What is the value of x after the following statements execute? ​ int x; x = (5 <= 3 && 'A' < 'F') ? 3 : 4 ​ a. 2 b. 3 c. 4 d. 5

c. Correct. The expression (5 <= 3 && 'A' < 'F') evaluates to (false && true), which evaluates to false. Thus, the value assigned to x is 4.

Which of the following expressions correctly determines that x is greater than 10 and less than 20? a. 10 < x < 20 b. (10 < x < 20) c. 10 < x && x < 20 d. 10 < x || x < 20

c. Correct. The expression 10 < x && x < 20 determines that the value of x is greater than the value 10 and the value of x is less than the value 20.

Suppose that ch1, ch2, and ch3 are variables of the type char. The input is: ​ A B C ​ Choose the value of ch3 after the following statement executes: ​ cin >> ch1 >> ch2 >> ch3; ​ a. 'A' b. 'B' c. 'C' d. '\n'

c. Correct. The first value, A, in the first line will be stored into the variable ch1, the second value , B, in the first line will be stored into the variable ch2, and the third value, C, in the second line will be stored into the variable ch3.

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; a. 1565.683 85.8000 123.98 b. 1565.680 85.8000 123.98 c. 1565.683 85.7800 123.98 d. 1565.683 85.780 123.980

c. Correct. The manipulator fixed is used to output numbers in a fixed decimal format, the manipulator showpoint is used to output number with the decimal point and trailing zeros, if any, and the manipulator setprecision is used to output numbers with a fixed number of decimal places. The value of x is output with three decimal places, the value of y is output with four decimal places, and the value of z is output with two decimal places. Because y = 85.78 has only two decimal places, it is output as 85.7800. Also, because z = 123.982 has three decimal places, the output value of z, which is 123.98, is rounded to two decimal places.

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; ​ a. 25.67 356.87 7623.96 b. 25.67 356.87 7623.97 c. 25.67 356.88 7623.97 d. 25.67 356.876 7623.967

c. Correct. The manipulator setprecision to control the output of floating-point numbers. When executed the output values of x, y, and z are 25.67, 356.88, and 7623.97, respectively.

Which of the following is the "not equal to" relational operator? a. ! b. | c. != d. &

c. Correct. The operator != is "not equal to" relational operator.

In a ____ control structure, the computer executes particular statements depending on some condition(s). a. selected b. responsive c. selection d. sequence

c. Correct. The selection control structure executes specific statements based on some conditions.

Suppose that alpha, beta, and gamma are int variables and the input is: ​ 100 110 120 200 210 220 300 310 320 ​ What is the value of gamma after the following statements execute? ​ cin >> alpha; cin.ignore(100, '\n'); cin >> beta; cin.ignore(100,'\n'); cin >> gamma; ​ a. 100 b. 200 c. 300 d. 320

c. Correct. The statement cin.ignore(100, '\n'); ignores either the next 100 characters or all characters until the newline character is found, whichever comes first. The first statement, cin >> alpha;, reads and stores 100 into alpha, and the second statement, cin.ignore(100, "\n");, skips the remaining input in the first line. Next, the third statement, cin >> beta;, reads and stores 200 into beta, and the fourth statements, cin.ignore(100, "\n");, skips the remaining input in the second line. Then the last statement, cin >> gamma;, reads and stores 300 into gamma. Therefore, after the given statements execute, gamma = 300.

When one control statement is located within another, it is said to be ____. a. blocked b. compound c. nested d. closed

c. Correct. When a control statement is placed inside another control statement, it is called nested.

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 reading a single character. a. True b. False

True FEEDBACK: Correct To input data into a char variable, after skipping any leading whitespaces, the extraction operator >> extracts the next character from the input stream and stores it in the char variable appearing in the input statement.

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

True FEEDBACK: Correct While giving the inputs one should be more cautious because computers does not tolerate with the mismatch of variables.

____ are executable statements that inform the user what to do. a. Variables b. Prompt lines c. Named constants d. Expressions

b. Correct. Prompt lines are executable lines that tell the programmer what to do

The expression static_cast<int>(6.9) + static_cast<int>(7.9) evaluates to ____. a. 13 b. 14 c. 14.8 d. 15

a. Correct. In the evaluation of static_cast<dataTypeName>(expression), first the expression is evaluated and its value is converted to the data type specified by dataTypeName. Thus, the evaluation result is 6+7 = 13.

Consider the following code. ​ // Insertion Point 1 ​ using namespace std; const float PI = 3.14; ​ int main() { //Insertion Point 2 ​ float r = 2.0; float area; area = PI * r * r; ​ cout << "Area = " << area <<endl; return 0; } // Insertion Point 3 ​ In this code, where does the include statement belong? a. Insertion Point 1 b. Insertion Point 2 c. Insertion Point 3 d. Anywhere in the program

a. Correct. Typically, include statements are included in the top of the C++ program.

Which of the following is the newline character? a. \r b. \n c. \l d. \bConsider the following code. ​

b. Correct. The escape sequence \n is newline character.

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

ANSWER: False FEEDBACK: Correct Reserved words are typically referred as keywords. They cannot be redefined within in any programs.

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

ANSWER: False FEEDBACK: Correct The escape sequence \r moves the cursor to the start of the current line.

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

ANSWER: True FEEDBACK: Correct In the absence of parentheses in a C++ arithmetic expression, using the precedence rules, operators are usually evaluated from left to right.

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

ANSWER: True FEEDBACK: Correct The maximum number of digits in data type double is 15.

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

ANSWER: True FEEDBACK: Correct The maximum number of digits in the data type float is 6 or 7.

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

ANSWER: True FEEDBACK: Correct The pre-increment operator increments the value of a by 1.

Suppose we declare a variable sum as an int. The statement "sum += 7;" is equivalent to the statement "sum = sum + 7;".

ANSWER: True FEEDBACK: Correct Using the compound operator +=, one can rewrite the assignment statement a = a + b as a += b.

A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time is called a(n) ____. a. algorithm b. linker c. analysis d. design

ANSWER: a FEEDBACK: a. Correct. An algorithm is a step-by-step problem-solving process; it helps to find a solution in a finite amount of time. b. Incorrect. Linker is a program which combines the object program with the programs from libraries. c. Incorrect. Analysis is the first step in solving a problem. d. Incorrect. The term design refers to a plan for the building of a system.

____ programs perform a specific task. a. Application b. System c. Operating d. Service

ANSWER: a FEEDBACK: a. Correct. Application programs perform a specific task. Games and word processors are examples of application programs. b. Incorrect. System programs control the computer. Operating system (OS) is an example of system program. c. Incorrect. Operating programs is not a defined term in computer programming. d. Incorrect. A service program is a collection of runnable procedures.

The digit 0 or 1 is called a binary digit, or ____. a. bit b. bytecode c. Unicode d. hexcode

ANSWER: a FEEDBACK: a. Correct. The digit 0 or 1 is called a binary digit, or bit. A sequence of eight binary digits is called a byte. b. Incorrect. Bytecode is object code which is processed by a program. c. Incorrect. Unicode is an international encoding standard. It consists of 65,536 characters. d. Incorrect. Hexcode uses hexadecimal values to represent colors.

A program that loads an executable program into main memory is called a(n) ____. a. compiler b. loader c. linker d. assembler

ANSWER: b FEEDBACK: a. Incorrect. A compiler is a program which translates instructions written in high-level languages into machine code. b. Correct. A loader is a program that loads an executable program into main memory. c. Incorrect. Linker is a program which combines the object program with the programs from libraries. d. Incorrect. Assembler is a program which translates an assembly language program into equivalent machine language program.

The term GB refers to ____. a. giant byte b. gigabyte c. group byte d. great byte

ANSWER: b FEEDBACK: a. Incorrect. Giant byte is not a defined term in binary units. b. Correct. The binary unit gigabyte is also referred to as GB. 1 gigabyte (GB) contains 1024 megabytes (MB). c. Incorrect. Group byte is not a defined term in binary units (groups of bytes can be referred to a specific unit; 1 kilobyte is group of 1024 bytes). d. Incorrect. There is no binary unit called great byte.

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

False FEEDBACK: Correct In the early 1980s through the early 1990s, the C++ language was evolving in slightly different ways in different compilers. Therefore,C++ programs were not always portable from one compiler to another.

The declaration int a, b, c; is equivalent to which of the following? a. inta , b, c; b. int a,b,c; c. int abc; d. int a b c;

Correct. The declaration int a,b,c; is equivalent to int a , b, c;.

The length of the string "computer science" is ____. a. 14 b. 15 c. 16 d. 18

Correct. The length of the string is the number of character in the string including any spaces in it. Thus the length of the string "computer science" is 16.

Suppose that count is an int variable and count = 1. After the statement count++; executes, the value of count is ____. a. 1 b. 2 c. 3 d. 4

Correct. The post-increment operator increments the value of count by 1. Thus, the value of count after the execution of count++; is 2.

Main memory is called ____. a. read only memory b. random access memory c. readily available memory d. random read only memory

ANSWER: b FEEDBACK: a. Incorrect. Read only memory (ROM) is a non-volatile memory, which contains boot-up programs of a computer. b. Correct. Main memory is also called random access memory (RAM). c. Incorrect. There is no memory called readily available memory. d. Incorrect. There is no memory called random read only memory.

The ____ handles the overall activity of the computer and provides services. a. central processing unit b. operating system c. arithmetic logic unit d. control unit

ANSWER: b FEEDBACK: a. Incorrect. The central processing unit (CPU) is the brain of a computer and it is a most expensive piece of hardware in a personal computer. It is used to execute all instructions. b. Correct. Operating system is a system program that handles the overall activity of the computer and provides services. c. Incorrect. Arithmetic logic unit (ALU) performs arithmetic and logical operations. d. Incorrect. Control unit (CU) directs the operations of a processor.

A sequence of eight bits is called a ____. a. binary digit b. byte c. character d. double

ANSWER: b FEEDBACK: a. Incorrect. The digit 0 or 1 is called a binary digit, or bit. b. Correct. Byte is a unit used to represent digital information. A sequence of eight binary digits (bits) is called a byte. c. Incorrect. The term character represents any number, letter, special symbol, or space. For example, "A" is a character. d. Incorrect. double is a data type.

The devices that feed data and programs into computers are called ____ devices. a. entry b. input c. output d. secondary

ANSWER: b FEEDBACK: a. Incorrect. There is no device called entry device in computer technology. b. Correct. The devices that feed data and programs into computers are called input devices. Examples of an input device are a keyboard, scanner, and mouse. c. Incorrect. The devices that help to show computer results are called output devices. Examples of output devices are monitors and printers. d. Incorrect. There is no device called secondary device in computer technology (secondary storage device is used to store data permanently).

The basic commands that a computer performs are ____, and performance of arithmetic and logical operations. a. input, file, list b. output, folder, storage c. input, output, storage d. storage, directory, log

ANSWER: c FEEDBACK: a. Incorrect. A file is an object used to store data and list is an abstract data type. b. Incorrect. Folder is a directory used to organize computer files. c. Correct. Input, output, storage, and performance of arithmetic and logical operations are the basic commands performed by a computer. d. Incorrect. A directory represents a location of the files stored in a computer.

. ____ represent information with a sequence of 0s and 1s. a. Analog signals b. Application programs c. Digital signals d. System programs

ANSWER: c FEEDBACK: a. Incorrect. Analog signals are continuously varying wave signals; it is represented with the sine waves. b. Incorrect. Application programs perform a specific task. Games and word processors are examples of application programs. c. Correct. Digital signal is a type of electrical signal. The digital signals represent information with a sequence of 0s and 1s. A low voltage will be represented by a 0 and a high voltage will be represented by a 1. d. Incorrect. System programs control the computer. Operating system (OS) is an example of system program.

A program called a(n) ____ translates instructions written in high-level languages into machine code. a. assembler b. decoder c. compiler d. linker

ANSWER: c FEEDBACK: a. Incorrect. Assembler is a program which translates an assembly language program into equivalent machine language program. b. Incorrect. Decoder is an electronic device used to translate signals from one form to another. c. Correct. A compiler is a program which translates instructions written in high-level languages into machine code. d. Incorrect. Linker is a program used to combine the object program with other programs in the library.

A program called a(n) ____ combines the object program with the programs from libraries. a. assembler b. decoder c. linker d. compiler

ANSWER: c FEEDBACK: a. Incorrect. Assembler is a program which translates an assembly language program into equivalent machine language program. b. Incorrect. Decoder is an electronic device used to translate signals from one form to another. c. Correct. Linker is a program which combines the object program with the programs from libraries. d. Incorrect. A compiler is a program which translates instructions written in high-level languages into machine code.

The programming language C++ evolved from ____. a. BASIC b. assembly c. C d. C+

ANSWER: c FEEDBACK: a. Incorrect. BASIC is a high-level programming language. b. Incorrect. Assembly is a low-level programming language designed to make the programmer's job easier. c. Correct. The C++ programming language is evolved from the programming language C. d. Incorrect. There is no programming language called "C+".

Dividing a problem into smaller subproblems is called ____ design. a. OOD b. top-down refinement c. structured d. analog

ANSWER: c FEEDBACK: a. Incorrect. Object Oriented Design (OOD) is an extensively used programming methodology. b. Incorrect. The top-down refinement is not a defined term in structured programming. c. Correct. The structured design is the process of dividing a problem into smaller subproblems. d. Incorrect. Analog is a type of electrical signal. The analog signals are continuously varying wave signals; it is represented with the sine waves.

Main memory is an ordered sequence of items, called ____. a. pixels b. registers c. memory cells d. addresses

ANSWER: c FEEDBACK: a. Incorrect. Pixel is also called as picture element; it is a smallest piece of an image. The combination of pixels will form a computer display. b. Incorrect. Register is a type of computer memory used to store processing data. c. Correct. Main memory is an ordered sequence of items, called memory cells. d. Incorrect. An address represents a specific location in a computer memory.

The devices that the computer uses to display results are called ____ devices. a. exit b. entry c. output d. input

ANSWER: c FEEDBACK: a. Incorrect. The devices fixed at the building doors to open and close the doors are referred as exit devices. b. Incorrect. The devices fixed at the entrance of a building are referred as entry devices. c. Correct. The devices that the computer uses to display results are called output devices. Examples of output devices are monitors and printers. d. Incorrect. The devices that feed data and programs into computers are called input devices. Examples of input devices are a keyboard, scanner, and mouse.

____ consists of 65,536 characters. a. ASCII-8 b. ASCII c. Unicode d. EBCDIC

ANSWER: c FEEDBACK: a. Incorrect. The eight-bit extended American Standard Code for Information Interchange (ASCII) data set consists of 256 characters. b. Incorrect. American Standard Code for Information Interchange (ASCII) data set consists of 128 characters. c. Correct. Unicode is an international encoding standard. It consists of 65,536 characters. Two bytes are required to store a Unicode character. d. Incorrect. The Extended Binary Code Decimal Interchange Code (EBCDIC) is an eight-bit character encoding.

A(n) ____ consists of data and the operations on those data. a. disk b. compiler c. interpreter d. object

ANSWER: d FEEDBACK: a. Incorrect. A disk is a secondary storage used to store information permanently. b. Incorrect. A compiler is a program which translates instructions written in high-level languages into machine code. c. Incorrect. An interpreter is a program used to execute high-level language instructions. d. Correct. An object consists of data and the operations on those data. An object is the combination of data and operations on the data.

Several categories of computers exist, such as ____. a. microframe, midframe, and miniframe b. midsize, microframe, and mainframe c. mainsize, midsize, and microsize d. mainframe, midsize, and micro

ANSWER: d FEEDBACK: a. Incorrect. There is no computer category called microframe, midframe, or miniframe. b. Incorrect. Microframe is not a defined term in categories of computers. c. Incorrect. Mainsize and microsize are not defined terms in categories of computers. d. Correct. Several categories of computers exist, such as mainframe, midsize, and micro.

The command that does the linking on Visual C++ Express (2013 or 2016) and Visual Studio 2015 is Make or Remake.

False FEEDBACK: Correct The Build or Rebuild is the command, which does the linking on Visual C++ Express (2013 or 2016) and Visual Studio 2015.

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

False FEEDBACK: Correct The devices that feed data and programs into computers are called input devices. A mouse, scanner, webcam, and keyboard are examples of input devices.

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

False FEEDBACK: Correct The extraction operator >> not only skips leading blanks but also skips all leading whitespaces. Whitespaces consist of blanks and certain non-printable characters such as tabs and new line characters.

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; a. True b. False

False FEEDBACK: Correct The input values can be in the same line separated by whitespaces or in separate lines.

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

False In the given C++ statement, the extraction operator >> is binary. Left-side to extraction operator is the input stream variable cin and right-side to extraction operator is variable x. The purpose of cin is to read and store values in variables, where variables refer to memory locations.

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

object-oriented

In a C++ program, one and two are double variables and input values are 10.5 and 30.6. After the statement cin >> one >> two; executes, ____. a. one = 10.5, two = 10.5 b. one = 10.5, two = 30.6 c. one = 30.6, two = 30.6 d. one = 11, two = 31

b. Correct. The statement reads the value 10.5 and stores it in one and reads the value 30.6 and stores it in two.

he value of the expression 33/10, assuming both values are integral data types, is ____. a. 0.3 b. 3 c. 3.0 d. 3.3

b. Correct. When the operator / is used with int data type, it performs ordinary division and performs quotient as result and integer division truncates the fractional part. Thus, 33/1

Suppose that alpha and beta are int variables. The statement alpha = beta++; is equivalent to the statement(s) ____.a. alpha = 1 + beta; b. alpha = alpha + beta; c. alpha = beta; beta = beta + 1; d. beta = beta + 1; alpha = beta;

c. Correct. In the statement alpha = beta++;, first the value of beta is assigned to alpha and then beta is incremented by 1; so alpha = beta; beta = beta + 1; is a valid choice.

Suppose that x is an int variable and y is a double variable. The input is: ​ 10 20.7 ​ Choose the values after the following statement executes: cin >> x >> y;. a. x = 10, y = 20 b. x = 10, y = 20.0 c. x = 10, y = 20.7 d. x = 10, y = 21.0

c. Correct. Since x is an int variable and y is a double variable, after reading 10 into x, the extraction operator reads and stores 20.7 into y. Thus, after the statement cin >> x >> y; executes x = 10 and y = 20.7.

The value of the expression 17 % 7 is ____. a. 1 b. 2 c. 3 d. 4

c. Correct. The operator % determines the remainder of the division. Thus, 17 % 7 = 3.

Suppose that alpha and beta are int variables and alpha = 5 and beta = 10. After the statement alpha *= beta; executes, ____. a. alpha = 5 b. alpha = 10 c. alpha = 50 d. alpha = 50.0

c. Correct. The statement alpha *= beta results in multiplying the values of alpha and beta; that is, alpha * beta = 5 * 10 = 50, and then storing the result in alpha.

Choose the output of the following C++ statement: cout << "Sunny " << '\n' << "Day " << endl; a. Sunny \nDay b. Sunny \nDay endl c. Sunny Day d. Sunny \n Day

c. Correct. When a newline escape sequence \n is used in output statement, the insertion point or cursor point moves to the beginning of the next line. Thus, Sunny is printed in the first line and \n moves the cursor to the next line and printing Day.

Suppose that alpha and beta are int variables. The statement alpha = beta--; is equivalent to the statement(s) ____. a. alpha = 1 - beta; b. alpha = beta - 1; c. beta = beta - 1; alpha = beta; d. alpha = beta; beta = beta - 1;

d. Correct. In the statement alpha = beta--;, first the value of beta is assigned to alpha and then beta is decremented by 1; so alpha = beta; beta = beta - 1; is a valid choice.

The memory allocated for a float value is ____ bytes. a. two b. four c. eight d. sixteen

four

____________________ languages include FORTRAN, COBOL, Pascal, C, C++, Java, and Python.

high level

46. The maximum number of significant digits is called the ____________________.

precision

____________________ is the process of planning and creating a program.

programming

The smallest individual unit of a program written in any language is called a(n) ____________________

token

A(n) ____________________ is a memory location whose contents can be changed.

variable


Ensembles d'études connexes

Module 4/Unit 4: The Accounting Cycle and Accounting Information Systems

View Set

The Catcher In The Rye Study Guide English III Honors

View Set

Specific Gynecology Course Objectives: Infections PA 603 Women's Health

View Set

General Biology 1011 Exam 3 Review

View Set

Comprehensive MSK Review (all classes)

View Set