Вы находитесь на странице: 1из 1

CS 100 Lab Five – Fall 2019

Create a directory called lab5 on your machine using mkdir lab5 and move into that directory with cd lab5

Complete the following programs.

1. Name this program range.c – This program looks at all the command-line arguments that are always real
numbers and prints the range of these numbers. Recall the range is the difference between the maximum and
the minimum. If there are no command line arguments, print out an error message and return. Two executions
of the program are shown below.

./a.out
This program requires at least one argument
./a.out 99 55.5 11 -6.5 600.35 32.7
The range of these 6 values is 606.85

2. Name this program filter.c – The program takes a single command line argument, the name of an input
file. The program should first confirm the input file can be opened for reading (print an error message and
return if it cannot be). Then the program will read the file string by string and if the string (up to 50 characters
in length) is a word or a word followed by just one punctuation character, it will print the word after removing
the trailing punctuation character if it exists and converting any uppercase letters in the word into lowercase
ones. A word here is defined as any combination of uppercase and lowercases letters. You can use ispunct
declared in ctype.h to check whether a character is a punctuation character. Please see the following for an
example.

Contents of myData
The Quick Brown Fox Jumps over the Lazy Old Dog.
ALABAMA? Roll Tide!!! P2P 1831 (UA)
./a.out myData
the quick brown fox jumps over the lazy old dog alabama
roll

3. Name this program merge.c – The program takes two file names as command line arguments. You can
assume that these two files exist and can be opened for reading, and each file contains a list of unique integers in
ascending order. The program merges these two lists into one list (again consisting of unique integers in
ascending order) and prints the list to standard output. As an example, for the files named data1 and data2
as shown below, both
./a.out data1 data2 and ./a.out data2 data1 would generate the output shown below.

data1: 1 2 5 7 9 10 11 13 15 17 19 20 21 24 25
data2: 3 4 6 8 10 11 12 14 16 18 20

output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 24 25

Please refer to https://en.wikipedia.org/wiki/Merge_algorithm for the standard merge algorithm.

Submit your lab

First, on your local machine, compress your lab5 directory into a single (compressed) file, i.e. lab5.zip. Please
make sure lab5.zip contains the lab5 directory as well as range.c, filter.c and merge.c under it.
Second, once you have a compressed file named lab5.zip, submit that file to Blackboard.

Вам также может понравиться