Objectives:

  • Make use of multiple Functions
  • Make use of an array to store data (temperatures)
  • Make use of sorting and searching techniques

Instructions:

In this lab, you will be examining a set of temperatures collected over a twenty four hour period. Be sure to make use of an array to store these temperatures. You will be required to read in the data points from a file. You could make this read into a function. (See file details below.) After reading in the data, you will need to write a function that will find the average of the data set. Make sure to print out the average, either in main or in the function. You will also need to write a function to display the temperatures in the table format shown below.

Table Format:

Hour Temperature Difference from the Average
0 35 +- ???
1 32 +- ???

After you finish the function for printing out the data, you need to write a function that will find the lowest piece of data in the array. You could sort the data, and grab the piece of data in the first position. However, this will result in no credit. You will have to use a linear search to find the lowest piece of data. Once you find it, print out the value you found. This can be done by having a for loop run over the array, and search for the value using an if statement such as:

if (tempArray[i] > low)
low = tempArray[i];

Once you have written that, create another function that does the same thing for finding the highest number. Again, printing your results in either the function or main.

Your next task is to write a method that will sort the array in descending order. You can use any of the sorts provided on the sorting sheet: minMax, Selection, Insertion, Bubble. The key is to make sure that you modify the sample code to sort in descending order.

After sorting the array, print out the entire array on a single line. Above, we had a method to print the array in a table, now you need to print out all on one line. You could do this in a separate function, or in main.

Data:

Below is the set of data that you should include in your text file. Remember! Your text file must be in the same folder as your .cpp file. See lab 5’s instructions on how to add files to Visual Studio if you need to.

35 32 31 28 25 22 23 25 26 30 32 38 41 43 45 48 52 55 49 44 43 42 49 37

Run:

Just run the program, and see if your results are correct.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.