Objective:
The purpose of this program is to create a simple calendar application using C++ to manage and view events. The calendar allows users to add events for specific dates and view those events later. This application is ideal for learning basic file handling, user input processing, and time manipulation in C++.
Code:
#include
#include
#include
#include
Explanation of Program Structure:
This program is structured into a class CalendarApp
which handles all the functionalities of the calendar. The key methods are:
- formatDate(int day, int month, int year): Converts the date into a string format “DD-MM-YYYY”.
- loadEvents(): Loads existing events from the “events.txt” file.
- saveEvents(): Saves the current events to the “events.txt” file.
- addEvent(int day, int month, int year, const string& event): Adds a new event for a specific date.
- viewEvent(int day, int month, int year): Displays the event for a specific date.
How to Run the Program:
- Open a text editor and copy the code into a new file named calendar.cpp.
- Ensure you have a C++ compiler installed (such as GCC or MinGW).
- Compile the code using the following command:
g++ calendar.cpp -o calendar
- Run the compiled program using:
./calendar
- Follow the on-screen prompts to add and view events.