本文实例为大家分享了C++实现评教管理系统的具体代码,供大家参考,具体内容如下
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
#include<iostream> #include<fstream> #include<cstring> #include <stdlib.h> #include <conio.h> #include<vector> using namespace std; int n; class Student { public : char sname[20]; char snum[20]; char sclass[20]; void input(); }; /*--------------------------学生登陆-----------------------------*/ void Student::input() { cout<< "请输入您的姓名:" ; cin>>sname; cout<< "请输入您的学号:" ; cin>>snum; cout<< "请输入您的班级:" ; cin>>sclass; cout<< "登陆成功!输入任意字符继续" ; getch(); } /*--------------------------评教信息 类模板-----------------------------*/ template < typename T1, typename T2, typename T3> class Lesson { public : Lesson(){}; ~Lesson(){}; T1 tname[20]; T2 tlesson[20]; T3 grade; void display(); void input(); void show(); }; /*--------------------------输出函数-----------------------------*/ template < typename T1, typename T2, typename T3> void Lesson<T1,T2,T3>::show() { cout<< "教师姓名:" <<tname<<endl; cout<< "课程名称:" <<tlesson<<endl; cout<< "评教分数:" <<grade<<endl; } /*--------------------------新建类-----------------------------*/ class System { public : System(){}; ~System(){}; void add(); int lname( char *x); void find(); void change(); void dele(); void menu(); void display(); void save(); void read(); }; vector<Lesson< char , char , double > >v; /*--------------------------输入函数-----------------------------*/ template < typename T1, typename T2, typename T3> void Lesson<T1,T2,T3>::input() { cout<< "请输入教师姓名:" ; cin>>tname; cout<< "请输入课程名称:" ; cin>>tlesson; cout<< "请输入打分(0-100):" ; cin>>grade; try { //异常处理 if (grade<0||grade>100) throw 0; else cout<<endl;} catch ( int ) {cout<< "输入数据错误,请重新输入" ;} cout<<endl; } /*--------------------------读取函数-----------------------------*/ void System::read() { Lesson< char , char , double > ch; ifstream infile( "sys.txt" ,ios::binary); if (!infile){ cout<< "文件打不开" <<endl; } infile.read(( char *)&ch, sizeof (ch)); while (!infile.eof()) { v.push_back(ch); infile.read(( char *)&ch, sizeof (ch)); cout<< "教师姓名:" <<ch.tname<<endl; cout<< "课程名称:" <<ch.tlesson<<endl; cout<< "评教分数:" <<ch.grade<<endl; cout<<endl; } infile.close(); cout<< "读取成功" <<endl; getch(); } /*--------------------------保存函数-----------------------------*/ void System::save() { ofstream outfile( "sys.txt" ,ios::binary); Lesson< char , char , double >t; vector<Lesson< char , char , double > >::iterator ap; if (!outfile) cout<< "文件不能被打开" <<endl; else { for (ap=v.begin();ap!=v.end();ap++) { t=*ap; outfile.write(( char *)&t, sizeof (t)); cout<< "保存成功" <<endl; } outfile.close(); getch(); } } void System::display() { for ( int i=0;i<n;i++) {v[i].show();} cout<< "输入任意字符继续" ; getch(); } /*--------------------------主菜单-----------------------------*/ void System::menu() { cout<< "--------------*评 教 管 理 系 统*-------------" <<endl; cout<< "--------------*$1. 学生登陆界面*--------------" <<endl; cout<< "--------------*$2. 增加评教信息*--------------" <<endl; cout<< "--------------*$3. 更改评教信息*--------------" <<endl; cout<< "--------------*$4. 查找评教信息*--------------" <<endl; cout<< "--------------*$5. 显示评教信息*--------------" <<endl; cout<< "--------------*$6. 删除评教信息*--------------" <<endl; cout<< "--------------*$7. 保存相关数据*--------------" <<endl; cout<< "--------------*$8. 读取相关数据*--------------" <<endl; cout<< "--------------*$9. 退出评教系统*--------------" <<endl; } /*--------------------------添加数据-----------------------------*/ void System::add() { string h= "y" ; do { Lesson< char , char , double >l; l.input(); n++; v.push_back(l); cout<< "是否继续添加(y/n)?" ; cin>>h; } while (h== "y" ); cout<< "添加成功!输入任意字符继续" ; getch(); } /*--------------------------查找课程-----------------------------*/ int System::lname( char *x) { int i; for (i=0;i<n;i++) { if ( strcmp (v[i].tlesson,x)==0) { return i;} } return -1; } void System::find() { char x[20]; int a; cout<< "请输入要查找的课程名称:" ; cin>>x; a=lname(x); if (a!=-1) v[a].show(); else cout<< "没有找到相关课程信息" <<endl; cout<< "输入任意字符继续" ; getch(); } /*--------------------------更改数据-----------------------------*/ void System::change() { char b[20]; int k; cout<< "请输入需要修改的课程名称:" ; cin>>b; k=lname(b); if (k!=-1){ cout<< "已找到,请输入新的信息:" <<endl; v[k].input();} cout<< "输入任意字符继续:" ; getch(); } /*--------------------------删除数据-----------------------------*/ void System::dele() { char c[20]; int d; cout<< "请输入要删除的课程名称:" ; cin>>c; d=lname(c); if (d!=-1) { for (;d<n-1;d++) { strcpy (v[d].tname,v[d+1].tname); strcpy (v[d].tlesson,v[d+1].tlesson); v[d].grade==v[d+1].grade; } n--; } else cout<< "输入错误,找不到该课程信息" <<endl; cout<< "输入任意字符继续" ; getch(); } /*--------------------------主函数-----------------------------*/ int main() { Student x; System y; int a; string ss= "y" ; do { system ( "cls" ); cout<< "====================欢迎进入评教管理系统!====================" <<endl; y.menu() ; cout<< "请输入相应阿拉伯数字:" ; cin>>a; switch (a) { case 1:x.input(); break ; case 2:y.add(); break ; case 3:y.change(); break ; case 4:y.find(); break ; case 5:y.display(); break ; case 6:y.dele(); break ; case 7:y.save(); break ; case 8:y.read(); break ; case 9:ss= "n" ; break ; } } while (ss== "y" ); return 0; } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/wind_day/article/details/76468297