COP3502-Spr11-Exam1-sol-exp

# COP3502-Spr11-Exam1-sol-exp - COP 3502 Spring 2011 Exam 1...

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

COP 3502 – Spring 2011 – Exam 1 Solutions (with Instructor comments) Exam 1 NOTES: As mentioned in class, my intention with this first exam is to have, at most, one hard question, which is almost always going to be the recursive coding question, simply due to the fact that you have to actually think instead of regurgitate. Other than that, I wanted all other questions to be “workable”; meaning, every student who did an average amount of studying could successfully solve the problem. All test questions were straightforward, and anyone who truly studied and understood the PPT slides, lab questions, and programs would have done very well. The average grade was a 76, with many high grades, including some 105s. Several students commented that, although the questions were not tough, individually, the length of the exam was a challenge. Last semester, we had a similar exam, but with TWO additional questions. Understandably, many students said it was too long, BUT even then, they also said that they “just finished in time”. Literally, at least 80% of the class was still present (last semester) when the exam time was finished. Fast forward to this semester. More than one half of the students were gone with seven or eight minutes remaining. That is a good indicator as to the length and difficulty of an exam. When the time was up, only around 20-30% were still working (or reading over their answers). So although some may feel the exam was long, I do feel the length was appropriate for this class and certainly workable by those students that invested enough time in studying. Now to the solutions… 1) (10 pts) Dynamic Memory Allocation. The following struct can be used to store information about a student: struct student { char first[20]; char last[20]; int* programGrades; int* testGrades; }; The last two items of the struct are meant to be pointers to dynamically allocated arrays of int s that stores program grades and test grades, respectively. Write a segment of code that asks the user to enter three positive integers: 1) n , representing the number of students 2) p , representing the number of programs each student writes 3) t , representing the number of tests each student takes and allocates space for a dynamically allocated array of size n of struct student , where each student has space to store exactly p program and t test grades. Note: You don’t need to initialize any of the allocated space, you just need to allocate it . The beginning part of the code segment is given to you. Declare any extra variables you need. int n,p,t;

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

View Full Document
struct student* studentList; printf(“How many students do you have?\n”); scanf(“%d”, &n); printf(“How many programs have they written?\n”); scanf(“%d”, &p); printf(“How many tests have they taken?\n”); scanf(“%d”, &t); studentList = (struct student*)malloc(sizeof(struct student)*n); for (int i=0; i<n; i++) { studentList[i].programGrades = (int*)malloc(sizeof(int)*p); studentList[i].testGrades = (int*)malloc(sizeof(int)*t);
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 8

COP3502-Spr11-Exam1-sol-exp - COP 3502 Spring 2011 Exam 1...

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

View Full Document
Ask a homework question - tutors are online