Assignment #1 - C Programming Basics - Introduction to Systems Programming Solution

In this assignment you will develop a program to manage several data types, data structures and arrays. The purpose of this exercise is to either remind or familiarize student with the basics of C programming, as well as to expose students to the management and use of UNIX. Please read the following instructions very carefully and perform the assignment per the instructions.

Note: Study the example output (in #8 below) before beginning, as it will help you understand what needs to be done.

Login to your virtual machine. Install the wget utility using the apt-get tool. Refer to the course notes for details on how to perform installation of programs.
From your virtual machine, download the starter source code provided for this assignment. To do this, use the wget utility to download the file off the main course website:
Create a directory for your assignments and copy the file into it. Change into that directory.

% mkdir cmpsc311
% cp assign1-starter.tgz cmpsc311
% cd cmpsc311
% tar xvfz assign1-starter.tgz
Once unpacked, you will have the following starter files in the assign1 directory: Makefile, cmpsc311-f15-assign1.c and a1support.h. The Makefile contains commands to make your program from the source code. cmpsc311-f15-assign1.c contains the main function which reads in values from standard input, as well as calls the functions you are to create as part of this 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 cmpsc311-f15-assign1 program. The cmpsc311-f15-assign1 program receives 20 floating point 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.
Complete the code in the cmpsc311-f15-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 numbers into an array. (this code is provided to you).
For each value in float arrays, convert as follows:

Numbers greater than of equal to 10 should be multiplied by Π. Note that Π is in the file math.h as M_PI.
Numbers less than 10 should be multiplied by 42.4.
Declare and assign values to a second array of 20 integers, where the value is rounded absolute value of the float of the same index (i.e., integer at index 1 should be assigned the rounded absolute value of the float value at index 1).
Implement a function (in a1support.c) to print out the values of the float and integer arrays, as below. Each function should take two values, the array length and the array itself. The functions are defined print_array_float (this function should print out the float values to three decimal places, one per line), and print_array_integer (this should be print the integer values, one per line).

Call both functions in the main function.
Create a function implementing Euclid's algorithm (euclids_algorithm) to calculate the greatest common divisor of two integers. The inputs to this function are two integers, a and b. See:
In the main function, write a loop to compute and print out GCD of all adjacent values in the integer array using euclids_algorithm, i.e., euclids_algorithm(array[0], array[1]), euclids_algorithm(array[1], array[2]), ..., euclids_algorithm(array[18], array[19])
Implement two functions that compute the sum of values for each array and return the value; sum_array_float and sum_array_integer . Each function should take two values, the array length and the array itself. Call these two functions on the arrays and print out the result values.
Implement a selection sort that sorts the arrays in place; selection_sort_float and selection_sort_integer. Call both functions to sort in the main function, then print out the values using the print_array_integer and print_array_integer functions. For insight into how the selection sort works, see:
You are to graph a multiplier of the sin function in a C function graph_sin. More specifically, you are to graph the function y=sin(x*mult) where mult is a floating point number passed into the graphing function. You will use text to graph the function as provided by the C printf function. The Y axis should go from -1.5 to 1.5 at 0.1 increments, and the X axis should go from -3.5 to 3.5 at 0.1 increments. Make label the axes as shown in the sample output.
Call graph_sin from the main function with four input values (1.0, 1.5, 2.0, and 3.0).
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.
The assignment starter package also includes a sample input (test-input1.txt) and output test-output1.txt which you can use to test your program. The test-input.txt file was input used to produce test-output1.txt. To test your program with these inputs, run the code an pipe in the input file to the program as follows:

./cmpsc311-f13-assign1 < test-input1.txt
Please try to make the output for your program at close to that of the test program output.
Powered by