ADD file via upload

main
pqzbgempc 3 days ago
parent 1d3eb8ba4b
commit d2f15cb799

@ -0,0 +1,85 @@
#include <stdio.h>
#include <string.h>
struct s
{
char id[20];
int mclass; // 学号
char name[20];
float m, p, e; // 总成绩
};
void deleteAndShowStudent()
{
struct s stu[3] = {
{"10001", 11, "Zhang", 99.5, 88.5, 89.5},
{"10002", 12, "Yang", 77.9, 56.5, 87.5},
{"10003", 11, "Liang", 92.5, 99.0, 60.5}
};
struct s stu2[3] = {
{"10001", 11, "Zhang", 99.5, 88.5, 89.5},
{"10002", 12, "Yang", 77.9, 56.5, 87.5},
{"10003", 11, "Liang", 92.5, 99.0, 60.5}
};
int numStudents = 3;
char input[20];
scanf("%s", input);
int found = 0;
int i,j;
for ( i = 0; i < numStudents; i++)
{
if (strcmp(stu[i].id, input) == 0 || strcmp(stu[i].name, input) == 0)
{
found = 1;
for ( j = i; j < numStudents - 1; j++)
{
stu[j] = stu[j + 1];
}
numStudents--;
break;
}
}
if (found)
{
for ( i = 0; i < numStudents; i++)
{
printf("%s %d %s %.1f %.1f %.1f\n", stu[i].id, stu[i].mclass, stu[i].name, stu[i].m, stu[i].p, stu[i].e);
}
char confirm[5];
printf("Are you sure to delete? (yes/no): ");
fflush(stdin); // 清空输入缓冲区
fgets(confirm, sizeof(confirm), stdin); // 使用fgets来获取用户输入
confirm[strcspn(confirm, "\n")] = '\0'; // 去掉输入中的换行符
if (strcmp(confirm,"y") == 0)
{
return;
}
else if (strcmp(confirm,"n") == 0)
{
for ( i = 0; i < numStudents+1; i++)
{
printf("%s %d %s %.1f %.1f %.1f\n", stu2[i].id, stu2[i].mclass, stu2[i].name, stu2[i].m, stu2[i].p, stu2[i].e);
}
return;
}
}
else
{
for (i = 0; i < numStudents; i++)
{
printf("%s %d %s %.1f %.1f %.1f\n", stu[i].id, stu[i].mclass, stu[i].name, stu[i].m, stu[i].p, stu[i].e);
}
return;
}
}
int main()
{
deleteAndShowStudent();
// getchar();
return 0;
}
Loading…
Cancel
Save