CSCE 206: Structured Programming in C++ 2017 Spring Exam 1 Monday, February 13, 2017 Total - 100 Points B Instructions: Total of 11 pages, including this cover and the last page. Before starting the exam, count the pages to make sure you have all 11. Read the questions and instructions carefully to see what kind of answer is expected. Put the Exam Code on your scantron in the lower right corner There are 50 questions worth 2 points each. On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work Signature: Name (Print): UIN: Section: 1
TR UE/FALSE: Select A if the statement is true and B if the statement is false. 1) When typing in your source code into the computer, you must be very careful since most of your C++ instructions, header files, and variable names are case sensitive. 2) Software engineering is a field that encompasses designing, writing, testing, debugging, documenting, modifying, and maintaining computer programs. 3) In C++, when an operator is working with operands of different types, it strives to convert the operands to the same type through demotion. 4) A variable called "average" that stores the average of N numbers should be declared as an integer data type because it will probably hold data that contains decimal places. 5) The following statement will output $7.00 to the screen: cout << setprecision(7) << dollars << endl; 6) On a computer it is required that long integers are at least as big as integers 7) cin automatically converts the data read from the keyboard to the data type of the variable used to store it (assume data is reasonable). 8) Escape sequences are always stored internally as two consecutive characters 9) Arithmetic operators that share the same precedence have right to left associativity. 10) When a program uses the setw manipulator, the iosetwidth header file must be included in a preprocessor directive. 11) The output of the following program is A #include <iostream> #include <string> using namespace std; main() { char letter; letter = "A"; cout<<letter; } 12) The preprocessor reads a C++ program before it is compiled and only executes those lines beginning with a # symbol 2
13) In C++, it is impossible to display the number 34.789 in a field of 9 spaces with 2 decimal places of precision. 14) When the fixed manipulator is used, the value specified by the setprecision manipulator will be the number of digits to appear before the decimal point. 15) Machine language is an example of a high-level language. MULTIPLE CHOICE: Choose the the single option that best completes the statement or answers the question. 16) When this operator is used with string operands it concatenates them, or joins them together. A. & B. * C. % D. + 17) You want the user to enter the length, width, and height from the keyboard. Which cin statement is correctly written? A. cin << length, width, height; B. cin.get(length, width, height); C. cin >> length >> width >> height; D. cin >> length, width, height; E. cin << length; width; height; 18) What will the value of x be after the following statements execute? int x = 1; int y = 4; int z = 3; x = y + z * 2 % (z + y); A. 10 B. 14 C. 0 D. 2 E. Compiler error 19) Which character signifies the beginning of an escape sequence? A. // B. / C. \ D. # E. { 3
20) A 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 21) If a program produces incorrect answer when run, it is due to A. Syntax errors B. Logic errors C. Compiler errors D. Linker errors 22) In the process of translating a source file into an executable file, which of the following is the correct sequence? A. Source code, preprocessor, modified source code, compiler, object code, linker, executable code. B. Source code, preprocessor, modified source code, linker, object code, compiler, executable code. C. Preprocessor, source code, compiler, executable code, linker, modified source code, object code. D. Source code, compiler, modified source code, preprocessor, object code, linker, executable code. E. Source code, linker, object code, compiler, modified source code, preprocessor, executable code. 23) What is the value of number after the following statements execute? int number = 7; number += 5; number -= 2; number *= 4; A. 4 B. 30 C. 40 D. 2 4
24) In C++ the == operator indicates: A. equality B. assignment C. subtraction D. negation 25) are used to translate each source code instruction into the appropriate machine language instruction. A. Modules B. Library routines C. Compilers D. Preprocessor directives 26) What will the following code display? cout << "Four\n" << "score\n"; cout << "and" << "\nseven"; cout << "\nyears" << "\n" << "ago" << endl; A. Four score and seven years ago B. Four score and seven years ago C. Four score and seven years ago D. Four score and seven years ago 27) Relational operators allow you to numbers. A. add B. multiply C. compare D. average 5
28) This function tells the cin object to skip one or more characters in the keyboard buffer. A. cin.remove() B. cin.jump() C. cin.hop() D. cin.skip() 29) What is the output of the following program: #include <iostream> #include <string> using namespace std; int main() { string firstname; string lastname; firstname = "John "; lastname = "Jacobs"; cout << "My name is " << firstname + lastname <<'\n'; return 0; } A. John B. Jacobs C. John Jacobs D. Compiler error 30) Which statement is equivalent to the following? number += 2; A. number = number + 2; B. number + 2; C. number = 2; D. number + 2; E. number = number + number; 6
31) What is the output of the following statement: cout << 8 % 4 * (15 / (1 + 3)) << endl; A. 15 B. 6 C. 7.5 D. 8 32) In a C++ program, two slash marks ( // ) indicate: A. The end of a statement B. The beginning of a comment C. The end of the program D. The beginning of a block of code 33) When a relational expression is false, it has the value. A. one B. zero C. zero, one, or minus one D. less than zero 34) Which of the following best describes an operator? A. An operator is a rule that must be followed when constructing a program. B. An operator allows you to perform operations on one or more pieces of data. C. An operator marks the beginning or ending of a statement, or is used to separate items in a list. D. An operator is a word that has a special meaning. E. An operator is a symbolic name that refers to a variable. 35) What is the output of the following program: int main() { int x = 5, y = 20, z = 10; z *= x + y * x; cout << z; return 0; } A. 150 B. 100 C. 1050 D. 300 E. Compiler Error 7
36) A variable declaration announces the name of a variable that will be used in a program, as well as: A. The type of data it will be used to hold B. The operators that will be used on it C. The number of times it will be used in the program D. The area of the code in which it will be used 37) Assume that x is an int variable. What value is assigned to x after the following assignment statement is executed? x = -3 + 4 % 6 / 3; A. 0 B. -1 C. -2 D. -3 38) Programmer-defined names of memory locations that may hold data while the program is run are: A. Operators B. Variables C. Syntax D. Operands 39) What is the value stored at x, given the statements: int x; x = 6 / static_cast<int>(4.5 + 5.5); A..6 B. 0 C..275229 D. 3.3 40) Which statement will read an entire line of input into the following string object? string name; A. cin << name; B. cin name; C. getline(cin, name); D. cin.get(name); 8
41) Every complete C++ program must have a. A) Comment B) Function named main C) Preprocessor directive D) Symbolic constant E) cout statement 42) Characters or symbols that perform operations on one or more operands are: A. Syntax B. Op codes C. Operators D. Program ops 43) These are data items whose values do not change while the program is running. A. Literals B. Variables C. Comments D. Integers 44) What will the value of x be after the following statements execute? int x; x = 22.0 / 4; A. 5.5 B. 5 C. 2 D. 0. 45) At the heart of a computer is its central processing unit. The CPU's job is: A. To fetch instructions B. To carry out the operations commanded by the instructions C. To produce some outcome or resultant information D. All of the above 9
46) Which statement allows you to properly check the char variable code to determine whether it is equal to a "C" and then output "This is a check" and then advance to a new line? A) if code is equal to C cout << "This is a check\n"; B) if (code = "C") cout << "This is a check" << endl; C) if (code == 'C') cout << "This is a check\n"; D) if (code == C) cout << "This is a check" << endl; E) None of these 47) Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL; 7 MY_VAL = 77; 8 cout << MY_VAL << endl; 9 return 0; 10 } A. 6 B. 7 C. 8 D. 9 48) What is the value of cookies after the execution of the following statements? int number = 38, children = 47, cookies; cookies = number % children; A. 38 B. 47 C. 0.81 D. 1.24 10
49) A set of well-defined steps for performing a task or solving a problem is known as a(n): A. Hierarchy B. Machine Code C. Central Processing Unit D. Encoded instruction E. Pseudocode 50) Which one of the following would be an illegal variable name? A. dayofweek B. 21YearsOld C. _employee_num D. June1997 E. itemsorderedforthemonth 11