Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- void addItem(vector<string> &list, string &text);
- void removeItem(vector<string> &list, int size, int &position);
- void updateItem(vector<string> &list, int size, int &item);
- void showItems(vector<string> list, int size);
- void printActionList();
- int main()
- {
- int action = 0;
- string name;
- vector<string> list;
- int list_size = list.size();
- bool running = true;
- int position = 0;
- cout << "Enter your name: ";
- cin >> name;
- cout << "Welcome " << name << "!\n";
- while (running)
- {
- string text;
- printActionList();
- cout << "Enter action: ";
- cin >> action;
- switch (action)
- {
- case 1:
- showItems(list, list_size);
- continue;
- case 2:
- cout << "Enter text: ";
- cin >> text;
- addItem(list, text);
- text = "";
- case 3:
- cout << "Enter position to remove an item: ";
- cin >> position;
- removeItem(list, list_size, position);
- position = 0;
- case 4:
- cout << "Enter position to remove an item: ";
- cin >> position;
- updateItem(list, list_size, position);
- position = 0;
- case 5:
- running = false;
- }
- }
- cout << "Goodbye " << name << "!\n";
- return 0;
- }
- void printActionList()
- {
- cout << "------ ToDo-List manager ------\n\n";
- cout << "1. Show list\n";
- cout << "2. Add list\n";
- cout << "3. Remove list\n";
- cout << "4. Update list\n";
- cout << "5. Exit\n";
- cout << "-------------------------------\n\n";
- }
- void showItems(vector<string> list, int size)
- {
- for (int i = 0; i < size; i++)
- {
- cout << i << ". " << list[i];
- }
- cout << '\n';
- }
- void addItem(vector<string> &list, string &text)
- {
- list.push_back(text);
- }
- void removeItem(vector<string> &list, int size, int &position)
- {
- list.erase(list.begin() + position);
- }
- void updateItem(vector<string> &list, int size, int &item)
- {
- string place_text;
- for (int i = 0; i < size; i++)
- {
- if (i == item)
- {
- printf("Position: %d", i);
- cout << "Enter text: ";
- getline(cin >> ws, place_text);
- list[i] = place_text;
- break;
- }
- else
- {
- cout << "Item not found in the list";
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment