任务描述
现在你的数据库里已经存储了以下信息:
Name_f Name_l stu_id score retake GPA
Jingyu LI 202200000000 85 0 A
Jy LEE 202200100000 89 0 A
Jxxxyx Leeeee 202100100000 100 1 A+
Jingyu11 LI 202200000001 85 0 A
根据id删除学生的成绩信息,输出新的数据库和学生总数。 要求编写函数 Delete(id)。
编程要求
根据提示,在右侧编辑器补充代码,完成指定id学生信息的删除操作。
测试说明
输入说明: 若干个被删除学生的id。
输出说明: 输出新的成绩表。
平台会对你编写的代码进行测试:
测试输入: 202200000000
202200000001
预期输出:
Name_f Name_l stu_id score retake GPA
Jy LEE 202200100000 89 0 A
Jxxxyx Leeeee 202100100000 100 1 A+
Total: 2
代码实现:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
//=======begin=======
struct Information
{
char first_name[20];
char last_name[20];
char id[20];
int score;
int retake;
char GPA[5];
} stu[110] = {
{"Jingyu", "LI", "202200000000", 85, 0, "A"},
{"Jy", "LEE", "202200100000", 89, 0, "A"},
{"Jxxxyx", "Leeeee", "202100100000", 100, 1, "A+"},
{"Jingyu11", "LI", "202200000001", 85, 0, "A"}};//模拟一波数据库
int Delete(char id[])
{
for (int i = 0; i < 4; i++)
{
if (strcmp(stu[i].id, id) == 0)//这个函数比较 s1 和 s2 指向的字符串。返回值如下:
//如果 s1 小于 s2,返回一个负数。
//如果 s1 等于 s2,返回0。
//如果 s1 大于 s2,返回一个正数。
{
strcpy(stu[i].id, "\0");
return 1;
}
}
return 0;
}
int main() {
printf("Name_f Name_l stu_id score retake GPA\n");
char id[20];
int i = 4;
while (~scanf("%s", id))
{
if (strlen(id) != 12)
continue;//排除有些蠢egg错误输入位数
if (Delete(id))
i--;
}
for (int i = 0; i < 4; i++)
{
if (strcmp(stu[i].id, "\0") != 0)
printf("%s %s %s %d %d %s\n", stu[i].first_name, stu[i].last_name, stu[i].id, stu[i].score, stu[i].retake, stu[i].GPA);//不一样的留下来好吧
}
printf("Total: %d", i);
return 0;
}