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.
206 lines
5.9 KiB
206 lines
5.9 KiB
#include "mysyslib.h"
|
|
|
|
void stucpy(Student* dest, Student* src){
|
|
strcpy(dest->id,src->id);
|
|
strcpy(dest->clas,src->clas);
|
|
strcpy(dest->name,src->name);
|
|
dest->score1 = src->score1;
|
|
dest->score2 = src->score2;
|
|
dest->score3 = src->score3;
|
|
dest->score = src->score;
|
|
}
|
|
|
|
void stuswp(Student* fi, Student* se){
|
|
Student *tmp = newStudent();
|
|
stucpy(tmp,se);
|
|
stucpy(se,fi);
|
|
stucpy(fi,tmp);
|
|
}
|
|
|
|
//录入数据
|
|
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(ss *stu)
|
|
{
|
|
char tmp[5];
|
|
do {
|
|
int len = stu->nums;
|
|
Student* new_stu_info = newStudent();
|
|
|
|
printf("Id ");
|
|
scanf("%s", new_stu_info->id);
|
|
printf("\n");
|
|
|
|
printf("class ");
|
|
scanf(" %s", new_stu_info->clas);
|
|
printf("\n");
|
|
|
|
printf("name ");
|
|
scanf(" %s", new_stu_info->name);
|
|
printf("\n");
|
|
|
|
printf("score1 ");
|
|
scanf("%lf", &new_stu_info->score1);
|
|
printf("\n");
|
|
|
|
printf("score2 ");
|
|
scanf("%lf", &new_stu_info->score2);
|
|
printf("\n");
|
|
|
|
printf("score3 ");
|
|
scanf("%lf", &new_stu_info->score3);
|
|
printf("\n");
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
if (strcmp(new_stu_info->id, stu->student[i].id) == 0) {
|
|
stu->student[i] = new_stu_info[0];
|
|
stu->student[i].score = stu->student[i].score1 + stu->student[i].score2 + stu->student[i].score3;
|
|
}
|
|
}
|
|
|
|
char* max = malloc(sizeof(char) * 4), * min = malloc(sizeof(char) * 4);
|
|
strcpy(max, stu->student[0].clas);
|
|
strcpy(min, stu->student[0].clas);
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
if (strcmp(stu->student[i].clas , max)>0) {
|
|
strcpy(max, stu->student[i].clas);
|
|
}
|
|
if (strcmp(stu->student[i].clas , min)<0) {
|
|
strcpy(min, stu->student[i].clas);
|
|
}
|
|
}
|
|
int i = 0, flag = 0;
|
|
do {
|
|
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 %.1lf %.1lf %.1lf 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 %.1lf %.1lf %.1lf\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 %.1lf %.1lf %.1lf 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 %.1lf %.1lf %.1lf\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);
|
|
}
|
|
i++;
|
|
}
|
|
int class = atoi(min);
|
|
class++;
|
|
itoa(class,min,10);
|
|
} while (strcmp(max, min) >= 0);
|
|
printf("continue?\n");
|
|
scanf("%s", tmp);
|
|
}while (!strcmp(tmp, "yes"));
|
|
|
|
return;
|
|
}
|
|
//排序
|
|
void Order(ss *stu){
|
|
for(int i=0;i<stu->nums;i++){
|
|
char minclas[10];
|
|
int minp = i;
|
|
strcpy(minclas,stu->student[i].clas);
|
|
for(int j=i+1;j<stu->nums;j++){
|
|
if(strcmp(stu->student[j].clas,minclas)<0){
|
|
strcpy(minclas,stu->student[j].clas);
|
|
minp = j;
|
|
}
|
|
}
|
|
stuswp(&stu->student[i], &stu->student[minp]);
|
|
}
|
|
for(int i=0;i<stu->nums;i++){
|
|
double maxs = stu->student[i].score;
|
|
int maxp = i;
|
|
for(int j=i+1;j<stu->nums;j++){
|
|
if(strcmp(stu->student[j].clas,stu->student[j-1].clas)!=0){
|
|
break;
|
|
}
|
|
if(maxs<stu->student[j].score){
|
|
maxs = stu->student[j].score;
|
|
maxp = j;
|
|
}
|
|
}
|
|
stuswp(&stu->student[i],&stu->student[maxp]);
|
|
}
|
|
printf("Successfully ordered!\n");
|
|
}
|
|
|