Answer_Key_Version_3

.pdf

School

Michigan State University *

*We aren’t endorsed by this school

Course

232

Subject

Computer Science

Date

Jan 9, 2024

Type

pdf

Pages

11

Uploaded by BailiffHawk7826

Report
Exam 1 CSE 232 (Introduction to Programming II) Fall 2023 ANSWERS VERSION 3 Full Name: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . PID: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Instructions: DO NOT START/OPEN THE EXAM UNTIL TOLD TO DO SO. You may however write and bubble in your name, PID and VERSION/FORM NUMBER (with a #2 pencil) on the front of the printed exam and bubble sheet prior to the exam start. This exam is Answers Version 3. Present your MSU ID (or other photo ID) when returning your bubble sheet and printed exam. Only choose one option for each question. Assume any needed #include s and using std::...; namespace declarations are performed for the code samples. Every question is worth the same amount of points. There are 55 questions, but you only need 50 questions correct for a perfect score. No electronics are allowed to be used or worn during the exam. This means smart-watches, phones and headphones need to be placed away in your bag. The exam is open note, meaning that any paper material (notes, slides, prior exams, assignments, books, etc.) are all allowed. Please place all such material on your desk prior to the start of the exam, (so you won’t need to rummage in your bag during the exam). If you have any questions during the exam, please raise your hand and a proctor will assist you. http://xkcd.com/499/ Answers Version 3 Page 1 of 11
1. Which of the following invokes a function with no arguments provided? (a) Func {} (b) Func (c) Func(NULL) (d) Func(void) (e) Func() (f) (Func) Correct answers: (e) 2. Which of the following can you NOT make a const reference to? (a) A reference (b) A value returned by a function (c) A pointer (d) A const value (e) A non-const value (f) A literal value (g) All of the above permit const refer- ences Correct answers: (g) 3. C++ was created to extend which prior programming language? (a) Basic (b) C+ (c) Haskell (d) Bash (e) Fortran (f) C (g) Python (h) None of the above Correct answers: (f) 4. The following code is an example of what problem? if (is file open) if (data is full && process) Turn On Alarm(4); else Close File(); (a) Unsigned Overflow Problem (b) Overloaded Operator Problem (c) Dangling Else Problem (d) Inconsistent Capitalization Problem (e) Ambiguous Flow Control Problem (f) Under-Documented Problem Correct answers: (c) 5. What does this code output? for (unsigned i = 4; i >= 0; --i) { std::cout << i; } (a) 4321 (b) 43210 (c) 3210 (d) 321 (e) None of the above Correct answers: (e) 6. How many iterations of the while loop will occur? while (7) { int x = 4; ++x; if (x > 6) { break; } } (a) 0 iterations (b) 1 iteration (c) 2 iterations (d) 4 iterations (e) 6 iterations (f) 7 iterations (g) more than 13 iterations Correct answers: (g) Answers Version 3 Page 2 of 11
7. What is the return type of this function? std::string Exclamation(int num) { return "!"; } (a) std::string (b) Exclamation (c) int * (d) "!" (e) int (f) None of the above Correct answers: (a) 8. What happens if you index beyond the end of a string. Example: std::string s { "abc" } ; std::cout << s[3]; (a) A Run-Time Error (b) A Syntax Error (c) A random character will be returned (d) Undefined Behavior (e) A character from another string will be returned (f) The last character will be returned Correct answers: (d) 9. On my system, when I call sizeof(bool); I get the value 1 . What does this mean? (a) It means that a bool takes up one word (on a 64-bit machine this is 64 bits). (b) It means that a bool takes up one byte. (c) It means that a bool can hold at most one value. (d) It means that a bool takes up one bit. (e) It means that a bool’s size is the same as the size of a function. (f) It means that a bool true value is equivalent to an integer 1. (g) It means that a bool’s type deter- mines if it is true or false. Correct answers: (b) 10. The getline function will read from a stream until what type of character is en- countered? (a) A whitespace character (include space, newline, and tab) (b) The space character (c) A non-alphabetic character (d) A non-ASCII character (e) The newline character Correct answers: (e) 11. Declaring all local variables at the begin- ning of a function is bad practice because it results in unnecessarily large XXXXs. What term should replace XXXXs? (a) Functions (b) Code sizes (c) Memory uses (d) Scopes (e) Comments (f) Blocks (g) Exceptions (h) Variable names Correct answers: (d) 12. Why should you generally not compare floats for equality? (a) Because floats must be converted to ints before comparison operators can be used (b) Because float arithmetic is imprecise (c) Because floats don’t support the equality operator (d) Because a float’s value changes each time it is read (e) Because floats are casted to doubles when used in math (f) All of the above are false, floats should be compared for equality Correct answers: (b) Answers Version 3 Page 3 of 11
13. What is the output of the following code? std::cout << static cast<int>(’b’); (a) 0 (b) 1 (c) 2 (d) 3 (e) 4 (f) None of the above Correct answers: (f) 14. Which of the following is NOT a binary op- erator? (a) && (b) << (c) ++ (d) += (e) = (f) / (g) >= Correct answers: (c) 15. After the code below executes, which pointers have the same value as a ? int x = 67; int y = 34; int * a = &x; int * b = &y; int * c = b; int * d = &y; *c = 67; *b = *a; d = a; *d = 34; (a) b (b) c (c) d (d) Both b and c (e) All of b , c , and d (f) None of them have the same value as a (g) The code is invalid, and thus no an- swer can be given Correct answers: (c) 16. What type must x be for the following code to compile? x = cout << 4; (a) std::string (b) An integer type (c) A stream (d) No type exists that x could be as the code above can’t possibly compile (e) The type auto (f) None of the above Correct answers: (c) 17. The continue statement is different from the break statement in one key way, what is it? (a) It is actually identical to break , its use is entirely aesthetic. (b) It can’t be used in blocks due to the ambiguity. (c) It is only supported by specific com- pilers and isn’t in the language stan- dard (d) It requires the use of an if statement. (e) It causes iteration to resume instead of cease. (f) Its use is strongly discouraged due to the poor habits it inspires (g) It always creates an infinite loops, unless a break statement is also in- cluded. (h) It is only permitted in while loops, but not in other iterative statements. Correct answers: (e) Answers Version 3 Page 4 of 11
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help