Display day, month, year in different format
Hi!
I'm trying to write a program that will take in three numbers (day, month, year), and display them in different format (MM/DD/YYYY; Month in words, DD, YYYY; and DD Month in words YYYY).
Here's what I have so far, I can't figure out what's wrong. :(
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
{ setNames(); }
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 show;
Date month;
Date day;
Date year;
cout << "What is the month? ";
cin >> number;
month.setMonth(number);
cout << "What is the day? ";
cin >> number;
day.setDay(number);
cout << "What is the year? ";
cin >> number;
year.setYear(number);
system("PAUSE");
return 0;
}
On line 19 (I bolded it), it tells me "expected unqualified-id before { token". I tried searching through this forums for similar problems, but none of them applies to me (some I dont quite understand - still new to C++).
And in main (I boded them also), I can't quite figure out how I should fix the problem.
Thank you so much!