CSE 303, Spring 2005, Midterm Examination 29 April Please do not turn the page until everyone is ready.

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

CSE341, Spring 2013, Final Examination June 13, 2013

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

CSE341, Fall 2011, Midterm Examination October 31, 2011

CSE341, Fall 2011, Midterm Examination October 31, 2011

CSE341 Spring 2017, Final Examination June 8, 2017

CSE 341, Spring 2011, Final Examination 9 June Please do not turn the page until everyone is ready.

CSE 303 Midterm Exam

CSE341 Spring 2016, Midterm Examination April 29, 2016

CSE341 Spring 2017, Final Examination June 8, 2017

CSE 332, Spring 2010, Midterm Examination 30 April 2010

CSE341 Spring 2016, Midterm Examination April 29, 2016

CSE 303, Autumn 2006, Final Examination 12 December 2006

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

CSE351 Winter 2016, Final Examination March 16, 2016

CSE374 Winter 2016, Midterm Examination February 8, 2016 Please do not turn the page until the bell rings.

CSE505, Fall 2012, Midterm Examination October 30, 2012

A Concepts-Focused Introduction to Functional Programming Using Standard ML Sample Exam #1 Draft of August 12, 2010

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

CSE373 Fall 2013, Midterm Examination October 18, 2013

CSE 341 : Programming Languages Midterm, Spring 2015

CSE 374 Midterm Exam Sample Solution 2/6/12

CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings.

CSE 505, Fall 2008, Midterm Examination 29 October Please do not turn the page until everyone is ready.

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

CSE341 Spring 2017, Midterm Examination April 28, 2017

CSE 505, Fall 2007, Final Examination 10 December Please do not turn the page until everyone is ready.

CSE341 Autumn 2017, Final Examination December 12, 2017

CSE413 Midterm. Question Max Points Total 100

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings.

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

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

CSE 374 Midterm Exam Sample Solution 2/11/13. Question 1. (8 points) What does each of the following bash commands do?

CSE341 Spring 2016, Final Examination June 6, 2016

CSE351 Spring 2018, Midterm Exam April 27, 2018

CSE331 Winter 2014, Midterm Examination February 12, 2014

CSE331 Winter 2014, Midterm Examination February 12, 2014

CSE351 Spring 2018, Final Exam June 6, 2018

CS 0449 Sample Midterm

CSE331 Spring 2015, Final Examination June 8, 2015

CSE 505, Fall 2008, Final Examination 11 December Please do not turn the page until everyone is ready.

CSE341 Autumn 2017, Midterm Examination October 30, 2017

CSE 505, Fall 2008, Final Examination 11 December Please do not turn the page until everyone is ready.

CSE 505, Fall 2006, Final Examination 11 December Please do not turn the page until everyone is ready.

CS 223: Data Structures and Programming Techniques. Exam 2

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

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.

CSE 332, Spring 2010, Final Examination 8 June 2010

CSE373 Winter 2014, Midterm Examination January 29, 2014

CSE 374 Programming Concepts & Tools

CSE 413 Final Exam. June 7, 2011

CSE331 Fall 2014, Final Examination December 9, 2014 Please do not turn the page until 2:30. Rules:

CSE 505, Fall 2009, Final Examination 14 December Please do not turn the page until everyone is ready.

CSE 333 Midterm Exam 2/14/14

ECE264 Spring 2013 Exam 1, February 14, 2013

CSE 303 Winter 2008 Midterm Key

CSE331 Winter 2014, Final Examination March 17, 2014 Please do not turn the page until 8:30. Rules:

CSE 333 Midterm Exam 7/29/13

Pointer Basics. Lecture 13 COP 3014 Spring March 28, 2018

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

CSE 333 Midterm Exam 7/22/12

Midterm Exam 2 Solutions, C programming

CSE 333 Midterm Exam July 24, Name UW ID#

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

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

COMP 524 Spring 2018 Midterm Thursday, March 1

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

CSE 374: Programming Concepts and Tools. Eric Mullen Spring 2017 Lecture 4: More Shell Scripts

Intro to C: Pointers and Arrays

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

THE UNIVERSITY OF WESTERN ONTARIO. COMPUTER SCIENCE 211a FINAL EXAMINATION 17 DECEMBER HOURS

CSE 333 Midterm Exam 5/10/13

COS 126 General Computer Science Spring Midterm 1

CSE 374 Midterm Exam 11/2/15 Sample Solution. Question 1. (10 points) Suppose the following files and subdirectories exist in a directory:

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview

CSE373 Winter 2014, Final Examination March 18, 2014 Please do not turn the page until the bell rings.

Program Organization and Comments

Pointers. Pointers. Pointers (cont) CS 217

ELEC 377 C Programming Tutorial. ELEC Operating Systems

Consider the following program.

Algorithm Design and Analysis. What is an Algorithm? Do Algorithms Matter?

Please wait to turn the page until everyone is told to begin.

CS 1713 Introduction to Programming II

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

CSE 374 Programming Concepts & Tools. Brandon Myers Winter 2015 Lecture 11 gdb and Debugging (Thanks to Hal Perkins)

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

1 Inheritance (8 minutes, 9 points)

Prelim CS410, Summer July 1998 Please note: This exam is closed book, closed note. Sit every-other seat. Put your answers in this exam. The or

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

CSC209S Midterm (L0101) Spring 1999 University of Toronto Department of Computer Science

Lecture 7: file I/O, more Unix

CSE 413 Midterm, May 6, 2011 Sample Solution Page 1 of 8

CS536 Spring 2011 FINAL ID: Page 2 of 11

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

CSE373 Midterm I Fall 2009 (Closed book, closed notes)

CS Operating system

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

Transcription:

CSE 303, Spring 2005, Midterm Examination 29 April 2005 Please do not turn the page until everyone is ready. Rules: The exam is closed-book, closed-note, except for one side of one 8.5x11in piece of paper. Please stop promptly at 3:20. You can rip apart the pages, but please write your name on each page. There are 85 points total, distributed unevenly among 8 questions (some of which have multiple parts). When writing code, style matters, but don t worry about indentation. Advice: Read questions carefully. Understand a question before you start writing. Write down thoughts and intermediate steps so you can get partial credit. The questions are not necessarily in order of difficulty. Skip around. If you have questions, ask. Relax. You are here to learn. 1

1. (7 points) What do each of the following csh commands do: (a) rm x (b) rm *x (c) rm * x (d) rm "* x" (a) Deletes the file named x in the current directory. (b) Deletes all files in the current directory with names ending in x (and not starting with.). (c) Deletes all files (not starting with.) in the current directory. (d) Deletes the file in the current directory with the three-character name * x. 2

2. (15 points) For each of the following, give a regular expression suitable for grep that matches the lines described: (a) Lines containing the string dan. (b) Lines containing the string dan but with any number of the characters capitalized. (c) Lines containing a d and an a and an n in that order, but with any number of characters inbetween. (d) Lines containing the (five-character) string [dan]. (e) Lines not containing any lower-case English vowels. (a) dan (b) [dd][aa][nn] (c) d.*a.*n (d) \[dan\] (e) ^[^aeiou]*$ 3

3. (10 points) Write a (very, very short) shell script that is like dos2unix except it stores the result in a different file. Include the necessary first line for a shell script. Take 2 arguments: the first is the input file; the second is the output file. Do not include error-handling (assume the input file exists). A DOS file has each line end with two characters: \r and then \n. A UNIX file has each line end with one character \n. So your script should remove (replace with the empty string) every \r that is at the end of a line. Note: If a file already has UNIX-style line endings, your script should be equivalent to copying the file. #!/bin/csh sed s/\r$// $1 > $2 4

4. (5 points) Suppose you find the following line in a csh script: echo someprogram # these are backquote characters Describe why this line is bad style. Give a simpler way of doing the same thing. This lines takes the standard-out from executing someprogram, makes it a string inside the csh script and then uses echo to send the string to standard-out. It is equivalent just to write someprogram. 5

5. (13 points) Write a C function increasing that takes a pointer to a struct MidtermList and returns 1 if the linked list represented by the argument has increasing elements (each number less than the one after it) and 0 otherwise. As usual, NULL is the empty list. Big hint: All lists with 0 or 1 elements are increasing. A longer list is increasing if its first element is less than its second and the list without the first element is increasing. Solutions remembering the previous element are possible but complicated look at the next element instead. struct MidtermList { int num; struct MidtermList * rest; ; int increasing(struct MidtermList * lst) { if(lst==null) return 1; for(; lst->rest!= NULL; lst = lst->rest) if(lst->num >= lst->rest->num) return 0; return 1; // or a recursive one (consumes more space in C, but easier to get right) int increasing(struct MidtermList * lst) { if(lst == NULL lst->rest == NULL) return 1; if(lst->num >= lst->rest->num) return 0; return increasing(lst->rest); // or without multiple returns int increasing(struct MidtermList * lst) { return lst == NULL lst->rest == NULL (lst->num < lst->rest->num && increasing(lst->rest)); 6

6. (15 points) Indicate the values for a and b using the blanks at each program point indicated below. Warning: This problem is tricky. #include <stdio.h> #define FOO(x,y) { printf(" %d ",y); x = y; void foo(int x, int y) { printf(" %d ",y); x = y; int main(int argc, char**argv) { int a = 2; int b = 3; FOO(a,++b); // a is b is FOO(a,++b); // a is b is foo(a,++b); // a is b is foo(a,++b); // a is b is return 0; 5 5 7 7 7 8 7 9 7

7. (15 points) Consider this C function: void f(int * x, int * y) { free(x); // line 1 *y = 17; // line 2 Describe 4 ways (not including the example below) that a caller could use f such that line 1 is perfectly legal but line 2 might set the computer on fire. Exactly 1 of your 4 ways must involve x. Example: The caller could pass NULL for y. (a) The caller could pass an uninitialized value for y. (b) The caller could pass a dangling pointer for y. (c) The caller could cast an int to a pointer and pass that for y. (d) The caller could pass the same pointer for x and y (making the assignment a dangling-pointer dereference). 8

8. (5 points) Fill in the blanks so the program below prints 64. int f(int (*h)(int)) { return (*h)(13); int main(int argc, char**argv) { printf("%d",f(&g)); (Many other solutions exist.) int g(int x) { return 64; 9