I followed matsp and kcpilot's advice and changed my code to this:
Code:
#include <iostream>
#include <fstream>
using namespace std;
class Date
{
private:
int month;
int day;
int year;
static char slash;
public:
void setDate();
void showDate();
void setMonth();
void setDay();
void setYear();
};
char Date::slash = '/';
void Date::setDate()
{
cin >> month;
cin.get();
cin >> day;
cin.get();
cin >> year;
cin.get();
}
void Date::setMonth()
{
if(month > 12 || month == 0)
month = 12;
else
month = month;
}
void Date::setDay()
{
if(day > 31 || day == 0)
day = 31;
else
day = day;
}
void Date::setYear()
{
if(year <= 999 || year > 2500)
year = 2007;
else
year = year;
}
void Date::showDate()
{
cout << month << slash << day << slash << year << endl;
}
void main()
{
Date aDate[5];
cout << "Please enter five dates." << endl;
cout << "You can enter any slashes(/), only numbers(12 3 2007)" << endl;
ofstream out("H:\\Dates.txt");
for(int x = 0; x < 5; ++x)
{
aDate[x].setDate();
aDate[x].setMonth();
aDate[x].setDay();
aDate[x].setYear();
out << aDate[x].month << aDate[x].day << aDate[x].year << endl;
}
cout << endl << "The dates you entered were: " << endl << endl;
for(int x = 0; x < 5; ++x)
aDate[x].showDate();
cout << endl;
system("pause");
}
But then it gives me this error:
Error 1 error C2248: 'Date::month' : cannot access private member declared in class 'Date' h:\documents\c++\oop\program7\program7\program7.cp p 66
Anyway... thanks!