L-42 MCS 260 Wed 28 Nov 2001

Review Questions II for Final Exam

The questions below are meant to stimulate the preparation of the final exam. They cover some of the most important but not all topics in the course. You must review all course materials: textbook, exercises, lecture notes, quizzes, and exams.

  1. To implement the game scrabble we would need a function that returns a random letter.
        char random_letter ( void );
        /* returns a randomly generated lower case letter */
    
    Give a definition of random_letter.

  2. Suppose that a simple ATM machine offers the following functions: see the balance on your account, withdraw money from checking or saving, transfer from checking to saving or from saving to checking.

    Describe the design of a program that would simulate this ATM machine. Sketch the organization of the flow of the program and give prototypes of the most important functions in the program. Do NOT write definitions of functions, just use comments to specify their input and output.

  3. Sometimes we need to reformat a file, replacing one character by another one, e.g.: replace all tabs by a space or colon. Write a function with prototype:
        void replace ( char c1, char c2 );
        /* reads characters from input until EOF is reached,
           copies the symbols to the output, except that every
           occurrence of character c1 is replaced by c2   */
    
    Give two definitions: once using only getchar and putchar and once using only scanf and printf.

  4. Give a definition for the following function
        double weighted_sum ( int n, int a[] );
        /* returns the sum of a[i]/(i+1) */
    

  5. Define an enumeration type curve that can take the following values: { A, B, C, D, E }.

    1. Adjust your definition of curve so that the five values correspond to the respective integers (expressing scores on an exam) : 90, 80, 70, 60, 50.
    2. Write input/output routines for the type curve.
      The input routine scans the corresponding integer value defined above. Use call-by-reference.
      The output routine writes a meaningful string for each variable of the type curve.
    3. Give a definition of the following functions:
        char grade ( curve s );
        /* returns the representation of s as a character */
      
        curve assign_grade ( float p );
        /* returns the corresponding grade with the percentage p, 
           as follows : p >= A : A;  A > p >= B : B;  B > p >= C : C;
                        C > p >= D : D;  and p < D : E           */
      
      The function assign_grade must adapt itself to the changing values of A, B, C, D, and E, without changing its definition.

  6. Consider the following program, using the function f :
         void f ( float *p );
         #include<stdio.h>
         int main(void)                   void f ( float *p )
         {                                {
            float x = 3.0;                    static int i = 0;
            f(&x);                            static float x = 1.0;
            f(&x);                            float y = (i==0)? 0 : x * *p;
            printf("%f", x);                  i++; x = *p;
            return 0;                         *p = y + 1.0;
         }                                }
    
    Make a diagram representing all variables in main and f. Illustrate with the diagram what happens before, during, and after each call of f(&x). What is printed?

FINAL EXAM is in Lecture Center C6 on Monday 3 December 2001 from 1:00 till 3:00PM.

Please let me know as soon as possible if you cannot attend the exam and need to schedule a makeup.

Incomplete grades are only given in exceptional cases. At least the two following conditions must be satisfied: the student is in good standing (has decent scores on midterm exams, projects, and quizzes) and the student is unable to take an exam during the finals week.