Question: You are writing a program that works with a sensor that reads in measurements of sound in decibels. Each measurement is stored into an array.

You are writing a program that works with a sensor that reads in measurements of sound in decibels. Each measurement is stored into an array. Sometimes negative values are read. However, for the purposes of your program, you need all values to be positive.
Write a function called cleanArray that returns an integer. There should be two parameters. The first is an array of integers and the second is an integer that specifies the size of the array parameter.
Count up and return the number of negative values in the array. If you encounter a negative value, replace it with its absolute value.
Requirements:
Do not print anything in your function
Count up and return the number of negative values in the array.
For every negative value in the array, replace it with its absolute value. You may call the C++ function
abs( val )
which returns the absolute value of a given value.
You do not need to write a main function, when you submit to run the test, it has been provided for you and it will properly call your function to test it.If you want to test yourself (and you should!), remove comments in the code to provide a main function. Be sure to remove (comment out) main before submitting your code for grading.
You may assume that the input array will always have at least 1 element.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!