Advertisement
DrAungWinHtut

todo_color.cpp

Jun 4th, 2025
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.19 KB | None | 0 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. void printColor(const std::string& text, const std::string& colorCode) {
  12.     std::cout << colorCode << text << "\033[0m";
  13. }
  14.  
  15. // Add new note
  16. void addNote() {
  17.     std::string note;
  18.     // Clear any leftover newline characters in the input buffer
  19.     std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  20.  
  21.     while (true) {
  22.         std::cout << "Enter new note: ";
  23.         std::getline(std::cin, note);
  24.  
  25.         if (!note.empty()) {
  26.             notes.push_back(note);
  27.             noteCount++;
  28.             std::cout << "Note added.\n";
  29.             break;
  30.         }
  31.         std::cout << "Note cannot be empty. Please try again.\n";
  32.  
  33. #ifdef _WIN32
  34.         system("pause");
  35.         system("cls");
  36. #endif
  37.     }
  38. }
  39.  
  40.  
  41. // Review all notes
  42. void reviewNotes() {
  43.     if (noteCount == 0) {
  44.         std::cout << "No notes to show.\n";
  45.         return;
  46.     }
  47.     for (int i = 0; i < notes.size(); i++) {
  48.         printColor(std::to_string(i+1)+"."+notes[i]+"\n", "\033[1;33m");
  49.         //std::cout << i + 1 << ". " << notes[i] << "\n";
  50.     }
  51. }
  52.  
  53.  
  54.  
  55.  
  56. // Edit a note
  57. void editNote() {
  58.     reviewNotes();
  59.     std::cout << "Enter note number to edit: ";
  60.     int index;
  61.     std::cin >> index;
  62.     if (index < 1 || index > noteCount) {
  63.         std::cout << "Invalid note number.\n";
  64.         return;
  65.     }
  66.     std::cout << "Enter new content: ";
  67.     std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  68.     getline(std::cin, notes[index - 1]);
  69.     std::cout << "Note updated.\n";
  70. }
  71.  
  72.  
  73. // Delete a note
  74. void deleteNote() {
  75.     if (noteCount == 0) {
  76.         std::cout << "No notes to delete.\n";
  77.         return;
  78.     }
  79.     reviewNotes();
  80.     std::cout << "Enter note number to delete: ";
  81.  
  82.     int index;
  83.     std::cin >> index;
  84.  
  85.     if ( index < 1 || index > noteCount) {
  86.         std::cout << "Invalid note number.\n";
  87.         return;
  88.     }
  89.     notes.erase(notes.begin() + index - 1); // Remove the note from the vector
  90.     noteCount = noteCount - 1;
  91.     std::cout << "Note deleted.\n";
  92.  
  93. }
  94.  
  95.  
  96.  
  97. // Main menu
  98. int main() {
  99.     int choice;
  100.     //test open if the file exists
  101.     //if not exits, create file and close file
  102.     //open file again
  103.     //read all data from file and save in todos[]
  104.     do {
  105.         system("cls"); // Clear the console
  106.         std::cout << "--- NOTE TAKING APP ---\n";
  107.         std::cout << "1. New Note\n";
  108.         std::cout << "2. Review Notes\n";
  109.         std::cout << "3. Edit Note\n";
  110.         std::cout << "4. Delete Note\n";
  111.         std::cout << "0. Exit\n";
  112.         std::cout << "Choose an option: ";
  113.         std::cin >> choice;
  114.  
  115.         system("cls"); // Clear the console
  116.         switch (choice) {
  117.         case 1: addNote(); break;
  118.         case 2: reviewNotes(); break;
  119.         case 3: editNote(); break;
  120.         case 4: deleteNote(); break;
  121.         case 0: std::cout << "Goodbye!\n"; break;
  122.         default: std::cout << "Invalid choice.\n"; break;
  123.         }
  124.         system("pause"); // Pause the console to see the output
  125.     } while (choice != 0);
  126.     return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement