Implement a Simple Task Manager CLI in C++
Create a command-line task manager application that allows users to add, list, complete, and remove tasks stored in memory during the program session.
Challenge prompt
Write a C++ program that manages tasks using a simple command-line interface. The program should support the following commands: add a new task with a description, list all tasks with their status (completed or pending), mark a task as completed by its ID, and remove a task by its ID. Tasks should be stored in an appropriate data structure in memory. The program should keep running until the user types "exit".
Guidance
- • Use a vector or list of structs/classes to store tasks with an ID, description, and completion status.
- • Create a loop to continuously read user input and process commands.
- • Implement functions for each command to keep code organized and modular.
Hints
- • Consider using a struct or class named Task with fields like `id`, `description`, and `completed`.
- • You can assign incremental IDs to new tasks starting from 1 for easier reference.
- • Remember to check if the task ID exists before marking or removing to avoid errors.
Starter code
#include <iostream>
#include <vector>
#include <string>
struct Task {
int id;
std::string description;
bool completed;
};
int main() {
std::vector<Task> tasks;
std::string command;
// Your code here
return 0;
}Expected output
Commands should be handled interactively. Example session: > add Buy groceries Task added with ID 1 > add Finish homework Task added with ID 2 > list 1. [ ] Buy groceries 2. [ ] Finish homework > complete 1 Task 1 marked as completed. > list 1. [x] Buy groceries 2. [ ] Finish homework > remove 2 Task 2 removed. > list 1. [x] Buy groceries > exit Program ends.
Core concepts
Challenge a Friend
Send this duel to someone else and see if they can solve it.