|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
struct s
|
|
|
|
|
{
|
|
|
|
|
char id[20];
|
|
|
|
|
int class; // ѧ<><D1A7>
|
|
|
|
|
char name[20];
|
|
|
|
|
float m, p, e; // <20>ܳɼ<DCB3>
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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].class, 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); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뻺<EFBFBD><EBBBBA><EFBFBD><EFBFBD>
|
|
|
|
|
fgets(confirm, sizeof(confirm), stdin); // ʹ<><CAB9>fgets<74><73><EFBFBD><EFBFBD>ȡ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
confirm[strcspn(confirm, "\n")] = '\0'; // ȥ<><C8A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĻ<D0B5><C4BB>з<EFBFBD>
|
|
|
|
|
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].class, 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].class, stu[i].name, stu[i].m, stu[i].p, stu[i].e);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
deleteAndShowStudent();
|
|
|
|
|
// getchar();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|