954,157 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Rain or Shine

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 program that stores this information in a 3x30 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 reading the weather data in from a file. Then it should create a report that displays for each month and for the whole 3 month period, how many days were rainy, how many were cloudy, and how many were sunny. It should also report which of the three months had the largest number of rainy days. Data for the program can be found in rainorshine.dat file.


The data file says:


RRCSSSCSCRRRCSSSCSSRSCCRCRRCSS
SSSCCSSSCCSSSCCSSSCRCRCCSSSSSS
SSSSCSSSCSSSCRRCCCSSSSSCSSSSCS

de-de
Newbie Poster
6 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

nice assignment, now what do you think we should do for you?

Ancient Dragon
Retired & Loving It
Team Colleague
30,043 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 

i would like help setting up this program... I am looking for the comments... I don't want you to do it for... or anything like that... I just need to be started off.. we haven't covered this chapter in class yet....

de-de
Newbie Poster
6 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

Which chapter would that be? Of course there is nothing wrong with you reading the chapter yourself.

The instructions seem pretty clear to me Create the starter program with main() function
Add a character array that has 3 rows and 30 columns
Create an iostream object, open the data file and read the rows into the array.
Loop through the character array and, for each month, count the number of R's, S's and C's.
Display the report on the screen using std::cout.

If you don't know how to use ifstream then you can search for example code -- there is lots of it all over the net and even here at DaniWeb. Learn to make google one of your best programming buddies.

Ancient Dragon
Retired & Loving It
Team Colleague
30,043 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 

Thank you... And I did read the chapter...

de-de
Newbie Poster
6 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 
Thank you... And I did read the chapter...


did you figure this problem out by the way?

cassie_sanford
Junior Poster in Training
57 posts since Oct 2008
Reputation Points: 11
Solved Threads: 0
 

nope I am still working on it

de-de
Newbie Poster
6 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    const int NUM_MONTHS = 3;
    const int NUM_DAYS = 30;
    const int NUM_TYPES= 3;
    char forecast[NUM_MONTHS][NUM_DAYS];
    int counts [NUM_MONTHS][NUM_TYPES];
    int rainyDays = 0;

    ifstream datafile;
    
    datafile.open("RainOrShine.txt");
    if (!datafile)
        cout << "Error opening data file.\n";
    else
    {

        // Read data and load arrary
        
        for(int month = 0; month < NUM_MONTHS; month++)
        { 
            for(int day = 0; day < NUM_DAYS; day++)
        
            {
                datafile >> forecast[month][day];
                
            }
            datafile.ignore();
        }
        
        for(int month = 0; month < NUM_MONTHS; month++)
        { 
            for(int day = 0; day < NUM_DAYS; day++)
        
            {
                cout << forecast[month][day] << '\t';
                
            }
            cout << endl;
        }        
        
        
    // intialize counts arrarys to 0
        
        for(int month = 0; month < NUM_MONTHS; month++)
        { 
            for(int type = 0; type < NUM_TYPES; type++)
        
            {
                counts[month][type] =0;
                
            }
            
        }
        
     // count all data   
        
        for(int month = 0; month < NUM_MONTHS; month++)
        { 
            for(int day = 0; day < NUM_DAYS; day++)
            {
         
                  if(forecast [month][day] =='R')
                  {
                        counts[month][0]++;
                  }      
                           
                  if(forecast [month][day] =='S')
                  {
                        counts[month][1]++;
                  }
                  
                     
                  if(forecast [month][day] =='C')
                  {
                        counts[month][2]++;
                  }
      
            }
            
        }

        
        

        for(int month = 0; month < NUM_MONTHS; month++)
        { 
            for(int type = 0; type < NUM_TYPES; type++)
        
            {
                cout << counts[month][type] << '\t';
                
            }
            cout << endl;
        }
  
      
        
  
      
      // Determine month with largest number of rainy days
      
      
      
      
        
        
      // output report  
      
    cout << "Three-Month Analysis\n\n";      
        
  
  
        
        
    }
    
    
    system("pause");
    return 0;
  
}

How do i find the month with the largest amount of rain?

de-de
Newbie Poster
6 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

>>How do i find the month with the largest amount of rain?
You already have the array that contains the count of the number of Rs, Ss and Cs. Now all you have to do is iterate through that array and keep track of which month has the greatest number of Rs. How would you do that? Try it with pencil & paper first

Ancient Dragon
Retired & Loving It
Team Colleague
30,043 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You