Unformatted text preview:

CMSC 212 - Standard Midterm #2 - Spring 2007 - Hollingsworth/Plane - p. 1 of 13 CMSC 212 Midterm #2 (Spring 2007) Name ___KEY___________ Signature______________________________ University ID UID: _________________________________ GLUE/LDAP Login ID: _____________________________ Discussion Section Time (circle one): 10:00 11:00 12:00 1:00 Jose Cole (1) This exam is closed book, closed notes, with no other references. No calculators are permitted. Violation of any of these rules will be considered academic dishonesty. (2) You have 80 minutes to complete this exam. If you finish early, you may turn in your exam at the front of the room and leave. However if you finish during the last ten minutes of the exam please remain seated until the end of the exam so you don't disturb others. Failure to follow this direction will result in points being deducted from your exam. (3) Write all answers on the exam paper itself. If you need additional paper, we will provide it. Make sure your name is on any additional sheets and that you submit all sheets you are given. (4) Partial credit will be given for most questions assuming we can figure out what you were doing. (5) Please write neatly. Print your answers, if that will make your handwriting easier to read. If you write something, and wish to cross it out, simply put an X through it. Please clearly indicate if your answer continues onto another page. (6) The CMSC 212 Final Exam is scheduled: 5/12/07, Saturday: 4 - 6pm Location (as of right now) PHY 1412 Page Question Possible Score 2 1 (a & b) 8 3 1 (c & d) 8 4 2 a 13 5 2 b 15 6 2 c 15 7 3 15 8 4 16 9 5 10 Total 100CMSC 212 - Standard Midterm #2 - Spring 2007 - Hollingsworth/Plane - p. 2 of 13 1.) [16 points] Define and explain the following terms: a) Compare and contrast (both differences and similarities) “black box testing” and “white box testing”. Compare: both testing methods have the purpose of finding errors in the code you have written and/or inconsistencies between the written code and the specifications. Contrast: In white box testing you can use the fact that you know the implementation while you have no knowledge of the implementation in black box testing. –or – In white box testing you attempt to have maximum code coverage by testing all lines in the implementation while in black box testing you are determining if all output possibilities match what would be expected. b) Compare and contrast (both differences and similarities) a macro that is defined using the #define and a function (assume that the two do the same general task). Compare: both will allow you to take arguments and do operations on those arguments returning a value Contrast: The macro gets replaced into the code by the preprocessor while the function is connected to the call at link time –or- The macro is a character replacement method and so does no type checking/conversion while the function method can be tested for consistencies by the function header/prototype –or- Since macros are text replaced, parameters to macros can be types, structs, etc which is not possible with function params which must be variables.CMSC 212 - Standard Midterm #2 - Spring 2007 - Hollingsworth/Plane - p. 3 of 13 c) Compare and contrast (both differences and similarities) between malloc and calloc. Compare: both will allocate memory from the heap –or- both take the amount of space needed as the argument and return a void* pointer to that space Contrast: malloc does not initialize the space allocated while calloc does –or- calloc takes two arguments (multiplying them to know the amount of space) while malloc only takes one d) Give at least two practical benefits to using dynamically linked libraries rather than statically linked libraries. 1: Only one copy of the library needs to be on the system not one for each executable that uses it 2: The library is linked at run time and so can be changed up until that time (more flexibility) 3: The library is linked at run time and so the underlying implementation of the library’s functions can be changed up until that timeCMSC 212 - Standard Midterm #2 - Spring 2007 - Hollingsworth/Plane - p. 4 of 13 2.) [43 points] Assume the typedef’s below and it is used to store a binary search tree. The three parts of this question all deal with the same definitions (repeated at the top of each page). You may define and use any helper functions you need. Read through all three parts of this question before writing any of them. (typedef declarations are written in columns just to give more room on the page for your answer) typedef void (*pfuncty)(void *); // prints to standard output typedef int (*cfuncty)(void*,void*); // compares where 0 means equality, <0 means the first one is less and >0 means the second one is less typedef struct _node{ void * dataitem; struct _node * left; struct _node * right; } nodety; typedef struct _tree{ pfuncty printfunc; cfuncty compfunc; nodety * root; } treety; a) Write the complete function that will print the entire contents of the tree in ascending order. void phelper(nodety * curr, pfuncty pf){ if (curr == NULL) return; else{ phelper(curr->left,pf); pf(curr->dataitem); phelper(curr->right,pf); } } void printtree(treaty t){ phelper(t.root, t.printfunc); return; }CMSC 212 - Standard Midterm #2 - Spring 2007 - Hollingsworth/Plane - p. 5 of 13 This is retyped here for the ease of your reference – it is the same as what appears on the previous page: typedef void (*pfuncty)(void *); // prints to standard output typedef int (*cfuncty)(void*,void*); // compares where 0 means equality, <0 means the first one is less and >0 means the second one is less typedef struct _node{ void * dataitem; struct _node * left; struct _node * right; } nodety; typedef struct _tree{ pfuncty printfunc; cfuncty compfunc; nodety * root; } treety; b) Write the complete function that will return 1 if the value passed as the second argument already appears in the tree and a 0 if it does not. You may assume the second argument is either NULL or is pointing at data of the same type as currently stored in the tree, and you can assume that the root of the tree is either NULL or currently pointing at the root node of a tree storing that same kind of data.


View Full Document

UMD CMSC 212 - Midterm #2

Download Midterm #2
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 Midterm #2 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 Midterm #2 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?