Question
Application: Rainfall Statistics In this week's lecture on sorting we discussed a stable, straightforward algorithm in selection sort as well as a recursive algorithm known
Application: Rainfall Statistics
In this week's lecture on sorting we discussed a stable, straightforward algorithm in selection sort as well as a recursive algorithm known as merge sort. This lab will provide an opportunity to appreciate the significance of a stable sort in analyzing data for rainfall statistics accrued over a calendar year.
Make sure you have read and understood
- Unit module 4
- C++ Coding Style Guidelines
before submitting this assignment. Hand in only one submission.
Lab Assignment Objectives
- Implement a stable O(n^2) sort with efficient space requirements.
- Apply the selection sort heuristics to a practical statistical analysis.
Understand the Application
Write an interactive program that obtains user entry for the total monthly rainfall in their geographical area. Use a selection sort algorithm to sort the statistical rainfall data in increasing order.
The Program Specification
Selection Sort Algorithm Description
The first iteration of selection sort selects the smallest element and swaps it with the first element. The second iteration selects the second-smallest element(which is the smallest remaining element) and swaps it with the second element. This process continues until the last iterations selects the second-largest element and swaps it with the second-to-last index, leaving the largest element in the last index. At the ith iteration, the smallest i elements are sorted into the first i elements.
Interactive Data Collection
Obtain user input for rainfall figures for each of 12 months. Based on the user input data generate the following statistical report values over the 12 month period: total amount of rainfall, average amount of rainfall, the largest recorded monthly rainfall, the smallest recorded monthly rainfall.
Use a selection sort to arrange the data for your report.
Generate a report summary to display your monthly rainfall statistical findings.
Testing Specification
Input Errors
Negative input figures are not to be accepted for rainfall figures. Pigeonhole the user to obtain valid input data.
Test Run Requirements
Submit a test run validation to demonstrate the successfully collected and sorted statistics. Include a demonstration of user input validation.
Example Test Run
Here is an example run:
/* ---------------------- Sample run --------------------------------------- Enter the rainfall (in inches) for month #1: 0 Enter the rainfall (in inches) for month #2: 0 Enter the rainfall (in inches) for month #3: 1 Enter the rainfall (in inches) for month #4: -1 Rainfall must be 0 or more. Please re-enter: 3 Enter the rainfall (in inches) for month #5: 6 Enter the rainfall (in inches) for month #6: 8 Enter the rainfall (in inches) for month #7: 77 Enter the rainfall (in inches) for month #8: 2 Enter the rainfall (in inches) for month #9: 1 Enter the rainfall (in inches) for month #10: 1.5 Enter the rainfall (in inches) for month #11: 3.5 Enter the rainfall (in inches) for month #12: 66.9 The total rainfall for the year is 169.90 inches. The average rainfall for the year is 14.16 inches. The largest amount of rainfall was 77.00 inches in month 7. The smallest amount of rainfall was 0.00 inches in month 1. Here are the rainfall amounts, sorted in ascending order: ---------------------------------------- 0.00 0.00 1.00 1.00 1.50 2.00 3.00 3.50 6.00 8.00 66.90 77.00 ------------------------------------------------------------------------ */
What to Turn In
Hand in 3 files: a2.cpp, rain.cpp and rain.h No zip files.
- a2.cpp : test driver
- rain.cpp : user defined functions to determine statistical data
- rain.h : user defined header
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started