next up previous
Next: About this document

centering17

name:

  1. Suppose you are reading your email using the mail program.
    1. (3 pts) Is it possible to delete a message other than the current message? If so, explain how.
    2. (3 pts) If you mark messages for deletion, is it possible to quit the mail program without deleting those messages? If so, explain how.
  2. (5 pts) What is the value of variable count when the following program finishes execution?
    #include <stdio.h>
    
    main() {
      int count = 37;  
    
      do {
        count++;
        if (count > 5) break;
        count = 3;
      } while (count <= 10);
      if (count > 8) count = 23;
      else count = 24;
    }
  3. (5 pts) You are in insert mode while editing file myfile with vi. Give the sequence of keystrokes needed to save changes and quit vi. Indicate special keys by enclosing their names in angle brackets (i.e. <Enter> or <Esc>).
  4. Assume that the current working directory is your home directory, and you have a subdirectory called coolstuff.
    1. (6 pts) Assume that everyone can read, write, create and execute files in your home directory. Give a sequence of UNIX commands that will ensure that everyone in your group (including yourself) can read, create, write and execute files in your coolstuff directory, but others can only read and execute files in that directory.
    2. (5 pts) Give a sequence of UNIX commands which will create a subdirectory of coolstuff called frombob, and then copy file websites.txt from user bob's home directory to the frombob directory. (For 2 points extra credit, don't use the cd command anywhere in your sequence of commands.)
  5. (3 pts) What value would the following segment of C code print?
    int i = 13;
    
    printf("%d", (i > 13)? i - 1: i + 1);
  6. (5 pts) Explain why the following C program won't compile.
    #include <stdio.h>
    
    int fun1(int x) {
    
      return (fun2(x) + 1);
    }
    
    int fun2(int x) {
    
      return (x - 3);
    }
    
    main() {
    
      int z;
    
      z = fun1(5);
    }
  7. (5 pts) Why is it good program design to define symbolic constants for numbers that represent such things as flags and physical constants in mathematical equations?
  8. Given the following declarations:
    int i1 = 0, i2 = 1, i3 = 2;
    float f1 = 0.0, f2 = 4.0;
    double d1 = 5.0, d2 = 6.7;
    Give the result of evaluating each of the following expressions and the type of that result, or indicate that evaluating the expression would cause a run time error in a C program. If the result is a float or double, your answer only needs to show one place after the decimal point.
    1. (3 pts) (int) d2 - i2 + f2
    2. (3 pts) 5.0 + f2 / i2 - f2
    3. (3 pts) (float) d1 / f1
  9. Indicate whether each of the following C expressions evaluates to true (not 0), false (0), or causes a run time error when evaluated, given these declarations:
    int i1 = 0, i2 = 1, i3 = 2;
    float f1 = 3.0, f2 = 4.0;
    double d1 = 5.0, d2 = 6.0;
    1. (3 pts) (!(i2 > 7.0) || (i2 + f2 == d2))
    2. (3 pts) ((i2 + d2 / f1 == f2) && ((d1 / i1) == 7))
    3. (3 pts) ((f1 == 3) || ((d1 / i1) == 0))
  10. Consider a function that categorizes the value of an integer parameter a by printing:
    less than 50
    if a is less than 50,
    between 50 and 60
    if a is between 50 and 60 inclusive, and
    greater than 60
    if a is greater than 60.
    1. (7 pts) Write this function in C using if statements.
    2. (5 pts)Would it be easy to write this function with a switch statement? Why or why not?
  11. Consider the following while loop.
    int i = 0, prod = 1;
    
    while (prod <= 125) {
      printf("The current value is %d\n", i);
      i++;
      prod *= 5;
    }
    1. (4 pts) What is the value of i after the while loop executes?
    2. (6 pts) Write a for loop that produces the same output and final value of prod as this while loop.
  12. (5 pts) Why is it vital to log out when you finish a UNIX session?
  13. (15 pts) What output does the following program produce when it is run? You only need to show one place after the decimal point for floats and doubles.
    #include <stdio.h>
    int x = 4;
    
    void inc(int);
    float foo(int *, double *);
    
    main() {
      int y = 3, z = 5;
      float f;
      double d = 7.0;
    
      inc(y);
      printf("The value of x is %d and y is %d\n", x, y);
      f = foo(&z, &d);
      printf("The value of f is %f and z is %d and d is %lf\n", f, z, d);
    }
    
    void inc(int x) {
    
      x++;
    }
    
    float foo(int *y, double *z) {
    
      *z = *z + 2;
      return ((float) *y + 3);
    }



next up previous
Next: About this document

Tim Wahls
Tue Feb 18 13:08:00 EST 1997