Compare commits

...

3 Commits

@ -0,0 +1,55 @@
#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,20 +0,0 @@
#include "mysyslib.h"
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"));
}

@ -10,9 +10,8 @@ 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].class = (char*)malloc(sizeof(char)*3); stu->student[i].clas = (char*)malloc(sizeof(char)*3);
stu->student[i].name = (char*)malloc(sizeof(char)*10); stu->student[i].name = (char*)malloc(sizeof(char)*10);
} }
return stu; return stu;
} }

@ -1,39 +0,0 @@
#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].class);
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;
}

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

@ -4,7 +4,7 @@
typedef struct{ typedef struct{
char *id; char *id;
char *class; char *clas;
char *name; char *name;
double score1; double score1;
double score2; double score2;

@ -0,0 +1,120 @@
#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;
}
}

@ -1,15 +0,0 @@
#include "mysyslib.h"
void Print(Student*student){
printf("%s,%s,%s,%.1lf,%.1lf,%.1lf,%.1lf\n",student->id,student->class,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");
}
}
Loading…
Cancel
Save