-
Notifications
You must be signed in to change notification settings - Fork 0
/
TO-DOLIST.cpp
81 lines (71 loc) · 2.26 KB
/
TO-DOLIST.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
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <istream>
enum Operations{
REMOVE = 1,
ADD,
SHOW,
QUIT
};
void parameters(){
std::cout << std::setw(150) << std::right << "TO-DO LIST" << std::endl;
std::cout << "1. Remove Item\n2.Add Item \n3.Display Item \n4.Quit" << std::endl;
}
//TODO, ADD Task priorities
void AddTask(std::string task, std::vector<std::string>& items);
void RemoveTask(std::string task, std::vector<std::string>& items);
int main(){
std::vector<std::string> tasks;
bool flag = true;
parameters();
while(flag){
int choice = 0;
int pause = 1;
std::string some_item; //next time, don't init variables in switch statement
std::cout << "What would you like to do? : ";
std::cin >> choice;
std::cin.ignore();
std::string move;
switch(choice){
case REMOVE:
RemoveTask(some_item, tasks);
system("cls");
parameters();
break;
case ADD:
std::cout << "\nInput your new task: ";
std::getline(std::cin,some_item);//you don't have to worry about clearing string
AddTask(some_item,tasks);
system("cls");
parameters();
break;
case SHOW:
for(int i = 0; i <tasks.size(); ++i){
std::cout << i+1<<"." << tasks[i] << std::endl;
}
std::cout << "Press enter when done." << std::endl;
std::cin >> move;
if(move == '\n'){
system("cls");
parameters();
}
break;
case QUIT:
flag = false;
break;
default:
std::cerr << "Invalid Input";
}
}
}
void AddTask(std::string task, std::vector<std::string>& items){
items.push_back(task);
}
void RemoveTask(std::string task, std::vector<std::string>& items) {
auto it = std::find(items.begin(), items.end(), task);
if (it != items.end()) {
items.erase(it);
}
}