Advertisement
DrAungWinHtut

vector_todo.cpp

May 28th, 2025
608
2
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.61 KB | None | 2 0
  1.  
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include<stdlib.h>
  6. #include<vector>
  7.  
  8. std::vector<std::string> notes; // Vector to store notes
  9. int noteCount = 0;
  10.  
  11. // Add new note
  12. void addNote() {
  13.     std::string note;
  14.     std::cout << "Enter new note: ";
  15.     std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  16.     getline(std::cin, note);
  17.     if (note.empty()) {
  18.         std::cout << "Note cannot be empty.\n";
  19.         return;
  20.     }  
  21.     notes.push_back(note); // Store the note in the vector
  22.     noteCount++;
  23.     std::cout << "Note added.\n";
  24. }
  25.  
  26.  
  27. // Review all notes
  28. void reviewNotes() {
  29.     if (noteCount == 0) {
  30.         std::cout << "No notes to show.\n";
  31.         return;
  32.     }
  33.     for (int i = 0; i < notes.size(); i++) {
  34.         std::cout << i + 1 << ". " << notes[i] << "\n";
  35.     }
  36. }
  37.  
  38.  
  39. // Edit a note
  40. void editNote() {
  41.     reviewNotes();
  42.     std::cout << "Enter note number to edit: ";
  43.     int index;
  44.     std::cin >> index;
  45.     if (index < 1 || index > noteCount) {
  46.         std::cout << "Invalid note number.\n";
  47.         return;
  48.     }
  49.     std::cout << "Enter new content: ";
  50.     std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  51.     getline(std::cin, notes[index - 1]);
  52.     std::cout << "Note updated.\n";
  53. }
  54.  
  55.  
  56. // Delete a note
  57. void deleteNote() {
  58.     if (noteCount == 0) {
  59.         std::cout << "No notes to delete.\n";
  60.         return;
  61.     }
  62.     reviewNotes();
  63.     std::cout << "Enter note number to delete: ";
  64.  
  65.     int index;
  66.     std::cin >> index;
  67.  
  68.     if ( index < 1 || index > noteCount) {
  69.         std::cout << "Invalid note number.\n";
  70.         return;
  71.     }
  72.     notes.erase(notes.begin() + index - 1); // Remove the note from the vector
  73.     noteCount = noteCount - 1;
  74.     std::cout << "Note deleted.\n";
  75.  
  76. }
  77.  
  78.  
  79.  
  80. // Main menu
  81. int main() {
  82.     int choice;
  83.     do {
  84.         system("cls"); // Clear the console
  85.         std::cout << "--- NOTE TAKING APP ---\n";
  86.         std::cout << "1. New Note\n";
  87.         std::cout << "2. Review Notes\n";
  88.         std::cout << "3. Edit Note\n";
  89.         std::cout << "4. Delete Note\n";
  90.         std::cout << "0. Exit\n";
  91.         std::cout << "Choose an option: ";
  92.         std::cin >> choice;
  93.  
  94.         system("cls"); // Clear the console
  95.         switch (choice) {
  96.         case 1: addNote(); break;
  97.         case 2: reviewNotes(); break;
  98.         case 3: editNote(); break;
  99.         case 4: deleteNote(); break;
  100.         case 0: std::cout << "Goodbye!\n"; break;
  101.         default: std::cout << "Invalid choice.\n"; break;
  102.         }
  103.         system("pause"); // Pause the console to see the output
  104.     } while (choice != 0);
  105.     return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement