Unformatted text preview:

CMSC 212 - Standard Midterm #1 - Fall 2005 - Keleher/Plane - p. 1 of 11 CMSC 212 Midterm #1 (Fall 2005) Name _________________________ Signature ________________________ Discussion Section Time (circle one): 12:00 1:00 2:00 3:00 4:00 5:00 Elena Sorelle Morgan (1) This exam is closed book, closed notes, and closed neighbor. No calculators are permitted. Violation of any of these rules will be considered academic dishonesty. (2) You have 70 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. If you need additional paper, we will provide it. Make sure your name is on any additional sheets. (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) If you need additional paper, raise your hand and we will bring it to you. Any additional paper you receive must be submitted with your exam paper. You must clearly mark what question is on that page both on the extra paper and on this exam sheet. Page Possible Score 2 16 3 15 4 15 5 18 6 14 7 7 8 7 9 8 Total 100CMSC 212 - Standard Midterm #1 - Fall 2005 - Keleher/Plane - p. 2 of 11 1.) [16 points] Define and explain the following terms (compare and contrast means give at least one similarity and one difference): a) Compare and contrast the way space is allocated through the use of the stack and the use of the heap. b) List two things that should be in header files, and two things that shouldn’t. 1. Two things that SHOULD be in a header file: 2. Two things that SHOULD NOT be in a header file: c) Compare and contrast stderr and stdout. d) Functions may be defined with array dimensions omitted for example: int func1(int arr[][5]); or int func2(int arr[]); Explain why some of the dimensions (the 5 in this example) need to be specified and why others don’t.CMSC 212 - Standard Midterm #1 - Fall 2005 - Keleher/Plane - p. 3 of 11 2.) [15 points] Give the exact output that would be produced by the following code. You do not need to worry about the exact location of any whitespace characters in your output since none of the field width specifiers are given. You do need to make sure you include the line breaks appropriately. #include <stdio.h> #define ARRSIZE 12 typedef struct{ int size; int *arr; }SType; int main(void){ char name[ARRSIZE] = "Bob"; int i; SType s1; int *ipntr; char *cpntr1; char *cpntr2; SType *spntr; cpntr1 = name; s1.arr = calloc(3,sizeof(int)); s1.size = 3; for (i = 1; i < s1.size; i++){ *(s1.arr + i) = i + 10; } printf("%d, %d-%d-%d\n",s1.size, s1.arr[0],s1.arr[1],s1.arr[2]); cpntr1 = name; cpntr2 = malloc(strlen(name)+1); cpntr2 = name; *cpntr1 = 'S'; printf("%s %s %s\n", name,cpntr1,cpntr2); printf("%s %s %s\n", name+1,cpntr1+2,cpntr2+3); spntr = &s1; spntr -> size = 1; *(spntr -> arr) = 23; printf("%d, %d-%d-%d\n",s1.size, s1.arr[0],s1.arr[1],s1.arr[2]); return 0; }CMSC 212 - Standard Midterm #1 - Fall 2005 - Keleher/Plane - p. 4 of 11 3.) [15 points] Questions about the projects. a) Two of the registers in project 1 were special purpose registers (R0 and R1). Describe the purpose of R1 and how it would be updated when performing different elements of the instruction set. b) Write the portion of the hash function which will look at the last four bits (rightmost 4 bits) of the unsigned integer hashval. If any of the last four bits is a 1, it should shift the hashval 4 to the right. If none of the last four bits is a 1, it should shift the hashval 4 to the left. c) Why are hash tables often resized before they are completely full? (as we did in project 2)CMSC 212 - Standard Midterm #1 - Fall 2005 - Keleher/Plane - p. 5 of 11 4.) [18 points] Use the structure on the final page for the definitions of the types used here - that page can be torn off, but make sure you write your name on it and submit it with your exam paper. For each of the following questions, the first line gives the declaration of a variable, and the second is an expression using that variable. i) You may assume any space that would have had to be dynamically allocated has been. ii) You may also assume that if it is a pointer it is indeed pointing to valid space. iii) You need to fill in the first blank to say if that expression would be valid or invalid iv) If you put valid in the first column for a given item, in the second column you must then tell the type the expressions refers to. You can think of this in terms of how you would print the item – if it is something you would print using a %s, then say string, if it is something you would print using a %c then say character, etc. VALID/INVALID TYPE (if valid) a) PersonTy p; p.list->color[1] ______________________ _______________________ b) PersonTy *m; m->name _______________________ ______________________ c) InventoryTy j; j.invlist->peryard ________________________ _____________________ d) FabricTy f; *(f.color) ________________________ _____________________ e) InventoryTy *x; &(x.storename[0]) ______________________ _______________________ f) PersonTy *p; p->list->color ______________________ _______________________CMSC 212 - Standard Midterm #1 - Fall 2005 - Keleher/Plane - p. 6 of 11 5.) [21 points] Use the types defined on the last page of this exam to write each of the following functions. The last page of the exam can be torn off the exam, but make sure you put your name on that paper and submit it with your exam when you are finished. You must assume the prototype given is already present (in


View Full Document

UMD CMSC 212 - Midterm #1

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