Advertisement
DrAungWinHtut

arrayTodo.cpp

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