Overview
In this assignment you will be given an abstract problem to solve.
A few weeks into the semester, we will discuss how this assignment is
related to the course material.
In each part of the assignment you will be given an input sequence of at most 10 integers. From this you will produce an output string consisting of digits (printing characters) 0, 1, 2, etc. Each of these digits may be repeated multiple times in the string. The first integer in the input string will determine the number of '0' digits in the output string, the second will determine the number of '1' digits, the third will determine the number of '2' digits, etc., until you run out of input values. Each part will have a different algorithm for determining the order of the characters in the output string.
After producing the output string you will also calculate an output integer corresponding to each input value. The output integer corresponding to the nth input integer will be related to the positions of the digit n-1 in the output string. The output integer corresponding to the character x in the output string is the number of non-x characters in the output string before the last x in that string.
For example, if the output string is "000011112223331112224" then the output integers will be 0, 10, 14, 11, and 20. Lastly, you will calculate the average of the output integers (as a floating point number).
For each part you will write a C program that takes the input sequence as
command line parameters. The program should start by checking that there
are between 1 and 10 command line parameters and exit with an appropriate
error message otherwise. If the number of command line parameters is
correct, print a line indicating which part of the assignment is being
solved and indicating your name, such as the line below:
This is Part 1 and was written by S. Robbins
This will be followed by a single line containing the integers from the
input sequence, such as the line below:
Input values: 4 7 6 3 1
Organize your solution by writing functions. Put all of the functions other than the main in a single file called library1.c. Create a separate main program for each part. The main program for part x will be called assign1-x.c. These should be very short programs with most of the work done by calling functions in library1.c. The code in the main program should declare the appropriate variables, check the command line parameters, and print the initial message containing your name. It should be responsible for all printing. The rest of the work should be done by calling functions in library1.c. The three main programs that you write for this assignment should be almost identical, differing mainly in the messages printed and which functions in libray1.c are called. None of the functions in library1.c should do any printing. Put prototypes for all of the public functions from library1.c in library1.h.
Produce a single makefile for compiling and linting all of the programs in this assignment.
Make sure you understand the statement of the problem before writing any code. In each part (after Part 0) you will be given information about out to produce the output string from the input sequence. Once the output string is determined, you can use common functions to produce the output integers and the average.
For each part of the assignment, you will run the program with appropriate input to test to see of it is working. Save the output generated to be handed in with your assignment.
For Parts 1, 2, and 3, unless an error occurs, the main program should produce exactly 5 lines of output. The first two lines have already been described. The thiird line will contain the output string, the fourth line will contain the output values, and the last line will contain the average.
Each time you write a main program, use lint and make sure you understand all of the warning messages. Save the lint output. Read this information about running lint.
Part 0:
Create a directory called assign1 for this assignment.
Create two files, assign1-1.c and library1.c.
For now, assign1-1.c will check the command line parameters
and print the initial message. It will convert the command line parameters
(which are strings) to integers and print the integers generated.
Create a makefile for compiling and linting assign1-1.c.
Write the funcion:
double find_average(int array[], int size);
and put it in libray1-1.c.
Test this function by having the main program print the average of the
input values.
Part 1:
The output string will have all of the 0 characters first followed by
all of the 1 characters, followed by all of the 2 characters, etc.
For example, if the input sequence is: 4 7 6 3 1, the output string
will be "000011111112222223334". This program should produce output
like the following:
This is Part 1 and was written by S. Robbins Input values: 4 7 6 3 1 output string: 000011111112222223334 Output values: 0 4 11 17 20 Average: 10.400000
Part 2:
The output string will have all of the 0 characters together, all of the
1 characters together, etc., but the order will be determined by which
characters occur least, with the ones occurring a smaller number of times
first. If there is a tie, use numerical order of the output characters.
For example, if the input sequence is: 4 7 6 3 1, the output string
will be "433300002222221111111".
Part 3:
This will be like part 1, except that we do not allow more than 3
of the same characters in a row when other characters still need to be output.
If more than 3 of a given character are
needed in the output string, the additional ones are put at the end of
the string.
For example, if the input sequence is: 4 7 6 3 1, the output string
will be "000111222333401112221".
Turning in your assignment
For each part of the assignment, test your program and save the
output generated. Do a sufficient number of tests to convince you (and me)
that your program is working correctly.
Also, test each part with the following input sequence:
16 4 5 7 3 1 8 9 4 2
and save the results of all three parts on this test in a single file.
This will be turned in with your assignment. Put the page number of this
on the cover sheet under My test output page.
Use this cover sheet for handing in your assignment.
Assignments are due at the start of class on the due date.