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.   Expected Output: Enter the old and new consumer price indices: Inflation rate is 0.640626 2   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.184142 3   Try again? (y or Y): Enter the old and new consumer price indices: Error: CPI values must be greater than 0 4   Enter the old and new consumer price indices: Inflation rate is 0.378648 5   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.223225 6   Try again? (y or Y): Enter the old and new consumer price indices: Error: CPI values must be greater than 0 7   Enter the old and new consumer price indices: Inflation rate is -0.50658 8   Try again? (y or Y): Enter the old and new consumer price indices: Error: CPI values must be greater than 0 9   Enter the old and new consumer price indices: Inflation rate is 0.284456 10   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.489679 11   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.348243 12   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.368315 13   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.0926804 14   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.319909 15   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.190802 16   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.13949 17   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.384759 18   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.14665 19   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.1744 20   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.276358 21   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.195154 22   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.276591 23   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.231967 24   Try again? (y or Y): Average rate is 0.0496408 25   Median rate is 0.13354

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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.

 

Expected Output:

Enter the old and new consumer price indices: Inflation rate is 0.640626
2   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.184142
3   Try again? (y or Y): Enter the old and new consumer price indices: Error: CPI values must be greater than 0
4   Enter the old and new consumer price indices: Inflation rate is 0.378648
5   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.223225
6   Try again? (y or Y): Enter the old and new consumer price indices: Error: CPI values must be greater than 0
7   Enter the old and new consumer price indices: Inflation rate is -0.50658
8   Try again? (y or Y): Enter the old and new consumer price indices: Error: CPI values must be greater than 0
9   Enter the old and new consumer price indices: Inflation rate is 0.284456
10   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.489679
11   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.348243
12   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.368315
13   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.0926804
14   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.319909
15   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.190802
16   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.13949
17   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.384759
18   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.14665
19   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.1744
20   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.276358
21   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.195154
22   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.276591
23   Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.231967
24   Try again? (y or Y): Average rate is 0.0496408
25   Median rate is 0.13354

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education