Starting from:

$30

CMPSC311-Assignment 1 Solved

Assignment #1 - C Programming Basics

CMPSC311 - Introduction to Systems Programming 

 

Below are the files in this assignment and their descriptions:

1.    student.h: a header file with the declarations of the functions that you will implement.

2.    student.c: a source file in which you will implement the functions whose declarations appear in student.h. In other words, you will provide the definitions of the functions declared in student.h.

3.    reference.h: a header file with the declarations of the functions that are identical to those defined in student.h except they are prefixed with ref . These are the reference functions against which your implementations will be tested.

4.    reference.o: an object file that contains the reference implementations of the functions declared in reference.h. This is a binary file that contains compiled reference implementations of functions.

5.    tester.c: unit tests for the functions that you will implement. Each unit test passes an input to your implementation of a function and to the reference implementation of the same function and compares the outputs. This file will compile into an executable, tester, which you will run to see if you pass the unit tests.

6.    Makefile: instructions for compiling and building tester used by the make utility.

You workflow will consist of (1) implementing functions by modifying student.c, (2) typing make to build the tester, and (3) running tester to see if you pass the unit tests, and repeating these three steps until you pass all the tests. Although you only need to edit student.c for successfully completing the assignment, you can modify any file you want if it helps you in some way. When testing your submission, however, we will use the original forms of all files except student.c.

Below are the functions you need to implement:

1.    largest: Takes an array of integers and the length of the array as input, and returns the largest integer in the array. You can assume that the input array contains at least one element.

2.    sum: Takes an array of integers and the length of the array as input, and returns the sum of the integers in the array.

3.    swap: Takes a pointer to two integers and swaps the values of integers.

1

4.    rotate: Takes a pointer to three integers and rotates the values of integers. For example, if the inputs are pointers to integers a, b, and c, then after a call to rotate, c contains the value of b, b contains the value of a, and a contains the value of c.

5.    sort: Takes a pointer to an array of integers and the length of the array as input and sorts the array. That is, after a call to sort the contents of the array should be ordered in ascending order. You can implement any sorting algorithm you want but you have to implement the algorithm yourself—you cannot use sort functions from the standard C library. We recommend using something simple, such as Bubble sort or Selection sort.

6.    doubleprimes: Takes an array of integers and the length of the array as input and doubles every prime element of the array. For example, if the input array contains [1, 7, -2], then after a call to doubleprimes the array will contain [1, 14, -2].

7.    negatearmstrongs: Takes an array of integers and the length of the array as input and negates every element of the array that is an Armstrong number. An Armstrong number (also called a Narcissistic number) is a number that is equal to the sum of its digits each raised to the power of the number of digits. For example, 153 is an Armstrong number because it has 3 digits and 13 +53 +33 =153. Thus, if an input array contains [2, -153, 153], then after a call to negatearmstrongs the array will contain [2, -153, -153].

You are encouraged to write helper functions to simplify the implementations of the above functions. You should, however, not use a library function and implement all helper functions yourself. For example, if you need a function to raise number a to power b, you should implement that function yourself.

2

More products