Programming Assignment 1A
Version 1.0
|
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.
- The first parameter is the lower end of the range. This may be specified
either positionally or with the -l option.
- The second parameter is the upper end of the range. This may be specified
positionally (if the first parameter was specified positionally), or with
the -u option.
- The optional parameters are the -e and the -o options,
which specifies only the even or odd numbers should be printed.
When fibon is executed, it will print the fibonacci sequence between two
numbers. The possible range is 0 to 1000000 (inclusive).
Requirements of Task
-
fibon will have a global integer array called sequence declared
statically that will hold the sequence.
- fibon must use
getopt() to parse the parameters described above. An example of
getopt() can be found
here.
- 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.
-
The -e and the -o options are mutually exclusive.
-
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).
-
upper must be greater than or equal to lower.
-
Once the command line has been parsed, fibon will call an
internal function
compute_sequence passing it two integers, upper and lower.
-
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.
-
fibon will then call another function print_sequence passing
it the index returned from compute_sequence that will
print the sequence within the range.
-
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.
-
If the -e or -o option is specified, only the even (or odd) numbers
should be printed.
-
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 .
-
make target will create the tar file containing the .c file(s),
.h file(s), and Makefile.
-
make all will compile your program(s) according to the specifications
of the assignment.
-
make clean will remove any .o file(s), executables, and tar files in
directory.
- 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.