Question

In: Computer Science

Write a program that uses a structure to store the following weather data for a particular...

Write a program that uses a structure to store the following weather data for a particular month: Total Rainfall High Temperature Low Temperature Average Temperature.

The program should have an array of 12 structures to hold weather data for an entire year.

When the program runs, it should ask the user to enter data for each month. (The average temperature should be calculated.)

Once the data are entered for all the months, the program should calculate and display the average monthly rainfall, the total rainfall for the year, the highest and lowest temperatures for the year (and the months they occurred in), and the average of all the monthly average temperatures. Input Validation: Only accept temperatures within the range between –100 and +140 degrees Fahrenheit.

Solutions

Expert Solution

C++ program :-

#include <iostream>

using namespace std;

struct weather{
double rainfall;
int low_temp;
int high_temp;
double avg_temp;
};

int main() {
weather arr[12];
double avg_rainfall;
double total_rainfall = 0.0;
double total_temp = 0.0;
double avg_mon_temp;
int lowest_temp = 140;
int low_ind = 0;
int high_ind = 0;
int highest_temp = -100;
cout<<"Please enter weather data starting from Jan (1) to Dec (12):"<<endl;
for(int i=0;i<12;i++){
cout<<"Month index = "<<i+1<<" : "<<endl;
cout<<"Rainfall :";
cin>>arr[i].rainfall;
total_rainfall = total_rainfall + arr[i].rainfall;
cout<<"Lowest temperature :";
cin>>arr[i].low_temp;
if(arr[i].low_temp < lowest_temp){
lowest_temp = arr[i].low_temp;
low_ind = i;
}
cout<<"Highesh Temperature :";
cin>>arr[i].high_temp;
if(arr[i].high_temp > highest_temp){
highest_temp = arr[i].high_temp;
high_ind = i;
}
arr[i].avg_temp = (double) (arr[i].low_temp + arr[i].high_temp)/2.0 ;
total_temp = total_temp + arr[i].avg_temp;
}
  
avg_mon_temp = total_temp / 12.0;
avg_rainfall = total_rainfall / 12.0;
  
  
cout<<"Total rainfall :"<<total_rainfall<<endl;
cout<<"Average monthly rainfall :"<<avg_rainfall<<endl;
cout<<"Average monthly temperature :"<<avg_mon_temp<<endl;
  
cout<<"lowest temperature :"<<lowest_temp<<endl;
cout<<" Month:";
switch(low_ind){
case 0:
cout<<"January"<<endl;
break;
case 1:
cout<<"February"<<endl;
break;
case 2:
cout<<"March"<<endl;
break;
case 3:
cout<<"April"<<endl;
break;
case 4:
cout<<"May"<<endl;
break;
case 5:
cout<<"June"<<endl;
break;
case 6:
cout<<"July"<<endl;
break;
case 7:
cout<<"August"<<endl;
break;
case 8:
cout<<"September"<<endl;
break;
case 9:
cout<<"October"<<endl;
break;
case 10:
cout<<"November"<<endl;
break;
case 11:
cout<<"December"<<endl;
break;   
}

cout<<"highest temperature :"<<highest_temp<<endl;
cout<<" Month:";
switch(low_ind){
case 0:
cout<<"January"<<endl;
break;
case 1:
cout<<"February"<<endl;
break;
case 2:
cout<<"March"<<endl;
break;
case 3:
cout<<"April"<<endl;
break;
case 4:
cout<<"May"<<endl;
break;
case 5:
cout<<"June"<<endl;
break;
case 6:
cout<<"July"<<endl;
break;
case 7:
cout<<"August"<<endl;
break;
case 8:
cout<<"September"<<endl;
break;
case 9:
cout<<"October"<<endl;
break;
case 10:
cout<<"November"<<endl;
; break;
case 11:
cout<<"December"<<endl;
break;   
}
}


Related Solutions

Write a program that uses a structure to store the following data: (Remember to use proper...
Write a program that uses a structure to store the following data: (Remember to use proper formatting and code documentation) Member Name Description name student name idnum Student ID number Scores [NUM_TESTS] an array of test scores Average Average test score Grade Course grade Declare a global const directly above the struct declaration const int NUM_TESTS = 4; //a global constant The program should ask the user how many students there are and should then dynamically allocate an array of...
Write a program that uses a structure to store the following data about a customer account:...
Write a program that uses a structure to store the following data about a customer account: Name Address City, State and Zip Telephone number Account balance Date of last payment The program should use an array of at least 5 structures. It should let the user enter data into the array, change the contents of any element and display all the data stored in the array. The program should have a menu-driven interface and use functions as appropriate. Input validation:...
11.7: Customer Accounts Write a program that uses a structure to store the following data about...
11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account:      Customer name      Customer address      City      State      ZIP code      Telephone      Account balance      Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the data stored in the array. The program should have a menu-driven user interface. Prompts And...
Write a program that does the following in C++ 1 ) Write the following store data...
Write a program that does the following in C++ 1 ) Write the following store data to a file (should be in main) DC Tourism Expenses 100.20 Revenue 200.50 Maryland Tourism Expenses 150.33 Revenue 210.33 Virginia Tourism Expenses 140.00 Revenue 230.00 2 ) Print the following heading: (should be in heading function) Store name | Profit [Note: use setw to make sure all your columns line up properly] 3 ) Read the store data for one store (should be in...
Write a program for a beauty store that uses an InputBox to ask the guest for...
Write a program for a beauty store that uses an InputBox to ask the guest for a membership code. Embed this in a Do loop so that the user has to keep trying until the result is a valid membership code that starts with “Beauty” (case insensitive) and is followed by 4 digits with the final digit equal to either 6 or 8. Then use a message box to display the input promotion code and inform the user that the...
Write a C program that will read different data types from the following file and store...
Write a C program that will read different data types from the following file and store it in the array of structures. Given file: (This file have more than 1000 lines of similar data): time latitude longitude depth mag magType nst gap dmin 2020-10-19T23:28:33.400Z 61.342 -147.3997 12.3 1.6 ml 12 84 0.00021 2020-10-19T23:26:49.460Z 38.838501 -122.82684 1.54 0.57 md 11 81 0.006757 2020-10-19T23:17:28.720Z 35.0501667 -117.6545 0.29 1.51 ml 17 77 0.1205 2020-10-19T22:47:44.770Z 38.187 -117.7385 10.8 1.5 ml 15 100.22 0.049 2020-10-19T22:42:26.224Z...
Write a program that uses the defined structure and all the above functions. Suppose that the...
Write a program that uses the defined structure and all the above functions. Suppose that the class has 20 students. Use an array of 20 components of type studentType. Other than declaring the variables and opening the input and output files, the function main should only be a collection of function calls. The program should output each student’s name followed by the test scores and the relevant grade. It should also find and print the highest test score and the...
Write a program to implement linked list data structure that will have following functions: a. Append...
Write a program to implement linked list data structure that will have following functions: a. Append a node in the list b. Insert a node in the list c. Delete a node from the list d. Display list e. Find maximum value in the list f. Find how many times a value exists in the list. g. Search Portion of the code is give below. You have to write code for the items (e, f, g) Program: #include<stdlib.h> #include<stdio.h> #include<iostream>...
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
Write a C++ program that uses array to store the salaries of 10 employees working in...
Write a C++ program that uses array to store the salaries of 10 employees working in a small firm. The program should take average of the salaries and the max and min salaries being paid to the employees
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT