[Solved] : Assignment #1 C Programming Basics CMPSC311

$25

File Name: :_Assignment_#1__C_Programming_Basics_CMPSC311.zip
File Size: 433.32 KB

SKU: [Solved] : Assignment #1 – C Programming Basics CMPSC311 Category: Tag:
5/5 - (1 vote)

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.

  1. 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.
  2. 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:

    http://www.cse.psu.edu/~mcdaniel/cmpsc311-f15/docs/assign1-starter.tgz

  3. 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.tgzOnce 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).
  4. 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.
  5. 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.
  6. 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:
    1. Read in 20 float numbers into an array. (this code is provided to you).
    2. For each value in float arrays, convert as follows:
      1. Numbers greater than of equal to 10 should be multiplied by . Note that is in the file math.h as M_PI.
      2. Numbers less than 10 should be multiplied by 42.4.
    3. 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).
    4. 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.
    5. Create a function implementing Euclids algorithm (euclids_algorithm) to calculate the greatest common divisor of two integers. The inputs to this function are two integers, a and b. See:

      http://en.wikipedia.org/wiki/Euclidean_algorithm

    6. 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])
    7. 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.
    8. 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:

      http://en.wikipedia.org/wiki/Selection_sort

    9. 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.
    10. Call graph_sin from the main function with four input values (1.0, 1.5, 2.0, and 3.0).
  7. 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.
  8. 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.

To turn in:

  1. Create a tarball file containing the assign1 directory, source code and build files as completed above. Email the program to Professor McDaniel and the section TA (listed on course website) by the assignment deadline (11:59pm of the day of the assignment). The tarball should be named LASTNAME-PSUEMAILID-assign1.tgz, where LASTNAME is your last name in all capital letters and PSUEMAILID is your PSU email address without the @psu.edu. For example, the professor was submitting a homework, he would call the file MCDANIEL-pdm12-assign1.tgz. Any file that is incorrectly named, has the incorrect directory structure, or has misnamed files, will be assessed a one day late penalty.
  2. Before sending the tarball, test it using the following commands (in a temporary directory NOT the directory you used to develop the code):
    % tar xvzf LASTNAME-PSUEMAILID-assign1.tgz% cd assign1% make... (TEST THE PROGRAM)
    
    

Note: Like all assignments in this class you are prohibited from copying any content from the Internet or discussing, sharing ideas, code, configuration, text or anything else or getting help from anyone in or outside of the class. Consulting online sources is acceptable, but under no circumstances should anything be copied. Failure to abide by this requirement will result dismissal from the class as described in our course syllabus.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] : Assignment #1 C Programming Basics CMPSC311
$25