Multiple Choice Questions (20 questions * 6 points per question = 120 points)

Similar documents
Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

Multiple Choice Questions (20 questions * 5 points per question = 100 points)

EECS 183 Fall 2015 Exam 2 Free Response (134 points)

University of Michigan EECS 183: Elem. Programming Concepts Fall 2011 Exam 1: Part 1: Form 1. Professors: ML Dorf, Elliot Soloway

EECS 183 Winter 2016 Exam 2

Free Response (110 Points)

Exam 2. CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson. Question Points Score Total: 80

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

CSCS 261 Programming Concepts Exam 2 Fall EXAM 2 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

CSCS 261 Programming Concepts Exam 2 Fall EXAM 2 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties. Do not start the test until instructed to do so!

1. Which of the following best describes the situation after Line 1 has been executed?

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011

Midterm Practice Exam

Do not start the test until instructed to do so!

Exercise 1.1 Hello world

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

CSCE Practice Midterm. Data Types

CS 111X - Fall Test 1

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

1. (25 pts) Short Answer. Provide brief (1-3 sentence) answers to the following:

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011

CSCS 261 Programming Concepts Exam 1 Fall EXAM 1 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

Lecture 3 The character, string data Types Files

CS 103: Introduction to Programming Fall Written Final Exam 12/11/16, 4:30PM 6:30PM

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

The American University in Cairo Department of Computer Science & Engineeringt CSCI &09 Dr. KHALIL Exam-I Fall 2009

Spring 2002 Page 1 of 8 READ THIS NOW!

READ THIS NOW! Do not start the test until instructed to do so!

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2017

EECS 183, Week 5. General. Variables I/O. 0. At which location do you have to take the exam? 1. Source code vs. object code? 2. What s a library?

Discussion 10: Exam 2 Review

CPE Summer 2015 Exam I (150 pts) June 18, 2015

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

Pointers and Arrays CS 201. This slide set covers pointers and arrays in C++. You should read Chapter 8 from your Deitel & Deitel book.

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No.

2. It is possible for a structure variable to be a member of another structure variable.

CS101 PLEDGED SPRING 2001

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

COMP322 - Introduction to C++

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

CS 2604 Homework 1 C++ Review Summer I 2003

CSCE Practice Midterm. Data Types

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

a. a * c - 10 = b. a % b + (a * d) + 7 =

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

What will happen if the user presses <enter> after every input? Will all work like below? Enter the values of x, y, z: Result: The sum is 17.

Review Questions II KEY

PROGRAMMING EXAMPLE: Checking Account Balance

Definition Matching (10 Points)

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A.

CS24 Week 3 Lecture 1

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

Objects and streams and files CS427: Elements of Software Engineering

Midterm Exam #2 Spring (1:00-3:00pm, Friday, March 15)

C++_ MARKS 40 MIN

Computer Programming : C++

CS 31 Discussion 1A, Week 4. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m.

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

CS 1044 Programming in C++ Test 1 READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties.

CMSC 202 Midterm Exam 1 Fall 2015

COS 126 Midterm 1 Written Exam Fall 2011

Midterm Exam. Sample Solutions

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B. Name (last, First) Instructor. Total Possible. Received

Programming in C++: Assignment Week 8

CS 1044 Programming in C++ Test 1 Spring 2011 Form B Page 1 of 12 READ THIS NOW!

CS 1301 Exam 1 Fall 2010

Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Scientific Computing

C++ for Python Programmers

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi

Bruce Merry. IOI Training Dec 2013

Object Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name:

ENGR 100 Midterm (CSE Part) Winter 2014

This test is OPEN Textbook and CLOSED notes. The use of computing and/or communicating devices is NOT permitted.

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey

University of Toronto

(the bubble footer is automatically inserted into this space)

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program:

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

Text File I/O. #include <iostream> #include <fstream> using namespace std; int main() {

True or False (14 Points)

Transcription:

EECS 183 Fall 2014 Exam 2 Closed Book Minimal Notes Closed Electronic Devices Closed Neighbor Turn off Your Cell Phones We will confiscate all electronic devices that we see including cell phones, calculators, etc. Multiple Choice Questions (20 questions * 6 points per question = 120 points) Key 1 Instructions: Read Carefully! 1. You may have one 3" x 5" handwritten notecard. 2. Some questions are not simple. Therefore, read carefully. 3. Assume all code and code fragments are syntactically valid, unless otherwise specified. 4. Assume/use only the standard C++11 / Python 2.7. 5. In all the given code, if any character looks like a space, it is one. 6. On the scantron sheet, bubble in your name and UMID - - 10 pts off for incorrect UMID. 7. On the scantron sheet, bubble in Key 1 - - zero on exam if key not bubbled in. 8. Sign below and print your uniqname - - 10 pts off if we cannot read your uniqname I have neither given nor received aid on this examination, nor have I concealed any violations of the Honor Code. Signature uniqname 1 of 12

This page intentionally left blank for your use 2 of 12

C++ 1. Which is an invalid function declaration, given the following code? const int WIDTH = 5; const int HEIGHT = 3; A. void foo(int arr[height][width]); B. void foo(int arr[][width]); C. void foo(int arr[][]); D. void foo(int arr[5][3]); E. void foo(int arr[][3]); 2. Suppose we have the following code: int arr[5][3] = {{1,2,3,{4,5,6,{7,8,9,{10,11,12,{13,14,15; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << arr[i][j] << ' '; cout << endl; What will print as a result of running the above code? A. 1 2 3 4 5 6 7 8 9 B. 1 4 7 2 5 8 3 6 9 C. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 D. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 E. 1 4 7 10 13 2 5 8 11 14 4 6 9 12 15 3 of 12

C++ 3. Given the following code: const int SIZE = 5; char a[size][size]; for (int i = 0; i < SIZE; i++) { a[i][i+1] = i; What is the first location accessed by this code that goes out of bounds of the array? A. a[- 1][0] B. a[0][- 1] C. a[4][5] D. a[5][6] E. The code never goes out of bounds of the array. 4. The swap function below contains a bug. If a and b are declared integers in main, which assigned values would activate the bug in the code when swap(a,b) is called? void swap (int &x, int &y) { int temp = (x / y) * y + (x % y); x = (y / x) * x + (y % x); y = temp; A. a = 1; b = 1; B. a = 0; b = 1; C. a = 1; b = 2; D. a = 2; b = 1; E. a = 1; b = - 1; 4 of 12

C++ For questions 5 and 6, consider the following code. Steve has written a new cipher function in C++, which he calls sillycipher. It is implemented in the following function: void sillycipher(const string &original, string &result) { for (int x = 0; x < original.length(); x++) { if (original[x] >= 'A' && original[x] <= 'M') { result[x] = 'A'; else if (original[x] >= 'N' && original[x] <= 'Z') { result[x] = 'B'; 5. Suppose sillycipher is called and a string containing "LISA" is passed as the first parameter. What would be stored in result by the end of sillycipher s execution (assuming result is also of length 4)? A. "AABA" B. "ABAA" C. "ABAB" D. "BBAB" E. "BABA" 6. Which of the following sentences best describes the behavior of sillycipher? A. It is a clever and useful cipher, since it was written by Steve. B. It is not a useful cipher because its result cannot be decoded. C. It will not compile because one cannot index into strings like arrays. D. It will not work correctly because it has an off-by-one error. E. It will not work correctly because one of the strings is designated const. 5 of 12

C++ I/O 7. Which of the following is not a valid stream state? A. good B. bad C. fail D. eof E. clear 8. Which line of the following code contains a bug? 1 #include <iostream> 2 #include <fstream> 3 #include <string> 4 using namespace std; 5 6 int main() { 7 ifstream infile; 8 ifstream.open("myfile.txt"); 9 if (!infile) { 10 cout << "Could not open file." << endl; 11 return 1; 12 13 string line; 14 getline(infile, line); 15 cout << line << endl; 16 infile.close(); 17 return 0; 18 A. line 7 B. line 8 C. line 9 D. line 14 E. line 15 6 of 12

C++ Classes The following code will be used for Questions 9, 10, and 11. Given the following definition of a class named Square. class Square { public: void setlength(int newlength) { length = newlength; areavalue = length * length; int area() const { return areavalue; private: int length; int areavalue; ; 9. The area member function is an example of a: A. constructor B. destructor C. getter D. setter E. void function 10. What does const after int area() mean? A. area() returns a constant value. B. area() does not modify the value of areavalue. C. area() does not modify any member variables values. D. The programmer cannot modify the implementation of area(). E. No other functions named area() can exist. 7 of 12

C++ 11. Which of the following implementations of a constructor for Square would be correct and consistent with other member functions if implemented within the class along with setlength and area? A. Square() { length = 1; B. Square() { length = 1; area = 1; C. Square() { setlength(1); D. void Square() { length = 1; void Square() { length = 1; areavalue = 1; 12. In C++ classes, by default, member variables are and member functions are A. public, public B. public, private C. private, public D. private, private E. C++ class members have undefined default behavior. 8 of 12

Python Python 13. Python is a(n): A. C++ library B. compiler C. integrated developer environment (IDE) D. programming language E. web browser 14. An array in C++ is best compared to which data structure in Python? A. class B. dictionary C. float D. list E. range 15. What does the following code print? fibonacci = [1, 1, 2, 3, 5, 8, 13, 21] print fibonacci[1:3] A. [1, 1, 2, 3] B. [1, 2, 3] C. [1, 2] D. [1, 1, 2] E. [1, 2, 3, 5, 8, 13, 21] 9 of 12

Python 16. What prints after the execution of the following Python code if the user inputs 0<ENTER>? x = int(raw_input()) if x == 0: print 'x is 0' elif x == 1: print 'x is 1' print 'x is an integer' A. x is 0 B. x is 0 x is an integer C. x is 1 x is an integer D. x is an integer E. Nothing prints. 17. What does the following code print? lst = [] nums = [15, 6] lst.append(nums) nums = [10, 30, 20] lst.append(nums) lst.sort() print lst A. [6, 10, 15, 20, 30] B. [[6, 15], [10, 20, 30]] C. [[15, 6], [10, 30, 20]] D. [[10, 30, 20], [15, 6]] E. [[10, 20, 30], [6, 15]] 10 of 12

Python 18. What does the following print? import sys def foo(n): for i in range(0, n): print " " * i, print "*" * (n - i) def main(argv): foo(3) if name == ' main ': main(sys.argv) A. * ** *** B. *** ** * C. *** ** * D. ****** E. *** ** * 19. Which of the following is NOT a valid operation on a string variable in Python? A. Addition of strings, which is equivalent to appending strings: print 'Hello ' + ' World!' B. Addition of strings and integers, which is equivalent to appending integers to strings: course = 'EECS ' + 183 C. Multiplication of string and integers, which repeats the string the integer number of times: '$' * 5 D. Indexing into a string to get a single letter of the string: name = 'Maxim' c = name[0] E. Assignment of an integer to a variable currently holding a string: course = 'EECS 183' course = 183 11 of 12

Python 20. What does the following code output? s = 'ABC' n = 1 for c in s: print c * n, n += 1 A. A B C B. A B C C. A BB CCC D. A BB CCC E. 1 4 9 12 of 12