Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include<stdlib.h>
- #include<vector>
- std::vector<std::string> notes; // Vector to store notes
- int noteCount = 0;
- void printColor(const std::string& text, const std::string& colorCode) {
- std::cout << colorCode << text << "\033[0m";
- }
- // Add new note
- void addNote() {
- std::string note;
- // Clear any leftover newline characters in the input buffer
- std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- while (true) {
- std::cout << "Enter new note: ";
- std::getline(std::cin, note);
- if (!note.empty()) {
- notes.push_back(note);
- noteCount++;
- std::cout << "Note added.\n";
- break;
- }
- std::cout << "Note cannot be empty. Please try again.\n";
- #ifdef _WIN32
- system("pause");
- system("cls");
- #endif
- }
- }
- // Review all notes
- void reviewNotes() {
- if (noteCount == 0) {
- std::cout << "No notes to show.\n";
- return;
- }
- for (int i = 0; i < notes.size(); i++) {
- printColor(std::to_string(i+1)+"."+notes[i]+"\n", "\033[1;33m");
- //std::cout << i + 1 << ". " << notes[i] << "\n";
- }
- }
- // Edit a note
- void editNote() {
- reviewNotes();
- std::cout << "Enter note number to edit: ";
- int index;
- std::cin >> index;
- if (index < 1 || index > noteCount) {
- std::cout << "Invalid note number.\n";
- return;
- }
- std::cout << "Enter new content: ";
- std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- getline(std::cin, notes[index - 1]);
- std::cout << "Note updated.\n";
- }
- // Delete a note
- void deleteNote() {
- if (noteCount == 0) {
- std::cout << "No notes to delete.\n";
- return;
- }
- reviewNotes();
- std::cout << "Enter note number to delete: ";
- int index;
- std::cin >> index;
- if ( index < 1 || index > noteCount) {
- std::cout << "Invalid note number.\n";
- return;
- }
- notes.erase(notes.begin() + index - 1); // Remove the note from the vector
- noteCount = noteCount - 1;
- std::cout << "Note deleted.\n";
- }
- // Main menu
- int main() {
- int choice;
- //test open if the file exists
- //if not exits, create file and close file
- //open file again
- //read all data from file and save in todos[]
- do {
- system("cls"); // Clear the console
- std::cout << "--- NOTE TAKING APP ---\n";
- std::cout << "1. New Note\n";
- std::cout << "2. Review Notes\n";
- std::cout << "3. Edit Note\n";
- std::cout << "4. Delete Note\n";
- std::cout << "0. Exit\n";
- std::cout << "Choose an option: ";
- std::cin >> choice;
- system("cls"); // Clear the console
- switch (choice) {
- case 1: addNote(); break;
- case 2: reviewNotes(); break;
- case 3: editNote(); break;
- case 4: deleteNote(); break;
- case 0: std::cout << "Goodbye!\n"; break;
- default: std::cout << "Invalid choice.\n"; break;
- }
- system("pause"); // Pause the console to see the output
- } while (choice != 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement