Question
Using C++... Date June 10, 1960 is special because when you write it in the format 6/10/60, the month times the day equals the year.
Using C++... Date June 10, 1960 is special because when you write it in the format 6/10/60, the month times the day equals the year.
Write a C++ program that asks the user to enter a date in the format month/day/year, where month and day are one or two digits each and year is exactly two digits. Use the getline function to read the input as one string. The program should extract the month, day and year from the input and display them to the user. The program then determines whether the month times the day is equal to the year. If so, it should display a message saying the date is magic. Otherwise, it should display a message saying the date is not magic.
The program should have a function named isMagicDate that returns true if the date is a magic date and returns false otherwise.
You may find the following string functions useful:
mystring.find('z', x) | Returns the first position at or beyond position x where 'z' is found in mystring. Default value for x is 0. |
mystring.substr(x, n) | Returns a copy of a substring. The substring is n characters long and begins at position x of mystring. Default value for n is up to the end of the string. |
stoi() | Accepts a string object as an argument. It converts that argument to an int and returns that value. Example usage: string s = "7524"; int num = stoi(s); |
Sample program runs are as follows, where user input is shown in red color:
Enter date in the format mm/dd/yy 6/10/60 month is 6 day is 10 year is 60 6/10/60 is a magic date
Enter date in the format mm/dd/yy 10/5/50 month is 10 day is 5 year is 50 10/5/50 is a magic date
Enter date in the format mm/dd/yy 1/1/12 month is 1 day is 1 year is 12 1/1/12 is not a magic date
Enter date in the format mm/dd/yy 10/12/01 month is 10 day is 12 year is 1 10/12/01 is not a magic date
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started