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.

244 lines
5.7 KiB

#include <stdio.h>
#include <cstring>
#include <iostream>
const int MAX_STU = 10;
struct Stu{
int code;
char num[5];
int cla;
char name[10];
float mathScore;
float phyScore;
float engScore;
float sumScore;
float aveScore;
bool isInserted;
bool isModified;
};
void toCode(struct Stu s[]){
for(int i=0;i<MAX_STU;i++){
sscanf(s[i].num, "%d", &s[i].code);
}
}
void Input(struct Stu s[]){
for(int i=0;i<MAX_STU;i++){
if(s[i].code==0){
scanf("%s\t%d\t%s\t%f\t%f\t%f",&s[i].num,&s[i].cla,&s[i].name,&s[i].mathScore,&s[i].phyScore,&s[i].engScore);
s[i].sumScore=s[i].mathScore+s[i].phyScore+s[i].engScore;
break;
}
}
toCode(s);
}
void Output(struct Stu s[]){
toCode(s);
for(int i=0;i<MAX_STU;i++){
if(s[i].code!=0){
printf("%s %d %s %.1f %.1f %.1f %.1f\n",s[i].num,s[i].cla,s[i].name,s[i].mathScore,s[i].phyScore,s[i].engScore,s[i].sumScore);
}
}
}
void Order(struct Stu s[]){
toCode(s);
for(int i=0;i<MAX_STU;i++){
if(s[i].code!=0){
for(int j=0;s[j+1].code!=0;j++){
if(s[j].cla>s[j+1].cla){
struct Stu tem=s[j];
s[j]=s[j+1];
s[j+1]=tem;
}
}
}
}
for(int i=0;i<MAX_STU;i++){
if(s[i].code!=0){
for(int j=0;s[j+1].code!=0;j++){
if(s[j].cla==s[j+1].cla&&s[j].sumScore<s[j+1].sumScore){
struct Stu tem=s[j];
s[j]=s[j+1];
s[j+1]=tem;
}
}
}
}
Output(s);
}
void delStu(struct Stu s[]){
toCode(s);
char waitDel[10];
scanf("%s",&waitDel);
for(int i=0;i<MAX_STU;i++){
if(strcmp(waitDel, s[i].num) == 0 || strcmp(waitDel, s[i].name) == 0){
s[i]=s[MAX_STU];
}
}
Output(s);
}
void findStu(struct Stu s[]){
toCode(s);
int a=0;
int flag=1;
scanf("%d",&a);
for(int i=0;i<MAX_STU;i++){
if(s[i].code==a||s[i].cla==a){
printf("%s %d %s %.1f %.1f %.1f\n",s[i].num,s[i].cla,s[i].name,s[i].mathScore,s[i].phyScore,s[i].engScore,s[i].sumScore);
flag=0;
}
}
if(flag)
printf("there is no eligible student\n");
}
int Meum(struct Stu s[]){
printf(" 1.Input\n");
printf(" 2.Delete\n");
printf(" 3.Select\n");
printf(" 4.Order\n");
printf(" 5.Output\n");
printf(" 6.Quit\n");
printf("please input your option\n");
int a;
scanf("%d",&a);
char reward[5];
switch(a){
case 1:
do{
Input(s);
printf("continue?\n");
scanf("%s",&reward);
}
while(strcmp(reward, "yes")==0);
break;
case 2:
do{
delStu(s);
printf("continue?\n");
scanf("%s",&reward);
}
while(strcmp(reward, "yes")==0);
break;
case 3:
do{
findStu(s);
printf("continue?\n");
scanf("%s",&reward);
}
while(strcmp(reward, "yes")==0);
break;
case 4:
do{
Order(s);
printf("continue?\n");
scanf("%s",&reward);
}
while(strcmp(reward, "yes")==0);
break;
case 5:
do{
Output(s);
printf("continue?\n");
scanf("%s",&reward);
}
while(strcmp(reward, "yes")==0);
break;
}
return a;
}
int main(){
struct Stu s[MAX_STU+1];
for (int i = 0; i < MAX_STU+1; ++i) {
s[i].code=0;
memset(s[i].num, 0, sizeof(s[i].num));
s[i].cla = 0;
memset(s[i].name, 0, sizeof(s[i].name));
s[i].mathScore = 0.0f;
s[i].phyScore = 0.0f;
s[i].engScore = 0.0f;
s[i].sumScore = 0.0f;
s[i].aveScore = 0.0f;
s[i].isInserted = false;
s[i].isModified = false;
}
while(Meum(s)!=6);
return 0;
}
//strcpy(s[0].num, "10001");
// s[0].code=1;
// s[0].cla = 11;
// strcpy(s[0].name, "Zhang");
// s[0].mathScore = 99.5f;
// s[0].phyScore = 88.5f;
// s[0].engScore = 89.5f;
// s[0].sumScore = s[0].mathScore + s[0].phyScore + s[0].engScore;
// s[0].aveScore = s[0].sumScore / 3.0f;
//
// strcpy(s[1].num, "10002");
// s[1].code=2;
// s[1].cla = 12;
// strcpy(s[1].name, "Yang");
// s[1].mathScore = 77.9f;
// s[1].phyScore = 56.5f;
// s[1].engScore = 87.5f;
// s[1].sumScore = s[1].mathScore + s[1].phyScore + s[1].engScore;
// s[1].aveScore = s[1].sumScore / 3.0f;
//
// strcpy(s[2].num, "10003");
// s[2].code=3;
// s[2].cla = 11;
// strcpy(s[2].name, "Liang");
// s[2].mathScore = 92.5f;
// s[2].phyScore = 99.0f;
// s[2].engScore = 60.5f;
// s[2].sumScore = s[2].mathScore + s[2].phyScore + s[2].engScore;
// s[2].aveScore = s[2].sumScore / 3.0f;
//
// strcpy (s[3].num,"10004");
// s[3].code=4;
// s[3].cla=11;
// strcpy(s[3].name,"Cai");
// s[3].mathScore=89.6f;
// s[3].phyScore=56.9f;
// s[3].engScore=90.5f;
// s[3].sumScore=s[3].mathScore+s[3].phyScore+s[3].engScore;
// s[3].aveScore=s[3].sumScore/3.0f;
//
// strcpy (s[4].num,"10005");
// s[4].code=5;
// s[4].cla=14;
// strcpy(s[4].name,"Fu");
// s[4].mathScore=55.6f;
// s[4].phyScore=67.9f;
// s[4].engScore=98.9f;
// s[4].sumScore=s[4].mathScore+s[4].phyScore+s[4].engScore;
// s[4].aveScore=s[4].sumScore/3.0f;
//
//strcpy (s[5].num,"10006");
//s[5].code=6;
//s[5].cla=12;
//strcpy(s[5].name,"Mao");
//s[5].mathScore=22.1f;
//s[5].phyScore=45.9f;
//s[5].engScore=99.2f;
//s[5].sumScore=s[5].mathScore+s[5].phyScore+s[5].engScore;
//s[5].aveScore=s[5].sumScore/3.0f;
//
//strcpy (s[6].num,"10007");
//s[6].code=7;
//s[6].cla=13;
//strcpy(s[6].name,"Zhan");
//s[6].mathScore=35.6f;
//s[6].phyScore=67.9f;
//s[6].engScore=88.0f;
//s[6].sumScore=s[6].mathScore+s[6].phyScore+s[6].engScore;
//s[6].aveScore=s[6].sumScore/3.0f;