main
高世波 1 year ago
parent 30c86172cd
commit 3c6597c8d6

1
.gitignore vendored

@ -1,2 +1,3 @@
*.*~ *.*~
*.out *.out
.*.swp

@ -1,55 +0,0 @@
#include "mysyslib.h"
typedef struct Student
{
char* id;
char* clas;
char* name;
double score1;
double score2;
double score3;
double score;
}student;
void ModifyInfo(Student stu_info[],int len)
{
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_info[i].id) == 0) {
stu_info[i] = new_stu_info;
}
}
char* max, min;
strcpy(max, stu_info[0].clas);
strcpy(min, stu_info[0].clas);
for (int i = 0; i < len; i++) {
if (stu_info[i].clas > max) {
strcpy(max, stu_info[i].clas);
}
if (stu_info[i].clas < min) {
strcpy(min, stu_info[i].clas);
}
}
int i = 0, flag = 0;
while (strcmp(min, max) != 1) {
while (i < len && strcmp(min, stu_info[i++].clas) == 0) {
if (flag == 1) {
if (strcmp(stu_info[i].id, new_stu_info.id) == 0) {
printf(" %s %s %lf %lf %lf modified\n", stu_info[i].id, stu_info[i].name, stu_info[i].score1, stu_info[i].score2, stu_info[i].score3);
}
else
printf(" %s %s %lf %lf %lf\n", stu_info[i].id, stu_info[i].name, stu_info[i].score1, stu_info[i].score2, stu_info[i].score3);
}
else {
flag = 1;
if (strcmp(stu_info[i].id, new_stu_info.id) == 0) {
printf("%s %s %s %lf %lf %lf modified\n", stu_info[i].clas, stu_info[i].id, stu_info[i].name, stu_info[i].score1, stu_info[i].score2, stu_info[i].score3);
}
else
printf("%s %s %s %lf %lf %lf modified\n", stu_info[i].clas, stu_info[i].id, stu_info[i].name, stu_info[i].score1, stu_info[i].score2, stu_info[i].score3);
}
}
min = min + 1;
}
}

@ -1,4 +1,4 @@
w#include "mysyslib.h" #include "mysyslib.h"
ss* init(int Nums){ ss* init(int Nums){
ss* stu = (ss*)malloc(sizeof(ss)); ss* stu = (ss*)malloc(sizeof(ss));
@ -10,8 +10,16 @@ w#include "mysyslib.h"
for(int i = 0; i < Nums; ++i){ for(int i = 0; i < Nums; ++i){
stu->student[i].id = (char*)malloc(sizeof(char)*6); stu->student[i].id = (char*)malloc(sizeof(char)*6);
stu->student[i].clas = (char*)malloc(sizeof(char)*3); stu->student[i].clas = (char*)malloc(sizeof(char)*4);
stu->student[i].name = (char*)malloc(sizeof(char)*10); stu->student[i].name = (char*)malloc(sizeof(char)*20);
} }
return stu; return stu;
} }
Student *newStudent(){
Student *stu = (Student*)malloc(sizeof(Student));
stu->id = (char*)malloc(sizeof(char)*6);
stu->clas = (char*)malloc(sizeof(char)*4);
stu->name = (char*)malloc(sizeof(char)*20);
return stu;
}

@ -4,7 +4,7 @@ int main(){
int ipt; int ipt;
ss* stu = init(20); ss* stu = init(20);
while(1){ while(1){
if(mainMenu(stus)){ if(mainMenu(stu)){
break; break;
} }
} }

@ -21,9 +21,11 @@ int mainMenu(ss *stu) {
break; break;
case 3: case 3:
printf("You are trying to Selete info\n"); printf("You are trying to Selete info\n");
ModifyInfo(stu); //修改学生信息
break; break;
case 4: case 4:
printf("You are trying to Make things ordered\n"); printf("You are trying to Make things ordered\n");
Order(stu);
break; break;
case 5: case 5:
printf("You are trying to Output info\n"); printf("You are trying to Output info\n");

@ -18,10 +18,15 @@ typedef struct{
}ss; }ss;
ss* init(int); ss* init(int);
Student* newStudent();
void stucpy(Student* dest, Student* src);
void stuswp(Student* fi, Student* se);
int mainMenu(ss *stu); int mainMenu(ss *stu);
void ModifyInfo(ss* stu);
void getCom(ss*); void getCom(ss*);
void Print(Student*); void Print(Student*);
void allPrint(ss*); void allPrint(ss*);
void input(ss*); void input(ss*);
void cancel(ss*); void cancel(ss*);
void Select(ss*); void Select(ss*);
void Order(ss*);

@ -1,5 +1,22 @@
#include "mysyslib.h" #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){ void input(ss*stu){
char tmp[5]; char tmp[5];
@ -75,17 +92,17 @@ void cancel(ss*stu){
} }
//修改学生信息 //修改学生信息
void ModifyInfo(Student stu->student[]) void ModifyInfo(ss *stu)
{ {
int len = stu->nums; int len = stu->nums;
Student new_stu_info; 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); 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++) { for (int i = 0; i < len; i++) {
if (strcmp(new_stu_info.id, stu->student[i].id) == 0) { if (strcmp(new_stu_info.id, stu->student[i].id) == 0) {
stu->student[i] = new_stu_info; stu->student[i] = new_stu_info;
} }
} }
char* max, min; char *max = malloc(sizeof(char)*20), *min = malloc(sizeof(char)*20);
strcpy(max, stu->student[0].clas); strcpy(max, stu->student[0].clas);
strcpy(min, stu->student[0].clas); strcpy(min, stu->student[0].clas);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
@ -118,3 +135,35 @@ void ModifyInfo(Student stu->student[])
min = min + 1; min = min + 1;
} }
} }
//排序
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");
}

Loading…
Cancel
Save