Question: This problem is divided into seven parts. Your main program should make a call to these seven functions, passing the necessary parameters and getting the
This problem is divided into seven parts. Your main program should make a call to these
seven functions, passing the necessary parameters and getting the necessary return values. You must provide functions with the given names and parameters. The names of any other supporting functions are named at your discretion. The names of the supporting functions that you implement should be reflective of the function they perform.
You will not take any user inputs in the functions in your Assignment5.cpp file. The problem statement is designed in a way that all the inputs to the functions are being passed from your main function. Secondly, you will not be printing any values in these functions. You need to evaluate the correctness of your implementation by writing code in your main program and validating the return values from these function. If you add debugging outputs, please remove that code before submitting. In this assignment you will make use of arrays as your data structure to store values and looping should be preferably done using for loops.
Treat every function as an independent function, where each function can take a different array as an input. Each of these functions will return a value or modify an array parameter. Your main should be used to setup the parameters and print out the returned value(s) of the function.
Homework Problem:
There are seven parts to the problem. The following is the step by step description of each.
Part 1 Sum all the values of the array
In this part, you will sum all the values in an array:
float sumArray(float array[], int size)
The sumArray function will take two arguments, a reference to an array and the size of the array. The function will return the sum of all the values in the array as a float.
Part 2 - Search a value in an array
In this part, you will search a target value in an array, and return the index of that target value"
int search(int array[], int size, int target)
The Search function takes in three arguments: an integer array, the size of that array and the target value we are searching for. Your function should return the index of that target value in the input array. If the target is not found, return -1.
Part 3 Calculate sum of squared differences between two arrays
In this part, you will find the sum of squared differences between two arrays of the same size:
float calculateDifference(int a, int b, int size)
The calculateDifference function takes in three arguments: a reference to array a, reference to array b, and the common size of the arrays. The function will use these values to calculate the sum of squared differences between each value of the two arrays and return that value as a float.
For example, the squared differences of two numbers a and b is (a-b)2.
Part 4 Sort the array
In this part, you will arrange the items in your array in ascending order, with the lowest item being at the start of the array and the highest item at the end. You can use the Bubble sort algorithm or the selection sort algorithm to sort the array.
void sortArray(float unsortedArray[], int size)
The sortArray function will take two arguments, i.e. a reference to the array and the size of the array. The function does not return any value, but will modify the elements of the array given as a parameter.
Part 5 Copy the array
In this part, you will copy the values from one array to another array.
void copyArray(float source[], int size, float dest[])
The copyArray function will take three arguments, a reference to the source array to copy the values from, the size of this array, and a destination array.
Part 6 - Convert and fill another array
In this part, you will fill in the values of array b, corresponding to each value in array a. Map the values as follows:
| Rating | Text | Meaning |
| 0 | Not-read | Havent read it |
| -5 | Terrible | Hated it |
| -3 | Disliked | Didnt like it |
| 1 | Average | Ok, neither hot nor cold about it |
| 3 | Goo | Liked it! |
| 5 | Excellent | Really liked it! |
For example, when a is [0, 3, -5], b should be [Not-read, Good, Terrible] after the function is executed. Use "INVALID" if the value does not match any valid rating.
void convert(int rating[], string text[], int size)
Part 7 Find the median score
In this part, you will find the median item in the array. The median value of a list arranged in numerical order is the middle element of that list. However, you are not allowed to change the order of the elements or change the values in the array that you receive as a parameter.
float findMedian(float array[], int size)
The findMedian function should take two arguments, i.e. a reference to the array and the size of the array. The function should return the median of numbers in the array.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
