CSE 333 Midterm Exam 7/25/16. Name UW ID#

Similar documents
CSE 333 Midterm Exam 7/25/16 Sample Solution. Question 1. (10 points) Preprocessor. Suppose we have the following two files:

CSE 333 Midterm Exam July 24, Name UW ID#

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

CSE 333 Midterm Exam 2/14/14

CSE 333 Midterm Exam 5/10/13

CSE au Midterm Exam Nov. 2, 2018 Sample Solution

CSE 333 Midterm Exam 7/22/12

CSE 333 Midterm Exam 7/29/13

CSE 333 Midterm Exam 2/12/16. Name UW ID#

CSE 333 Midterm Exam Nov. 3, 2017 Sample Solution

CSE 333 Midterm Exam July 24, 2017 Sample Solution

CSE 333 Midterm Exam Nov. 3, Name UW ID#

CSE 374 Final Exam 3/15/17. Name UW ID#

CSE 333 Final Exam 3/19/14

CSE 333 Midterm Exam 7/27/15 Sample Solution

CSE 333 Midterm Exam 5/9/14 Sample Solution

CSE 303 Final Exam. March 16, 2009

CSE 333 Midterm Exam Sample Solution 5/10/13

CSE 374 Final Exam 3/15/17 Sample Solution. Question 1. (8 points) Suppose we have the following two statements in a C program:

CSE 374 Final Exam Sample Solution 3/17/11

CSE wi Midterm Exam 2/8/18. Name UW ID #

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

CSE 303, Winter 2007, Final Examination 15 March Please do not turn the page until everyone is ready.

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

CSE 303 Midterm Exam

CSE 333 Final Exam June 6, 2017 Sample Solution

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes

CSE 303, Winter 2007, Final Examination 15 March Please do not turn the page until everyone is ready.

CSE 303, Autumn 2006, Final Examination 12 December 2006

CSE 333 Final Exam Sample Solution 3/19/14

CSE 303, Spring 2006, Final Examination 6 June Please do not turn the page until everyone is ready.

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

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

CSE351 Winter 2016, Final Examination March 16, 2016

ANSI C. Data Analysis in Geophysics Demián D. Gómez November 2013

CSE wi Final Exam 3/12/18. Name UW ID#

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

CSE 333 Midterm Exam Sample Solution 7/28/14

CSE 374 Final Exam Sample Solution 3/15/12

CSCI-243 Exam 2 Review February 22, 2015 Presented by the RIT Computer Science Community

Do not turn the page until 12:30.

6. Pointers, Structs, and Arrays. 1. Juli 2011

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

CSE 374 Final Exam Sample Solution 6/10/10

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

CSE 331 Midterm Exam 2/13/12

6. Pointers, Structs, and Arrays. March 14 & 15, 2011

CS 240 Data Structure Spring 2018 Exam I 03/01/2018

COP Programming Concepts Spring 1999 CLOSED BOOK Exam #1 100 Points NAME

Name. CPTR246 Spring '17 (100 total points) Exam 2

The make Utility in Unix SEEM

CSE 303, Winter 2006, Final Examination 16 March Please do not turn the page until everyone is ready.

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012

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

CSE 331 Final Exam 12/9/13

Compiling with Multiple Files The Importance of Debugging CS 16: Solving Problems with Computers I Lecture #7

CSE 374 Midterm Exam 2/6/17 Sample Solution. Question 1. (12 points, 4 each) Suppose we have the following files and directories:

CSE 303, Spring 2009 Final Exam Wednesday, June 10, 2009

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

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

Part I: Short Answer (12 questions, 65 points total)

The make Utility in Unix SEEM

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

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

CS 104 (Spring 2014) Final Exam 05/09/2014

pointers + memory double x; string a; int x; main overhead int y; main overhead

CSE 333 Autumn 2013 Midterm

There are, of course, many other possible solutions and, if done correctly, those received full credit.

CSE 331 Final Exam 3/12/12

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

CSE 333 Lecture 6 - data structures

Final Exam 1 /12 2 /12 3 /10 4 /7 5 /4 6 /10 7 /8 8 /9 9 /8 10 /11 11 /8 12 /10 13 /9 14 /13 15 /10 16 /10 17 /12. Faculty of Computer Science

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

CSE P 501 Exam 8/5/04

Question 1. [15 marks]

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Understanding main() function Input/Output Streams

CSE 401/M501 18au Midterm Exam 11/2/18. Name ID #

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

WARM UP LESSONS BARE BASICS

CMSC 202 Midterm Exam 1 Fall 2015

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

CSE 303: Concepts and Tools for Software Development

CSE 303, Winter 2007, Midterm Examination 9 February Please do not turn the page until everyone is ready.

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

CSCI 2132 Software Development. Lecture 29: Dynamic Memory Allocation

C for C++ Programmers

! Determine if a number is odd or even. ! Determine if a number/character is in a range. ! Assign a category based on ranges (wind speed)

Lab 5 Pointers and Arrays

CS 455 Final Exam Spring 2015 [Bono] May 13, 2015

W3101: Programming Languages C++ Ramana Isukapalli

CSE 374 Programming Concepts & Tools

2 Compiling a C program

C: Pointers. C: Pointers. Department of Computer Science College of Engineering Boise State University. September 11, /21

Solution to CSE 250 Final Exam

LAB 5, THE HIDDEN DELIGHTS OF LINKED LISTS

CSE 331 Final Exam 6/5/17. Name UW ID#

CIS 190: C/C++ Programming. Lecture 2 Pointers and More

Operator overloading

Transcription:

Name UW ID# There are 7 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes, closed electronics, closed telepathy, open mind. If you don t remember the exact syntax for something, make the best attempt you can. We will make allowances when grading. Don t be alarmed if there seems to be more space than is needed for your answers we tried to include more than enough blank space. Relax, you are here to learn. Please wait to turn the page until everyone is told to begin. Score / 100 1. / 10 2. / 9 3. / 17 4. / 22 5. / 20 6. / 20 7. / 2 Page 1 of 10

Question 1. (10 points) Preprocessor. Suppose we have the following two files: defs.h: #define DIV(a,b) a / b #define INCDIV(c,d) DIV(c + 1, d + 1) main.c: #include <stdio.h> #include "defs.h" int main() { int n = INCDIV(5, 1); printf("%d\n", n); return 0; (a) (7 points) Show the result produced by the C preprocessor when it processes file main.c (i.e., if we were compiling this file, what output would the preprocessor send to the C compiler that actually translates the program to machine code?). You should ignore the #include <stdio.h> directive since that includes library declarations that we do not have access to. Write the rest of the preprocessor output below. (b) (3 points) What output does this program print when it is executed? Page 2 of 10

Make and related things. We have the following diagram that describes the dependencies between the various files that are involved in building an executable program named gadget. widget.c widget.h gadget.h gadget.c widget.o gadget.o gadget Question 2. (9 points, 3 each) What can we conclude from the above diagram? In the statements below, circle the number of the best choice in each group of possible answers: (a) The widget.c source file: (i) Definitely contains a #include "widget.h" preprocessor directive. (ii) Might contain a #include "widget.h" preprocessor directive, but might not. (iii) Does not contains a #include "widget.h" preprocessor directive. (b) The gadget.c source file: (i) Definitely contains a #include "widget.h" preprocessor directive. (ii) Might contain a #include "widget.h" preprocessor directive, but might not. (iii) Does not contains a #include "widget.h" preprocessor directive. (c) The main function for this program: (i) Definitely is implemented (defined) in the gadget.c source file. (ii) Might be implemented (defined) in the gadget.c source file, but might not. (iii) Is not implemented (defined) in the gadget.c source file. (more about this diagram on the next page) Page 3 of 10

Question 3. (17 points) Making stuff. Write an appropriate Makefile that will compile and link the files described by the dependency diagram on the previous page to build the executable program named gadget. Your Makefile should only recompile or relink files if needed to bring targets up to date. The default target in the Makefile should be the executable program gadget, i.e., if make is run with no arguments, the gadget program (target) should be built. You should use gcc with appropriate options to compile the program. To save a little time and writing, you may omit -std=c11, but you should include -Wall and -g in appropriate places. In addition, you may find the following options to be useful: -o outputfilename specify gcc output file -c only create a.o file and then stop without linking. (If -c is given, then the option -o filename.o is assumed as the default, where filename.c is the input file.) Reminder: the format of a makefile rule is: target: sources command Page 4 of 10

Question 4. (22 points) C programming! This question involves adding a function to the code from HW2. Copies of the HashTable.h and memindex.h header files, which are the ones needed for this problem, are provided on separate pages. You should assume that those headers, and any other necessary header files and declarations, have already been included in the source files. After building the inverted index data structures in HW2, we would like to scan the index and, for each word we find, print out the number of different documents where the word appears. For example, here is the inverted index diagram from the HW2 assignment: The output of the function should list each word in the inverted index and the number of documents where it appears, using a separate line for each word. For the above data the output might be: recommend 1 love 3 course 1 The words may appear in any order, and the exact spacing doesn t matter. The output should be written to stdout (i.e., feel free to use printf). On the next page, implement function PrintWordDocCounts to produce this output. (Hint: Don t panic! The solution isn t particularly long the sample solution is less than 15 or 20 lines of code. Of course, yours isn t required to be any particular length.) Page 5 of 10

Question 4. (cont.) Write your implementation of function PrintWordDocCounts below. // For each word in MemIndex mi, print on stdout a line // containing that word and the number of documents where // it appears. void PrintWordDocCounts(MemIndex mi) { Verify333(mi!= NULL); // add your code here Page 6 of 10

Question 5. (20 points) Bugs R Us. One of your friends has been trying to learn C and has been experimenting with a linked list of strings, using dynamically allocated nodes and string values. The list allows duplicates and strings are not stored in any particular order. The problem is that the code is badly broken, and, in fact, doesn t even compile. Make changes needed in the code below so that function new_node allocates a properly initialized new node and insert successfully adds it to the front of the list. If you want to rewrite the code instead of modifying it here, you can use the next page. #include <stdlib.h> struct strnode { // node in a string linked list: char * str; // copy of the string (on the heap) struct strnode * next; // next node or NULL if none ; struct strnode * str_list; // global pointer to list of strings // return a new node with copy of string s and next == NULL struct strnode * new_node(char * s) { struct strnode * node; node->str = s; node->next = NULL; return node; // add a new node with a copy of s to the front of str_list void insert(char * s) { struct strnode p = new_node(s); str_list = p; p->next = str_list; (You can use the next page if you want to write your answers there instead of editing the code on this page; if you do that you can remove this page from the exam.) Page 7 of 10

Question 5. (cont) Extra space for your answer, if you prefer to write it here. Page 8 of 10

Question 6. (20 points) Not quite the traditional what-does-it-print question. Consider the following C++ program, which, as is usual, compiles and executes with no errors. #include <iostream> using namespace std; int f(int &n, int *pa, int &k, int *pb) { k = pb[1]; pb[2] = pa[1]; n = *pb**pa; return k+1; int main() { int a = 1; int &b = a; int ray[4] = { 10, 11, 12, 13 ; int *p = ray; int *q = &ray[1]; *p = f(ray[2], p, b, q); cout<< "a = " << a << ", b = " << b << ", *q = " << *q << endl; cout<< "ray = "; for (int k = 0; k < 4; k++) cout << ray[k] << " "; cout << endl; return 0; What output does this program produce when it runs? (You are not required to draw a boxes-n-arrows diagram, but you might find doing so to be very helpful, and it might help us if we need to assign partial credit to a not-completely-perfect answer.) Page 9 of 10

Question 7. (2 free points) (All reasonable answers receive the points. All answers are reasonable as long as there s something written here. J) (a) (1 point) What question were you expecting to appear on this exam that wasn t here? (b) (1 point) Should we include that question on the final exam? (circle or fill in) Yes No Heck No!! $!@$^*% No!!!!! None of the above. My answer is. Page 10 of 10