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.
284 lines
5.2 KiB
284 lines
5.2 KiB
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
//³õʼ»¯ÉùÃ÷
|
|
|
|
int addnum=0;
|
|
struct info{
|
|
int number;
|
|
int clas;
|
|
char name[20];
|
|
float math;
|
|
float physic;
|
|
float english;
|
|
float grade;
|
|
};
|
|
struct info stu[20];
|
|
int judge();
|
|
void swap(int i,int j);
|
|
void initial();
|
|
void ind();
|
|
void inputinfop1();
|
|
void deleteinfop2();
|
|
void selectinfop3();
|
|
void rangeinfop4();
|
|
void printinfop5();
|
|
|
|
//Ö÷³ÌÐò
|
|
|
|
int main(){
|
|
initial();
|
|
int in;
|
|
while(1){
|
|
ind();
|
|
scanf("%d",&in);
|
|
switch(in){
|
|
case 1:
|
|
printf("You are trying to Input info\n");
|
|
inputinfop1();break;
|
|
case 5:
|
|
printf("You are trying to Output info\n");
|
|
printinfop5();break;
|
|
case 4:
|
|
printf("You are trying to Make things ordered\n");
|
|
rangeinfop4();
|
|
break;
|
|
case 6:
|
|
printf("You are about to Quit\n");return 0;
|
|
case 2:deleteinfop2();break;
|
|
case 3:selectinfop3();break;
|
|
default:
|
|
printf("Wrong input\n");break;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
//³õʼ»¯ini
|
|
|
|
void initial(){
|
|
int i;
|
|
for(i=0;i<20;i++){
|
|
stu[i].number=0;
|
|
stu[i].math=0.0;
|
|
stu[i].physic=0.0;
|
|
stu[i].english=0.0;
|
|
stu[i].clas=0;
|
|
memset(stu[i].name,0,sizeof(stu[i].name));
|
|
}
|
|
return;
|
|
}
|
|
|
|
//ÊäÈë²½Öè
|
|
|
|
void inputinfop1(){
|
|
int j,k,l,temp,num=0;
|
|
char str[10];
|
|
float total[2][20];
|
|
memset(total,0,sizeof(total));
|
|
do{
|
|
printf("Id ");
|
|
scanf("%d",&stu[addnum].number);
|
|
printf("class ");
|
|
scanf("%d",&stu[addnum].clas);
|
|
printf("name ");
|
|
scanf("%s",&stu[addnum].name);
|
|
printf("score1 ");
|
|
scanf("%f",&stu[addnum].math);
|
|
printf("score2 ");
|
|
scanf("%f",&stu[addnum].physic);
|
|
printf("score3 ");
|
|
scanf("%f",&stu[addnum].english);
|
|
stu[addnum].grade=stu[addnum].math+stu[addnum].physic+stu[addnum].english;
|
|
total[1][addnum]=stu[addnum].grade;
|
|
total[0][addnum]=addnum;
|
|
addnum++;
|
|
num++;
|
|
if(judge()){
|
|
continue;
|
|
}
|
|
else{
|
|
break;
|
|
}
|
|
}while(1);
|
|
//ÅÅÐò
|
|
//
|
|
|
|
}
|
|
|
|
//rangeinfo
|
|
|
|
void rangeinfop4(){
|
|
int i,j,k,l=0,num=addnum,clas[20];
|
|
float grade[20];
|
|
for(i=0;i<num;i++){
|
|
clas[i]=stu[i].clas;
|
|
grade[i]=stu[i].grade;
|
|
}
|
|
for(j=0;j<num-1;j++){
|
|
for(k=0;k<num-1;k++){
|
|
if(clas[k]>clas[k+1]){
|
|
swap(k,k+1);
|
|
}
|
|
}
|
|
}
|
|
while(clas[l]==clas[l+1]&&l<num-1){
|
|
if(grade[l]<grade[l+1]){
|
|
swap(l,l+1);
|
|
}
|
|
l++;
|
|
}
|
|
printinfop5();
|
|
}
|
|
|
|
//selectinfo
|
|
|
|
void selectinfop3(){
|
|
int j,num=addnum,jud=1;
|
|
char selnum[20];
|
|
while(1){
|
|
scanf("%s",&selnum);
|
|
for(j=0;j<num;j++){
|
|
if((atoi(selnum)==stu[j].number)||(atoi(selnum)==stu[j].clas)){
|
|
printf("%d,%d,%s,%.1f,%.1f,%.1f,%.1f\n",stu[j].number,stu[j].clas,stu[j].name,stu[j].math,stu[j].physic,stu[j].english,stu[j].grade);
|
|
jud=0;
|
|
}
|
|
}
|
|
if(jud){
|
|
printf("there is no eligible student \n");
|
|
}
|
|
if(judge()){
|
|
continue;
|
|
}
|
|
else{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//deleteinfo
|
|
|
|
void deleteinfop2(){
|
|
int num=addnum,i,j;
|
|
char delnum[20];
|
|
while(1){
|
|
scanf("%s",&delnum);
|
|
if(delnum[0]>='0'&&delnum[0]<='9'){
|
|
for(i=0;i<num;i++){
|
|
if(atoi(delnum)==stu[i].number){
|
|
for(j=i;j<num-1;j++){
|
|
stu[j].number=stu[j+1].number;
|
|
stu[j].clas=stu[j+1].clas;
|
|
strcpy(stu[j].name,stu[j+1].name);
|
|
stu[j].math=stu[j+1].math;
|
|
stu[j].english=stu[j+1].english;
|
|
stu[j].physic=stu[j].physic;
|
|
stu[j].grade=stu[j+1].grade;
|
|
}
|
|
addnum--;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else{
|
|
for(i=0;i<num;i++){
|
|
if(strcmp(delnum,stu[i].name)==0){
|
|
for(j=i;j<num-1;j++){
|
|
stu[j].number=stu[j+1].number;
|
|
stu[j].clas=stu[j+1].clas;
|
|
strcpy(stu[j].name,stu[j+1].name);
|
|
stu[j].math=stu[j+1].math;
|
|
stu[j].english=stu[j+1].english;
|
|
stu[j].physic=stu[j].physic;
|
|
stu[j].grade=stu[j+1].grade;
|
|
}
|
|
addnum--;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if(judge()){
|
|
continue;
|
|
}
|
|
else{
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
printinfop5();
|
|
}
|
|
//Ë÷Òý
|
|
|
|
void ind(){
|
|
int i,j;
|
|
printf("\n");
|
|
for(i=1;i<=6;i++){
|
|
printf("%d.",i);
|
|
switch(i){
|
|
case 1:printf("input\n");break;
|
|
case 2:printf("delete\n");break;
|
|
case 3:printf("select\n");break;
|
|
case 4:printf("order\n");break;
|
|
case 5:printf("output\n");break;
|
|
case 6:printf("quit\n");break;
|
|
}
|
|
}
|
|
printf("please input your option");
|
|
}
|
|
|
|
//Êä³öinfo
|
|
|
|
void printinfop5(){
|
|
int j;
|
|
for(j=0;j<addnum;j++){
|
|
printf("%d,%d,%s,%.1f,%.1f,%.1f,%.1f\n",stu[j].number,stu[j].clas,stu[j].name,stu[j].math,stu[j].physic,stu[j].english,stu[j].grade);
|
|
}
|
|
}
|
|
|
|
//¼ÌÐøÊäÈë?
|
|
|
|
int judge(){
|
|
char judge[]="yes",str[20];
|
|
printf("continue?\n");
|
|
scanf("%s",&str);
|
|
if((int)strcmp(str,judge)==0){
|
|
return 1;
|
|
}
|
|
else{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
//swap
|
|
|
|
void swap(int i,int j){
|
|
int tempint;
|
|
char tempchar[20];
|
|
float tempfloat;
|
|
tempint=stu[i].number;
|
|
stu[i].number=stu[j].number;
|
|
stu[j].number=tempint;
|
|
tempint=stu[i].clas;
|
|
stu[i].clas=stu[j].clas;
|
|
stu[j].clas=tempint;
|
|
strcpy(tempchar,stu[i].name);
|
|
strcpy(stu[i].name,stu[j].name);
|
|
strcpy(stu[j].name,tempchar);
|
|
tempfloat=stu[i].english;
|
|
stu[i].english=stu[j].english;
|
|
stu[j].english=tempfloat;
|
|
tempfloat=stu[i].math;
|
|
stu[i].math=stu[j].math;
|
|
stu[j].math=tempfloat;
|
|
tempfloat=stu[i].physic;
|
|
stu[i].physic=stu[j].physic;
|
|
stu[j].physic=tempfloat;
|
|
tempfloat=stu[i].grade;
|
|
stu[i].grade=stu[j].grade;
|
|
stu[j].grade=tempfloat;
|
|
}
|