Computer Science 157 – Fall 1999                Mid Term Test # 2                        Answer Sheet

  1. Prototype
  2. Recursive
  3. Subscript (or index)
  4. x,y,m,r,s,u
  5. Invalid – with 10 elements, subscripts are 0-9; there is no element 10
  6. Invalid – subscript cannot be a decimal number
  7. Invalid – switch must test an integral value, not a double
  8. Valid
  9. Valid
  10. Invalid – formal parameters must give type and name of parameter
  11. D:  0

Z:  0

X:  1

Z:   1 Q:  4

D:  0  E:  4

  1. 23
  2. A 4 B 10
  3.  4

6

8

10

4

5

6

  1.  11  16  8

   3    5  8

  1.   10  3  14  9  7  5  7  14
  2.  

int numLarger = 0;

for (cnt = 0; cnt < 20; cnt++) {

     if (data[cnt] > 100) {

                numLarger++;

       }

}

  1. double CalcFee (int hrsParked) {

              double fee;

              int extraTime;

              double extraCost;

              fee = 2.0;

              if (hrsParked > 3) {

                extraTime = hrsParked – 3;

                extraCost  =  extraTime * 0.5;

                fee += extraCost;

                }

             return fee;

         }

      int main() {

           double cost;

          

           cost = CalcFee(currHours);