You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.5 KiB

1 year ago
#include "mysyslib.h"
//录入数据
void input(ss*stu){
char tmp[5];
do{
int pst = stu->nums;
printf("Id ");
scanf(" %s",stu->student[pst].id);
printf("\n");
printf("class ");
scanf(" %s",stu->student[pst].clas);
printf("\n");
printf("name ");
scanf(" %s",stu->student[pst].name);
printf("\n");
printf("score1 ");
scanf("%lf",&stu->student[pst].score1);
printf("\n");
printf("score2 ");
scanf("%lf",&stu->student[pst].score2);
printf("\n");
printf("score3 ");
scanf("%lf",&stu->student[pst].score3);
printf("\n");
stu->student[pst].score = stu->student[pst].score1 + stu->student[pst].score2 + stu->student[pst].score3;
stu->nums++;
printf("continue?\n");
scanf("%s",tmp);
}while(!strcmp(tmp,"yes"));
return;
}
//输出相关
void Print(Student*student){
printf("%s,%s,%s,%.1lf,%.1lf,%.1lf,%.1lf\n",student->id,student->clas,student->name,student->score1,student->score2,student->score3,student->score);
}
void allPrint(ss*stu){
if(stu->nums){
for(int i = 0; i < stu->nums; ++i){
Print(&stu->student[i]);
}
}else{
printf("No data exist\n");
}
}
//删除学生信息
void cancel(ss*stu){
char* tmp = (char*)malloc(sizeof(char)*3);
do{
char*ID = (char*)malloc(sizeof(char)*6);
scanf("%s",ID);
for(int i = 0; i < stu->nums; ++i){
if(strcmp(stu->student[i].id,ID) == 0){
for(int j = i; j < stu->nums-1; ++j){
stu->student[j] = stu->student[j+1];
}
}
}
stu->nums--;
allPrint(stu);
printf("continue?\n");
scanf("%s",tmp);
}while(!strcmp(tmp,"yes"));
}
//修改学生信息
void ModifyInfo(Student stu->student[])
{
int len = stu->nums;
Student new_stu_info;
scanf("%s%s%s%lf%lf%lf", new_stu_info.id, new_stu_info.clas, new_stu_info.name, new_stu_info.score1, new_stu_info.score2, new_stu_info.score3);
for (int i = 0; i < len; i++) {
if (strcmp(new_stu_info.id, stu->student[i].id) == 0) {
stu->student[i] = new_stu_info;
}
}
char* max, min;
strcpy(max, stu->student[0].clas);
strcpy(min, stu->student[0].clas);
for (int i = 0; i < len; i++) {
if (stu->student[i].clas > max) {
strcpy(max, stu->student[i].clas);
}
if (stu->student[i].clas < min) {
strcpy(min, stu->student[i].clas);
}
}
int i = 0, flag = 0;
while (strcmp(min, max) != 1) {
while (i < len && strcmp(min, stu->student[i++].clas) == 0) {
if (flag == 1) {
if (strcmp(stu->student[i].id, new_stu_info.id) == 0) {
printf(" %s %s %lf %lf %lf modified\n", stu->student[i].id, stu->student[i].name, stu->student[i].score1, stu->student[i].score2, stu->student[i].score3);
}
else
printf(" %s %s %lf %lf %lf\n", stu->student[i].id, stu->student[i].name, stu->student[i].score1, stu->student[i].score2, stu->student[i].score3);
}
else {
flag = 1;
if (strcmp(stu->student[i].id, new_stu_info.id) == 0) {
printf("%s %s %s %lf %lf %lf modified\n", stu->student[i].clas, stu->student[i].id, stu->student[i].name, stu->student[i].score1, stu->student[i].score2, stu->student[i].score3);
}
else
printf("%s %s %s %lf %lf %lf modified\n", stu->student[i].clas, stu->student[i].id, stu->student[i].name, stu->student[i].score1, stu->student[i].score2, stu->student[i].score3);
}
}
min = min + 1;
}
}