Question
Use c++ Create a dynamic array of double variables. Use 4 as the initial array size. Ask the user to enter rainfall amounts one line
Use c++
Create a dynamic array of double variables. Use 4 as the initial array size.
Ask the user to enter rainfall amounts one line at a time. Instruct the user to enter -1 to end the list.
As the user enters amounts, store the amount in the array. The program should ignore any negative values except for -1.
If the array is not large enough to store the incoming value, take these steps.
1. Create a new dynamic array that is twice the size of the current array
2. Copy the current array values into the new array
3. Copy the user-entered (i.e. incoming) value into the new array
4. Deallocated the memory used by the current array
5. Make the current arrays pointer now point to the same address as the new array.
When the user enters -1, print the following data
1. The number of rainfall amounts
2. The sum of the amounts
3. The average of the amounts (including entries of 0)
4. The average of the amounts (excluding entries of 0)
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