Question: IN C++ PLEASE Topic Branching switch Statement Description This assignment is the same as the last assignment except you are to additionally include the input
IN C++ PLEASE
Topic
Branching
switch Statement
Description
This assignment is the same as the last assignment except you are to additionally include the input validation code in this assignment.
This assignment will validate (check) the values of day, month, and year entered by the user to ensure that they are valid (correct) before computing day number. If any value is invalid (incorrect), the program will display an error message and end. The program will do the input validation (checking) before computing the day number.
The program will validate (check) the input values to ensure that:
Year value (entered by the user) is in the range of 2000 to 2099 inclusive.
Month value (entered by the user) is in the range of 1 to 12 inclusive.
Day value (entered by the user) is valid (correct) for the given month and the year.
Note:
Do input validation (checking) immediately after inputting the value (from the user) and before computing the day number.
Testing
Input Test Run 1
Enter Month: 4
Enter Day: 31
Enter Year: 2003
Output Test Run 1
Mismatching Month/Day Values Entered.
Month Value Entered: 4
Day Value Entered: 31
(The program ended)
Input Test Run 2
Enter Month: 3
Enter Day: 31
Enter Year: 201
Output Test Run 2
Unacceptable Year Entered 201.
Acceptable range for year is 2000 to 2099
(The program ended)
Input Test Run 3
Enter Month: 2
Enter Day: 29
Enter Year: 2003
Output Test Run 3
Mismatching Month/Day/year Values Entered.
Year Value Entered: 2003
Month Value Entered: 2
Day Value Entered: 29
(The program ended)
Input Test Run 4
Enter Month: 2
Enter Day: 29
Enter Year: 2004
Output Test Run 4
Date: 2/29/2004
Day Number: 60
Input Test Run 5
Enter Month: 3
Enter Day: 1
Enter Year: 2003
Output Test Run 5
Date: 3/1/2003
Day Number: 60
Input Test Run 6
Enter Month: 3
Enter Day: 1
Enter Year: 2004
Output Test Run 6
Date: 3/1/2004
Day Number: 61
Sample Code
/*
First, input from the user (ask the user to enter) month, day and year one after the other.
Then, validate (check) the input (values entered by the user). If any of the values is invalid (incorrect), display an error message to the effect and end the program.
When all input values (values entered by the user) are validated (checked), only then compute and display the dayNum.
See the sample code below.
*/
//For doing this assignment, follow the code sequence as shown below.
int day, month, year, dayNum;
//Input day, month, and year values.
//Validate input values
//Determine if it's a Leap year
bool leapyear = false;
if ((year % 4) == 0)
{
leapyear = true;
}
//Validate YearValue
if ( year < 2000 || year > 2099 )
{
cout << Unacceptable Year Entered: << year << endl;
cout << Valid Range For Year 2000 to 2099 << endl;
return 0;
}
//Validate Month Value
if ( month < 1 || month > 12 )
{
cout << Invalid Month Entered: << month << endl;
return 0;
}
//Validate Day Value
if ( ( day < 1 ) || ( day > 31 ) )
{
cout << Invalid Day Entered: << day << endl;
return 0;
}
//Validate Other Day Values
if ( ( month == 4 || month == 6 || month == 9 || month == 11) && ( day > 30 ) )
{
cout << Mismatching Month/Day Values Entered. << endl;
cout << Month Value Entered: << month << endl;
cout << Day Value Entered: << day << endl;
return 0;
}
if ( (month == 2) && ( day > 29 ) && ( leapyear ) )
{
cout << Mismatching Month/Day Values Entered: << endl;
cout << Month Value Entered: << month << endl;
cout << Day Value Entered: << day << endl;
return 0;
}
if ( (month == 2) && ( day > 28 ) && ( ! leapyear ) )
{
cout << Mismatching Month/Day Values Entered: << endl;
cout << Month Value Entered: << month << endl;
cout << Day Value Entered: << day << endl;
return 0;
}
//Determine dayNum
//Display the date and dayNum
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
