-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment_6.cpp
More file actions
209 lines (173 loc) · 5.49 KB
/
Copy pathAssignment_6.cpp
File metadata and controls
209 lines (173 loc) · 5.49 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
2/28/2023
A multi-file project in with a templated linked list which is used to create a
simple list of composers
*/
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include "Composers.h"
#include "LinkedList.h"
#include "Node.h"
using namespace std;
int main() {
LinkedList<Composer> composers;
ifstream inFile("composers.txt");
char input;
string name;
Composer newComposer;
if (inFile) {
string line;
while (getline(inFile, line)) {
size_t commaPos = line.find(',');
if (commaPos != string::npos) {
string name = line.substr(0, commaPos);
int year = stoi(line.substr(commaPos + 2));
composers.append(Composer(name, year));
}
}
composers.sortByDate();
cout << "Enter 's' to search, 'r' to remove, 'd' to display, or 'e' to "
"exit: ";
cin >> input;
cin.ignore();
while (input != 'e') {
switch (input) {
case 's':
cout << "Enter a composer's name to search for: ";
getline(cin, name);
newComposer.setName(name);
if (composers.find(newComposer)) {
cout << "\n"
<< "\t" << newComposer.getName()
<< " was found in the list\n\n";
}
else {
cout << "\n"
<< "\t" << newComposer.getName()
<< " was not found in the list\n\n";
}
break;
case 'r':
cout << "Enter a composer's name to remove: ";
getline(cin, name);
newComposer.setName(name);
if (composers.remove(newComposer)) {
cout << "\n"
<< "\t" << newComposer.getName()
<< " was successfully removed from the list\n\n";
}
else {
cout << "\n"
<< "\t" << newComposer.getName()
<< " was not found in the list when attempting to "
"remove\n\n";
}
break;
case 'd':
cout << "\n ";
composers.printList();
break;
case 'e':
break;
}
cout << "Enter 's' to search, 'r' to remove, 'd' to display, or "
"'e' to exit: ";
cin >> input;
cin.ignore();
}
inFile.close();
}
else {
cout << "Cannot open file.\n";
}
return 0;
}
/*
Enter 's' to search, 'r' to remove, 'd' to display, or 'e' to exit: d
Claudio Monteverdi, 1643
Henry Purcell, 1695
Antonio Vivaldi, 1741
Johann Sebastian Bach, 1750
George Frideric Handel, 1759
Wolfgang Amadeus Mozart, 1791
Joseph Haydn, 1809
Ludwig van Beethoven, 1827
Franz Schubert, 1828
Felix Mendelssohn, 1847
Frederic Chopin, 1849
Robert Schumann, 1856
Hector Berlioz, 1869
Richard Wagner, 1883
Franz Liszt, 1886
Pyotr Ilyich Tchaikovsky, 1893
Johannes Brahms, 1897
Giuseppe Verdi, 1901
Antonin Dvorak, 1904
Edvard Grieg, 1907
Gustav Mahler, 1911
Claude Debussy, 1918
Camille Saint-Saens, 1921
Giacomo Puccini, 1924
Maurice Ravel, 1937
George Gershwin, 1937
Sergei Rachmaninoff, 1943
Bela Bartok, 1945
Arnold Schoenberg, 1951
Sergei Prokofiev, 1953
Igor Stravinsky, 1971
Dmitri Shostakovich, 1975
Aaron Copland, 1990
Leonard Bernstein, 1990
Enter 's' to search, 'r' to remove, 'd' to display, or 'e' to exit: s
Enter a composer's name to search for: Franz Liszt
Franz Liszt was found in the list
Enter 's' to search, 'r' to remove, 'd' to display, or 'e' to exit: s
Enter a composer's name to search for: Hanz Zimmer
Hanz Zimmer was not found in the list
Enter 's' to search, 'r' to remove, 'd' to display, or 'e' to exit: r
Enter a composer's name to remove: Camille Saint-Saens
Camille Saint-Saens was successfully removed from the list
Enter 's' to search, 'r' to remove, 'd' to display, or 'e' to exit: r
Enter a composer's name to remove: CPE Bach
CPE Bach was not found in the list when attempting to remove
Enter 's' to search, 'r' to remove, 'd' to display, or 'e' to exit: d
Claudio Monteverdi, 1643
Henry Purcell, 1695
Antonio Vivaldi, 1741
Johann Sebastian Bach, 1750
George Frideric Handel, 1759
Wolfgang Amadeus Mozart, 1791
Joseph Haydn, 1809
Ludwig van Beethoven, 1827
Franz Schubert, 1828
Felix Mendelssohn, 1847
Frederic Chopin, 1849
Robert Schumann, 1856
Hector Berlioz, 1869
Richard Wagner, 1883
Franz Liszt, 1886
Pyotr Ilyich Tchaikovsky, 1893
Johannes Brahms, 1897
Giuseppe Verdi, 1901
Antonin Dvorak, 1904
Edvard Grieg, 1907
Gustav Mahler, 1911
Claude Debussy, 1918
Giacomo Puccini, 1924
Maurice Ravel, 1937
George Gershwin, 1937
Sergei Rachmaninoff, 1943
Bela Bartok, 1945
Arnold Schoenberg, 1951
Sergei Prokofiev, 1953
Igor Stravinsky, 1971
Dmitri Shostakovich, 1975
Aaron Copland, 1990
Leonard Bernstein, 1990
Enter 's' to search, 'r' to remove, 'd' to display, or 'e' to exit: e
Press any key to close this window . . .
*/