-
Notifications
You must be signed in to change notification settings - Fork 0
/
notebook.cpp
98 lines (87 loc) · 2.38 KB
/
notebook.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <vector>
#include <string>
#include<algorithm>
using namespace std;
class Note {
public:
Note(const string& title, const string& content)
: title(title), content(content) {}
void display() const {
cout << "Title: " << title << "\nContent: " << content << "\n\n";
}
const string& getTitle() const {
return title;
}
private:
string title;
string content;
};
class Notebook {
public:
void addNote() {
string title, content;
cout << "Enter note title: ";
getline(cin, title);
cout << "Enter note content: ";
getline(cin, content);
notes.push_back(Note(title, content));
cout << "Note added successfully!\n";
}
void viewNotes() const {
if (notes.empty()) {
cout << "No notes available.\n";
} else {
for (const auto& note : notes) {
note.display();
}
}
}
void deleteNote() {
string title;
cout << "Enter the title of the note to delete: ";
getline(cin, title);
auto it = find_if(notes.begin(), notes.end(), [title](const Note& note) {
return note.getTitle() == title;
});
if (it != notes.end()) {
notes.erase(it);
cout << "Note deleted successfully!\n";
} else {
cout << "Note with title '" << title << "' not found.\n";
}
}
private:
vector<Note> notes;
};
int main() {
Notebook notebook;
int choice;
do {
cout << "Notebook Menu:\n";
cout << "1. Add Note\n";
cout << "2. View Notes\n";
cout << "3. Delete Note\n";
cout << "4. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
cin.ignore();
switch (choice) {
case 1:
notebook.addNote();
break;
case 2:
notebook.viewNotes();
break;
case 3:
notebook.deleteNote();
break;
case 4:
cout << "Exiting the notebook. Goodbye!\n";
break;
default:
cout << "Invalid choice. Please try again.\n";
}
} while (choice != 4);
return 0;
}