Question: Make a program that should have Date (Randomize start of the month) Weather Status of those certain Days of the Week: Sunny, Cloudy, or Rainy

Make a program that should have

  • Date (Randomize start of the month)
  • Weather Status of those certain Days of the Week: Sunny, Cloudy, or Rainy (Randomized)
  • Print the Calendar (Month view only)

Expected Output: In each run of the program, there will be a random start of the month and weather status. Example output: Make a program that should have Date (Randomize start of the month)

Note: This is a discussion during the topic of our union, structures, and enum, so please include it if possible. Please put the code itself, not the photo. No need for inputs, just initialize everything inside the code and randomize what should be outputted (as indicated in the instructions) Show the side-by-side interpretation of the algorithm to its corresponding code. Use only C programming (NOT C++).

Here is my previous code also, the problem here is I cannot put the weather like in the example output, please just modify this so it will look the same on the example output. Thanks!

#include #include #include

//enum defining the week typedef enum { Sun, Mon, Tue, Wed, Thu, Fri, Sat } Week; //enum defining the weather typedef enum { Sunny, Cloudy, Rainy } Weather; //enum defining the month typedef enum { Jan, Feb, Mar, Apr, May, Jun, July, Aug, Sept, Oct, Nov, Dec } Month;

char* getMonth(Month month); int getRandom(int si, int ei); void showCalender( Week start, int len , char* month);

int main() { //seed for generating random time srand(time(0)); // getting random start Week sdate = getRandom(Sun,Sat); // getting random month Month month = getRandom(Jan,Dec); // getting random days of the month int days = getRandom(28,31); //getting the name of the month char* month_ = getMonth(month); //call to print the calender showCalender(sdate,days,month_); system("pause"); return 0; }

//function to get the month name char* getMonth(Month month) { switch (month) { case Jan: return "January"; case Feb: return "February"; case Mar: return "March"; case Apr: return "April"; case May: return "May"; case Jun: return "June"; case July: return "July"; case Aug: return "August"; case Sept: return "September"; case Oct: return "October"; case Nov: return "November"; case Dec: return "December"; } return ""; } //function to get a random value for a given range int getRandom(int si, int ei) { //since , there is no specific thing to get output for range , we can deduce this formula int val = (rand() % (ei - si + 1)) + si; return val; } //function to print the calender void showCalender( Week start, int len , char* month) { //it will be used to calculate the week day Week weekD = start % 7;

int day; printf(" %s ",month); printf(" Sun Mon Tue Wed Thu Fri Sat "); // it will print white spaces before the start of the date for (day=0; day

printf("%7d", day); //generating random weather Weather wday = getRandom(Sunny,Rainy);

//storing the random weather w.r.t to their weather if(wday == 0) { sunny[s] = day; s++; } else if(wday == 1) { cloudy[c] = day; c++; } else { rainy[r] = day; r++; } //used to print next line if(weekD==0) printf(" "); }

printf(" "); //printing rainy days printf(" Rainy at the days of : "); int i; for( i = 0 ; i 0) printf("%d",rainy[r-1]); printf(" ");

//printing cloudy days printf(" Cloudy at the days of : "); for( i = 0 ; i 0) printf("%d",cloudy[c-1]); printf(" ");

//printing sunny days printf(" Sunny at the days of : "); for( i = 0 ; i 0) printf("%d",sunny[s-1]); printf(" ");

}

Sun Mon Tue January Wed 1 Sunny Thu 2 Sunny Fri 3 Rainy Sat 4 Cloudy 8 6 Sunny 7 Sunny 8 Sunny 9 Rainy 10 Sunny 11 Sunny 12 Rainy 13 Sunny 14 Sunny 15 Rainy 16 Sunny 17 Sunny 18 19 Cloudy Rainy 20 Rainy 21 22 Cloudy Rainy 23 24 cloudy Sunny 25 26 Cloudy Cloudy 27 28 29 30 Cloudy Cloudy Cloudy Cloudy Process exited after 0.2913 seconds with return value o Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!