//Program for Calendar of 700 years(1700-2400) #include<iostream> #include<conio.h> #include <ctime> #include<Windows.h> using namespace std; void heading(char ch, int i) { int j; for (j = 0; j <= i; j++) cout << ch; } void Start_up() { char ch[30] = "Wellcome to 131362 Project\n"; cout << "\t\t\t"; for (int i = 0; i < 30; i++) { Sleep(150); cout << ch[i]; } for (int i = 0; i <= 79; i++) { Sleep(30); cout << "\xDB"; } system("cls"); } class calender { private: int date, month,year; public: calender(int d = 1, int m = 1, int y = 1700) // constructor { date = d; month = m; year = y; } void day(int); // name of a specific day void monthcal(int,int); // for printing specific month's calender bool leapyear(int); // condition for leapyear int DaysInMonth(int,int); // number of days in each month int DayNumber(int,int,int); // total number of days passed from January 1, 1583 to current day. }; bool calender :: leapyear(int y) { bool Leap; if ((y % 4 == 0) && ((y % 100 != 0) || (y % 400 == 0))) Leap = true; else Leap = false; return Leap; } int calender :: DaysInMonth(int m, int y) // m is the month number (1,2,3,...12), y is the year number (four digits) { switch (m) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 2: if (leapyear(y)) return 29; else return 28; default: return 30; } } int calender :: DayNumber(int d, int m, int y) { int i; int dow = 6; for (i = 1583; i<y; i++) // In the Gregorian Calendar, January 1, 1583, was a Saturday, so we will start with 6 { dow += (leapyear(i)) ? 2 : 1; dow+=364; } for (i = 1; i<m; i++) dow += DaysInMonth(i, y); dow += d; return dow; } void calender::day(int a) { switch (a) { case 1: cout << "Monday"; break; case 2: cout << "Tuesday"; break; case 3: cout << "Wednesday"; break; case 4: cout << "Thursday"; break; case 5: cout << "Friday"; break; case 6: cout << "Saturday"; break; case 0: cout << "Sunday"; break; default: cout << "\a\a\a\n\nERROR!!!"; //Exceptional cases and bugs if present } } void calender::monthcal(int month, int year) { int j, mon, c; j = 0; for (j = 0; j <= 6; j++) // For printing 7 days of week { day(j); cout << " "; } j = 1; c = DayNumber(--j, month, year); c=c%7; cout << "\n"; switch (c) //position of 1st date of month { case 0: break; case 1: cout << "\t"; break; case 2: cout << "\t\t"; break; case 3: cout << "\t\t\t"; break; case 4: cout << "\t\t\t\t"; break; case 5: cout << "\t\t\t\t\t"; break; case 6: cout << "\t\t\t\t\t\t"; } mon = DaysInMonth(month, year); for (j = 1; j <= mon; j++) //Printing the month's calendar { cout << " " << j << "\t"; c++; if (!(c % 7)) cout << "\n"; } } int main() { int x,y,z; system("color 5f"); // Start_up(); char ch; char t = '\xCD'; do { system("cls"); // clrscr(); int i, date, year, month; heading(t, 79); cout << "\t\t\tCalendar of 700 years(1700-2400)\n"; heading(t, 79); cout << "\nEnter 1 for knowing the day of a specific date\nEnter 2 to view the calendar of any given month\nEnter 3 to calculate your age "; cin >> i; if (i == 1) //OPTION 1 { cout << "Enter date:(dd)"; cin >> date; if (date>31 || date<1) //Condition for ambiguous date as input { cout << "\nPlease provide valid date.\t Press any key"; getch(); system("cls"); main(); } month: cout << "Enter month:(mm)"; cin >> month; if (month>12 || month<1) //Condition for ambiguous month as input { cout << "\nPlease provide valid month.\t Press any key"; getch(); goto month; } year: cout << "Enter year:(yyyy)"; cin >> year; if (year>2400 || year<1700) //Condition for ambiguous month as input { cout << "\nPlease enter year within given range (1700 - 2400 ).\t Press any key"; getch(); goto year; } calender obj(date, month, year); i = obj.DayNumber(--date, month, year); cout << "\n" << ++date << "/" << month << "/" << year << " is "; i=i%7; obj.day(i); // for printing the day name } else if (i == 2) //OPTION 2 { cout << "Enter month:(mm)"; cin >> month; month2: if (month>12 || month<1) //Condition for ambiguous month as input { cout << "\nPlease provide valid month.\t Press any key"; getch(); goto month2; } cout << "Enter year:(yyyy)"; cin >> year; year2: if (year>2400 || year<1700) //Condition for ambiguous month as input { cout << "\nPlease enter year within given range (1700 - 2400 ).\t Press any key"; getch(); goto year2; } calender obj; obj.monthcal(month, year); } else if (i == 3) { cout<<"Enter your date of Birth:\n"; cout << "Day:(dd)"; cin >> date; if (date>31 || date<1) //Condition for ambiguous date as input { cout << "\nPlease provide valid date.\t Press any key"; getch(); system("cls"); main(); } month3: cout << "Month:(mm)"; cin >> month; if (month>12 || month<1) //Condition for ambiguous month as input { cout << "\nPlease provide valid month.\t Press any key"; getch(); goto month3; } year3: cout << "Year:(yyyy)"; cin >> year; if (year>2014 || year<1900) //Condition for ambiguous month as input { cout << "\nPlease enter year within given range (1900 - 2014 ).\t Press any key"; getch(); goto year3; } long int p; calender dob(date, month, year); p = dob.DayNumber(date, month, year); // current date calculation time_t t = time(0); // get time now struct tm *now = localtime( &t ); date = now->tm_mday; //day month = (now->tm_mon +1 );//month year =(now->tm_year +1900 );//year long int q; calender cur(date, month, year); q = cur.DayNumber(date, month, year); int my_y = (q-p)/365; int my_m = ((q-p)%365)/30; int my_d = ((q-p)%365)%30; cout<<"Your age is "<<my_y<<" years "<<my_m<<" months and "<<my_d<<" days.\n"; } cout << "\nWould you like to try again (y/n)"; ch = _getch(); } while (ch == 'y' || ch == 'Y'); return 0; }
//Program for Calendar of 700 years(1700-2400)
Post A Comment:
0 comments: