Name: ________________________________________________________
Umail Address: __________________________________@ umail.ucsb.edu
Circle Lab section: 8AM 10AM 11AM noon
Link to Printer Friendly PDF Version Answer Key
Please write your name only on this page. That allows me to grade your exams without knowing whose exam I am grading.
This exam is closed book, closed notes, closed mouth, cell phone off,
except for:
There are 100 points worth of questions on the exam, and you have 50 minutes to complete the exam.
A hint for allocating your time:
struct GPAreport { int perm; // perm number double gpa; // between 0.00 and 4.00 };
// FOR FULL CREDIT, FOLLOW THE INSTRUCTIONS EXACTLY, including // using EXACTLY THESE VARIABLE NAMES for the parameters... // The function initGPAreport should take these parameters: // gpaRpt: a pointer to a struct GPAreport called gpaRpt // thePerm: a perm number (integer) // theGpa: a grade point average (number between 0.00 and 4.00) // It should initialize the struct pointed to with the values passed in. // It doesn't return anything.
struct GPAreport { int perm; // perm number double gpa; // between 0.00 and 4.00 };
// FOR FULL CREDIT, FOLLOW THE INSTRUCTIONS EXACTLY, including // using EXACTLY THESE VARIABLE NAMES for the parameters... // This function deansListCount should take two parameters: // (1) an array of GPAreports called gpas // (2) an integer called n, which indicates the size of the gpas array // It should return the number of GPAs in the array that are 3.5 or higher
(40 pts) Together with this exam, there is a program (on a separate handout).
Assuming each of the expressions below appeared in this program, indicate the type they would have, or write error if the expression is not valid, e.g.
The first few are done for you as an example.
Hints--for full credit:
See solution
Expression | Type | Expression | Type | |
a | double * | i.x | ||
*b | error | i->y | ||
e | &(j.y) | |||
b | (*g).x | |||
&b | (*g)->y | |||
*a | h.x | |||
*d | *(h.x) | |||
e.center | &g | |||
e->x | argc | |||
f->y | argv[0] | |||
e->center->x | argv[0][0] |
rwxr-xr-x
blah
is rw-r--r--
. ./blah
at the Unix prompt?foobar
to have the permission string r-xr-xr-x
With that in mind, indicate the values of each element of the array after the 1st, 2nd and 3rd swap.
Keeping in mind that some of these swaps may be cases of an element being swapped with itself—those still "count" as swaps!
a[0] |
a[1] |
a[2] |
a[3] |
a[4] |
|
initial values | 42 |
88 |
13 |
9 |
27 |
after 1st swap | |||||
after 2nd swap | |||||
after 3rd swap | |||||
after 4th swap (final array) | 9 |
13 |
27 |
42 |
88 |
Total points: ?
Program for question about types
// types.c Code for exam question, 11/15/2009 // P. Conrad for CS16, 09F, UCSB #include <stdio.h> struct Point { double x; double y; }; struct Date { int d; int m; int y; }; struct Circle { struct Point center; double radius; }; int main(int argc, char *argv[]) { double *a; double b; int *c; int d; struct Circle *e; struct Circle f; struct Date *i; struct Date j; struct Point *g; struct Point h; // Program does no useful work // It is just the basis of a homework assignment about types
// Pretend there is useful code here, and then // answer questions about the types of various expressions // as if they appeared right here. return 0; }