Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Starter code You can copy the code from a previous lab in the term3 window. If Mimir does not create a directory for you, it

Starter code

You can copy the code from a previous lab in the term3 window. If Mimir does not create a directory for you, it will usually put you in a previous project. Any words mean press the tab key, press the return (Enter) key.

user@mimir: ~/2000_csii_f20/01_inflationrate_part2 > cd .. user@mimir: ~/2000_csii_f20 > mkdir 02_inflationrate_part3 user@mimir: ~/2000_csii_f20 > cp 01_inflationrate_part2/InflationRate.cpp 02 user@mimir: ~/2000_csii_f20 > cd 02 user@mimir: ~/2000_csii_f20/02_inflationrate_part3 > ls InflationRate.cpp user@mimir: ~/2000_csii_f20/02_inflationrate_part3 > 

Expected Output:

Enter the old and new consumer price indices: 238.343 238.250 Inflation rate is -0.0390204 Try again? (y or Y): y Enter the old and new consumer price indices: 238.250 237.852 Inflation rate is -0.167049 Try again? (y or Y): y Enter the old and new consumer price indices: 237.852 238.123 Inflation rate is 0.113935 Try again? (y or Y): n Average rate is -0.0307116 Median rate is -0.0390204

Directions

Take a breath and do each part, one at a time. Start at the top and work your way down.

- Add a function to get the CPI values from the user and validate that they are greater than 0.

1. Declare and implement a void function called getCPIValues that takes two float reference parameters for the old_cpi and new_cpi.

2. Move the code that reads in the old_cpi and new_cpi into this function.

3. Add a do-while loop that validates the input, making sure that the old_cpi and new_cpi are valid values.

+ if there is an input error, print "Error: CPI values must be greater than 0." and try to get data again.

4. Replace the code that was moved with a call to this new function.

- Add an array to accumulate the computed inflation rates

1. Declare a constant called MAX_RATES and set it to 20.

2. Declare an array of double values having size MAX_RATES that will be used to accumulate the computed inflation rates.

3. Add code to main that inserts the computed inflation rate into the next position in the array.

4. Be careful to make sure the program does not overflow the array.

- Add a function that sorts the values in an array of doubles.

1. Declare and implement a function called swap_values that takes two double parameters like the one we defined in class. It will be used by the sort_array function to swap inflation rates in the array.

2. Declare and implement a function that uses either a selection sort or bubble sort to put the array values into ascending order (i.e. smallest to largest). In order to sort an array, you must be able to move the values around using swap_values.

+ Function parameters: an array of doubles and an int with the number of elements in the arra

+ Your sort function must use the swap_values function defined above to exchange the values in the array during the sort.

+ You can use either a selection sort or a bubble sort in the sort_array function but it must use the swap_values function.

- Add a function called findMedianRate that calculates the median inflation rate using sort above.

1. Declare and implement a function called findMedianRate that takes two parameters and returns a double which will be the median rate.

+ parameters: an array of doubles and an int with the number of elements in the array (e.g. numRates).

2. Sort the array using your sort_array function defined above. Once the array is sorted, use the following logic to calculate the median value:

+ if the number of rates is odd, then the median rate has as many values preceeding it as following it or in other words, it's the one in the middle.

+ if the number of rates is even, then the median rate is calculated as the average of the two rates in the middle.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions

Question

3-39. You want to be granted a business loan.

Answered: 1 week ago