Question

Question #7. (8 points) (P313) The following algorithm yields the season (Spring, Summer, Fall or Winter) for a given month and day. If month is 1, 2, or 3, season Winter Else if month is 4, 5, or 6, season Spring Else if month is 7, 8, or 9, season Summer Else if month is 10, 11, or 12, season Fall If month is divisible by 3 and day 21 If season is winter, season = Spring Else if season is Spring season Summer Else if season is Summer, season Fall Else season Spring Write a program (seasons.cpp) that prompts the user for a month and day and then prints the season, as determined by this algorithm.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

SourceCode:

/******************************************************************************

Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
int month=0;
int day;
cout<<"Enter month(1 to 12):";
cin>>month;
while(month <0 || month >12) {
cout<<"Enter valid month b/w 1 to 12:";
cin>>month;
}
cout<<"Enter day(1 to 30):";
cin>>day;
while(day <0 || day >30) {
cout<<"Enter valid day(1 to 30):";
cin>>day;
}
string season="";
//If month is 1, 2 or 3, season = “Winter”
if(month >= 1 && month <=3)
season = "Winter";

//Else if month is 4, 5 or 6, season = “Spring”
else if(month >= 4 && month <=6)
season = "Spring";

//Else if month is 7, 8, or 9, season = “Summer”
else if(month >= 7 && month <=9)
season = "Summer";

// Else if month is 10, 11, or 12, season = “Fall”
else if(month >= 10 && month <=12)
season = "Fall";

// If month is divisible by 3 and day is greater than or equal to 21
if(month % 3 == 0 && day >=21) {
if(season=="Winter")
// If season is winter, season equals “spring”
season = "Spring";

// Else if season is spring, season equal “summer”
else if(season=="Spring")
season = "Summer";
// Else if season is summer, season equals “fall”
else if(season=="Summer")
season = "Fall";
// Else season equals winter
else
season = "Winter";
}
cout<<"season: "<< season << endl;

return 0;
}

Output:

main.cpp 47- 48 if (month % 3-0 && day >-21) { if(season-Winter) If season is winter, season equals spring 50 51 season-//Hi, please comment in here in case of any queries and do rate the solution if it is helpful...Thanks

Add a comment
Know the answer?
Add Answer to:
Question #7. (8 points) (P313) The following algorithm yields the season (Spring, Summer, Fall or Winter)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The administrator of a hospital is interested in predicting the amount of gross patient revenue that the organization expects to earn during the winter, spring, summer, and fall of the next year. the...

    The administrator of a hospital is interested in predicting the amount of gross patient revenue that the organization expects to earn during the winter, spring, summer, and fall of the next year. the following data represent the gross patient revenue earned in the past 6 years. Season Time Gross Revenue Moving average Winter 1 36 Spring 2 27 Summer 3 15.1 Fall 4 37.8 = Winter 5 47.6 Spring 6 41.4 Summer 7 26.9 Fall 8 51.7 Winter 9 53.3...

  • Use R to solve these problems 8. The year is divided into four seasons: spring, summer,...

    Use R to solve these problems 8. The year is divided into four seasons: spring, summer, fall and winter While the exact dates that the seasons change vary a little bit from year to year because of the way that the calendar is constructed, we will use the following dates for this exercise: Season rin Summer Fall Winter Start March June September December End Ma August November Februa Create a program that reads a month from the user. The user...

  • Create a function that will accept a date as input and will return if this date happens in fall, spring, winter or summ...

    Create a function that will accept a date as input and will return if this date happens in fall, spring, winter or summer. Before you start writing this function experiment with queries below. Current date select sysdate from dual; Yesterday select sysdate - 1 from dual; Tomorrow select sysdate + 1 from dual; The date format element D returns the number of the day of the week (1-7). select to_char(sysdate,'D') from dual; MM returns two-digit numeric abbreviation of month (01-12;...

  • C++ Help. Any help is appreciated, thank you very much! Write a C++ program that asks...

    C++ Help. Any help is appreciated, thank you very much! Write a C++ program that asks the user for the month of the year (as a number), and prints “Happy Winter” if it is strictly before 3 or strictly larger than 11, “Happy Spring” if it is 3 or greater, but strictly before 7, and “Happy Summer” if it is 7 or greater, but strictly before 9, and “Happy Fall” otherwise. A sample run: Enter month (as a number): 12...

  • A psychologist would like to know whether the season (fall, winter, spring and summer) has any...

    A psychologist would like to know whether the season (fall, winter, spring and summer) has any consistent effect on people’s sexual activity. In the middle of eachseason he selected a random sample of n= 25 students. Each individual is given a sexual activity questionnaire. A one- factor ANOVA was used to analyze these data. Complete the following ANOVA summary table (a=0.05) Source SS df MS F Crit value Between 5.00 Within 960 Total Part A: Complete the ANOVA Summary table...

  • Write a program that takes a date as input and outputs the date's season. The input...

    Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day. Ex: If the input is: April 11 the output is: Spring In addition, check if the string and int are valid (an actual month and day). Ex: If the input is: Blue 65 the output is: Invalid The dates for each season are: Spring: March 20 - June 20 Summer:...

  • Plan production for the next year. The demand forecast is: spring, 19,500; summer, 9,400; fall, 15,000;...

    Plan production for the next year. The demand forecast is: spring, 19,500; summer, 9,400; fall, 15,000; winter, 18,800. At the beginning of spring, you have 66 workers and 990 units in inventory. The union contract specifies that you may lay off workers only once a year, at the beginning of summer. Also, you may hire new workers only at the end of summer to begin regular work in the fall. The number of workers laid off at the beginning of...

  • The administrator of a hospital is interested in predicting the amount of gross patient revenue that...

    The administrator of a hospital is interested in predicting the amount of gross patient revenue that the organization expects to earn during the winter, spring, summer, and fall of the next year. the following data represent the gross patient revenue earned in the past 6 years. Season Time Gross Revenue Winter 1 36 Spring 2 27 Summer 3 15.1 Fall 4 37.8 Winter 5 47.6 Spring 6 41.4 Summer 7 26.9 Fall 8 51.7 Winter 9 53.3 Spring 10 44.7...

  • 24. Consider the following C++ code. (6, 8) string seasons [4](*Winter", "Spring", "Summer", "Falla) stringstrPtr; strPtr...

    24. Consider the following C++ code. (6, 8) string seasons [4](*Winter", "Spring", "Summer", "Falla) stringstrPtr; strPtr new string[5]; for (int į = 0; i < 4; i++) strPtr liseasons [i] a. Write a C++ code that outputs the contents of the array to whiclh strPtr points. Write the C++ statement that deallocates the memory space occu- pied by the array to which strptr points b.

  • Write a C# program that prints a calendar for a given year. Call this program calendar....

    Write a C# program that prints a calendar for a given year. Call this program calendar. The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:             0 Sunday                     1 Monday                   2 Tuesday                   3 Wednesday       4 Thursday                 5 Friday                      6 Saturday Your program should...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT