943,681 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 949
  • C++ RSS
Apr 20th, 2009
0

Rain or Shine

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
de-de is offline Offline
6 posts
since Apr 2009
Apr 20th, 2009
0

Re: Rain or Shine

nice assignment, now what do you think we should do for you?
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,949 posts
since Aug 2005
Apr 20th, 2009
0

Re: Rain or Shine

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....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
de-de is offline Offline
6 posts
since Apr 2009
Apr 20th, 2009
0

Re: Rain or Shine

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,949 posts
since Aug 2005
Apr 21st, 2009
0

Re: Rain or Shine

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

Re: Rain or Shine

Click to Expand / Collapse  Quote originally posted by de-de ...
Thank you... And I did read the chapter...
did you figure this problem out by the way?
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
cassie_sanford is offline Offline
57 posts
since Oct 2008
Apr 28th, 2009
0

Re: Rain or Shine

nope I am still working on it
Reputation Points: 10
Solved Threads: 0
Newbie Poster
de-de is offline Offline
6 posts
since Apr 2009
Apr 29th, 2009
0

Re: Rain or Shine

C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
de-de is offline Offline
6 posts
since Apr 2009
Apr 29th, 2009
0

Re: Rain or Shine

>>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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,949 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Binary Files and Seekg
Next Thread in C++ Forum Timeline: New Delete Runtime error.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC