Rain or Shine

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2009
Posts: 6
Reputation: de-de is an unknown quantity at this point 
Solved Threads: 0
de-de de-de is offline Offline
Newbie Poster

Rain or Shine

 
0
  #1
Apr 20th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,634
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1497
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Rain or Shine

 
0
  #2
Apr 20th, 2009
nice assignment, now what do you think we should do for you?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 6
Reputation: de-de is an unknown quantity at this point 
Solved Threads: 0
de-de de-de is offline Offline
Newbie Poster

Re: Rain or Shine

 
0
  #3
Apr 20th, 2009
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....
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,634
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1497
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Rain or Shine

 
0
  #4
Apr 20th, 2009
Which chapter would that be? Of course there is nothing wrong with you reading the chapter yourself.

The instructions seem pretty clear to me
  1. Create the starter program with main() function
  2. Add a character array that has 3 rows and 30 columns
  3. Create an iostream object, open the data file and read the rows into the array.
  4. Loop through the character array and, for each month, count the number of R's, S's and C's.
  5. 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.
Last edited by Ancient Dragon; Apr 20th, 2009 at 11:41 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 6
Reputation: de-de is an unknown quantity at this point 
Solved Threads: 0
de-de de-de is offline Offline
Newbie Poster

Re: Rain or Shine

 
0
  #5
Apr 21st, 2009
Thank you... And I did read the chapter...
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 57
Reputation: cassie_sanford is an unknown quantity at this point 
Solved Threads: 0
cassie_sanford cassie_sanford is offline Offline
Junior Poster in Training

Re: Rain or Shine

 
0
  #6
Apr 28th, 2009
Originally Posted by de-de View Post
Thank you... And I did read the chapter...
did you figure this problem out by the way?
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 6
Reputation: de-de is an unknown quantity at this point 
Solved Threads: 0
de-de de-de is offline Offline
Newbie Poster

Re: Rain or Shine

 
0
  #7
Apr 28th, 2009
nope I am still working on it
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 6
Reputation: de-de is an unknown quantity at this point 
Solved Threads: 0
de-de de-de is offline Offline
Newbie Poster

Re: Rain or Shine

 
0
  #8
Apr 29th, 2009
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. const int NUM_MONTHS = 3;
  9. const int NUM_DAYS = 30;
  10. const int NUM_TYPES= 3;
  11. char forecast[NUM_MONTHS][NUM_DAYS];
  12. int counts [NUM_MONTHS][NUM_TYPES];
  13. int rainyDays = 0;
  14.  
  15. ifstream datafile;
  16.  
  17. datafile.open("RainOrShine.txt");
  18. if (!datafile)
  19. cout << "Error opening data file.\n";
  20. else
  21. {
  22.  
  23. // Read data and load arrary
  24.  
  25. for(int month = 0; month < NUM_MONTHS; month++)
  26. {
  27. for(int day = 0; day < NUM_DAYS; day++)
  28.  
  29. {
  30. datafile >> forecast[month][day];
  31.  
  32. }
  33. datafile.ignore();
  34. }
  35.  
  36. for(int month = 0; month < NUM_MONTHS; month++)
  37. {
  38. for(int day = 0; day < NUM_DAYS; day++)
  39.  
  40. {
  41. cout << forecast[month][day] << '\t';
  42.  
  43. }
  44. cout << endl;
  45. }
  46.  
  47.  
  48. // intialize counts arrarys to 0
  49.  
  50. for(int month = 0; month < NUM_MONTHS; month++)
  51. {
  52. for(int type = 0; type < NUM_TYPES; type++)
  53.  
  54. {
  55. counts[month][type] =0;
  56.  
  57. }
  58.  
  59. }
  60.  
  61. // count all data
  62.  
  63. for(int month = 0; month < NUM_MONTHS; month++)
  64. {
  65. for(int day = 0; day < NUM_DAYS; day++)
  66. {
  67.  
  68. if(forecast [month][day] =='R')
  69. {
  70. counts[month][0]++;
  71. }
  72.  
  73. if(forecast [month][day] =='S')
  74. {
  75. counts[month][1]++;
  76. }
  77.  
  78.  
  79. if(forecast [month][day] =='C')
  80. {
  81. counts[month][2]++;
  82. }
  83.  
  84. }
  85.  
  86. }
  87.  
  88.  
  89.  
  90.  
  91. for(int month = 0; month < NUM_MONTHS; month++)
  92. {
  93. for(int type = 0; type < NUM_TYPES; type++)
  94.  
  95. {
  96. cout << counts[month][type] << '\t';
  97.  
  98. }
  99. cout << endl;
  100. }
  101.  
  102.  
  103.  
  104.  
  105.  
  106. // Determine month with largest number of rainy days
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113. // output report
  114.  
  115. cout << "Three-Month Analysis\n\n";
  116.  
  117.  
  118.  
  119.  
  120.  
  121. }
  122.  
  123.  
  124. system("pause");
  125. return 0;
  126.  
  127. }
How do i find the month with the largest amount of rain?
Last edited by Narue; Apr 29th, 2009 at 4:03 pm. Reason: added code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,634
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1497
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Rain or Shine

 
0
  #9
Apr 29th, 2009
>>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
Last edited by Ancient Dragon; Apr 29th, 2009 at 6:06 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 460 | Replies: 8
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC