Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// C code -Raindata // This program will input and store meteorological data into an array. // Developer: Faculty CMIS102 // Date: Jan 31, XXXX

// C code -Raindata

// This program will input and store meteorological data into an array.

// Developer: Faculty CMIS102

// Date: Jan 31, XXXX

// Global constants

#define NUMYEARS 3

#define NUMMONTHS 12

#include

// Function Prototypes

void InputData();

void PrintData();

// Global variables - These are available to all functions

float Raindata[NUMYEARS][NUMMONTHS];

char years[NUMYEARS][5] = {"2011","2012","2013"};

char months[NUMMONTHS][5] ={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};

int main () {

// Call Function to Input data

InputData();

// Call Function to display data

PrintData();

printf("Thank you. Please try the Precipitation program again. ");

return 0;

} // end main

//-------------------------------------------------------

// Function to input data --------------------------------

void InputData() { // This function will collect at the input data

// Input: Globals NUMYEARS, NUMMONTHS - number of years and months

// Output: Global array Raindata -- collection of rain data

// variable definition:

float Rain=0.0;

// Loop and collect Input Data

for (int year=0;year < NUMYEARS; year++) {

for (int month=0; month< NUMMONTHS; month++) {

printf("Enter rain for %d, %d: ", year+1, month+1);

scanf("%f",&Rain);

Raindata[year][month]=Rain;

}

}

}

// Function to print data -----------------------

void PrintData(){

// This function will display all the collected rain data

// Input: Globals NUMYEARS, NUMMONTHS - number of years and months

// Input: Global array Raindata -- collection of rain data

// Output: none

// Display column headers

printf (" year\t month\t rain ");

// Loop and display the collected rain data

for (int year=0;year < NUMYEARS; year++) {

for (int month=0; month< NUMMONTHS; month++) {

printf("%s\t %s\t %5.2f ", years[year],months[month], Raindata[year][month]);

}

}

}

1. Modify the program to calculate and display the sum of rainfall for each year. And to calculate and display the monthly average for that year. (Hint: this is NOT part of the input.) You have all the data collected. You need to sum the monthly rainfall that you already collected during the input. You can do this during the output function PrintData or you can create a separate function to do the sum. Support your experimentation with screen captures of executing the new code showing ALL the output.

2. Enhance the program to allow the user to enter another meteorological element such as snowfall or windspeed (e.g. 2.4 mph). (Hint: you will need another array). Note, the user should be able to enter both rainfall and the 2nd meteorological element in your new implementation. You will need to update the InputData and PrintData functions. Support your experimentation with screen captures of executing the new code showing ALL the output.

3. Modify the program to calculate and display the sum of your 2nd meteorological element for each year. And to calculate and display the monthly average for that year. (Hint: this is NOT part of the input.) You have all the data collected. You need to sum the monthly rainfall that you already collected during the input. You can do this during the output function PrintData or you can create a separate function to do the sum or you can do it at the same time as you do the rainfall Support your experimentation with screen captures of executing the new code showing ALL the output.

4. Prepare a new test table with at least 2 distinct test cases listing input and expected output for the code you created after step 3. You need to only show the input and output for the first and last year of each test case.

5. Modify the program so that it will prompt and calculate and display 5 years of your two meteorological elements. Support your experimentation with screen captures of executing the new code. Showing ALL the output.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions