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

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

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

Free Response (110 Points)

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

EECS 183 Winter 2016 Exam 2

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

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!

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

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

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.

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

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

CSCE 206: Structured Programming in C++

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

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

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

Spring 2002 Page 1 of 8 READ THIS NOW!

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

Do not start the test until instructed to do so!

EECS 183 Week 8 Diana Gage. www-personal.umich.edu/ ~drgage

ENGR 100 Midterm (CSE Part) Winter 2014

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

Discussion 10: Exam 2 Review

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

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

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

CSCI 111 First Midterm Exam Fall Solutions 09.00am 09.50am, Wednesday, October 18, 2017

4. Structure of a C++ program

Final Exam. COMP Summer I June 26, points

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

CS 1044 Project 1 Fall 2011

COS 126 General Computer Science Spring Written Exam 1

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

CSE 131 Introduction to Computer Science Fall Exam II

CS 2150 Exam 1, Spring 2018 Page 1 of 6 UVa userid:

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?

Computer Programming : C++

CS 3114 Data Structures and Algorithms Test 1 READ THIS NOW!

CSC 210, Exam Two Section February 1999

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

COS 126 Midterm 1 Written Exam Fall 2011

A A B U n i v e r s i t y

Spring 2017 CS 1110/1111 Exam 1

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

CSc Introduc/on to Compu/ng. Lecture 17 Edgardo Molina Fall 2011 City College of New York

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

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.5. for loop and do-while loop

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

Final Exam CS 152, Computer Programming Fundamentals December 9, 2016

Your First C++ Program. September 1, 2010

Chapter 9 Objects and Classes. Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved.

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

CSCI 1226 Second Midterm Test

CSc Introduction to Computing

(the bubble footer is automatically inserted into this space)

Introduction to Object-Oriented Programming with C++

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

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

CS 1301 Exam 1 Fall 2010

CS 1044 Project 2 Spring 2003

Fundamentals of Programming. Lecture 19 Hamed Rasifard

Fundamentals of Programming Session 23

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

I/O Streams and Standard I/O Devices (cont d.)

CSE 131 Introduction to Computer Science Fall Exam II

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

CSE 131S Introduction to Computer Science Summer SON Exam I

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

UEE1302 (1102) F10: Introduction to Computers and Programming

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

Chapter 2. C++ Syntax and Semantics, and the Program Development Process. Dale/Weems 1

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

Lab # 02. Basic Elements of C++ _ Part1

Do not start the test until instructed to do so!

Lab 1: First Steps in C++ - Eclipse

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

Fundamentals of Programming Session 25

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012

CS 1044 Program 6 Summer I dimension ??????

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

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Summer I Instructions:

Use the dot operator to access a member of a specific object.

2 nd Week Lecture Notes

Question 1 Consider the following structure used to keep employee records:

causing a set of statements (the body) to be executed repeatedly. C++ provides three control structures to support iteration (or looping).

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

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

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

Final Exam CS 152, Computer Programming Fundamentals May 9, 2014

CS 111X - Fall Test 1

2. [20] Suppose we start declaring a Rectangle class as follows:

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.

CSE 131 Introduction to Computer Science Fall Exam I

Review. Relational Operators. The if Statement. CS 151 Review #4

Lecture 3 The character, string data Types Files

Java Object Oriented Design. CSC207 Fall 2014

CE221 Programming in C++ Part 1 Introduction

Transcription:

EECS 183 Fall 2015 Exam 2 Free Response (134 points) Closed Book Closed Notes No Electronic Devices Closed Neighbor Turn off Your Cell Phone, even in your backpack We will confiscate all electronic devices that we see or hear including cell phones, calculators, smart watches, etc. Instructions: Read Carefully! 1. You may have one personally handwritten 3 5 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 and Python 2.7. 5. If a read into a variable fails, assume that the variable is changed to 0. 6. In all the given code, if any character looks like a space, it is one. 7. Write clearly. If we cannot read your writing, it will be marked wrong. This includes indentation and curly braces. 8. This course operates under the rules of the College of Engineering Honor Code. Your signature endorses the pledge below. After you finish your exam, sign below: I have neither given nor received aid on this examination, nor have I concealed any violations of the Honor Code. SIGN your name above Print your full name above, zero on exam if not legible or if not your full name Print your uniqname above, zero on exam if not legible or if not your uniqname Page Number Question Number Points Possible 3 1 24 4 2 15 5 3 25 6 4 30 8 5 40

Page 2 of 10 You can use this area as scratch paper for working out problems.

1. (24 points total, 2 points each) Crossword: put a letter in each box according to the clues below. 0 Page 3 of 10 1 e n c a p s u l a t 2 i o n 4 3 5 6 7 8 9 10 11 12 Across (C++) 1. Packaging code and data together is referred to as encapsulation. 4. Member variables and functions in classes can be directly accessed from outside of their class if they are. 5. This operator is used to call class member functions given an instance of a class. 6. Given the following code snippet: Dog snoopy; then snoopy is an instance of the Dog. 9. The keyword used to make class data members available only to member functions. 10. This constructor has no parameters. 11. When calling a function, all arrays are passed by. Down (Python) 0. Python is rather than compiled. 2. The data type in Python that is the equivalent of an int in C++. 3. This data structure stores any non-negative number of elements, which can be of different types. 7. A(n) is a way to specify a portion of a list in Python. 8. Put this in the blank space below to convert 1989 to a string. s = (1989) 12. Put this at the end of a print statement to suppress a new line.

Page 4 of 10 2. (15 points) Implement the following function, which returns the index of an element in an array. You do not have to use all the space available. /** * Requires: size > 0, and size is the size of array * Modifies: Nothing. * Effects : Returns the index of the first occurrence of value in * array, or -1 if it is not in array. * Example : The following code will print: 1-1 * int array[] = { 1, 2, 3, 2, 4 ; * cout << indexof(array, 5, 2) << " " << indexof(array, 5, 5); */ int indexof(int array[], int size, int value) {

Page 5 of 10 3. (25 points) An upper triangular matrix is a square matrix where every element that is strictly below the diagonal is equal to zero. For example, the matrix on the left is not upper triangular, while the one on the right is. 1 2 3 1 2 3 4 5 6 0 5 6 7 8 9 0 0 9 The function below, copyuppertriangular(), copies the elements that are in or above the diagonal from frommatrix to tomatrix, setting the remaining elements in tomatrix to zero, resulting in an upper triangular matrix. For example, if frommatrix is the matrix on the left above, tomatrix will be set to the matrix on the right. Fill in the definition, assuming that matrices are stored with the top row first and the bottom row last. // Requires: size > 0 and size <= MAX_SIZE, and size is the number of rows // and columns in both frommatrix and tomatrix // Modifies: tomatrix // Effects : Copies the elements in and above the diagonal in frommatrix to // tomatrix. Sets the remaining elements in tomatrix to zero. Does // not change any elements that are outside the valid size x size // portion of tomatrix. void copyuppertriangular(const int frommatrix[max_size][max_size], int tomatrix[max_size][max_size], int size) {

Page 6 of 10 4. (30 points) Professor Dorf wants to determine the class s average scores for Projects 3 and 4. She has a file called scores.txt with the following format: Email Project3 Project4 hjpotter@hogwarts.edu 62 65 rweasley@hogwarts.edu 50 56 granger@hogwarts.edu 67.75 67.75 The first line is a header with column labels, and each remaining line consists of an email address, a score for Project 3, and a score for Project 4. Professor Dorf started writing a C++ program to compute the class averages. However, she's too busy to finish it and needs your help. Fill in the rest of the program on the next page. Your code should work for any number of students greater than zero, and it should read every line in the file. You may assume that there is at least one student entry in scores.txt and that all entries are properly formatted. You may write code in any blank space, but you are not required to use every blank space or all of the blank space provided. Assume the following appears at the top of the C++ program file: #include <iostream> #include <string> #include <fstream> using namespace std; // Continued on next page... Kittens!!!

Page 7 of 10 //...Continued from previous page. int main() { ifstream ins; if ( ) { cout << "Could not open file" << endl; return 0; double p3sum = 0; double p4sum = 0; int numstudents = 0; while ( ) { cout << "Project 3 average: " << p3sum / numstudents << endl; cout << "Project 4 average: " << p4sum / numstudents << endl; ins.close();

Page 8 of 10 5. (40 points total) On the eecs183.org website, there is a map that has a dot for every city where students or staff members are from. The map stores coordinates, composed of a latitude and longitude, for each city. Suppose the Coordinates class is declared as follows in Coordinates.h: class Coordinates { public: Coordinates(); void setlatitude(double newlat); double getlatitude(); void setlongitude(double newlong); double getlongitude(); private: double latitude; double longitude; ; Valid latitude values range from -90 to 90, inclusive, and valid longitude values range from -180 to 180, inclusive. The default constructor sets both the latitude and longitude to 0. a) The getlatitude() member function is a getter for the latitude data member. In the box below, write the full definition of getlatitude() as it would appear in Coordinates.cpp. Assume that all necessary header files have been included in Coordinates.cpp. b) The setlatitude() member function is a setter for the latitude data member. However, if its argument is not a valid latitude, it makes no changes to the latitude data member. Write the full definition of setlatitude() as it would appear in Coordinates.cpp.

Page 9 of 10 Suppose the map also contains a Location class, declared as follows in Location.h: class Location { public: Location(); Location(string inname, Coordinates incoordinates); void write(ostream &outs); private: string name; Coordinates geolocation; ; c) The default location in the map has the name "Ann Arbor", latitude 42.3, and longitude -83.7. In the box below, write the full definition of the default constructor for Location that sets its data members to the values above, as it would appear in Location.cpp. Assume that all necessary header files have been included in Location.cpp, and that the Coordinates class has been implemented correctly. d) Now write the definition for the write() member function as it would appear in Location.cpp. It should write the name, latitude, and longitude, separated by spaces. No newline should be written. For example, for the default location, "Ann Arbor 42.3-83.7" would be written to the output stream (without the quotes).

Page 10 of 10 e) Write a test suite for the Location class below. Finish implementing test.cpp (using the main() function) to test the Location class. You do not have to use all the blank space provided. Assume that the Coordinates and Location classes have been implemented correctly. Your test suite should do the following: Use the default Location constructor to create a default location. Print out the Location to standard output, using the appropriate member function, followed by a newline. Create a second Location instance with name "Diagon Alley", latitude 51.7, longitude -0.42. Print out the second Location to standard output, followed by a newline. #include <iostream> #include "Coordinates.h" #include "Location.h" using namespace std; int main() { // Write your test code below