-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask4.cpp
99 lines (96 loc) · 2.65 KB
/
task4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// C++ program TO-DO LIST
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct Task
{
string description;
bool completed;
};
void displayTasks(const vector<Task> &tasks)
{
cout << "To-Do List: \n";
for (size_t i = 0; i < tasks.size(); i++)
{
cout << i + 1 << ". [" << (tasks[i].completed ? "X" : " ") << "]" << tasks[i].description << endl;
}
}
int main()
{
vector<Task> tasks;
int choice;
cout << "Simple To-Do List Manager\n";
while (1)
{
cout << "\n Options: \n";
cout << "1. Add Task\n";
cout << "2. View Tasks\n";
cout << "3. Mark Task as Completed\n";
cout << "4. Remove Task\n";
cout << "5. Exit\n";
cout << "Enter your choice: ";
//code for doing operation
cin >> choice;
if (choice == 1)
{
Task newTask;
cout << "Enter task description: ";
cin.ignore();
getline(cin, newTask.description);
newTask.completed = false;
tasks.push_back(newTask);
cout << "Task added!\n";
}
else if (choice == 2)
{
if (tasks.empty())
{
cout << "No tasks to display.\n";
}
else
{
displayTasks(tasks);
}
}
else if (choice == 3)
{
int taskIndex;
cout << "Enter the index of the task to mark as completed: \n";
cin >> taskIndex;
if (taskIndex >= 1 && taskIndex <= static_cast<int>(tasks.size()))
{
tasks[taskIndex - 1].completed = true;
cout << "Task marked as completed!\n";
}
else
{
cout << "Invalid task index.\n";
}
}
else if (choice == 4)
{
int taskIndex;
cout << "Enter te index of the task to remove: \n";
cin >> taskIndex;
if (taskIndex >= 1 && taskIndex <= static_cast<int>(tasks.size()))
{
tasks.erase(tasks.begin() + taskIndex - 1);
cout << "Task removed!\n";
}
else
{
cout << "Invalid task index.\n";
}
}
else if (choice == 5)
{
cout << "Exiting the program.\n";
break;
}
else
{
cout << "Invalid choice. Please choose a valid option.\n";
}
} // end of while loop
return 0;
} // end of main