|
发表于 2021-12-26 20:34:34
|
显示全部楼层
本楼为最佳答案
 - #include <stdio.h>
- #include <string.h>
- struct {
- char id[5];
- char name[8];
- double score[3];
- } student[5];
- void input(void) {
- printf("请依次输入5个学生的学号、姓名、平时成绩、考试成绩\n");
- for(size_t i = 0; i < 5; ++i) {
- scanf("%s", student[i].id);
- scanf("%s", student[i].name);
- scanf("%lf", &student[i].score[0]);
- scanf("%lf", &student[i].score[1]);
- student[i].score[2] = student[i].score[0] * 0.3 + student[i].score[1] * 0.7;
- }
- }
- void search(void) {
- printf("请输入学生id: ");
- char id[5];
- scanf("%s", id);
- for(size_t i = 0; i < 5; ++i) {
- if(!strcmp(id, student[i].id)) {
- printf("%s ", student[i].id);
- printf("%s ", student[i].name);
- printf("%lf ", student[i].score[0]);
- printf("%lf ", student[i].score[1]);
- printf("%lf ", student[i].score[2]);
- puts("");
- return;
- }
- }
- }
- void output(void) {
- printf("请输入总评成绩: ");
- double score;
- scanf("%lf", &score);
- for(size_t i = 0; i < 5; ++i) {
- if(student[i].score[2] >= score) {
- printf("%s ", student[i].id);
- printf("%s ", student[i].name);
- printf("%lf ", student[i].score[0]);
- printf("%lf ", student[i].score[1]);
- printf("%lf ", student[i].score[2]);
- puts("");
- }
- }
- }
- int main(void) {
- while(1) {
- printf("1. 信息录入\n");
- printf("2. 信息查询\n");
- printf("3. 总评信息\n");
- printf("0. 退出系统\n");
- printf("# ");
- size_t sel;
- scanf("%lu", &sel);
- switch(sel) {
- case 0: goto done;
- case 1: input(); break;
- case 2: search(); break;
- case 3: output(); break;
- default: printf("输入错误!\n");
- }
- }
- done:
- return 0;
- }
复制代码 |
|