Programming Assignment 1A

Version 1.0

Colorado State University

CS370: Operating Systems


DUE DATE:
10:00 pm
Sunday January 26th, 2014


Programming Assignment 1A: getopt(), functions, return values

The purpose of this assignment is to (re-) introduce the basic concepts of C programming after a long cold semester break.


Description of Task

For this assignment you will be creating a single program, fibon. When

fibon takes 2 required parameters and 2 optional parameters from the commmand line.

When fibon is executed, it will print the fibonacci sequence between two numbers. The possible range is 0 to 1000000 (inclusive).

Requirements of Task

  1. fibon will have a global integer array called sequence declared statically that will hold the sequence.
  2. fibon must use getopt() to parse the parameters described above. An example of getopt() can be found here.
  3. If the two required parameters are not specified, or there is any other type of command line error, only the usage statement will be printed. See below for an example.
  4. The -e and the -o options are mutually exclusive.
  5. The upper and lower ends of the range must be specified either positionally or with the letter options - but not with both (i.e. upper must be specified the same way as lower).
  6. upper must be greater than or equal to lower.
  7. Once the command line has been parsed, fibon will call an internal function compute_sequence passing it two integers, upper and lower.
  8. compute_sequence will fill the sequence array with the values of the fibonacci sequence starting with the first number greater than or equal to the lower range value and will return the index in the array of the last value within the range.
  9. fibon will then call another function print_sequence passing it the index returned from compute_sequence that will print the sequence within the range.
  10. print_sequence will print the sequence 10 per line, comma seperated with a space after the comma. Be sure the last number on the line does not have a comma or a space after it.
  11. If the -e or -o option is specified, only the even (or odd) numbers should be printed.
  12. You must submit a makefile meeting the specifications defined below. An example of a makefile can be found here.

Note: all error conditions have not be specified. If the input specified on the command line does not meet the specifications, you should take the same actions as other error conditions.


Example:

waker> fibon
Usage: fibon [[lower upper] | [-l lower -u upper]] [-e | -o]
waker>

waker> fibon -l 0 1000
Usage: fibon [[lower upper] | [-l lower -u upper]] [-e | -o]
waker>

waker> fibon 0 -u 1000
Usage: fibon [[lower upper] | [-l lower -u upper]] [-e | -o]
waker>

waker> fibon l 1000 -x
Usage: fibon [[lower upper] | [-l lower -u upper]] [-e | -o]
waker>

waker> fibon l 1000 -e -o
Usage: fibon [[lower upper] | [-l lower -u upper]] [-e | -o]
waker>

waker> fibon 0 1000
0, 1, 1, 2, 3, 5, 8, 13, 21, 34
55, 89, 144, 233, 377, 610, 987
waker>

waker> fibon 2 1000
2, 3, 5, 8, 13, 21, 34, 55, 89, 144
233, 377, 610, 987
waker>

waker> fibon 2 1000 -o
3, 5, 13, 21, 55, 89, 233, 377, 987
waker>

waker> fibon 2 1000 -e
2, 8, 34, 144, 610
waker>

waker> fibon 22 22
waker>


What to Submit

The program files should be well documented with both data dictionaries and logic flow descriptions.

Your makefile should perform a make target, a make clean and a make all. Name the executables per the requirements .

Perform a make target and submit the tar file containing your .c file(s), .h file(s), and Makefile using the RamCT assignment submission page.

You are required to work alone on this lab.

This is Programming Assignment 1A.


Late Policy

Click here for the class policy on submitting late assignments.



Copyright © 2001-2014: Colorado State University for CS370. All rights reserved.