-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtictactoe.cpp
More file actions
96 lines (82 loc) · 2.39 KB
/
Copy pathtictactoe.cpp
File metadata and controls
96 lines (82 loc) · 2.39 KB
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
using namespace std;
#include <iostream>
#include <vector>
struct Task {
string description;
bool completed;
};
void addTask(vector<Task>& tasks, const string& description) {
Task newTask;
newTask.description = description;
newTask.completed = false;
tasks.push_back(newTask);
cout << "Task added successfully!" << endl;
}
void viewTasks(const vector<Task>& tasks) {
if (tasks.empty()) {
cout << "No tasks found." << endl;
return;
}
cout << "Tasks:" << endl;
for (const Task& task : tasks) {
cout << "- " << task.description;
if (task.completed) {
cout << " (completed)";
}
cout << endl;
}
}
void markTaskAsCompleted(vector<Task>& tasks, int index) {
if (index >= 0 && index < tasks.size()) {
tasks[index].completed = true;
cout << "Task marked as completed!" << endl;
} else {
cout << "Invalid task index." << endl;
}
}
void removeTask(vector<Task>& tasks, int index) {
if (index >= 0 && index < tasks.size()) {
tasks.erase(tasks.begin() + index);
cout << "Task removed successfully!" << endl;
} else {
cout << "Invalid task index." << endl;
}
}
int main() {
vector<Task> tasks;
while (true) {
cout << "Choose an option:" <<endl;
cout << "1. Add Task" <<endl;
cout << "2. View Tasks" <<endl;
cout << "3. Mark Task as Completed" <<endl;
cout << "4. Remove Task" <<endl;
cout << "5. Exit" <<endl;
int option;
cin >> option;
if (option == 1) {
cout << "Enter task description: ";
string description;
cin.ignore();
getline(std::cin, description);
addTask(tasks, description);
} else if (option == 2) {
viewTasks(tasks);
} else if (option == 3) {
cout << "Enter task index: ";
int index;
cin >> index;
markTaskAsCompleted(tasks, index);
} else if (option == 4) {
cout << "Enter task index: ";
int index;
cin >> index;
removeTask(tasks, index);
} else if (option == 5) {
break;
} else {
cout << "Invalid option." <<endl;
}
cout <<endl;
}
return 0;
}