Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include<stdlib.h>
- const int MAX_NOTES = 100;//array size
- std::string notes[MAX_NOTES];// array data type declare
- int noteCount = 0;
- // Add new note
- void addNote() {
- if (noteCount >= MAX_NOTES) {
- std::cout << "Note limit reached!\n";
- return;
- }
- std::cout << "Enter new note: ";
- std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- getline(std::cin, notes[noteCount]);
- noteCount++;
- std::cout << "Note added.\n";
- }
- // Review all notes
- void reviewNotes() {
- if (noteCount == 0) {
- std::cout << "No notes to show.\n";
- return;
- }
- for (int i = 0; i < noteCount; i++) {
- 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;
- }
- for (int i = 0; i < noteCount; i++) {
- if (i >= index - 1) {
- notes[i] = notes[i + 1];
- }
- }
- noteCount = noteCount - 1;
- std::cout << "Note deleted.\n";
- }
- // Main menu
- int main() {
- int choice;
- 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