#include <iostream>
#include<string>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
struct Task {
string title;
string description;
string dueDate;
int priority;
bool isComplete;
};
vector<Task> tasks;
void displayMenu() {
cout << "Task Scheduler Menu:" << endl;
cout << "1. Add Task" << endl;
cout << "2. View Tasks" << endl;
cout << "3. Mark Task as Complete" << endl;
cout << "4. Exit" << endl;
}
bool sortByDueDate(const Task& a, const Task& b) {
return a.dueDate < b.dueDate;
}
bool sortByPriority(const Task& a, const Task& b) {
return a.priority > b.priority;
}
void addTask() {
Task newTask;
cout << "Enter task title: ";
getline(cin, newTask.title);
cout << "Enter task description: ";
getline(cin, newTask.description);
cout << "Enter due date (YYYY-MM-DD): ";
getline(cin, newTask.dueDate);
cout << "Enter priority (1-5, where 5 is highest priority): ";
cin >> newTask.priority;
newTask.isComplete = false;
tasks.push_back(newTask);
cin.ignore(); // Clear the newline character from the buffer
}
void viewTasks() {
if (tasks.empty()) {
cout << "No tasks available." << endl;
return;
}
cout << left << setw(20) << "Title" << setw(30) << "Description" << setw(15) << "Due Date" << setw(10) <<
"Priority" << setw(15) << "Status" << endl;
cout << string(90, '-') << endl;
sort(tasks.begin(), tasks.end(), sortByDueDate);
for (const auto& task : tasks) {
cout << left << setw(20) << task.title << setw(30) << task.description << setw(15) << task.dueDate << setw(10) <<
task.priority << setw(15) << (task.isComplete ? "Complete" : "Incomplete") << endl;
}
}
void markTaskComplete() {
int index;
cout << "Enter the index of the task to mark as complete: ";
cin >> index;
if (index >= 0 && index < tasks.size()) {
tasks[index].isComplete = true;
cout << "Task marked as complete." << endl;
}
else {
cout << "Invalid index." << endl;
}
}
int main() {
int choice;
do {
displayMenu();
cout << "Enter your choice (1-4): ";
cin >> choice;
cin.ignore(); // Clear the newline character from the buffer
switch (choice) {
case 1:
addTask();
break;
case 2:
viewTasks();
break;
case 3:
markTaskComplete();
break;
case 4:
cout << "Exiting Task Scheduler. Goodbye!" << endl;
break;
default:
cout << "Invalid choice. Please enter a number between 1 and 4." << endl;
}
} while (choice != 4);
return 0;
}