Midterm-w10

# Midterm-w10 - EECS 280 Midterm Winter 2010 This is a...

This preview shows pages 1–6. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Uniqname:________________________________________________________________________________ EECS 280 Winter 2010 2
Uniqname:________________________________________________________________________________ EECS 280 Winter 2010 3 Problem 1 _________ out of 20 Problem 2 _________ out of 20 Problem 3 _________ out of 20 Problem 4 _________ out of 20 Problem 5 _________ out of 20 Total: ________ out of 100

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Uniqname:________________________________________________________________________________ EECS 280 Winter 2010 4 1. Correctness In the following problems, you are given: An English description of a function A (potentially erroneous) implementation of that function For each implementation, state whether or not it is correct. If it is not correct, list the specific bugs. You do not need to correct the bugs; only identify them! 1.a locate Returns true if the string s2 appears anywhere inside of the string s1, returns false otherwise. For example, "lo" appears in "hello" whereas "la" does not. bool locate(const char * s1, const char * s2) { // REQ: s1 and s2 are non-empty, NULL-terminated strings // EFF: returns true if s2 is contained anywhere inside of s1, // false otherwise. while (*s1) { if (*s1 == *s2) { while (*s1 && *s2 && (*s1 == *s2)) { s1++; s2++; } if (!*s2) return true; } else s1++; } return false; }
Uniqname:________________________________________________________________________________ EECS 280 Winter 2010 5 1.b strnrev Reverses the first n characters of the string str and returns the result to the user. char* strnrev(char* str, int n) {

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/07/2012 for the course EECS 280 taught by Professor Noble during the Fall '08 term at University of Michigan.

### Page1 / 13

Midterm-w10 - EECS 280 Midterm Winter 2010 This is a...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online