Homework #1

Assigned: August 26
Due: September 9, 2:00pm, in class


  1. (16 points) Write a C (not C++) program /home/<logname>/homeworks/hw1/words.c to read a stream of text from standard input until EOF and write to standard output only the total number of words read and the average number of words per line, in that order, where a word is defined as any string of characters except whitespace. For instance,
    $ hostname
    cpsfedora1.fs.udayton.edu
    $ ./a.out < /etc/mime.types
    1957 2.27
    

    Keep your program to approximately 30 lines and submit a pretty-printing listing of it in class using a2ps.

    You can convert your source code file into a pretty-printed PDF file by executing the following command lines on our system from the directory in your UNIX account containing your source file words.c.

    a2ps words.c -o words.ps
    ps2pdf words.ps
    
    or simply
    a2ps words.c
    
    which will print words.c to the printer in the AN 131 lab.

  2. (16 points) Write a C (not C++) program /home/<logname>/homeworks/hw1/OS.c to synchronize 20 processes to print the following (of course, with different process and parent process ids):
    PPID: 310, PID: 497, operating
    PPID: 497, PID: 498, systems
    PPID: 498, PID: 499, operating
    PPID: 499, PID: 500, systems
    PPID: 500, PID: 501, operating
    PPID: 501, PID: 502, systems
    PPID: 502, PID: 503, operating
    PPID: 503, PID: 504, systems
    PPID: 504, PID: 505, operating
    PPID: 505, PID: 506, systems
    PPID: 506, PID: 507, operating
    PPID: 507, PID: 508, systems
    PPID: 508, PID: 509, operating
    PPID: 509, PID: 510, systems
    PPID: 510, PID: 511, operating
    PPID: 511, PID: 512, systems
    PPID: 512, PID: 513, operating
    PPID: 513, PID: 514, systems
    PPID: 514, PID: 515, operating
    PPID: 515, PID: 516, systems
    

    The first process must print operating and its child must print systems, then the child of that child must print operating and its child must print systems, and so on.

    No fancy C functions, beyond what has been covered in class, is necessary for this program. Do not use any C constructs not presented in class unless you have discussed their use in your approach with the instructor first.

    Keep your program to approximately 25 lines and submit a pretty-printed listing of it in class using a2ps.


Return Home