next_inactive up previous


CISC 105 sections 010-025 Midterm 2 11/10/04

Name





Please circle your section number:



010 014 018 022
011 015 019 023
012 016 020 024
013 017 021 025



General Instructions

Multiple Choice

  1. (2 pts) Consider the function inc1 contained in the program listing of Q5.c shown on the following page of this exam.

    Which of the following are the names of the formal parameters of this function

    (a) r and s (b) 3 and 4 (c) &a and b
    (d) n and m (e) none of the above  

  2. (2 pts) Which of the following are the actual parameters of inc2?

    (a) 3 and 4 (b) &a and b (c) r and s  
    (d) *r and s (e) none of the above  

  3. (2 pts) The line inc2(&a,b); represents which of the following:

    (a) function definition (b) function prototype (c) function call  
    (d) function library (e) none of the above  

  4. (2 pts) The line void inc1(int n, int m); represents which of the following:

    (a) function definition (b) function prototype (c) function call  
    (d) function library (e) none of the above  

  5. (2 pts) The lines following the comment /* +++ */ down to the end of the page, as a group, represent which of the following:

    (a) function definition (b) function prototype (c) function call  
    (d) function library (e) none of the above  

  6. (2 pts) When this program runs, the first line of output will be:

    (a)
    main1: 3 4
    (b)
    main1: 4 4
    (c)
    main1: 4 5
    (d)
    inc1: 4
    (e)
    inc1: 5

  7. (2 pts) When this program runs, the last line of output will be:

    (a)
    inc2: 3
    (b)
    inc2: 4
    (c)
    main3: 3 4
    (d)
    main3: 4 4
    (e)
    main3: 5 6

    /* Q5.c */
    
    
    void inc1(int n, int m);
    
    void inc2(int a1[], int i);
    
    #include <stdio.h>
    int main()
    {
      int a = 3;
      int b = 4;
      
      printf("main1: %d %d\n",a, b);
      inc2(&a,b);
      printf("main2: %d %d\n",a, b);
      inc1(a,b);
      printf("main3: %d %d\n",a, b);  
    
    
      return 0;
    }
    
    void inc1(int n, int m)
    {
      n++;
      m++;
      printf("inc1: %d\n",m);
    }
    
    /* +++ */
    
    void inc2(int *r, int s)
    {
      (*r)++;
      s++;
      printf("inc2: %d\n",(*r));
    }
    

What is the output? (Multiple choice)

Each of the questions in this section consists of a short C program.

For each one, either select the answer that matches the output of the program, or, if the program contains an error that would prevent you from determining the output, select ``error'' as your answer.

(2 pts) What is the output?

/* Q2.c */

#include <stdio.h>
int main(void)
{
  int a[4] = {13, 15, 15, 19};  
  printf("%d",a[1]);
  return 0;
}

(a) 0 (b) 4 (c) 13 (d) 15 (e) error

(2 pts) What is the output?

/* Q3.c */

#include <stdio.h>
int main(void)
{
  int a[6] = {13, 15, 15, 19};  
  printf("%d",a[5]);
  return 1;
}

(a) 0 (b) 1 (c) 4 (d) 13 (e) 15

(2 pts) What is the output?

/* Q6.c */

#include <stdio.h>
int main(void)
{
  int a[6] = {13, 15, 17, 19, 20, 21};  
  printf("%d",a[6]);
  return 0;
}

(a) 0 (b) 19 (c) 20 (d) 21 (e) error

(2 pts) What is the output?

/* Q4.c */

#include <stdio.h>
int main(void)
{
  int a[6] = {1};  
  printf("%d",a[3]);
  return 0;
}

(a) 0 (b) 1 (c) 3 (d) 6 (e) error

(2 pts) What is the output?

/* Q7.c */

#include <stdio.h>
int main(void)
{
  int a[6] = {13, 15, 17, 19, 20, 21};  
  printf("%lf",a[3]);
  return 0;
}

(a) 13 (b) 15 (c) 17 (d) 19 (e) error

Addresses and Pointers

(2 pts) If the variable x is of type int, which of the following expressions would determine the address of that variable?

(a) *x (b) &x (c) addr(x)
(d) %x (e) none of the above  

(2 pts) If the variable p is of type double *, which of the following expressions would ``dereference'' the variable p?

(a) *p (b) &p (c) deref(p)
(d) %p (e) none of the above  

(2 pts) If you want the variable a to contain the address of an integer, which of the following would be a correct declaration of a?

(a) int a; (b) int &a; (c) int *a;
(d) int %a; (e) none of the above  

Functions (multiple choice)

All of the questions in this section deal with the following segment of a complete C program.

...
int findMax(int a, int b);
int findLargest(int a[], int n);
double areaOfCircle(double r);
void midPoint(double x1, double y1, double x2, double y2, 
              double *x, double *y);

#include <stdio.h>

int main(void)
{
   int  a=2, b=3, c=4;
   double d=5.0, e=-6.0, f=7.5;
   int scores[4] = {97, 65, 72, 80};
   double weights[4] = {0.15, 0.15, 0.2, 0.5};

...

(2 pts) Which of the following statements is true about the section of the C code above that appears before the line #include <stdio.h> ?

(a)
This is a list of function prototypes.
(b)
This is a list of function calls.
(c)
This is a list of function definitions.
(d)
This is a list of header files.
(e)
None of the above.

(2 pts) Which of the following could NOT appear legally later in this main program?

(a)
printf("%d\n",findMax(3, 4));
(b)
printf("%lf\n",areaOfCircle(d));
(c)
midPoint(4.0, 5.0, -2.0, -3.0, &d, &e);
(d)
f = midPoint(4.0, 5.0, -2.0, -3.0, &d, &e);

(2 pts) Which of the following could NOT appear legally later in this main program?

(a)
printf("%d\n",findMax(a * 2, b/3));
(b)
d = findMax(a, 3);
(c)
midPoint(4.0, 5.0, -2.0, -3.0, d, e);
(d)
a = findLargest(scores, 4);

(2 pts) Which of the following could NOT appear legally later in this main program?

(a)
midPoint(d, e, 0.0, 0.0, &d, &e);
(b)
a = findLargest(scores[0], 4);
(c)
e = areaOfCircle(f);
(d)
f = areaOfCircle(weights[1]);

Project 1 Related Questions (multiple choice)

(4 pts) From Project 1: The following function is supposed to return true if the number of trips is not different by more than one, and false otherwise. Select the choice below that replaces ??? and makes the function work correctly.

int meetsDiffOneOrLessRule(int tripsA, int tripsB)
{
   return ???
}

(a)
((tripsA > tripsB) && ((tripsA - tripsB) > 1));
(b)
((tripsA >= 1) && (tripsB >= 1));
(c)
1 >= abs(tripsA - tripsB);
(d)
pow((tripsA - tripsB), 2) < 1;
(e)
none of the above

(4 pts) From Project 1: The following function is supposed to return false if one parameter is more than 60 percent of the sum of the parameters, and true otherwise. Select the choice below that replaces both ??? and makes the function work correctly.

int meetsSixtyFortyRule(int tripsA, int tripsB)
{
    if (tripsA > tripsB)
    return tripsA ??? * (tripsA + tripsB);
    else
    return tripsB ??? * (tripsA + tripsB);
}

(a)
<= .60
(b)
< .60
(c)
> .40
(d)
>= .40
(e)
none of the above

(4 pts) From Project 1: Now suppose there is only one truck. The following function returns the number of trips that truck must take given two parameters: the starting number of tons, and the capacity of the truck in tons. Select the choice below that replaces ??? and makes the function work correctly.

int countTrips(int startTons, int capacity){
    int truckCount = 0;
    while ( ??? ){
    startTons -= capacity;
    truckCount++;
    }
    return truckCount;
}

(a)
startTons >= 0
(b)
startTons <= capacity
(c)
truckCount < capacity/startTons
(d)
startTons > 0
(e)
none of the above

C Programming

(20 pts) Write a complete C program that behaves as follows:

  1. prompts a user for ten integers
  2. uses scanf to get the integers and put the integers into an array
  3. prints out the array on a single line
  4. prints out the minimum value in the array

Sample script:

% a.out 
Please enter ten integers: 
9 3 2 4 5 6 7 3 8 6

array is: 9 3 2 4 5 6 7 3 8 6 
min is: 2

(Extra space in case you need it.)

(20 pts) Write a complete program that reads 100 integers from a file named data.txt into an array.

All the integers will be in the range 0 - 10 inclusive.

Your program should include a function to find the maximum value in an array, given the array and the array size as parameters.

Have your main() call the function and print the result.

Unix Commands (short answer)

(10 pts) One of the reasons we teach Unix in CISC105 is because the CIS dept and the Electrical and Computer Engineering departments have asked us to.

They want to be able to assume that their students know how to use Unix when they take later courses.

So, assume that in a future semester, having already mastered CISC105, you go on to take CPEG202.

Your goal is to make a report available at the following URL (assuming that userid is your own userid):

  http://~userid/cpeg202/reports/myReport.html

Assume the following:

Your assigment is to

Give the entire sequence of Unix commands that you use to accomplish this task. Note that even though I've listed four steps above, you might NOT need exactly four commands.

For each command spell out the entire command line (e.g. don't just say ``cp'', say ``cp foo bar''.) You don't have to give the editor commands, but you do need to show the command you use to ``startup'' the editor on your file.

End of Exam. Total Points: 100

About this document ...

This document was generated using the LaTeX2HTML translator Version 99.2beta8 (1.43)

Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney.

The command line arguments were:
latex2html -split 0 E02_F04.tex

The translation was initiated by Phillip T Conrad on 2004-11-20


next_inactive up previous
Phillip T Conrad 2004-11-20