L-44 MCS 275 Fri 27 Apr 2001

Review Questions on Chapter 14

  1. The UNIX command cal displays the calendar of the current month. To see the calendar for the month May of 2001, we type
          prompt> cal 5 2001
    
    and our friend, the computer shows us
                May 2001
          Su Mo Tu We Th Fr Sa 
                 1  2  3  4  5
           6  7  8  9 10 11 12
          13 14 15 16 17 18 19
          20 21 22 23 24 25 26
          27 28 29 30 31
    

    1. Write a program that calls the UNIX command cal.

    2. Write a interactive program that prompts the user to enter the number of the month and the year. Then invoke the cal command with those arguments.

    3. Modify the program above to find out how many days a particular month of some year has. The last day is the last integer number displayed by cal.

  2. The UNIX command pwd prints the working directory.

    1. Use the command pwd to write the function int depth () that returns the number of directories the current working directory is away from the root (the / in UNIX). (Hint: count the number of slashes / in what pwd returns.)

    2. PWD is also an environment variable on UNIX systems. Use the environment variable PWD to implement int depth().

  3. Consider the makefile
    A: C
            @echo 1
    B:
            @echo 2
    C: B
            @echo 3
    
    Give the sequence of numbers displayed when the user types

    1. make A
    2. make B
    3. make C

FINAL EXAM in LC C3 on Monday 30 April 2001 at 1:00-3:00PM.