DOC PREVIEW
UW CSE 303 - Exam Guide

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Name:CSE 303, Spring 2006, Midterm Examination1 May 2006Please do not turn the page until everyone is ready.Rules:• The exam is closed-book, closed-note, except for one 8.5x11in piece of paper (both sides).• Please stop promptly at 3:20.• You can rip apart the pages, but please write your name on each page.• There are 75 points total, distributed unevenly among 6 questions (all of which have multiple parts).Question Max Grade1 122 93 44 155 256 10Total 75Advice:• 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.1Name:1. (12 p oints)What do es e ach one of the following commands do?(a) ls ~/hw2/ >> documents(b) cat my-file | less(c) mv mytaxes*200[0-4]* old-tax-documents/(d) wc -l *.html | sort -n | head -n 1Assume that wc -l *.html by itself produces the following output:624 course_dictionary.html25 grades.html28 index.html65 mainpage.html166 overview.html31 resources.html204 schedule.html1745 total2Name:2. (9 points) For each of the following, give a regular expression suitable for grep (or egrep) thatmatches the lines described:(a) Lines that contain the letters a, b, and c, in that order, with at most one character betweenconsecutive letters. For example, abc would match, so would axbxc, but axxbxxc would not.(b) Lines that start with the word dog and end with the word cat.(c) Lines that contain a floating point number. The number must have a decimal point and at leastone digit before and one digit after the decimal point.3Name:3. (4 points) Explain what the following sed command does. Read the command carefully.sed -e ’s/dog/cat/’ -e ’s/puppie/kitten/g’ animals.txt4Name:4. (15 points) Explain the behavior of the bash script below. Do not explain how it works, just theeffects that a use r of the script will see.Reminders:• $@ refers to the list of command line arguments starting with $1.• date prints the current date.• [ -d name ] tests if a file name is a directory.#!/bin/bashif [ $# -lt 2 ]thenecho "usage: ‘basename $0‘ output_file dir1 dir2 ... dirn" >&2exit 1fioutput_file=$1echo "Snapshot as of ‘date‘" > $output_filefor arg in $@doif [ -d $arg ]thenfor i in ${arg}/*.{c,h}donew="${i}.back"echo "$i $new" >> $output_filecp $i $newdonefidone5Name:[Problem 4 continued]6Name:5. (25 points)(a) Indicate the output of the program using the provided blanks.#include <stdio.h>#define SIZE 100int main() {int array[SIZE];int i;for ( i = 0; i < SIZE; i++) {array[i] = i;}int *p1;int *p2;p1 = &array[1];p2 = array + 4;printf("%d %d\n", *p1, *p2); // Output: _______________p2 = p1;*p2 = 25;printf("%d %d\n", *p1, *p2); // Output: _______________int **pp1;int **pp2;pp1 = &p1;pp2 = &p2;*pp2 = p1 + 4;*(*pp1) = 50;printf("%d %d\n", *p1, *p2); // Output: _______________return 0;}7Name:[Problem 5a continued]8Name:(b) Next to each sequence of instructions, indicate if it is correct or if there is a bug. If there is abug, say what the problem is:// Sequence 1int *p1 = (int *)malloc(sizeof(int));int *p2 = p1;*p1 = 10;free(p2);p1 = NULL;p2 = NULL;// Sequence 2int *p1 = (int *)malloc(sizeof(int));int *p2 = p1;*p1 = 10;free(p1);free(p2);p1 = NULL;p2 = NULL;// Sequence 3int *p1 = (int *)malloc(sizeof(int));int *p2 = (int *)malloc(sizeof(int));*p1 = 10;free(p1);free(p2);p1 = NULL;p2 = NULL;// Sequence 4int *p1 = (int *)malloc(sizeof(int));int *p2 = (int *)malloc(sizeof(int));p1 = p2;free(p1);p1 = NULL;p2 = NULL;9Name:[Problem 5b continued]10Name:6. (10 points) Indicate the output of the program using the provided blanks. Warning: be careful!#include <stdio.h>#define INCR 2#define PRINT(x) printf("%d\n", x )#define COMPUTE(x) (x * x + INCR)int compute(int x ) {return ( x * x + INCR );}int main() {int a = 2;int b = 3;PRINT( compute(a) ); // Output is: ___________PRINT( COMPUTE(a) ); // Output is: ___________PRINT( compute(a+b) ); // Output is: ___________PRINT( COMPUTE(a+b) ); // Output is: ___________return


View Full Document

UW CSE 303 - Exam Guide

Documents in this Course
Profiling

Profiling

11 pages

Profiling

Profiling

22 pages

Profiling

Profiling

11 pages

Testing

Testing

12 pages

Load more
Download Exam Guide
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Exam Guide and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Exam Guide 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?