forked from ASD-ADF/ASD_Task_2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
128 lines (118 loc) · 3.42 KB
/
Main.cpp
File metadata and controls
128 lines (118 loc) · 3.42 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
#include "array_based.h"
void menu();
mytype database[10];
int n_data = 0; // integer to trach the number of data inside database array
int main() {
cout<<"Test My Data"<<endl;
mytype d;
d = create_data();
cout<<endl;
cout<<"Test View My New Data"<<endl;
view_data(d);
cout<<endl;
cout<<"Test Edit My New Data"<<endl;
edit_data(d);
cout<<"edit result"<<endl;
view_data(d);
cout<<endl;
cout<<"is the data really edited? "<<endl;
cout<<"make sure it can actually edit your data"<<endl;
cout<<endl<<"press enter to continue"<<endl;
cin.get();
cin.get();
cout<<endl;
n_data = 0;
cout<<"Test Add Data to Database, Twice"<<endl;
d = create_data();
add_new_data(database, n_data, d);
d = create_data();
add_new_data(database, n_data, d);
cout<<endl;
cout<<"Test View Database"<<endl;
view_data(database, n_data);
cout<<endl;
cout<<"Test Add Priority Data to Database, Twice"<<endl;
d = create_data();
add_new_priority_data(database, n_data, d);
d = create_data();
add_new_priority_data(database, n_data, d);
cout<<endl;
cout<<"Test View Database"<<endl;
view_data(database, n_data);
cout<<endl;
cin.get();
cout<<endl;
cout<<"Test Array Based Application Data"<<endl;
menu();
return 0;
}
void menu() {
n_data = 0;
mytype d;
int idx;
int ch;
int nim_to_find;
int nim_to_remove;
do {
cout<<"MENU"<<endl;
cout<<n_data<<endl;
cout<<"1. add new data to the end of database"<<endl;
cout<<"2. add new data to the front of database"<<endl;
cout<<"3. view all data from database"<<endl;
cout<<"4. find and view a data based on its ID"<<endl;
cout<<"5. find and edit a data based on its ID"<<endl;
cout<<"6. remove a data based on its ID"<<endl;
cout<<"7. sort data based on its float variable"<<endl;
cout<<"0. exit aplication"<<endl;
cout<<"input choice:";
cin>>ch;
switch(ch) {
case 1:
d = create_data();
add_new_data(database, n_data, d);
break;
case 2:
d = create_data();
add_new_priority_data(database, n_data, d);
break;
case 3:
view_data( database, n_data);
break;
case 4:
cout<<"insert ID to find: ";
cin>>nim_to_find;
idx = find_data( database, n_data, nim_to_find);
if(idx!=-1) {
view_data(database[idx]);
} else {
cout<<"data not found"<<endl;
}
break;
case 5:
cout<<"insert ID to edit: ";
cin>>nim_to_find;
idx = find_data( database, n_data, nim_to_find);
if(idx!=-1) {
edit_data(database[idx]);
} else {
cout<<"data not found"<<endl;
}
break;
case 6:
cout<<"insert ID to remove: ";
cin>>nim_to_remove;
remove_data( database, n_data, nim_to_remove);
break;
case 7:
sort_data( database, n_data);
cout<<"Data Sorted"<<endl;
break;
case 0:
cout<<"Thank You"<<endl;
break;
default:
cout<<"Wrong Input"<<endl;
break;
}
} while (ch!=0);
}