Help, I have a Date Template where everything has gone wrong. I am not sure If I am understanding this correctly. My text tells me to create a regular function and then convert it to a template my Date class before when it was an int worked fine. Now that I have attempted to convert it to a Date Template -- I get a lot of error. Am I seeing this right. Eventually, I will need to use this date class template to work with a linked list. [That's a later question]
Here is what I have. Please help
**********************
#include <iostream.h>
#include <stdlib.h>
#include <iomanip.h>
//#include <fstream.h>
//class template
template <class T>
class Date
{
private:
T month;
T day;
T year;
public:
void setMonth(T);
void setDay(T);
void setYear(T);
T getMonth(void);
T getDay(void);
T getYear(void);
};
void Date::setMonth(T m)
{
month = m;
}
void Date::setDay(T d)
{
day = d;
}
void Date::setYear(T y)
{
year = y;
}
T Date::getMonth(void)
{
return month;
}
T Date::getDay(void)
{
return day;
}
T Date::getYear(void)
{
return year;
}
void main(void)
{
Date format;
T Mo, Dy, Year, i = 0, year = 0;
char alphaMonth[12][10] = {"January", "February", "March", "April",
"May", "June", "July", "August", "September",
"October", "November", "December"};
cout.precision(2);
cout.setf(ios::fixed);
cout << "This program calculates a date in different formats.";
cout << endl;
cout << endl;
cout << "Enter the month number: ";
cin >> Mo;
while (Mo < 0 || Mo > 12)
{
cout << "Enter the numeric equivalent for month (1 to 12): ";
cin >> Mo;
}
format.setMonth(Mo);
cout << "Enter the day: ";
cin >> Dy;
while (Dy < 0 || Dy > 31)
{
cout << "Enter a day between (1 to 31): ";
cin >> Dy;
}
format.setDay(Dy);
cout << "Enter the year (XXXX): ";
cin >> Year;
cout << endl;
format.setYear(Year);
if(format.getYear() < 2000)
{
year = format.getYear() - 1900;
}
else if (format.getYear() > 1999)
{
year = format.getYear() - 2000;
}
cout << "Numeric date format: ";
cout << ((format.getMonth() < 10) ? "0":"") << format.getMonth() << "/"
<<((format.getDay() < 10) ? "0":"") << format.getDay() << "/"
<< ((year<10) ? "0":"") << year;
cout << endl;
i = format.getMonth() - 1;
cout << endl;
cout << "Standard date format: ";
cout << alphaMonth[i] << " " << ((format.getDay() < 10) ? "0":"")
<< format.getDay() << ", " << format.getYear() << "\n";
cout << endl;
cout << "Alternate date format: ";
cout << ((format.getDay() < 10) ? "0":"") << format.getDay()
<<" " <<alphaMonth[i] << " " << format.getYear();
cout << endl << endl;
}