CSE 100 Exam 1

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

The expression 5 % 2 evaluates to A) 1 B) 2 C) 2.5 D) 5.2 E) 10

A) 1

The expression 7 % 2 evaluates to A) 1 B) 3 C) 3.5 D) 7.2 E) 14

A) 1

What value will be assigned to the variable number by the following statement? int number = 3.75; A) 3 B) 4 C) 3.75 D) None of the above. E) It's unpredictable. That's the problem.

A) 3

What value will be assigned to the variable number by the following statement? int number = 7.8; A) 7 B) 8 C) 7.8 D) None of the above. E) It's unpredictable. That's the problem.

A) 7

What value will be assigned to the variable number by the following statement? int number = 7.8; A) 7 B) 8 C) 7.8 D) None of the above. E) It's unpredictable. That's the problem.

A) 7

n C++ when a relational expression is false, it has the value A) 1. B) 0. C) -1. D) "0". E) of any negative number.

B) 0.

The expression 5 / 2 evaluates to A) 1 B) 2 C) 2.5 D) 5.2 E) 10

B) 2

The expression 7 / 2 evaluates to A) 1 B) 3 C) 3.5 D) 7.2 E) 14

B) 3

________ can be used to override the rules of operator precedence. A) Some operators B) Parentheses C) Operands D) Associativity E) Nothing

B) Parentheses

________ is used in a C++ program to mark the end of a statement, or to separate items in a list. A) A separator B) Punctuation C) An operator D) A keyword E) A blank space

B) Punctuation ( ; )

________ causes a program to wait until information is typed at the keyboard and the Enter key is pressed. A) An input device B) The cin object C) The cout object D) A preprocessor E) Nothing

B) The cin object

The ________ operator always follows the cin object, and the ________ operator follows the cout object. A) input, endl B) getChar, printChar C) >> , << D) >> , >> E) << , >>

C) >> , <<

What will the following statement do if x equals 17 and answer = 20? answer = x > 100 ? 0 : 1; A) Assign 0 to answer. B) Assign 0 to x. C) Assign 1 to answer. D) Assign 1 to x. E) Assign 17 to answer.

C) Assign 1 to answer.

Which of the following is/are valid C++ identifiers? A) June-2010 B) June.2010 C) June_2010 D) 2010June E) Both C and D.

C) June_2010

________ is an example of volatile memory, used for temporary storage while a program is running. A) A flash drive B) The ALU C) RAM D) The CPU E) A hard disk

C) RAM

The following 4 lines of C++ code, use strings. string firstName; // Define a string object char lastName[7]; // Define a C-string firstName = "Abraham"; // Assign a value to the string object lastName = "Lincoln"; // Assign a value to the C-string Which of the following statements is /are true? A) The string object is defined incorrectly because no size is given for it. B) The 2 string definitions are correct, but the 2 assignment statements are wrong. C) The string object is assigned a value correctly, but the C-string is not. D) The C-string is assigned a value correctly, but the string object is not. E) All 4 lines of code are correct.

C) The string object is assigned a value correctly, but the C-string is not.

If number is an int variable, both of the following statements will print out its value: cout << number; cout << "number";

False

T/F: Most modern computers can understand and execute pseudocode.

False

T/F: Once a value has been stored in a variable it cannot be changed.

False

T/F: The purpose of the compiler is to convert object code into source code.

False

T/F: executable code is computer code that contains no errors.

False

True/False: A switch statement branches to a particular block of code depending on the value of a numeric (i.e. integer or floating-point) variable or constant.

False

True/False: A variable of the char data type can hold a set of characters like "January".

False

True/False: IDE stands for internal data engine.

False

True/False: If a variable is defined as int sum; it may be written in the program code as sum or Sum, but not SUM.

False

True/False: If the sub-expression on the left side of an && operator is true, the expression on the right side will not be checked.

False

True/False: If the value of dollars is 5.0, the following statement will output 5.00 to the monitor: cout << fixed << showpoint << setprecision(4) << dollars << endl;

False

True/False: In C++, the 5 basic arithmetic operators are addition (+), subtraction (-), multiplication (*), division (/), and exponentiation (^).

False

True/False: Relational operators connect two or more relational expressions into one, or reverse the logic of an expression.

False

True/False: The cin object lets the user enter a string that contains embedded blanks.

False

True/False: The following C++ statement will assign 1.5 to the result variable. int result = 3.0 / 2.0;

False

True/False: The following C++ test checks if the variable child is in the range 3 - 12. if (child >= 3 && <= 12)

False

True/False: The following C++ test checks if the variable child is in the range 3 to 12. if (child >= 3 || child <= 12)

False

True/False: The following is a legal C++ statement to define and initialize a variable. char firstName = "Jack";

False

True/False: The following pair of C++ statements is legal. const double taxRate; taxRate = .05;

False

True/False: The following pair of C++ statements will cause 3.5 to be output. double number = 7 / 2; cout << number;

False

True/False: The following statement sets the value of total to -3. total -= 3;

False

True/False: The following statements both declare the variable num to be an integer. int num; INT num;

False

True/False: The following statements will not print anything. x = 5; if (x < 5) cout << "Hello "; cout << "world \n";

False

True/False: The following two C++ statements perform the same operation. wages = regPay + overTime; regPay + overTime = wages;

False

True/False: The following two statements both assign the value 5 to the variable dept. 5 = dept; dept = 5;

False

True/False: The only difference between C-strings and string objects is how they are declared and internally stored. They are used exactly the same way.

False

True/False: The scope of a variable is the program it is defined in.

False

True/False: To check if a variable has a particular value, use the = relational operator, as in the statement if (s = 3) cout << "S has the value 3";

False

True/False: When a C++ expression is evaluated, binary operations are performed before unary operations.

False

True/False: logical operators AND and OR have a higher precedence than the NOT operator.

False

T/F: Before a computer can execute a program written in a high level language, such as C++, it must be translated into object code.

True

T/F: Most of the lines in a program contain something meaningful, however, some of the lines may contain nothing at all

True

T/F: Syntax involves rules that must be followed when writing a program.

True

T/F: if a new value is stored in a variable, it replaces whatever value was previously there.

True

True/False: A pair of characters or a pair of string objects can be compared with any of the relational operators.

True

True/False: All of the relational operators are binary..

True

True/False: An expression in a C++ if statement that evaluates to 5, -5, or for that matter anything other than 0, is considered true.

True

True/False: Assuming goodData is a Boolean variable, the following two tests are logically equivalent. if (goodData == false) if (!goodData)

True

True/False: Assuming moreData is a Boolean variable, the following two tests are logically equivalent. if (moreData == true) if (moreData)

True

True/False: C++ is a case-sensitive language.

True

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

True

True/False: Relational expressions and logical expressions are both Boolean, which means they evaluate to true or false.

True

True/False: The cin object can be used to input more than one value in a single statement.

True

True/False: The following statement sets sum1, sum2, and sum3 all to zero. sum1 = sum2 = sum3 = 0;

True

True/False: The following two expressions evaluate to the same thing: c + a * b c + (a * b)

True

True/False: The following two statements could be used interchangeably in a C++ program. // Program Payroll /* Program Payroll */

True

True/False: The following two statements will assign the same value to result. result = a + b * c; result = b * c + a;

True

True/False: The rule for matching an else with an if is that an else goes with the last if statement before it that doesn't have its own else.

True

True/False: The statement pass = (score >= 7) ? true : false; does exactly the same thing as the if/else statement below: if (score >= 7)pass = true; else pass = false;

True

True/False: When an operator has two operands of different data types, C++ always converts them both to double before performing the operation.

True

True/False: When an operator's operands are of different data types, such as int and double, C++ automatically converts one of them so that they are the same data type.

True

The five elements that are common to all programming languages.

keywords, programmer-defined symbols, operators, punctuation, and syntax

________ are data items whose values cannot change while the program is running. A) Literals B) Variables C) Fixed data D) Integers E) None of the above

A) Literals

Even when there is no power to the computer, data can be held in A) a secondary storage device. B) random access memory (RAM). C) variables. D) a computer program. E) any of the above.

A) a secondary storage device.

A storage location in the computer's memory that can hold a piece of data is called A) a variable. B) a number. C) a data cell. D) a storage box. E) RAM.

A) a variable.

In the C++ statement pay = rate * hours; the * symbol is an example of A) an operator. B) an operand. C) a variable separator. D) syntax. E) none of the above.

A) an operator.

An operation that copies a value into a variable is called a(n) ________ operation. A) assignment B) equals C) copy D) declaration E) cout

A) assignment

If a switch statement has no ________ statements, the program "falls through" all of the statements below the one with the matching case expression. A) break B) exit C) case D) default E) relational

A) break

The ________ object causes data to be input from the keyboard. A) cin B) cout C) keyboard buffer D) standard input E) dataIn

A) cin

Which of the following will cause the next output to begin on a new line? A) cout << endl; B) cout << "endl"; C) cout << "/n"; D) All of the above E) A and C, but not B

A) cout << endl;

Which of the following correctly declares an enumerated data type named student? A) enum student { Bill, Tom, Mary }; B) enum student { "Bill", "Tom", "Mary" }; C) int Bill = 1, Tom = 2, Mary = 3; enum student { 1, 2, 3 }; D) Any of the above 3 methods will work. E) None of the above 3 methods will work.

A) enum student { Bill, Tom, Mary };

A(n) ________ is a variable, usually a bool, that signals when a condition exists. A) flag B) identifier C) named constant D) condition variable E) logical variable

A) flag

Which of the following will allow an entire line of text to be read into a string object, even if it contains embedded blanks? A) getline() B) cin >> C) cin.get() D) cin.ignore() E) both A and B, but not C or D.

A) getline()

The ________ statement executes one statement, or block of statements, if a condition is true and skips it, doing nothing, if the condition is false. A) if B) if/else C) if/else if D) switch E) if/endif

A) if

When a program lets the user know that an invalid menu choice has been made, this is an example of A) input validation. B) output validation. C) menu reselection. D) invalidation. E) being user unfriendly.

A) input validation.

A trailing else placed at the end of an if/else if statement provides a default action when ________ of the if conditions is/are true. A) none B) any one C) only the last one D) at least two E) all

A) none

The CPU includes A) the arithmetic and logic unit (ALU) and the control unit. B) the ALU and the I/O unit. C) the I/O unit and the control unit. D) the ALU and the main memory unit. E) all of the above.

A) the arithmetic and logic unit (ALU) and the control unit.

In any program that uses the cin object, you must #include A) the iostream header file. B) the fstream header file. C) >> and << operators. D) named constants. E) none of the above.

A) the iostream header file.

The purpose of a memory address is A) to identify the location of a memory cell. B) to allow multitasking. C) to prevent multitasking. D) to locate a program. E) none of the above.

A) to identify the location of a memory cell.

A variable definition always specifies the name of a variable and tells A) what type of data it can hold. B) how many times it will be used in the program. C) the part of the code where it will be used. D) what its starting value is. E) all of the above.

A) what type of data it can hold.

________ must be included in a program in order to use the cout object. A) Opening and closing braces B) The iostream header file C) A cout declaration D) Strings E) None of the above

B) The iostream header file

In a C++ program, two slash marks ( // ) indicate the beginning of A) a block of code. B) a comment. C) a variable definition. D) a program. E) none of the above.

B) a comment.

In programming terms, a group of characters inside a set of double quotation marks (" ") is called A) a character literal. B) a string literal. C) a character set. D) none of the above. E) any of the above.

B) a string literal.

You must have a(n) ________ for every variable you include in a program. A) purpose B) definition C) comment D) numeric value E) output statement

B) definition

The bool data type A) can be used to store a single character. B) has only two values: true and false. C) is used to store extra-large numbers. D) is used to represent numbers in E notation. E) does none of the above.

B) has only two values: true and false.

The ________ statement executes one block of statements if a test condition is true, and another block if the condition is false. A) if B) if/else C) if/else if D) switch E) trailing else

B) if/else

Mistakes that allow a program to run, but cause it to produce erroneous results are called A) syntax errors. B) logic errors. C) compiler errors. D) linker errors. E) none of the above.

B) logic errors.

When an arithmetic expression contains two or more different operators, such as * and +, the order in which the operations is done is determined by A) left to right order. B) operator precedence. C) operator associativity. D) the programmer. E) the compiler.

B) operator precedence.

The computer's main memory is commonly known as A) direct-access memory (DAM). B) random-access memory (RAM). C) read only memory (ROM). D) secondary storage. E) none of the above.

B) random-access memory (RAM).

The term hardware refers to A) the difficulty of programming. B) the physical components that make up a computer. C) the way a computer's storage space is organized. D) the fixed order of a program's instructions. E) none of the above.

B) the physical components that make up a computer.

Memory locations that can hold data are called A) operators. B) variables. C) syntax. D) operands. E) none of the above.

B) variables.

Hand tracing a program is A) a program design technique. B) a program run-time testing technique. C) a program debugging technique. D) creating a drawing of what a program's output screen will look like. E) none of the above.

C) a program debugging technique.

To use the sqrt() function, or other mathematical library functions, you must #include the ________ header file in your program. A) iostream B) iomanip C) cmath D) algebra E) mathlib

C) cmath

Relational operators allow you to ________ numbers. A) add B) multiply C) compare D) average E) verify

C) compare

The ________ is used to display information on the computer's screen. A) < symbol B) cin object C) cout object D) print object E) output object

C) cout object

++ is an example of a ________ programming language. A) low-level B) mid-level C) high-level D) binary E) non-structured

C) high-level

The ________ statement acts like a chain of if statements. Each performs its test, one after the other, until one of them is found to be true or until the construct is exited without any test ever evaluating to true. A) if/then B) if/else C) if/else if D) if/not if E) if/endif

C) if/else if

Words with a special meaning that may be used only for their intended purpose are known as A) single purpose words. B) programmer-defined identifiers. C) keywords. D) syntax words. E) none of the above.

C) keywords.

When an if statement is placed within the conditionally-executed code of another if statement, this is known as a(n) A) complex if B) overloaded if C) nested if D) conditional if E) double if

C) nested if

Characters or symbols that perform operations on one or more operands are A) syntax. B) op codes. C) operators. D) program ops. E) none of the above.

C) operators.

#include <iostream> is an example of a(n) A) comment. B) I/O statement. C) preprocessor directive. D) stream directive. E) compiler option.

C) preprocessor directive.

A(n) ________ is a set of instructions that tells the computer how to solve a problem. A) compiler B) linker C) program D) operator E) variable

C) program

Creating a program requires many steps. Three of these are A) input, processing, and output. B) keywords, operators, and punctuation. C) program design, writing source code, and testing. D) syntax, logic, and error handling. E) none of the above.

C) program design, writing source code, and testing.

The expression x < y is called a(n) ________ expression. A) arithmetic B) logical C) relational D) comparison E) binary

C) relational

Operator associativity is either left to right or A) top to bottom. B) front to back. C) right to left. D) inside to outside. E) nothing else; it is always left to right.

C) right to left.

A ________ is used to mark the end of a complete C++ programming statement. A) comment B) period C) semicolon D) closing brace E) new line

C) semicolon

The ________ stream manipulator can be used to establish a field width for the value immediately following it. A) cin B) setField C) setw D) iomanip E) width

C) setw

The statements written by a programmer are called A) syntax. B) object code. C) source code. D) language elements. E) none of the above.

C) source code.

A ________ is a complete instruction that causes the computer to perform some action. A) line B) line number C) statement D) statement number E) programming construct

C) statement

Internally, the central processing unit (CPU) consists of two parts: A) input devices and output devices. B) software and hardware. C) the arithmetic and logic unit (ALU) and the control unit. D) single-task devices and multi-task devices. E) the compiler and the linker.

C) the arithmetic and logic unit (ALU) and the control unit.

When the final value of an expression is assigned to a variable, it will be converted to A) the smallest possible data type. B) the largest possible data type. C) the data type of the variable. D) the data type of the expression. E) none of the above.

C) the data type of the variable.

C++ automatically places ________ at the end of a string literal. A) a semicolon B) quotation marks C) the null terminator D) a newline escape sequence E) a blank

C) the null terminator

The default section of a switch statement performs a similar task as the ________ portion of an if/else if statement. A) conditional test B) break C) trailing else D) else if E) body

C) trailing else

The ________ operator takes an operand and reverses its truth or falsehood. A) relational B) && C) || D) ! E) !=

D) !

The ________ directive causes the contents of another file to be inserted into a program. A) #getfile B) #library C) #insert D) #include E) None of the above

D) #include

What does the following C++ expression evaluate to? 6 - 6 / 3 + 3 A) 0 B) 3 C) 5 D) 7 E) None of the above

D) 7

The ________ operator is used in C++ to test for equality. A) = B) <> C) && D) == E) ||

D) ==

Which of the following definitions will allow the variable average to hold floating-point values? A) float average; B) double average; C) auto average = 0.0; D) All of the above E) A and B, but not C

D) All of the above

Which of the following definitions will allow the variable total to hold floating-point values? A) float total; B) double total; C) auto total = 0.0; D) All of the above E) A and B, but not C

D) All of the above

If s1 and s2 are string objects, s1 == s2 is true when A) s1 = "lion" and s2 = "lioness". B) s1 = "dog" and s2 = "DOG". C) s1 = "cat" and s2 = "cat ". D) None of these because in each case one or more characters in the strings have different ASCII codes. E) None of these because string objects cannot be compared with relational operators.

D) None of these because in each case one or more characters in the strings have different ASCII codes.

Every C++ program must have A) comments. B) variables. C) literals. D) a function called main. E) all of the above.

D) a function called main.

An integrated development environment (IDE) normally includes A) a text editor. B) a compiler. C) a debugger. D) all of the above. E) none of the above.

D) all of the above.

High-level programming languages include A) C++ and Java. B) C++ and JavaScript. C) C++ and Visual Basic. D) all of the above. E) A and B, but not C.

D) all of the above.

A set of well-defined steps for performing a task or solving a problem is known as A) a hierarchy chart. B) a flowchart. C) a solution engine. D) an algorithm. E) software engineering.

D) an algorithm.

A variable must be defined A) in every program. B) and initialized at the same time. C) in order to perform output. D) before it can be used. E) in all of the above cases.

D) before it can be used.

A flag is a variable, usually of data type ________, that signals whether or not some condition exists. A) char B) string C) int D) bool E) logical

D) bool

The ________ coordinates the computer's operations by fetching the next instruction and using control signals to regulate the other major computer components. A) arithmetic and logic unit (ALU) B) traffic controller C) instruction manager D) control unit E) operating system

D) control unit

At the heart of a computer is its central processing unit (CPU). Its job is to A) fetch instructions. B) carry out the operations commanded by the instructions. C) produce some result. D) do all of the above. E) do none of the above.

D) do all of the above.

Three primary activities of a typical program are A) creating variables, operators, and keywords. B) executing lines, statements, and keywords. C) reading, writing, and arithmetic. D) input, processing, and output. E) compiling, linking, and debugging.

D) input, processing, and output.

To use stream manipulators, you should include the ________ header file. A) stream B) fstream C) format D) iomanip E) iostream

D) iomanip

Which of the following statements will assign number a value from 90 - 100. A) number = rand() % 90 + 10; B) number = rand() % 90 + 11; C) number = rand() % 10 + 90; D) number = rand() % 11 + 90; E) None of the above.

D) number = rand() % 11 + 90;

The cin object must be followed by A) a single stream insertion (<<) operator. B) one or more stream insertion operators (<<). C) a single stream extraction (>>) operator. D) one or more stream extraction (>>) operators. E) no operators.

D) one or more stream extraction (>>) operators.

When converting some algebraic expressions to C++, you may need to insert ________ and ________ that do not appear in the algebraic expression. A) values, exponents B) operators, calculations C) operators, operands D) operators, parentheses E) operands, parentheses

D) operators, parentheses

A C++ character literal is enclosed in ______ quotation marks, whereas a string literal is enclosed in ______ quotation marks. A) double, single B) triple, double C) open, closed D) single, double E) no, some

D) single, double

The programs that control and manage the basic operations of a computer are generally referred to as A) control programs. B) utility programs. C) system hardware programs. D) system software. E) computer application programs.

D) system software.

In C++, a value can be raised to a power by using A) the ^ operator. B) the exp operator. C) the power operator. D) the pow function. E) the square function.

D) the pow function.

What will the following expression evaluate to? !( 6 > 7 || 3 == 4) A) 0 B) -1 C) 6 D) true E) false

D) true

The ________ operator is known as the logical OR operator. A) ! B) & C) && D) || E) //

D) ||

The C++ ________ operator represents logical AND. A) ++ B) .AND. C) || D) & E) &&

E) &&

11) Which of the following keywords is/are the names of C++ data types? A) short B) long C) double D) bool E) All of the above

E) All of the above

Which of the following is/are valid C++ identifiers? A) department_9 B) aVeryLongVariableName C) last-name D) All of the above. E) Both A and B, but not C.

E) Both A and B, but not C.

Which of the following expressions will evaluate to 2.5? A) static_cast<double>(5/2) B) static_cast<double>(5)/2 C) 5/static_cast<double>(2) D) All three of the above E) Both B and C, but not A

E) Both B and C, but not A

Which of the following statements doubles the value stored in answer? A) answer += 2; B) answer *= 2; C) answer = answer * 2; D) All three of the above E) Both B and C, but not A

E) Both B and C, but not A

Which of the following statements about named constants is/are true? A) A named constant must be initialized with a value at the time it is declared. B) The identifier name of a named constant can only contain capital letters and underscores. C) The initial value of a named constant cannot be changed during the program execution. D) All 3 of the above statements are true. E) Statements A and C are true, but B is not.

E) Statements A and C are true, but B is not.

Which of the following is an example of a secondary storage device? A) a hard disk drive B) a USB flash drive C) a CD D) a DVD E) all of the above

E) all of the above

A ________ variable can hold only one of two values: true or false. A) binary B) single precision C) T/F D) char E) bool

E) bool

9) What literal(s) appear in the following C++ statement? int number = 4 + 8; A) number B) 4 C) 8 D) 12 E) both B and C

E) both B and C

The statement cout << setw(4) << num4 << " "; A) outputs the value of num4 rounded to 4 decimal places. B) outputs "setw(4)" before the value in the variable num4. C) outputs the first 4 digits of the number stored in num4. D) outputs the value stored in num4 four times. E) does none of above.

E) does none of above.

Program code that can be evaluated to a value is called a(n) A) operation. B) line. C) evaluator. D) result. E) expression.

E) expression.

The ________ statement causes other program statements to execute only under certain conditions. A) logical B) relational C) cin D) cout E) if

E) if

A software package that includes a text editor, compiler, debugger, and assorted utilities for creating, testing, and running software is called A) a low-level programming language. B) a high-level programming language. C) a software utility package (SUP). D) an operating system. E) none of the above.

E) none of the above.

The following statement number = rand() % 5 + 10; assigns number a value in the range of A) 5 - 10 B) 0 - 15 C) 5 - 15 D) 10 - 15 E) none of the above.

E) none of the above.

The programmer usually enters source code into a computer using A) a preprocessor. B) a compiler. C) a linker. D) a debugger. E) none of the above.

E) none of the above.


Kaugnay na mga set ng pag-aaral

Cognitive Psychology: Chapter 13

View Set

APEH Unit 1C Exploration & Conquest Test

View Set

First Aid, Emergency Care, and Disaster Management Merry

View Set

NUR 304 Chapter 47 Concepts of Care for Patients with Stomach Conditions

View Set

Landing Gear Brakes Practice Quiz

View Set

Week 5: Chapter 12: Recognizing Employee Contributions with Pay

View Set