13 EECS 280 Midterm Exam Review

EECS 280 Programming and Introductory Data Structures Midterm Exam Review Slides by Andrew DeOrio 1 Time and location Wednesday 26 Feb, 7:00pm (Michigan time) - 8:30pm (80min) Where: (by uniqname) STAMPS AUD aakashag - ivanbrad GGBL1504 jackwags - kozdowy BEYST1670 kploof - mjcar BEYST1690 mjshen - mursean DOW1013 mvitez - rshconn DOW1005 rsoltesz - sjfried DOW1006 skarl - taykraus DOW1010 tbourani - woodmatt DOW1017 wuyuting - zzhiqing 2 Schedule Wednesday (day of exam) No lecture No discussion all week All office hours following the exam (Thu 27 February - Fri 28 February) are canceled 3 Policies Closed book Closed notes One "cheat sheet" 8.5"x11", double-sided, hand-written, with your name on it No calculators or electronics None needed Given under the engineering honor code 4 Engineering honor code Exams in the CoE are given under the honor code, which hold that students are honorable and trustworthy people No proctor Staff available outside for questions You must sign the honor pledge on the exam "I have neither given nor received unauthorized aid on this examination, nor have I concealed any violations of the Honor Code." 5 Study materials Practice exams posted on CTools Labs Including optional exercises Lecture slides Exercises from lecture Text book Study groups 6 Topics Everything we have covered up to and including Abstract Data Types Topics you should definitely study: Recursion and tail recursion Lists and trees (project 2) Function pointers Arrays and pointers Strings and C-Strings Structs, classes and abstract data types Structs, enums and pointers (project 3) 7 Recursion http://icannotdraw.thecomicseries.com/ 8 Group Exercise: pow(x, y) Write a tail-recursive version of the power function that returns x to the power of y. It needs a helper function - why? Here is a non-tail-recursive, but recursive version of this function: int power(int x, int y) { if (y == 0) { return 1; } else { return x * power(x, y-1); } } Before you begin, why isn't this tail recursive? 9 Function Pointers 12 I couldn’t find anything funny about function pointers on the  internet. Exercise: Use function pointers to write all_even() and all_odd() bool all_of(list_t list, bool(*fn)(int)) { //EFFECTS: returns true if fn returns true for all if (list_isEmpty(list)) //base case return true; if (!fn(list_first(list))) //check current item return false; return all_of(list_rest(list), fn); //recurse } Write these. Use all_of(). Use helper functions. bool all_even(list_t list); bool all_odd(list_t list); 13 Arrays and pointers http://xkcd.com 16 Ptr Example void inc(int *x) { cout << "inc : x=" << x << " *x=" << *x << endl; x += 1; cout << "inc : x=" << x << " *x=" << *x << endl; } int main (void) { int n = -1; int* p = &n; cout << "main: p=" << p << " *p=" << *p << endl; inc(p); cout << "main: p=" << p << " *p=" << *p << endl; } Draw a stack diagram - why is the third line of output different? Bonus: what is sizeof(int) on this machine? output: main: p=0x7fff1e9c958c *p=-1 inc : x=0x7fff1e9c958c *x=-1 inc : x=0x7fff1e9c9590 *x=513578624 main: p=0x7fff1e9c958c *p=-1 17 Code this //REQUIRES: "a" points to an array of length "size" //EFFECTS: Returns a pointer to the first // occurrence of "search" in "a". // Returns NULL if not found. int *find (int *a, unsigned int size, int search); 19 Do not use array indexing, e.g., a[i] or *(a+i) Strings 21http://stevehanov.ca/blog Code this //REQUIRES: "s" is a NULL-terminated C-string //EFFECTS: Returns a pointer to the first // occurrence of "search" in "s". // Returns NULL if not found. char *strchr (char *s, char search); 22 Do not use array indexing, e.g., a[i] or *(a+i) Structs, Classes, ADTs 24 Exercise Write a class called Rectangle Include appropriate member variables Include a default constructor Include a second constructor to initialize member variables Write one set() function that sets all member variables Include an area() function Write a print() function Use public and private to expose member functions and hide member variables Write a main function that defines a Rectangle variable of size 2x4, calls the print() function, and then calls the area() function 25




需要 3 金币 [ 分享pdf获得金币 ] 0 人已下载





下载需要 3 金币 [金币充值 ]
亲,您也可以通过 分享原创pdf 来获得金币奖励!