COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
cp9.1list.cpp
Go to the documentation of this file.
1
#include <iostream>
2
#include <string>
3
#include <list>
4
using namespace
std;
5
6
class
student
{
7
public
:
8
string
name
;
9
string
major
;
10
int
number
;
11
};
12
13
int
main
() {
14
string
input;
15
list<student> record;
16
while
(
true
) {
17
cin >> input;
18
student
temp;
19
if
(input ==
"Add"
) {
20
cin >> temp.
name
>> temp.
major
>> temp.
number
;
21
record.push_back(temp);
22
cout <<
"Added Successfully"
<< endl;
23
}
24
else
if
(input ==
"Search"
) {
25
list<student>::iterator itr;
26
bool
found =
false
;
27
cin >> temp.
name
>> temp.
major
;
28
for
(itr = record.begin(); itr != record.end(); itr++) {
29
if
(itr->name == temp.
name
&& itr->major == temp.
major
) {
30
cout <<
"Student number:"
<< itr->number << endl;
31
found =
true
;
32
break
;
33
}
34
}
35
if
(!found) {
36
cout <<
"No Record found"
<< endl;
37
}
38
}
39
else
if
(input ==
"Quit"
) {
40
cout <<
"Bye"
<< endl;
41
break
;
42
}
43
}
44
}
student
Definition
cp9.1list.cpp:6
student::name
string name
Definition
cp9.1list.cpp:8
student::major
string major
Definition
cp9.1list.cpp:9
student::number
int number
Definition
cp9.1list.cpp:10
main
int main()
Definition
cp9.1list.cpp:13
Module9
cp9.1list.cpp
Generated on Sun Sep 29 2024 16:39:53 for COMP2113 by
1.12.0