Answer key for Midterm Exam 2, CS16, Fall 2009 


1)

void initGPAreport(struct GPAreport* gpaRpt, int thePerm, double theGpa){

      (*gpaRpt).perm = thePerm;            
      (*gpaRpt).gpa = theGpa;
} 
   
2)
int deansListCount(struct GPAreport* gpas, int n)
{      
  int count,i;
  count = 0;

  for(i = 0; i<n;i++)
  {
     if(gpas[i].gpa >= 3.5) count++;
  }

  return count;
} 
3)
a    double*             i.x   error
*b    error              i->y   int
e     struct Circle*     &(j.y)   int*
b    double              (*g).x   double
&b     double*           (*g)->y    error
*a     double            h.x   dobule
*d    error              *(h.x)   error
e.center  error          &g   struct Point**
e->x     error           argc   int
f->y      error          argv[0]  char*
e->center->x  error      argv[0][0]  char 

4)

a) No, the owner does not have executable permissions.
b) chmod 555 foobar
c) rwxr-xr-x 

5)

 
a[0]
a[1]
a[2]
a[3]
a[4]
initial values
42
88
13
9
27
after 1st swap
42
27
13
9
88
after 2nd swap
9
27
13
42
88
after 3rd swap
9
13
27
42
88
after 4th swap (final array)
9
13
27
42
88

 

6)

An example of a file that doesn't contain machine code but does contain executable code, and should therefore have executable permissions is a shell script, which is a script of unix commands that the unix shell can interpret directly and run as a file. Another example is a C program source file when run under the Ch program.