CS16 Final Exam E03, 10S, Phill Conrad, UC Santa Barbara Wednesday, 06/09/2010

Similar documents
***PRACTICE EXAM 02 for*** CS16 Midterm Exam 2 E02, 09F, Phill Conrad, UC Santa Barbara Actual exam scheduled for: 11/18/2009

CS16 Midterm Exam 2 E02, 09F, Phill Conrad, UC Santa Barbara Wednesday, 11/18/2009

CS16 Midterm Exam 2 E02, 10W, Phill Conrad, UC Santa Barbara Tuesday, 03/02/2010

CS16 Midterm Exam 1 E01, 10S, Phill Conrad, UC Santa Barbara Wednesday, 04/21/2010, 1pm-1:50pm

#101 Page: 1 Name: CS32 Midterm Exam. E01, W15, Phill Conrad, UC Santa Barbara

CS32 Final Exam. E03, F15, Phill Conrad, UC Santa Barbara

CS8 Final Exam E03, 09M, Phill Conrad, UC Santa Barbara 09/10/2009

CS56 Midterm Exam. E01, W16, Phill Conrad, UC Santa Barbara Wednesday, 02/10/2015

CS32 Final Exam. E03, S15, Phill Conrad, UC Santa Barbara Tuesday, 06/08/2015, 8am 11am

CS56 final (E03) W15, Phill Conrad, UC Santa Barbara Wednesday, 03/18/2015. Name: Umail umail.ucsb.edu. Circle one: 4pm 5pm 6pm

NOTE: All references to Python on this exam mean Python 3, so you should answer accordingly.

E02, W16, Phill Conrad, UC Santa Barbara

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

CS32 Midterm Exam E01, F15, Phill Conrad, UC Santa Barbara Wednesday, 10/28/2015, 11am 12:15pm

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

W13:Homework:H07. CS40 Foundations of Computer Science W13. From 40wiki

Sonoma State University Computer Science Department CS 115 Fall 2010 Watts. Project 3 Part 1

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

NOTE: All references to Python on this exam mean Python 3, so you should answer accordingly.

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

This exam is worth 24 points, or 24% of your total course grade. The exam contains six

W13:Homework:H08. CS40 Foundations of Computer Science W13. From 40wiki

Question 1. [5 points] Consider the following partially-complete program, which begins on the left and continues on the right: HERE

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #34. Function with pointer Argument

CS 61B, Midterm #3 and solutions, Spring 1996

15110 PRINCIPLES OF COMPUTING SAMPLE EXAM 2

CSE 333 Midterm Exam 7/29/13

CS 161 Computer Security

Computer Science Foundation Exam

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Signature: Question # Out Of Marks Marker Total

CS Exam 2 - Spring 2010

Department of Electrical Engineering and Computer Sciences Spring 2007 Instructor: Dr. Dan Garcia

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

University of California, Berkeley College of Engineering

CS61B (Clancy) Spring 1996 Exam 3, solutions, and grading standards. April 12, 1996 Exam 3

COS 126 General Computer Science Spring Written Exam 1

5. PLEASE TAKE HOME the question bundle, but turn in 2 paper sheets: The scantron AND the paper where you wrote your programming question solution!

EECE.2160: ECE Application Programming Fall 2017 Exam 3 December 16, 2017

Course Outline. TERM EFFECTIVE: Spring 2016 CURRICULUM APPROVAL DATE: 10/12/2015

Slide Set 3. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Wawrzynek & Weaver CS 61C. Sp 2018 Great Ideas in Computer Architecture MT 1. Print your name:,

CSc 328, Spring 2004 Final Examination May 12, 2004

Wawrzynek & Weaver CS 61C. Sp 2018 Great Ideas in Computer Architecture MT 1. Print your name:,

University of California, Berkeley College of Engineering

Second Examination Solution

15-110: Principles of Computing, Spring 2018

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Integrated Math 1 Module 3 Honors Sequences and Series Ready, Set, Go! Homework

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

CS Final Exam Review Suggestions - Spring 2014

Computer Science Foundation Exam

Computer Science Foundation Exam

Question 2. [5 points] Given the following symbolic constant definition

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

Ch. 11: References & the Copy-Constructor. - continued -

CSE 333 Midterm Exam 5/10/13

Q1: Multiple choice / 20 Q2: Arrays / 40 Q3: Functions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

University of California, Berkeley College of Engineering

CS3L Summer 2011 Exam 2 Time: up to 170 minutes (you may leave when finished; or, you must stop promptly at noon)

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE 333 Midterm Exam Cinco de Mayo, 2017 (May 5) Name UW ID#

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

Midterm II Exam Principles of Imperative Computation Frank Pfenning. March 31, 2011

CSE 143 Final Exam Part 1 - August 18, 2011, 9:40 am

CS 2113 Software Engineering

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA === Homework submission instructions ===

CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

COS 126 General Computer Science Spring Midterm 1

Midterm Sample Answer ECE 454F 2008: Computer Systems Programming Date: Tuesday, Oct 28, p.m. - 5 p.m.

Do not start the test until instructed to do so!

Practice final for EECS 380, 2001: Prof Markov

Midterm I - Solution CS164, Spring 2014

Spring CS Homework 3 p. 1. CS Homework 3

cd h: mkdir -p CS101 cd CS101 curl -O unzip zipfile cd CS101_Exam4

Carleton University Department of Systems and Computer Engineering SYSC Foundations of Imperative Programming - Winter 2012

Problem 1. Multiple Choice (choose only one answer)

ENCM 369 Winter 2019 Lab 6 for the Week of February 25

CSE 374 Midterm Exam 11/2/15. Name Id #

CSE100 Principles of Programming with C++

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin

CS150 Sample Final. Name: Section: A / B

University of California, Berkeley College of Engineering

ECE264 Fall 2013 Exam 3, November 20, 2013

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

Problem Set 5 Due: Friday, November 2


CSCI-1200 Data Structures Spring 2014 Lecture 5 Pointers, Arrays, Pointer Arithmetic

CS61c MIDTERM EXAM: 3/17/99

Consider the above code. This code compiles and runs, but has an error. Can you tell what the error is?

Math Exam 2 Solutions. Problem 1 (8 points) Problem 2 (8 points) Problem 3 (12 points) Problem 4 (26 points) Problem 5 (14 points)

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

Parameters and Objects

Read every line of the exam sheet before programming!

Prelim One Solution. CS211 Fall Name. NetID

CSC D84 Assignment 2 Game Trees and Mini-Max

Final CSE 131B Spring 2004

LAB 4.1 Relational Operators and the if Statement

Transcription:

CS16 Final Exam E03, 10S, Phill Conrad, UC Santa Barbara Wednesday, 06/09/2010 Name: Umail Address: @ umail.ucsb.edu Circle Lab section: 9AM 10AM 11AM Noon Link to Printer Friendly PDF Version Please write your name only on this page. That allows me to grade your exams without knowing whose exam I am grading. This exam is closed book, closed notes, closed mouth, cell phone off, except for: You are permitted one sheet of paper (max size 8.5x11") on which to write notes These sheets will be collected with the exam, and might not be returned Please write your name on your notes sheet There are 100 points worth of questions on the exam, and you have 3 hours (180 minutes) to complete the exam. A hint for allocating your time: if a question is worth 10 points, spend no more than 10 minutes on it if a question is worth 20 points, spend no more than 20 minutes on it etc. That will leave you with 80 extra minutes to check your work, or come to problems that gave you trouble.

1. (5 pts) Read the instructions carefully and completely so you don't lose points! You were given an extra handout along with this exam, with a definition of a struct Date. Using that definition, write a definition of struct Hwk where Hwk stands for "Homework Assignment" that contains the following fields. For full credit, use exactly the names and types given. num, an integer representing the homework assignment number earned, an integer representing the points earned poss, an integer representing the points possible on that assignment. date, an instance of struct Date representing the date the student completed the assignment. Material below this line goes with the question on the next page int main() int failures=0; struct Hwk asns[]= 1, 9, 10,4,10,2010, 2, 9, 10,4,10,2010, 3, 10, 10,4,17,2010 ; // compute expected grade as a percentage double expected= ((9+9+10)*100.0)/(10+10+10); const double tol=0.0001; failures += CHECK_EXPECT_DOUBLE(overallGrade(asns,3),expected,tol); return tddfinish(failures);

2. (10 pts) Now, using the struct Hwk you defined in in the previous question, consider a function with the following prototype: double overallgrade(struct Hwk *asns, int n); The parameter asns represents an array of homework assignments (each one an instance of struct Hwk), and n represnts the number of elements in that array. The function is intended to return the overall grade the student earned on all of the assignmets, i.e. total points earned divided by total points possible, as a percentage. The box on the previous page shows a test case for the function (written using the test-driven development framework we've been using thorughout the course.) The function definition below is correct, except that some lines of code are missing. Fill in the missing lines of code so that the function works properly. double overallgrade(struct Hwk *asns, int n) int totalposs=0, totalearned=0; int i; for (i=0; i<n; i++)

3. (10 pts) Consider the definition of struct Circle and struct Point on the handout that came with this exam. Now consider this function prototype: void movecircle(struct Circle *c, double dx, double dy); The purpose of this function is to move a circle by dx pixels in the x direction, and dy pixels in the y direction. For example, here is a test case the function should pass (written using the test-driven development framework we've been using throughout the course): int main() int failures=0; struct Circle c = 10.0, 5.0, 3.0 ; movecircle(&c, 2.0, -3.0); failures += CHECK_EXPECT_INT(c.center.x, 10.0 + 2.0); failures += CHECK_EXPECT_INT(c.center.y, 5.0-3.0); return tddfinish(failures); Write the function definition for movecircle.

4. (18 pts) Give the value of each of these integer C expressions. Express your answers in decimal (base 10). Hint: remember the notations for hex and octal in C. The first two are done for you as an examples. Expression Value in decimal 0xA 10 1 ^ 0 1 4 ^ 2 0xA & 0xC 3 9 7 && 4 9 0 1 << 4 32 >> 1 020 0x20

5. (2 pts) As we discussed in class, the memory of a C program is divided into several parts: code, static area, stack, and heap. Which part is the place local variables are stored? Circle one: code static area stack heap 6. (2 pts) When you return from a function in C does the stack grow or shrink? Circle one: grow shrink 7. Suppose I have the variables: char thiscity[20] = "Santa Barbara"; char thatcity[20] = "Los Angeles"; And then I have these lines of code: thiscity[5]='\0'; // backslash zero thatcity[3]='0'; // just plain old zero After executing these additional lines of code: a. (2 pts) What is the output of printf("%s",thiscity); b. (2 pts) What is the output of printf("%s",thatcity); c. (2 pts) What is the output of printf("%i",strlen(thiscity)); d. (2 pts) What is the output of printf("%i",strlen(thatcity));

8. (10 pts) You are at a job interview for a job involving C programming. The interview seems to be going well, and then your potential new boss narrows her eyes, and gives you this funny look. She says: So, last question. I hear that Conrad makes all his students memorize "an address is a pointer, and a pointer is an address". That's cute, and all, but I'm not convinced that his students understand what that really means. (I think they are just memorizing a saying.) So, explain it to me in a way that shows you understand, and you've got the job. How do you answer so that you get the job?

9. Here is the definition for a C function called copynonzero() with a few parts missing that you need to supply. Fill in the missing lines of code in the places where you see comments with the @@@ symbol // Copy all numbers not equal to zero from array src into array dest. // n is the occupancy of array src. // Destination array should have capacity at least of size n. // Return the number of values copied into dest int copynonzero(int *src, int *dest, int n) int i; int count=0; for (i=0;i<n;i++) if (!= 0) // @@@ (4 pts) = src[i]; // @@@ (4 pts) count++; return ; // @@@ (2 pts)

10. Homework H15 involved an exercise that mimicked one from the Etter textbook, where you had to draw diagrams representing variable values and pointers. This exam question asks you to draw similar drawings (see box at right for an example.) For each of the following, give the FINAL drawing the one that would occur AFTER all the code executes. Each problem starts from scratch. I've left space for "scratch work" as well as your final answer I recommend you draw the initial state, make each change by crossing things out, then copy your final answer into the box given. a. (5 pts) Scratch work int a=6, b=7, *p1=&b, *p2=&a; p1 = p2; (*p1) = 8; p2 = &b; Final answer b. (5 pts) Scratch work int a=2, b=3, *p1, *p2; p2 = &a; p1 = &b; (*p1) = (*p1) + (*p2); Final answer

11. (10 pts) In project proj0, you were provided several definitions and function prototypes to work with. Here are a few of them: struct Point double x; ; double y; void initpoint(struct Point *p, double xval, double yval); struct Point makepoint(double xval, double yval); void drawline(struct Drawing *d, struct Point p1, struct Point p2, int color); Using these, write the function definition for a function drawt that draws the letter T(as shown below). Here is the function prototype for the drawt function you should define: void drawt(struct Drawing *d, struct Point ul, // upper left corner double w, // width double h, // height int color); And here is a sample main, and its output int main() struct Drawing d; initdrawing(&d, DRAWINGTYPE_COLOR, 200, 100, COLOR_WHITE); drawt(&d,makepoint(10,10),20,50,color_red); drawt(&d,makepoint(100,10),50,20,color_blue); writefile(&d, FILENAME); return 0; If you need extra room, use the space on the next page

Extra space for your drawt function (answer to question 11)

12. (5 pts) Here is a recursive function with the name mysteryfunction. As parameters, it takes an array of integers a, and the length of that array n as parameters, and returns an integer. What it actually computes is a mystery for you to solve. int mysteryfunction(int *a, int n) if (n<2) return 1; if (a[0]>a[1]) return 0; else return mysteryfunction(a+1, n-1); Solve the mystery by figuring out what the mystery function computes, then decide which of the following is a more reasonable name for the function. Among these possible function names, one (and only one) of them would be a reasonable answer to this question. Just circle the correct answer. average counteven countmax countmin countneg countodd countpos countsevens countzeros indexfirsteven indexfirstodd indexlasteven indexlastodd indexofmax indexofmin issorted isalleven isallodd maxvalue minvalue nodups alldups sum sumeven sumneg sumodd sumpos End of Exam Total Points: 100

CS16 Final Exam, Spring 2010 Extra Handout Struct definitions for Questions 1 and 2: struct Point double x; double y; ; struct Circle struct Point center; double radius; ; struct Date int m; int d; int y; ;