COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
user_commands.cpp
Go to the documentation of this file.
1
// Handling user commands
2
3
#include <iostream>
4
#include <string>
5
using namespace
std;
6
7
const
int
MAX
= 100;
8
struct
Course
{
9
string
code
,
name
,
lecturer
;
10
};
11
12
struct
Courselist
{
13
Course
courses
[
MAX
];
14
int
count
= 0;
15
int
add
(
string
code,
string
name,
string
lecturer){
16
if
(
count
<
MAX
){
17
courses
[
count
].
code
= code;
18
courses
[
count
].
name
= name;
19
courses
[
count
].
lecturer
= lecturer;
20
count
++;
21
}
22
return
0;
23
}
24
void
show
(
string
code){
25
for
(
int
i = 0; i <
count
; i++){
26
if
(
courses
[i].code == code){
27
cout <<
"Name: "
<<
courses
[i].
name
<<
", Lecturer: "
<<
courses
[i].
lecturer
<< endl;
28
return
;
29
}
30
}
31
}
32
};
33
34
int
main
() {
35
string
input;
36
cin >> input;
37
Courselist
course_list;
38
while
(input !=
"exit"
) {
39
if
(input ==
"add"
) {
40
// handle add commnad
41
string
data[3];
42
cin >> data[0] >> data[1] >> data[2];
43
course_list.
add
(data[0], data[1], data[2]);
44
}
45
if
(input ==
"show"
) {
46
// handle show commnad
47
string
data[1];
48
cin >> data[0];
49
course_list.
show
(data[0]);
50
}
51
cin >> input;
52
}
53
return
0;
54
}
Course
Definition
user_commands.cpp:8
Course::lecturer
string lecturer
Definition
user_commands.cpp:9
Course::code
string code
Definition
user_commands.cpp:9
Course::name
string name
Definition
user_commands.cpp:9
Courselist
Definition
user_commands.cpp:12
Courselist::courses
Course courses[MAX]
Definition
user_commands.cpp:13
Courselist::add
int add(string code, string name, string lecturer)
Definition
user_commands.cpp:15
Courselist::show
void show(string code)
Definition
user_commands.cpp:24
Courselist::count
int count
Definition
user_commands.cpp:14
main
int main()
Definition
user_commands.cpp:34
MAX
const int MAX
Definition
user_commands.cpp:7
Module7
user_commands.cpp
Generated on Sun Sep 29 2024 16:39:53 for COMP2113 by
1.12.0