iView AD's Calendar With To-Do using C++

Made using Dev-C++!! Updated Periodically!! 

Source Code:



#include<iostream> #include<ctime> #include<time.h> #include<cstdlib> #include<iomanip> #include<string.h> #include<fstream> #include<cstdio> #include<conio.h> #include <iomanip> using namespace std; /***********************************************************************************/ int y; time_t t = time(NULL); tm* timePtr = localtime(&t); /***********************************************************************************/ class calender { public: bool isLeapYear (int); //To check for leap years int firstDayofnewyearMonth (int ); //To Check 1st day of jan year int numOfDaysInMonth (int, bool); //takes the number of the month, a flag saying whether year is leap void printHeader (int); //takes the number of the month, and the first day, prints, and updates void printMonth (int, int&); //the first day of the next month void skip (int); //prints the specified amount of spaces void skipToDay (int); //prints leading spaces in monthly calendar void Quit(); //terminates program in case of unrecoverable errors void opt(); //Calendar Menu void runyear(int); //Run the system Year void ListOpt1(); //To Do List option void ListSearch(); //Search void ListInput(); //insert string date,event; }; /***********************************************************************************/ class monthlyCal { public: 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); void opt12(); }; /***********************************************************************************/ class interfaces:public calender,public monthlyCal { public : int op=0; char date[9]; void interface() { cout<<"\t\t\tWelcome to iView AD's Calender"<<endl; cout<<"\t\t\t______________________________\n\n"; dashboard(); } void choose() { while(op!=4) { cout<<" 1.Calender\t2.To-Do List\t3.DashBoard\t4.Exit\n\t"; cout<<"\n\n Enter your Choice:"; cin>>op; switch (op) { case 1: opt(); break; case 2: ListOpt1(); break; case 3: system("cls"); dashboard(); break; case 4: system("cls"); Quit(); default : system("cls"); cout<<"Choose Correct Option Please!!\n\n"; break; } } } void dashboard() { cout<<" Your DashBoard"<<endl; cout<<" ______________\n\n\n"; /********* Today ********/ _strdate(date); cout <<" Today : "<<date<<endl; cout<<"\n\n\n Month's Calender : "; opt12(); cout<<"\n\n\ Press enter to Menu"; getch(); system("CLS"); choose(); } }; ////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////// Yearly CaL /////////////////////////////////////////////////////////////////////////////////////////////////////// void calender::opt() { int op=1,year; runyear(y); while(op!=4) { cout<<" 1.Next Year"<<endl<<" 2.Last Year"<<endl<<" 3.Random Year"<<endl;
cout<<" 4.Back"; cout<<"\n Enter your choice:"; cin>>op; switch(op) { case 1: system("cls"); runyear(++y); break; case 2: system("cls"); runyear(--y); break; case 3: system("cls"); cout<<" Enter Year : "; cin >>year; cout<<endl; runyear(year); break; case 4: system("cls"); return; default: system("cls"); cout<<"Choose Correct Option Please!!\n\n"; break; } } } /***********************************************************************************/ void calender::runyear (int year=y) { int firstDayInCurrentMonth; int currentMonth = 1; int numDays; bool leap; firstDayInCurrentMonth=firstDayofnewyearMonth(year); leap=isLeapYear(year); skip(9); cout<<year<<endl; while (currentMonth <= 12) { numDays = numOfDaysInMonth(currentMonth, leap); printHeader(currentMonth); printMonth(numDays, firstDayInCurrentMonth); cout<<endl<<endl<<endl; currentMonth = currentMonth + 1; } cout<<endl; } /***********************************************************************************/ bool calender::isLeapYear(int year) { return ((year%4==0) && (year%100 !=0))||(year%400==0); } /***********************************************************************************/ int calender::firstDayofnewyearMonth(int year) { int day_start; int x1,x2,x3; x1=(year-1)/4; x2=(year-1)/100; x3=(year-1)/400; day_start=(year+x1-x2+x3)%7; return day_start; } /***********************************************************************************/ int calender::numOfDaysInMonth (int m, bool leap) { if (m == 1) return(31); else if (m == 2) if (leap) return(29);else return(28); else if (m == 3) return(31); else if (m == 4) return(30); else if (m == 5) return(31); else if (m == 6) return(30); else if (m == 7) return(31); else if (m == 8) return(31); else if (m == 9) return(30); else if (m == 10) return(31); else if (m == 11) return(30); else if (m == 12) return(31); else Quit(); } /***********************************************************************************/ void calender::printHeader (int m) { if (m == 1) { skip(7); cout << "January" << endl; } else if (m == 2) { skip(7); cout << "February" << endl; } else if (m == 3) { skip(7); cout << "March" << endl; } else if (m == 4) { skip(7); cout << "April" << endl; } else if (m == 5) { skip(7); cout << "May" << endl; } else if (m == 6) { skip(7); cout << "June" << endl; } else if (m == 7) { skip(7); cout << "July" << endl; } else if (m == 8) { skip(7); cout << "August" << endl; } else if (m == 9) { skip(7); cout << "September" << endl; } else if (m == 10) { skip(7); cout << "October" << endl; } else if (m == 11) { skip(7); cout << "November" << endl; } else if (m == 12) { skip(7); cout << "December" << endl; } else Quit(); cout << " S M T W T F S" <<endl; cout << "____________________" << endl; } /***********************************************************************************/ void calender::skip (int i) { while (i > 0) { cout << " "; i = i - 1; } } /***********************************************************************************/ void calender::printMonth (int numDays, int &weekDay) { int day = 1; skipToDay(weekDay); while (day <= numDays) { cout << setw(2) << day << " "; if (weekDay == 6) { cout << endl; weekDay = 0; } else weekDay = weekDay + 1; day = day + 1; } } /***********************************************************************************/ void calender::skipToDay(int d) { return skip(3*d); } /***********************************************************************************/ void calender::Quit () { cout<<"\tThanks For iView-ing!!\n\t\tExiting"<<endl; getch(); exit(-1); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// TO DO LIST ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// void calender::ListOpt1() { int choice; system("CLS"); cout<<" 1.Add Event"<<endl; cout<<" 2.Search Events"<<endl; cout<<" 3.Back"<<endl; cin>>choice; switch (choice) { case 1: ListInput(); break; case 2: ListSearch(); break; case 3: system("cls"); break; default: system("cls"); cout<<"Choose Correct Option Please!!\n\n"; break; } } /***********************************************************************************/ void calender::ListInput() { int n = 1; int option = 0; int i=0; ofstream file; while(1) { cout<<" Enter the Date [dd/mm/yy] :" << endl; cin>>date; system("cls"); for(int i=0;i<n;i++) { cout<<" Enter the Agenda:"<<endl; cin>>event; cin.sync(); file.open("list.txt",ios::app); for(int i=0;i<n;i++) { file<<date<<" "<<event; file.close(); system("cls"); cout<<" The file is saved"<<endl; } } ListOpt1(); } } /***********************************************************************************/ void calender::ListSearch() { ifstream file("list.txt"); int n=1; char dattta[20]; char datee[8]; char str[8]; int i=0; system("CLS"); cout<<" Enter the Date [dd/mm/yy]: "; cin>>str; for(int i=0;i<n;i++) { while(1) { file.read((char*)&dattta,20); file.read((char*)&datee,8); if(strcmp(str,datee)) { system ("CLS"); cout<<" Event found!!"<<endl; cout<<" Date"<<" "<< "Event"<<endl; cout<<" _______________________"<<endl; cout<<" "<<dattta; getch(); ListOpt1(); } else { cout<<" Please Create Event First!! "<<endl; cout<<" Do you want to create event now? "<<endl; cout<<" [y]es\t\t\t[n]o"<<endl; char abc; cin>>abc; if(abc=='y') { ListInput(); } else ListOpt1(); return; } } } } ////////////////////////////////////////////////////////////////////////////////////////////////////////// // MONTHLY CALENDAR ////////////////////////////////////////////////////////////////////////////////////////////////////////// /*********************************************************************** * Gets the month number. **********************************************************************/ int monthlyCal::getMonth(int month) { month=(timePtr->tm_mon)+1; return month; } /*********************************************************************** * Gets the year. **********************************************************************/ int monthlyCal::getYear(int year) { year=(timePtr->tm_year)+1900; return year; } /*********************************************************************** * Computes the offset. **********************************************************************/ int monthlyCal::computeOffset(int year, int month) { int offset=3; int count=year-1753; for ( int iYear = 0; iYear < count; iYear++) { offset = ( offset + 365 + isLeapYear(year)) % 7; } for ( int iMonth = 1; iMonth < month; iMonth++) { offset = ( offset + numDaysMonth(year, iMonth)) % 7; } return offset; } /*********************************************************************** * Computes the number of days in the given year. **********************************************************************/ int monthlyCal::numDaysYear(int year) { int daysYear = 365 + isLeapYear(year); return daysYear; } /*********************************************************************** * Calculates the number of days in the given month. **********************************************************************/ int monthlyCal::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; } /*********************************************************************** * Determines if given year is a leap year. **********************************************************************/ bool monthlyCal::isLeapYear(int year) { if ( year % 4 == 0 || year % 100 == 0 || year % 400 == 0) return true; else return false; } /********************************************************************** * Displays the calender table. **********************************************************************/ void monthlyCal::display(int year, int month, int offset) { int dayOfWeek; int day; 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\n"; // Display month header cout<<" S M T W T F S \n"; cout<<" __________________________\n" << endl; // Gets the correct offset width and end the line on the right //day of the week if (offset == 0) { day = 2; cout << setw(6); } else if (offset == 1) { day = 3; cout << setw(10); } else if (offset == 2) { day = 4; cout << setw(14); } else if (offset == 3) { day = 5; cout << setw(18); } else if (offset == 4) { day = 6; cout << setw(22); } else if (offset == 5) { day = 7; cout << setw(26); } else if (offset == 6) { day = 1; cout << setw(2); } else cout << "Error offset must be >= 0 and <=6\n"; // 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; ++day; if (day == 8) { cout << "\n"; day = 1; } } if(day >= 2 && day<= 7) cout<<"\n"; return; } /*****************************************************************************/ void monthlyCal::opt12() { int numDays; int offset; int month; int year; month=getMonth(month); year=getYear(year); offset=computeOffset(year, month); display(year,month,offset); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //// INT MAIN /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int main() { system ("color f1");
time_t t = time(NULL);
tm* timePtr = localtime(&t);
y = timePtr->tm_year+1900 ;
interfaces i; i.interface(); }



Outputs

  • DashBoard


  • Menu Page


  • Yearly Calendar:

    1. Present Year


    2. Random Year


    3. Menu Option


  • To-Do List:

    1. Add Event


    2. Search Event

    3. To-Do List Menu

  • Exit



Comments

Popular posts from this blog

To implement the various components of HTML5 Canvas

Program to illustrate the concept of templates.

Program to illustrate the order of execution of constructors and destructors in inheritance.