Question

In: Computer Science

An amateur meteorologist wants to keep track of weather conditions during the past year's three -month...

An amateur meteorologist wants to keep track of weather conditions during the past year's three -month summer season and has designated each day as either rainy ('R'), cloudy ('C'), or sunny ('S'). Write a modu lar program that stores this information in a 3 x 30 array of characters, where the row indicates the month (0 = June, 1 = July, 2 = August) and the column indicates the day of the month. Note that data is not being collected for the 31st of any month . The program should begin by calling a function to read the weather data in from a file. Then it should create a report that displays for each month and for the whole three-month period, how many days were rainy, how many were cloudy, and how many were sunny. To help it do this, it should use a value -returning function that is passed the array, the number of the month to examine, and the character to look for ('R', 'C', or 'S') . This function shou ld return the number of days the indicated month had the requested weather. Data for the program can be found in the Rai nOrShi ne. da t file located in the Chapter 8 programs folder on this book's companion website. please do this program in c++ and please add comments.

Solutions

Expert Solution

C++ Program :

#include <iostream>
using namespace std;


//This function helps in reading the weather data from the file RainOrShine.dat
//I have assumed that the file contains data in the following format as it was not specified
//in the question:
//RRRRSSSS...CCR ---> representing days of june
//RRRRSSSS...CCR ---> representing days of july
//RRRRSSSS...CCR ---> representing days of august

void readFromFile(char *weatherData[3]){
    string line;
    ifstream myfile("RainOrShine.dat");
    if(myfile.is_open()){
        int month = 0;
        while(getline(myfile,line)){
            for(int i=0;i<30;i++){
                weatherData[month][i] = line[i];
            }
            month++;
        }
        myfile.close();
    }else{
        cout<<"Unable to open data file"<<endl;
    }
}

//This is the helper function which accepts the monthNumber and the condition of the
//day to be looked for i.e. whether rainy,cloudy or sunny and returns the number of
//days in that month having that condition.

int analysis(char *weatherData[3],int monthNumber,char condition){
    int ans = 0;
   for(int i=0;i<30;i++){
       if(weatherData[monthNumber][i] == condition)ans++;
   }
   return ans;
}  

int main() {
  
    char *weatherData[3];
  
    for(int i=0;i<3;i++){
        weatherData[i] = new char[30];  
    }
  
    //Now we have a 2d character array of size 3x30
  
  
    //This reads the file and stores the data into the char array
    readFromFile(weatherData);
  
  
    //Output for june
    cout<<"FOR JUNE:\n";
    cout<<"Number of rainy days: "<<analysis(weatherData,0,'R')<<endl;
    cout<<"Number of sunny days: "<<analysis(weatherData,0,'S')<<endl;
    cout<<"Number of cloudy days: "<<analysis(weatherData,0,'C')<<endl;
    cout<<endl;
  
  
  
    //Output for july
    cout<<"FOR JULY:\n";
    cout<<"Number of rainy days: "<<analysis(weatherData,1,'R')<<endl;
    cout<<"Number of sunny days: "<<analysis(weatherData,1,'S')<<endl;
    cout<<"Number of cloudy days: "<<analysis(weatherData,1,'C')<<endl;
    cout<<endl;
  
  
  
    //Output for august
    cout<<"FOR AUGUST:\n";
    cout<<"Number of rainy days: "<<analysis(weatherData,2,'R')<<endl;
    cout<<"Number of sunny days: "<<analysis(weatherData,2,'S')<<endl;
    cout<<"Number of cloudy days: "<<analysis(weatherData,2,'C')<<endl;
   return 0;
  
  
}


Related Solutions

An amateur meteorologist keeps a list of daily temperatures and wants a program to calculate how...
An amateur meteorologist keeps a list of daily temperatures and wants a program to calculate how many times the maximum temperature occurred. For example, if the list of temperatures is [21, 24, 24, 23, 20, 19, 21, 24], the maximum of 24 occurs 3 times. a.Consider the problem of calculating how many times the maximum temperature occurs. i.What are the admissible inputs of the problem? ii.What is the output of this problem? b.Write three tests for this problem. The inputs...
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...
Ava wants to use a database to keep track of the data recordsfor her insurance...
Ava wants to use a database to keep track of the data records for her insurance company and to enforce the following business policies/requirements: USE MS ACCESS TO CREATE A DATABASE & RELATIONASHIP-Every customer must be uniquely identified.-A customer can have many insurance policies.-Every insurance policy must be uniquely identified.-An insurance policy must belong to a valid customer.-Every customer must be served by a valid insurance agent (employee).-An insurance agent (employees) serves many customers.-Every insurance agent (employee) must be uniquely...
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...
During the past month, the following costs were incurred in the three production departments and two...
During the past month, the following costs were incurred in the three production departments and two service departments of Kim & Co.: Using Department Supplying Department Administration Factory Support Fabrication Assembly Finishing Administration − 0.40 0.30 0.20 0.10 Factory support 0.15 − 0.15 0.15 0.55 Direct cost $ 680,000 $ 1,350,000 $ 1,760,000 $ 288,000 $ 258,000 Required: Allocate service department costs to Fabrication, Assembly, and Finishing using the reciprocal method, and determine the total costs of Fabrication, Assembly, and...
During the past month, the following costs were incurred in the three production departments and two...
During the past month, the following costs were incurred in the three production departments and two service departments of Kim & Co.: Using Department Supplying Department Administration Factory Support Fabrication Assembly Finishing Administration ? 0.40 0.20 0.10 0.30 Factory support 0.10 ? 0.10 0.20 0.60 Direct cost $ 570,000 $ 1,295,000 $ 1,650,000 $ 277,000 $ 247,000 Required: Allocate service department costs to Fabrication, Assembly, and Finishing using the reciprocal method, and determine the total costs of Fabrication, Assembly, and...
During the past month, the following costs were incurred in the three production departments and two...
During the past month, the following costs were incurred in the three production departments and two service departments of Kim & Co.: Using Department Supplying Department Administration Factory Support Fabrication Assembly Finishing Administration − 0.40 0.30 0.20 0.10 Factory support 0.10   −   0.30   0.10 0.50 Direct cost $ 520,000 $ 1,270,000 $ 1,600,000 $ 272,000 $ 242,000 Required: Allocate service department costs to Fabrication, Assembly, and Finishing using the reciprocal method, and determine the total costs of Fabrication, Assembly, and...
Task 2 introduction to software engineering A nursery wants to keep track of all its products,...
Task 2 introduction to software engineering A nursery wants to keep track of all its products, including plants, fountains, garden hardware (wheelbarrow, shovels etc) and also soil and sand which they sell. They buy all stock from the wholesalers. The management wants to know which staff members have been selling what, and from which wholesaler the products were purchased. There are also times when a customer returns a product for a refund, and such information should be available in the...
A gas station wants a program to keep track of sales. Your gas station sells diesel...
A gas station wants a program to keep track of sales. Your gas station sells diesel for 107.9 cents per litre and regular gas for 112.9 cents per litre. Have the user enter the type of fuel (1 = Regular gas, 2 = Diesel) and number of litres sold. Print out a total for each sale (remember fuel prices already include the GST). Once you enter a 0 for the type of fuel your program should stop and print out...
/////////////////JAVA PLEASE///////////////////////////////// Create a class called GVdate to keep track of a calendar date including month,...
/////////////////JAVA PLEASE///////////////////////////////// Create a class called GVdate to keep track of a calendar date including month, day and year.  You can do simple things like checking if it is your birthday, advancing to the next day, checking if a given date is valid and checking if it is a leap year. Class Fields/Instance Variables Provide appropriate names and data types for each of the private instance variables: the month, day and year (int) two final integers that represent YOUR birthday (month...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT