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>
5using namespace std;
6
7const int MAX = 100;
8struct Course{
9 string code, name, lecturer;
10};
11
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
34int 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}
string lecturer
string code
string name
Course courses[MAX]
int add(string code, string name, string lecturer)
void show(string code)
int main()
const int MAX