cplusplus
cplusplus

 

Introduction

Task reminder applications are useful tools for keeping track of tasks and ensuring that important activities are not forgotten. By building a task reminder application in C++, users can easily manage and get notified of their upcoming tasks, which can help improve productivity and organization.

Objective

The goal of this tutorial is to guide you in creating a simple task reminder application in C++. This application will allow users to add tasks, set reminders, and display the task list. It will make use of basic concepts such as loops, conditionals, and file handling in C++.

Code for Task Reminder Application

#include 
#include 
#include 
#include 
#include 

using namespace std;

// Structure to store task details
struct Task {
    string name;
    string date;
    string time;
};

// Function to display the menu
void showMenu() {
    cout << "\nTask Reminder Application\n";
    cout << "1. Add a new task\n";
    cout << "2. View tasks\n";
    cout << "3. Exit\n";
    cout << "Enter your choice: ";
}

// Function to add a new task
void addTask(vector& tasks) {
    Task newTask;
    cout << "\nEnter task name: ";
    cin.ignore();
    getline(cin, newTask.name);
    cout << "Enter task date (DD-MM-YYYY): "; cin >> newTask.date;
    cout << "Enter task time (HH:MM): "; cin >> newTask.time;

    tasks.push_back(newTask);
    ofstream outFile("tasks.txt", ios::app);
    if (outFile.is_open()) {
        outFile << newTask.name << ";" << newTask.date << ";" << newTask.time << "\n";
        outFile.close();
        cout << "Task added successfully!\n";
    } else {
        cout << "Error opening file to save the task.\n";
    }
}

// Function to display all tasks
void viewTasks(const vector& tasks) {
    cout << "\nTask List:\n";
    for (const auto& task : tasks) {
        cout << "Task: " << task.name << "\n";
        cout << "Date: " << task.date << " Time: " << task.time << "\n";
        cout << "--------------------------\n";
    }
}

// Function to load tasks from file
void loadTasks(vector& tasks) {
    ifstream inFile("tasks.txt");
    string line;
    while (getline(inFile, line)) {
        Task task;
        size_t pos = 0;
        pos = line.find(';');
        task.name = line.substr(0, pos);
        line.erase(0, pos + 1);

        pos = line.find(';');
        task.date = line.substr(0, pos);
        task.time = line.substr(pos + 1);

        tasks.push_back(task);
    }
    inFile.close();
}

int main() {
    vector tasks;
    loadTasks(tasks); // Load existing tasks from file

    int choice;
    while (true) {
        showMenu();
        cin >> choice;
        switch (choice) {
            case 1:
                addTask(tasks);
                break;
            case 2:
                viewTasks(tasks);
                break;
            case 3:
                cout << "Exiting the application.\n";
                return 0;
            default:
                cout << "Invalid choice. Please try again.\n";
        }
    }

    return 0;
}

Program Explanation

This task reminder application is designed to manage and store tasks in a text file. Let’s break down the structure:

  • Task Structure: The Task structure holds the task’s name, date, and time, which are essential to creating a reminder.
  • Menu System: The program displays a simple text-based menu allowing the user to either add a task, view existing tasks, or exit the application.
  • Add Task: The user can input the name, date, and time of the task, which is then saved both in memory and in a text file (“tasks.txt”).
  • View Tasks: All tasks stored in memory are displayed with their respective details (name, date, and time).
  • File Handling: Tasks are saved to and loaded from a text file for persistence. This ensures that even if the program is closed, tasks are not lost.

How to Run the Program

To run the program, follow these steps:

  1. Ensure you have a C++ compiler installed (such as GCC or Visual C++).
  2. Create a new C++ source file and paste the above code into the file (e.g., task_reminder.cpp).
  3. Compile the program using the following command (for GCC):
    g++ task_reminder.cpp -o task_reminder
  4. Run the compiled program with the following command:
    ./task_reminder
  5. Follow the menu to add or view tasks.
© 2025 Learn Programming. All rights reserved.

 

By Aditya Bhuyan

I work as a cloud specialist. In addition to being an architect and SRE specialist, I work as a cloud engineer and developer. I have assisted my clients in converting their antiquated programmes into contemporary microservices that operate on various cloud computing platforms such as AWS, GCP, Azure, or VMware Tanzu, as well as orchestration systems such as Docker Swarm or Kubernetes. For over twenty years, I have been employed in the IT sector as a Java developer, J2EE architect, scrum master, and instructor. I write about Cloud Native and Cloud often. Bangalore, India is where my family and I call home. I maintain my physical and mental fitness by doing a lot of yoga and meditation.

Leave a Reply

Your email address will not be published. Required fields are marked *

error

Enjoy this blog? Please spread the word :)