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: June 21 - September 21 Autumn: September 22 - December 20 Winter: December 21 - March 19
It is coded in c++
CODE:
#include<iostream>
using namespace std;
int main (){
string Month_input
int day_input,m_num;
bool Mflag = false,Dflag=false;//we use boolean flags
to save the validity or invalidity of month or day with Mflag and
Dflag resp.
cin>>Month_input>>day_input;
//checking if input month and day is valid or not
//we need to check if the user has input the right date for
February or not as February does not have more than 29
days(incl.leap year)
//we also need to check if the user does not exceed the month-end
dates. For example April 31 is an invalid input.
if(Month_input=="January"&&day_input>=1&&day_input<=31){
Mflag=true;Dflag=true;m_num=1;
}
else
if(Month_input=="February"&&day_input>=1&&day_input<=29){//including
leap year
Mflag=true;Dflag=true;m_num=2;
}
else
if(Month_input=="March"&&day_input>=1&&day_input<=31){
Mflag=true;Dflag=true;m_num=3;
}
else
if(Month_input=="April"&&day_input>=1&&day_input<=30){
Mflag=true;Dflag=true;m_num=4;
}
else
if(Month_input=="May"&&day_input>=1&&day_input<=31){
Mflag=true;Dflag=true;m_num=5;
}
else
if(Month_input=="June"&&day_input>=1&&day_input<=30){
Mflag=true;Dflag=true;m_num=6;
}
else
if(Month_input=="July"&&day_input>=1&&day_input<=31){
Mflag=true;Dflag=true;m_num=7;
}
else
if(Month_input=="August"&&day_input>=1&&day_input<=31){
Mflag=true;Dflag=true;m_num=8;
}
else
if(Month_input=="September"&&day_input>=1&&day_input<=30){
Mflag=true;Dflag=true;m_num=9;
}
else
if(Month_input=="October"&&day_input>=1&&day_input<=31){
Mflag=true;Dflag=true;m_num=10;
}
else
if(Month_input=="November"&&day_input>=1&&day_input<=30){
Mflag=true;Dflag=true;m_num=11;
}
else
if(Month_input=="December"&&day_input>=1&&day_input<=31){
Mflag=true;Dflag=true;m_num=12;
}
//if and only if both month and day inputs are valid, season will
be checked, otherwise it will output invalid
if(Dflag==true&&Mflag==true){
//we need to use month number in switch case as switch
case does not work on strings in C/C++
switch(m_num){
case 1:
cout<<"Winter";
break;
case 2: cout<<"Winter";
break;
case 3:
if(day_input<=19)cout<<"Winter";
else cout<<"Spring";
break;
case 4: cout<<"Spring";
break;
case 5: cout<<"Spring";
break;
case 6:
if(day_input<=20)cout<<"Spring";
else cout<<"Summer";
break;
case 7: cout<<"Summer";
break;
case 8: cout<<"Summer";
break;
case 9:
if(day_input<=21)cout<<"Summer";
else cout<<"Autumn";
break;
case 10:
cout<<"Autumn";
break;
case 11:
cout<<"Autumn";
break;
case 12:
if(day_input<=20)cout<<"Autumn";
else cout<<"Winter";
break;
}
}
else cout<<"Invalid";
}
OUTPUT:
CODE SCREENSHOT:
NOTE: I have assumed that the month input starts with an upper case. You may make changes in the above-mentioned code accordingly to accept the input of your own choice. In case the input starts with a lower case you can add an extra or condition to compare with lowercased months or all caps. For example:
month_input=="June" || month_input=="june" || month_input=="JUNE"...so on
Write a program that takes a date as input and outputs the date's season. The input...
Please show output in python 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...
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
2. Implement an application in Java such that if the user enters a month and a day, it should display the name of the season. Design a UI as per your choice. [Hint: The dates for each season are: Spring: March 20 - June 20 Summer: June 21 - September 21 Autumn: September 22 - December 20 Winter: December 21 - March 19]
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;...
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text.Ex: If the input is:Hello there Hey quitthen the output is:ereht olleH yeHThere is a mistake in my code I can not find. my output is : ereht olleH ereht olleHyeHHow can I fix this?I saw some people use void or the function reverse but we didnt...
Output of this in java? String season = ""; int n = 0; switch (season) { case "Spring": n = 16; break; case "Summer": n = 17; break; case "Fall": n = 18; break; case "Winter": n = 19; break; default: n = 20; break; } System.out.println(n);
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...
Write a program that takes in a line of text as input, and outputs that line of text in reverse. You may assume that each line of text will not exceed 50 characters. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text. Ex: If the input is: Hello there Hey quit then the output is: ereht olleH уен Hint: Use the fgets function to read a string with spaces from the user...
4.24 LAB: Print string in reverse Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or 'q" for the line of text. Ex: If the input is: Hello there Hey quit the output is: ereht ollel yeH
Write a basic ARM program that takes a string as input, then outputs a string that replaces all the vowels in the input string with 'x'. Vowels: a, A, e, E, i, I, o, O, u, U. **I am using DS-5 Eclipse Community Workspace with ARM assembly language.** The program should give the following input prompt: "Input a string: " Then, the program should output the string with the vowel(s) replaced with x. The program should terminate upon printing the...