题目要求:
学生信息管理系统
struct studentInfo
{
int id;
char
name[128];
int age;
char sex;
int c_score;
int
cpp_score;
int oc_scpre;
};
struct StudentInfo Arr[100]={};
int count=0;
show
1. 插入用户信息
scnaf("%s%d", Arr[count].age);
count++;
2. 显示用户信息
(1)输入id,按id显示信息
(2)输入name,按name显示信息
3. 显示所有用户信息
4. 删除用户信息
(1)输入id,按id删除信息
(2)输入name,按name删除信息
5. 统计
c-score
平均值
cpp-score-平均值
oc-score平均值
平均值成绩最高分
input: 1-6
switch()
{
}
我的代码:
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
|
#include <stdio.h> #include <string.h> typedef
struct studentInfo{
int
id;
char
name[128];
int
age;
char
sex;
int
c_score;
int
cpp_score;
int
oc_score;
}Student; Student student[100]; int
pos;
void
print_info( int
p){
printf ( "\n" );
printf ( "用户的ID: %d\n" , student[p].id);
printf ( "用户的名字: %s\n" , student[p].name);
printf ( "用户的年龄: %d\n" , student[p].age);
printf ( "用户的性别(m男性、f女性): %c\n" , student[p].sex);
printf ( "用户的c语言分数: %d\n" , student[p].c_score);
printf ( "用户的c++语言分数: %d\n" , student[p].cpp_score);
printf ( "用户的objective-c语言分数: %d\n" , student[p].oc_score);
} void
input();
void
show(){
printf ( "\n\n\n" );
printf ( "-----------------管理信息系统---------------------------\n" );
printf ( "| |\n" );
printf ( "| |\n" );
printf ( "| 1.插入用户信息 |\n" );
printf ( "| 2.显示用户信息 |\n" );
printf ( "| 3.显示所有用户信息 |\n" );
printf ( "| 4.删除用户信息 |\n" );
printf ( "| 5.统计信息 |\n" );
printf ( "| 6.退出系统 |\n" );
printf ( "| |\n" );
printf ( "--------------------------------------------------------|\n" );
printf ( "请输入数字:(1-6)\n" );
input();
} void
insert(){
char
name[128];
int
i = 0;
++pos;
printf ( "Please input user id :\n" );
scanf ( "%d" , &student[pos].id);
printf ( "Please input user name :\n" );
scanf ( "%s" , name);
strcpy (student[pos].name, name);
printf ( "Please input user age :\n" );
scanf ( "%d" , &student[pos].age);
printf ( "Please input user sex :\n" );
scanf ( " %c" , &student[pos].sex);
printf ( "Please input user C语言分数 :\n" );
scanf ( "%d" , &student[pos].c_score);
printf ( "Please input user C++分数 :\n" );
scanf ( "%d" , &student[pos].cpp_score);
printf ( "Please input user objective-c 分数 :\n" );
scanf ( "%d" , &student[pos].oc_score);
printf ( "插入成功!\n" );
show();
} void
showuser(){
printf ( "1>输入id, 按ID显示信息\n" );
printf ( "2>输入name, 按name显示信息\n" );
printf ( "请输入序号:(1-2)\n" );
int
i, id, num;
char
name[128];
scanf ( "%d" , &num);
if (num == 1){
printf ( "请输出ID:\n" );
scanf ( "%d" , &id);
for (i=1;i<=pos;++i)
if (id == student[i].id)
print_info(i);
}
if (num == 2){
printf ( "请输入用户名字:\n" );
scanf ( "%s" , name);
for (i=1;i<=pos;++i)
if (! strcmp (name, student[i].name))
print_info(i);
}
printf ( "按任意键返回菜单\n" );
getchar ();
getchar ();
show();
} void
showalluser(){
int
i = 0;
for (i=1;i<=pos;++i){
if (student[i].id == 0) continue ;
print_info(i);
printf ( "\n" );
}
show();
} void
delete (){
printf ( "1>输入id, 按ID删除信息\n" );
printf ( "2>输入name, 按name删除信息\n" );
printf ( "请输入序号:(1-2)\n" );
int
i, id, num;
char
name[128];
scanf ( "%d" , &num);
if (num == 1){
printf ( "请输入ID\n" );
scanf ( "%d" , &id);
for (i=1;i<=pos;++i)
if (id == student[i].id){
student[i].id = 0;
printf ( "删除成功!\n" );
}
}
if (num == 2){
printf ( "请输入用户名字:\n" );
scanf ( "%s" , name);
for (i=1;i<=pos;++i)
if (! strcmp (name, student[i].name)){
student[i].id = 0;
printf ( "删除成功!\n" );
}
}
show();
} void
sum(){
printf ( "1>输入C语言分数的平均值信息\n" );
printf ( "2>输入C++语言分数的平均值信息\n" );
printf ( "3>输入objective-C语言分数的平均值信息\n" );
printf ( "4>输入平均成绩总分信息(没看懂题目要求,暂时没做)\n" );
printf ( "请输入序号:(1-3)\n" );
int
num, i, sum, cnt;
scanf ( "%d" , &num);
if (num == 1){
cnt = 0;
sum = 0;
for (i=1;i<=pos;++i){
if (student[i].id == 0) continue ;
cnt++;
sum+=student[i].c_score;
}
printf ( "C语言评分分数 :%g\n" , sum/(cnt*1.0));
}
if (num == 2){
cnt = 0;
sum = 0;
for (i=1;i<=pos;++i){
if (student[i].id == 0) continue ;
cnt++;
sum+=student[i].cpp_score;
}
printf ( "C++语言评分分数 :%g\n" , sum/(cnt*1.0));
}
if (num == 3){
cnt = 0;
sum = 0;
for (i=1;i<=pos;++i){
if (student[i].id == 0) continue ;
cnt++;
sum+=student[i].oc_score;
}
printf ( "objective-C语言评分分数 :%g\n" , sum/(cnt*1.0));
}
if (num == 4){
cnt = 0;
sum = 0;
for (i=1;i<=pos;++i){
if (student[i].id == 0) continue ;
cnt++;
sum+=student[i].oc_score;
}
printf ( "objective-C语言评分分数 :%f\n" , sum/(cnt*1.0));
}
show();
} void
_quit(){}
void
input(){
int
num;
scanf ( "%d" , &num);
switch (num){
case
1: insert();
break ;
case
2: showuser();
break ;
case
3: showalluser();
break ;
case
4: delete ();
break ;
case
5: sum();
break ;
case
6: _quit();
break ;
}
} int
main(){
pos = 0;
show();
return
0;
} |
运行结果 截图: