Description
In this assignment, you will develop a C program to manage several data types, data structures and arrays.
Instructions:
- Download the following file from BlackBoard and copy it to your UNIX account on the server. assign1-starter.tgz
- Create a directory for your assignments and copy the file into it. Change into that directory.
% mkdir cmsc257
% mv assign1-starter.tgz ./cmsc257/
% cd cmsc257
% tar xvzf assign1-starter.tgz
Once unpacked, you will have the following starter files in the asgn1 directory: Makefile, cmsc257-s17-assign1.c and a1support.h. The Makefile contains commands to make your program from the source code. cmsc257-s17-assign1.c contains the main function which reads in values from the standard input, as well as calls the functions you are to create as part of the exercise. The a1support.h partially defines functions that you are to implement in the course of this assignment (see below).
- You are to complete the cmsc257-s17-assign1 program. It receives 20 float values, one per line. The code for
reading those values from standard input are provided in the assignment source code starter file.
- You are to create a new file a1support.c. This will include the code for each of the functions defined in a1support.h. You are also to complete the function definitions in a1support.h. These functions are defined in Table 1.
- Complete the code in the cmsc257-s17-assign1.c and a1support.h files. Places where code or declarations needs to be added are indicated by ???. See in file comments for hints. The program shall perform the following functions in order as implemented within the main() function:
- Read in 20 float values from the terminal and place them in an array. Note the code to perform this step is already provided.
- In the main function, create a second array of integer values. For each value in float array, convert as follows:
- Truncate the float value to an integer. o Convert all integers to positive values by taking their absolute
- Convert these positive integers to numbers in the range 0,…,15 by implementing the mod operation (i.e. number mod 16).
- Print out the values of each array on their line using the float_display_array and integer_display_array functions.
- For each integer, print out the number of ‘1’ bits in the resulting b i n a r y representation by calling
the function countBits.
- Sort the integer array using the integerQuickSort function. Print out the sorted integer array again using the showInts function.
- Create two functions that take an array and prints out the number of even values. The first function float_evens should ignore the part of the number to the right of the decimal point to determine if it is even. The second function integer_evens should count the number of even numbers as normal. Call both of these functions from the main function inside a single print statement annotating the returned values.
- Write a function most_values to figure out which values occur in the integer array calculated in the preceding step most frequently. The function will receive three parameters:
- arr – the array itself
- range – the number of elements in the array o maxval – the largest possible value in the array
The function will print out the value which occurs the most times in the array. If there are more than one that occur as the highest number, print them all. Hint: You can assume that maxval will never exceed 16.
- Cast each integer to an unsigned short type and compute a number with bits reversed by calling the reverseBits function. Print out a binary representation of each of the numbers by calling the binaryString on two string arrays and printing out the resulting text.
- Add comments to all of your files stating what the code is doing. Fill out the comment function header for each function you are defining in the code. A sample header you can copy for this purpose is provided for the main function in the code.
- Try to use bit-wise operators for each of the functions mentioned above. Specifically, use bit-wise operators for the following:
- calculating the “mod” and “absolute” values
- countBits function (where you keep dividing by 2)
- reverseBits function
- finding even numbers
- swapping variables in sorting without temporary variables
You can truncate floats to ints using a type-cast. The goal is to not use functions from the math.h library.




