Question

In: Computer Science

In this assignment, the program will keep track of the amount of rainfall for a 12-month...

In this assignment, the program will keep track of the amount of rainfall for a 12-month period. The data must be stored in an array of 12 doubles, each element of the array corresponds to one of the months. The program should make use of a second array of 12 strings, which will have the names of the months. These two arrays will be working in parallel. The array holding the month names will be initialized when the array is created using an initialization list (could also be created as an array of constants). The second array will hold doubles which will be the total rainfall for each month. Using a function, the program will prompt the user for the rainfall for each month (using both arrays) and store the value entered into the array with the rainfall totals; the other is used to display which month the program is asking for the rainfall total.

The output of the program will display the following once the data is all entered:

  • The total rainfall for the year
  • The average monthly rainfall
  • The month with the highest amount of rainfall (must display the month as a string)
  • The month with the lowest amount of rainfall (must display the month as a string)

The program must have the following functions:

  • void CollectRainData(double [ ], string [ ], int);
    • Gets the user input for the rain totals for each month
    • Parameters array for rainfail totals, array of month names and size of arrays
  • double CalculateTotalRainfall(double [ ], int);
    • Calculates the total rainfall from the array parameter.
  • double CalculateAverage(double, int);
    • Calculates the Average rainfall
    • First parameter is the total rainfall, second is number of months
  • double FindLowest(double [ ], int, int&);
    • Finds the month with the lowest amount of rainfall, returns this value
    • Provides the index of the lowest month in the last parameter.
  • double FindHighest(double [ ], int, int&);
    • Finds the month with the highest amount of rainfall, returns this value
    • Provides the index of the highest month in the last parameter.

Pseudocode must be provided in the comment block at the top of the file. This must be done with Visual Studio 2019 comm edition C++

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Simple pseudocode:

Initialize string array ‘months’ containing month names

Declare double array ‘rain’ to store rainfall for each month

Declare total=0, average=0, lowest=0, highest=0, monthLowest=-1, monthHighest=-1

For i in range(12):

                Read rainfall for the month months[i] to set rain[i]

For I in range(12):

                Add rain[i] to total

                If monthLowest is -1 or monthHighest is -1:

                                Set monthLowest=i, monthHighest=i, lowest=rain[i], highest=rain[i]

                Else:

If rain[i] < lowest:

                lowest=rain[i]

                monthLowest=i

if rain[i] > highest:

                highest=rain[i]

                monthHighest=i

Set average= total/12

Display total

Display average

Display months[monthLowest] and lowest

Display months[monthHighest] and highest

//Code

#include<iostream>

#include<iomanip>

using namespace std;

//reads rainfall for all 12 months and fill the rain array

void CollectRainData(double rain[], string months[], int count){

                for(int i=0;i<count;i++){

                                cout<<"Enter total rainfall for the month of "<<months[i]<<": ";

                                cin>>rain[i];

                }

}

//finds and returns the sum total of rainfall in the rain array

double CalculateTotalRainfall(double rain[], int count){

                double sum=0;

                for(int i=0;i<count;i++){

                                sum+=rain[i];

                }

                return sum;

}

//returns the average rainfall, given the total and count

double CalculateAverage(double total, int count){

                double avg=(double) total/count;

                return avg;

}

//returns the lowest rainfall, also updates monthIndex with the index of month with

//lowest rainfall. assuming rain array is not empty

double FindLowest(double rain[], int count, int& monthIndex){

                monthIndex=-1;

                for(int i=0;i<count;i++){

                                //if monthIndex is still -1 or current month has less rain than month pointed by

                                //monthIndex, updating monthIndex

                                if(monthIndex==-1 || rain[i] < rain[monthIndex]){

                                               monthIndex=i;

                                }

                }

                //returning rainfall for the month at monthIndex

                return rain[monthIndex];

}

//returns the highest rainfall, also updates monthIndex with the index of month with

//highest rainfall

double FindHighest(double rain[], int count, int& monthIndex){

                monthIndex=-1;

                for(int i=0;i<count;i++){

                                //if monthIndex is still -1 or current month has more rain than month pointed by

                                //monthIndex, updating monthIndex

                                if(monthIndex==-1 || rain[i] > rain[monthIndex]){

                                               monthIndex=i;

                                }

                }

                return rain[monthIndex];

}

int main(){

                //setting up the required arrays and variables

                const int count=12;

                string months[]={"January","February","March","April","May","June","July",

                                                                               "August","September","October", "November","December"};

                double rain[count];

                int monthLowest,monthHighest;

                double lowest, highest,total,avg;

               

                //collecting rain data

                CollectRainData(rain,months,count);

                //finding total, average, lowest and highest rainfall

                total=CalculateTotalRainfall(rain,count);

                avg=CalculateAverage(total,count);

                lowest=FindLowest(rain,count,monthLowest);

                highest=FindHighest(rain,count,monthHighest);

               

                //using a precision of 2 digits after decimal point

                cout<<setprecision(2)<<fixed;

                //displaying all stats

                cout<<"Total rainfall: "<<total<<endl;

                cout<<"Average rainfall: "<<avg<<endl;

                cout<<"The month with highest rainfall: "<<months[monthHighest]<<" ("<<highest<<")"<<endl;

                cout<<"The month with lowest rainfall: "<<months[monthLowest]<<" ("<<lowest<<")"<<endl;

                return 0;

}

/*OUTPUT*/

Enter total rainfall for the month of January: 2.3

Enter total rainfall for the month of February: 2.4

Enter total rainfall for the month of March: 1.8

Enter total rainfall for the month of April: 2.9

Enter total rainfall for the month of May: 2.5

Enter total rainfall for the month of June: 4.6

Enter total rainfall for the month of July: 6.3

Enter total rainfall for the month of August: 6.1

Enter total rainfall for the month of September: 4.3

Enter total rainfall for the month of October: 2.2

Enter total rainfall for the month of November: 1.1

Enter total rainfall for the month of December: 2.1

Total rainfall: 38.60

Average rainfall: 3.22

The month with highest rainfall: July (6.30)

The month with lowest rainfall: November (1.10)


Related Solutions

ASSIGNMENT: Write a program to keep track of the total number of bugs collected in a...
ASSIGNMENT: Write a program to keep track of the total number of bugs collected in a 7 day period. Ask the user for the number of bugs collected on each day, and using an accumulator, keep a running total of the number of bugs collected. Display the total number of bugs collected, the count of the number of days, and the average number of bugs collected every day. Create a constant for the number of days the bugs are being...
Write a c++ program for the Sales Department to keep track of the monthly sales of...
Write a c++ program for the Sales Department to keep track of the monthly sales of its salespersons. The program shall perform the following tasks: Create a base class “Employees” with a protected variable “phone_no” Create a derived class “Sales” from the base class “Employees” with two public variables “emp_no” and “emp_name” Create a second level of derived class “Salesperson” from the derived class “Sales” with two public variables “location” and “monthly_sales” Create a function “employee_details” under the class “Salesperson”...
Establishing a method for collecting rent each month will make it easier to keep track of...
Establishing a method for collecting rent each month will make it easier to keep track of the rent collection process. Choose the number of houses and rent per house by your choice. Develop a python program to maintain the rent collection process. Update the database with the details of every month like the name of the tenant, house number, month of the rent, rent amount, EB bill amount, maintenance charge, etc., Print the details of rent collection for all houses...
You will design a program to keep track of a restaurants waitlist using a queue implemented...
You will design a program to keep track of a restaurants waitlist using a queue implemented with a linked list. Make sure to read pages 1215-1217 and 1227-1251 1. Create a class named waitList that can store a name and number of guests. Use constructors to automatically initialize the member variables. 2. Add the following operations to your program: a. Return the first person in the queue b. Return the last person in the queue c. Add a person to...
Problem statement: You are tasked with writing a simple program that will keep track of items...
Problem statement: You are tasked with writing a simple program that will keep track of items sold by a retail store. We need to keep track of the stock (or number of specific products available for sale). Requirements: The program will now be broken up into methods and store all the inventory in an ArrayList object. The program will be able to run a report for all inventory details as well as a report for items that are low in...
You are going to create a console based program to keep track of a small business...
You are going to create a console based program to keep track of a small business that sells Doodads. First you will need to create a class Doodad that keeps track of two integers and two Strings. Next, create a constructor for the Doodad. Next, add getters and setters for each of the fields (two integers and two Strings). You need to use Doodad.java (see the starter code) Inside your main method ask the user to read in the two...
Problem statement: You are tasked with writing a simple program that will keep track of items...
Problem statement: You are tasked with writing a simple program that will keep track of items sold by a retail store. We need to keep track of the stock (or number of specific products available for sale). Requirements: The Food and Book items should inherit all the properties of the Product item in the previous assignment. Foods cannot be added to the inventory without an expiration date. Implement a toString method for Product, Food, and Book. Grading details: Correct usage...
Using c++ Design a system to keep track of employee data. The system should keep track...
Using c++ Design a system to keep track of employee data. The system should keep track of an employee’s name, ID number and hourly pay rate in a class called Employee. You may also store any additional data you may need, (hint: you need something extra). This data is stored in a file (user selectable) with the id number, hourly pay rate, and the employee’s full name (example): 17 5.25 Daniel Katz 18 6.75 John F. Jones Start your main...
Write a Java program that lets the user keep track of their homemade salsa sales. Use...
Write a Java program that lets the user keep track of their homemade salsa sales. Use 5-element arrays to track the following. The salsa names mild, medium, sweet, hot, and zesty. The number of each type sold. The price of each type of salsa. Show gross amount of money made (before tax). Calculate how much the user owes in sales tax (6% of the amount made). Then display the net profit (after subtracting the tax).
Design a program that lets the user enter the total rainfall for each of 12 months...
Design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Requirements You must use the given function prototypes. You can add more functions if you like. def get_total_rainfall(months, months_len): def get_average_monthly_rainfall(months, months_len): def get_month_with_highest_rainfall(months, months_len): def get_month_with_lowest_rainfall(months, months_len): Design Considerations Use a global parallel array of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT