Question

Daily Rainfal Total Week #1: 3 0 0 7 821 0 39mm Week #2 : 0 1 1 0 0 0 4 6mm Week #3: 9672000 24mm Week #4 : 0000013 4mm wee Week #6 : 1 0 1 0 0 0 0 2mm 0mm Total rainfall: 75mm (an average of 12.5mm per week) Driest week: 5 Wettest week: 1 Total rainfall on driest day of week: 7mm Con Monday, Saturday) Total rainfall on wettest day of week: 22mm Con Friday) liberty: ~/tmp/%

write a C programming that can run like this to find the rainfall data of 6 weeks with the data inported from a text file. do not use array. Notice that it's possible for the result to have two different days or week.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

#include <iomanip>

using namespace std;

// Constant for the number of months

const int NUM_MONTHS = 12;

// Function prototypes

double getTotal(double [], int);

double getAverage(double [], int);

double getLargest(double [], int, int &);

double getSmallest(double [], int, int &);

double getTotal(int rainFall,double NUM_MONTHS[])

{

double total = 0;

for (int count = 0; count < NUM_MONTH; count++)

total += NUM_MONTH[count];

return total;

}

double getAverage(int rainFall,double NUM_MONTH[])

{getTotal(rainFall,NUM_MONTH)

average= total/NUM_MONTHS;

return average;

}

double getHighest(int rainFall, double NUM_MONTHS[]) //I left out the subScript peice as I was not sure how to procede with that;

{

double largest;

largest = NUM_MONTHS[0];

for ( int month = 1; month <= NUM_MONTHS; month++ ){

                      if ( values[month] > largest ){

                  largest = values[month];

return largest;

             }

double getSmallest(int rainFall, double NUM_MONTHS[])
046
{

double smallest;

smallest = NUM_MONTHS[0];

for ( int month = 1; month <= NUM_MONTHS; month){
                      if ( values[month] < smallest ){
                  smallest = values[month];
return smallest;

             }
   
int main()
{
   // Array to hold the rainfall data
   double rainFall[NUM_MONTHS];

   // Get the rainfall for each month.
or (int month = 0; month < NUM_MONTHS; month++)

// Get this month's rainfall.

cout << "Enter the rainfall (in inches) for month #";

      cout << (month + 1) << ": ";

      cin >> rainFall[month];

     

      // Validate the value entered.

      while (rainFall[month] < 0)

      {

         cout << "Rainfall must be 0 or more.\n"

              << "Please re-enter: ";

         cin >> rainFall[month];

      }

   }

  

   // Set the numeric output formatting.

   cout << fixed << showpoint << setprecision(2) << endl;
  

   // Display the total rainfall.

   cout << "The total rainfall for the year is ";

   cout << getTotal(rainFall, NUM_MONTHS)

        << " inches." << endl;

   // Display the average rainfall.

   cout << "The average rainfall for the year is ";

   cout << getAverage(rainFall, NUM_MONTHS)

        << " inches." << endl;
   // Now display the largest & smallest amounts.

   // The subscript variable will be passed by reference

   // the the getLargest and getSmallets functions.

   int subScript;

   // Display the largest amount of rainfall.

   cout << "The largest amount of rainfall was ";

   cout << getLargest(rainFall, NUM_MONTHS, subScript)

        << " inches in month ";

   cout << (subScript + 1) << "." << endl;

   // Display the smallest amount of rainfall.

   cout << "The smallest amount of rainfall was ";

   cout << getSmallest(rainFall, NUM_MONTHS, subScript)

        << " inches in month ";

   cout << (subScript + 1) << "." << endl << endl;

   return 0;

}
     

Add a comment
Know the answer?
Add Answer to:
write a C programming that can run like this to find the rainfall data of 6...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Coding in C++ Write a program using structures to store the following weather information: - Month...

    Coding in C++ Write a program using structures to store the following weather information: - Month name - Day of month (Monday, Tuesday, etc) - High Temperature - Low Temperature - Rainfall for the day Use an the input.txt file to load the data into weather structures. Once the data for all the days is entered, the program should calculate and display the: - Total rainfall for the data - Average daily temperatures. (note: you'll need to calculate the days...

  • Need this program ASAP C++ language 1b. Write the implementation file timeClock.cpp for the class TimeClock....

    Need this program ASAP C++ language 1b. Write the implementation file timeClock.cpp for the class TimeClock. Com pile the file, and save it in the Chap 13 folder of your Student Data Files. 1c. Write a C++ program named weeklyPay.cpp to test your class Timeclock Your program should ask the user how many hours the user worked each day of the week. An object should be created for each day of the week with the number of hours for each...

  • C Programming Quesition (Structs in C): Write a C program that prompts the user for a...

    C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT