L-41 MCS 260 Mon 26 Nov 2001

Review Questions I 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. Consider the statements below. What is printed?
             int n = 11;
             printf("%o", n);
    

  2. Consider the following code:
           int i, s = 0;
           do
           {
              scanf("%d", &i);
              s += i;
           } while (i != 0);
           printf("%d", s);
    
    1. Write an equivalent piece of code using for instead of do-while.
    2. Write an equivalent piece of code using while instead of do-while.
    3. Suppose the user types 1 3 -4 8 5 0. Execute the code and make a table with three columns: step number in the loop, value for i and value for s. What is printed?

  3. Consider the following code:
           int n, i = 0;
           int ws = 0;
           while (i++ < 5)
           {
              scanf("%d", &n);
              ws += n/i;
           }
           printf("%d", ws);
    
    1. Write an equivalent piece of code using for instead of while.
    2. Write an equivalent piece of code using do-while instead of while.
    3. Suppose the user types 1 3 -4 8 5. Execute the code and make a table with four columns: step number in the loop, value for i, value for n, and value for ws. What is printed?

  4. Consider the following code:
           int max,n, i = 0;
           scanf("%d",&max)
           for (i = 1; i < 5 ;i++)
           {
              scanf("%d", &n);
              if (n > max) max = n;
           }
           printf("%d", max);
    
    1. Write an equivalent piece of code using while instead of for.
    2. Write an equivalent piece of code using do-while instead of for.
    3. Suppose the user types 1 3 -4 8 5. Execute the code and make a table with four columns: step number in the loop, value for i, value for n, and value for max. What is printed?

  5. Write a function int ask_user() that after the display of the menu
       Choose one of the following options :
         D. make a deposit;
         W. withdraw funds;
         A. ask customer assistance;
         R. return to the main menu;
         T. terminate the session;
       Type D, W, A, R, or T to choose : 
    
    reads the character typed in by the user and returns 0,1,2,3, or 4, corresponding to the 5 possible character choices. An error message should be displayed and -1 must be returned in case the user makes an invalid choice.

  6. The "pental" number systems uses digits 0,1,2,3,4. For example, 123 in the pental system evaluates to the decimal system into 1 x 5^2 + 2 x 5^1 + 3 x 5^0.
    1. Convert 68 from decimal to the pental number system.
    2. Consider the following functions
         void read_forwards ( int *n );
         /* reads a positive number in pental notation,
            starting with the most significant digit */
         void read_backwards ( int *n );
         /* reads a positive number in pental notation,
            starting with the least significant digit */
         void write_forwards ( int n );
         /* writes a positive number in pental notation,
            starting with the most significant digit */
         void write_backwards ( int n );
         /* writes a positive number in pental notation,
            starting with the least significant digit */
      
      Which of these functions need arrays to define? Give the definitions of the functions.

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.