int getMonth(int month);
int getYear(int year);
int computeOffset(int year, int month);
int numDaysYear(int year);
int numDaysMonth(int year, int month);
bool isLeapYear(int year);
void display(int year, int month, int offset);
int getDay(int year, int month);
// one event information
class Event
{
public:
Event();
Event(int id, int year, int month, int day, string description);
int getID();
int getYear();
int getMonth();
int getDay();
string getDescription();
private:
int _id;
int _year;//date
int _month;
int _day;
string _description;
};
cout<<"today is "<<t_tm->tm_year+1900<<" "<<t_tm->tm_mon+1<<" "<<t_tm->tm_mday<<endl;
return t_tm;
}
int main()
{
int numDays;
int offset;
int month;
int year;
int day;
tm* currentYearAndMonth = getSystemTime() ;
string filename = "events.txt";
Events events;
month = currentYearAndMonth->tm_mon+1;
year = currentYearAndMonth->tm_year+1900;
offset = computeOffset(year, month);
display(year, month, offset);
char m;
int temp;
string description="";
//string filename;
while(1){
cout<<"please select the operation: "<<endl;
cin>>m;
switch(m){
case 'N' :
if(month == 12) {
year++;
month = 1;
}else{
month++;
}
break;
case 'P' :
if(month == 1) {
year--;
month = 12;
}else{
month--;
}
break;
case 'C' :
month = getMonth(month);
year = getYear(year);
break;
case 'A' :
// To do ...
month = getMonth(month);
year = getYear(year);
day = getDay(year, month);
cout<<"please input the event description: ";
cin>>description;
events.addEvent(year, month, day, description);
break;
case 'L' :
// To do ...
events.displayAllEvents();
break;
case 'D' :
// To do ...
cout<<"please input the event id which you want cancel: ";
cin>>temp;
events.deleteEvent(temp);
break;
case 'S' :
// To do ...
filename = "events.txt";
events.saveEvents(filename);
break;
case 'R' :
// To do ...
break;
case 'Q' :
// To do ...
cout<<"ByeBye~~"<<endl;
return 0;
break;
default:
cout<<"error operation ! !"<<endl;
}
offset = computeOffset(year, month);
cout<<offset<<endl;
display(year, month, offset);
}
return 0;
}
int getMonth(int month)
{
cout << "Enter a month number: ";
cin >> month;
while ( month < 1 || month > 12)
{
cout << "Month must be between 1 and 12.\n"
<< "Enter a month number: ";
cin >> month;
}
while ( year < 1753)
{
cout << "Year must be 1753 or later.\n"
<< "Enter year: ";
cin >> year;
}
return year;
}
int getDay(int year, int month)
{
int day;
cout << "Enter day: ";
cin >> day;
int _numDaysMonth = numDaysMonth(year, month);
while ( day < 1 || month > _numDaysMonth)
{
cout << "day number is invalid.\n"
<< "Enter valid day number: ";
cin >> year;
}
return day;
}
int computeOffset(int year, int month)
{
int offset = 0;
int daysNumToNow = 0;
//int count = year - 1753;
int i;
for( i = 1753 ; i < year ; i++)
if( isLeapYear( i ) )
daysNumToNow += 366 ;
else
daysNumToNow += 365 ;
for( i = 1 ; i < month ; i++ )
daysNumToNow += numDaysMonth( year , i );
int firstDayOfTheMonth = 1;
//now, daysNumToNow is the number of days from 1800 to the year you insert (not including the days of the year)
daysNumToNow += firstDayOfTheMonth - 1 ;
int numDaysYear(int year)
{
int daysYear = 365 + isLeapYear(year);
return daysYear;
}
int numDaysMonth(int year, int month)
{
int daysMonth;
if ( month == 1)
daysMonth = 31;
else if ( month == 2)
{
if (isLeapYear(year) == true)
daysMonth = 29;
else
daysMonth = 28;
}
else if ( month == 3)
daysMonth = 31;
else if ( month == 4)
daysMonth = 30;
else if ( month == 5)
daysMonth = 31;
else if ( month == 6)
daysMonth = 30;
else if ( month == 7)
daysMonth = 31;
else if ( month == 8)
daysMonth = 31;
else if ( month == 9)
daysMonth = 30;
else if ( month == 10)
daysMonth = 31;
else if ( month == 11)
daysMonth = 30;
else if ( month == 12)
daysMonth = 31;
return daysMonth;
}
bool isLeapYear(int year)
{
//if ( year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
if ( (year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return true;
else
return false;
}
void display(int year, int month, int offset)
{
int dayOfWeek;
int day;
cout << 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";
cout << ", " << year << "\n";
// Display month header
cout << " Su Mo Tu We Th Fr Sa\n";
for(int i = 1 ; i <= offset ; i++)
cout<< setw( 4 ) << " " ; //space
// The loop for displaying the days and ending the line in the right place
for ( dayOfWeek = 1; dayOfWeek <= numDaysMonth(year, month); dayOfWeek++ )
{
cout << " " << setw(2) << dayOfWeek;
am using code blocks..what compiler dd u use
126 error: no match function for call to 'std::basic_ofstream<char>::basic_ofstream(std::string, cont openmode&)'