Hey guys, I have a homework problem that I'm having issues with. I've been having a difficult time understanding classes and what the point of them is when I feel like I can just write everything in main without using a class, but I'm forced to use them anyways. This is the homework problem:
write a program that prompts the user to enter a person's date of birth in numeric form such as 8-27-1980. The program then outputs the date of birth in the form: August 27, 1980. Your program must contain at least two exception classes: invalidDay and invalidMonth. If the user enters an invalid value for the day, then the program should throw and catch an invalidDay object. Similar conventions for the invalid values of month and year. (Note that your program must handle a leap year.)
And my code so far:
#include <iostream>
using namespace std;
class invalidMonth
{
public:
invalidMonth () throw();
invalidMonth (const exception&) throw();
invalidMonth& operator= (const exception&) throw();
}
class invalidDay
{
public:
invalidDay () throw();
invalidDay (const exception&) throw();
invalidDay& operator= (const exception&) throw();
}
int main()
{
int month, day, year;
cout << "Enter the # of the month" << endl;
cin >> month;
cout << "Enter the day" << endl;
cin >> day;
cout << "Enter the year" << endl;
cin >> year;
cout << "The date is " << month << "-" << day << "-" << year << "." << endl;
if(month==1)
cout << "January ";
else if(month==2)
cout << "February ";
else if(month==3)
cout << "March ";
else if(month==4)
cout << "April ";
else if(month==5)
cout << "May ";
else if(month==6)
cout << "June ";
else if(month==7)
cout << "July ";
else if(month==8)
cout << "August ";
else if(month==9)
cout << "September ";
else if(month==10)
cout << "October ";
else if(month==11)
cout << "November ";
else if(month==12)
cout << "December ";
else
cout << "Invalid date";
return 0;
}
I know I'm doing it wrong because I believe I'm supposed to be putting the if statement in one of my functions in the classes. I just don't know where to put it and how I'm supposed to write it. I'm having a hard time with parameters and the point of &'s so going into this new exception class issue is incredibly difficult for me when I'm already behind. I'm not asking for an answer for my homework, I'm just asking for help on where I should be putting the information. Thanks for your time!