Thank you guys!
I fixed the errors and decided to just input data manually. How do I display the final product?
Code:
#include <iostream>
#include <string>
using namespace std;
const int NUM_MONTHS = 12;
const int NAMESIZE = 10;
class Date
{
private:
int month, day, year;
char names[NUM_MONTHS][NAMESIZE];
public:
Date::Date(int m, int d, int y)
{
setMonth(m);
setDay(d);
setYear(y);
setNames();
}
void Date::setNames()
{
strcpy(names[0], "January");
strcpy(names[1], "Feburary");
strcpy(names[2], "March");
strcpy(names[3], "April");
strcpy(names[4], "May");
strcpy(names[5], "June");
strcpy(names[6], "July");
strcpy(names[7], "August");
strcpy(names[8], "September");
strcpy(names[9], "October");
strcpy(names[10], "November");
strcpy(names[11], "December");
}
void Date::setMonth(int m)
{
if (m >= 1 && m <= 12)
month=m;
else
{
cout << m << "is not a valid"
<< "value for the month.\n";
exit (EXIT_FAILURE);
}
}
void Date::setDay(int d)
{
if (d >= 1 && d <= 31)
day=d;
else
{
cout << d << "is not a valid"
<< "value for the month.\n";
exit (EXIT_FAILURE);
}
}
void Date::setYear(int y)
{
if (y <= 1)
year=y;
else
{
cout << y << "is not a valid"
<< "value for the month.\n";
exit (EXIT_FAILURE);
}
}
void Date::showDate1()
{
cout << month << "/"
<< day << "/"
<< year << endl;
}
void Date::showDate2()
{
cout << names[month+1]
<< " " << day << ", "
<< year << endl;
}
void Date::showDate3()
{
cout << day << " "
<< month << " "
<< year << endl;
}
int Date::getMonth() const
{
return month;
}
int Date::getDay() const
{
return day;
}
int Date::getYear() const
{
return year;
}
};
int main()
{
int number;
Date today (12, 25, 2006);
today.showDate1();
today.setMonth(12);
today.setDay(25);
today.setYear(2006);
today.showDate2();
today.showDate3();
system("PAUSE");
return 0;
}
Thank you!