This question deals with palindromic dates-that is, dates that read the same for
ID: 3852050 • Letter: T
Question
This question deals with palindromic dates-that is, dates that read the same forward and backward. The year 2002 was a palindromic year. When is the next palindromic year? If dates are written MMDDYYYY, then May 2, 2050, is a palindromic date. What is the earliest palindromic date of the 21st century? Create a program that identifies all palindromic dates in a given year. First a user enters a year. Then the program reports the palindromic dates. Finally, the program asks the user if he or she wishes to try again. Note that you need a Palindrome class that permits testing "digit" characters.Explanation / Answer
Answer for the given Palindrom Question:
As given in problem statement implemented with the help of class Palindrom and functions with user choice
#include <iostream>
using namespace std;
class Palindrome
{
int year;
public:
Palindrome()
{
year = 0;
}
Palindrome(int year1)
{
year = year1;
}
void PalindromeYear(int num)
{
int n, digit, rev = 0;
//cout << "Enter a year: "<<endl;
//cin >> num;
n = num;
do
{
digit = num % 10;
rev = (rev * 10) + digit;
num = num / 10;
} while (num != 0);
cout << " The reverse of the number is: " << rev << endl;
if (n == rev)
cout << " The Year is a palindrome year";
else
cout << " The year is not a palindrome year";
}
};
int main()
{
Palindrome pal;
char ch;
int year2;
do{
cout<<"Enter Year :"<<endl;
cin>>year2;
pal.PalindromeYear(year2);
cout<<"Do you want try one more time enter y or n"<<endl;
cin>>ch;
}while(ch == 'y' || ch == 'Y');
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.