ADD file via upload

main
p3afi4g2n 3 months ago
parent 9ee9c4944e
commit 10486230d3

@ -0,0 +1,140 @@
#include <stdio.h>
#include <string.h>
struct Message
{
char Id[6];
char clas[3];
char name[10];
double score1;
double score2;
double score3;
double score;
}student[10];
int sum=0;
int main(){
void MENU();
void INPUT(int i);
void DELETE();
void SELECT();
void SORT();
void PRINT(int sum);
int choose;
MENU();
scanf("%d",&choose);
while(choose!=6){
MENU();
if(choose==1){
INPUT(0);
}
else if(choose==2){
DELETE();
}
else if(choose==3){
SELECT();
}
else if(choose==4){
SORT();
}
else {
PRINT(sum);
}
scanf("%d",&choose);
}
}
void MENU(){
printf("1.input\n2.delete\n3.select\n4.order\n5.output\n6.quit\n");
printf("please input your option\n");
}
void PRINT(int sum){
int i;
for(i=0;i<=sum;i++){
printf("%s,%s,%s,%.1lf,%.1lf,%.1lf,%.1lf\n",student[i].Id,student[i].clas,student[i].name,student[i].score1,student[i].score2,student[i].score3,student[i].score);
}
}
int RESPONSE(){
printf("continue?\n");
char approve[5]="yes";
char response[5];
scanf("%s",response);
if(strcmp(response,approve)==0)
return 1;
else
return 0;
}
int INPUT(int i){
printf("Id ");
scanf("%s",student[i].Id);
printf("class ");
scanf("%s",student[i].clas);
printf("name ");
scanf("%s",student[i].name);
printf("score1 ");
scanf("%lf",&student[i].score1);
printf("score2 ");
scanf("%lf",&student[i].score2);
printf("score3 ");
scanf("%lf",&student[i].score3);
int word=RESPONSE();
if(word){
sum++;
INPUT(i+1);
}
student[i].score=student[i].score1+student[i].score2+student[i].score3;
return 0;
}
void DELETE(){
char input[10];
int i,t=0;
scanf("%s",input);
for(i=0;i<=sum;i++){
if(strcmp(student[i].Id,input)==0||strcmp(student[i].name,input)==0){
t=1;
break;
}
}
if(t==0){
PRINT(sum);
}
else{
while(i<sum){
student[i]=student[i+1];
i++;
}
sum--;
PRINT(sum);
}
int word=RESPONSE();
if(word){
DELETE();
}
}
void SELECT(){
char input[6];
int i;
scanf("%s",input);
for(i=0;i<=sum;i++){
if(strcmp(student[i].Id,input)==0||strcmp(student[i].clas,input)==0){
printf("%s,%s,%s,%.1lf,%.1lf,%.1lf,%.1lf\n",student[i].Id,student[i].clas,student[i].name,student[i].score1,student[i].score2,student[i].score3,student[i].score);
}
}
int word=RESPONSE();
if(word){
SELECT();
}
}
void SORT(){
int i,j;
for(i=1;i<=sum;i++){
for(j=0;j<sum+1-i;j++){
if(strcmp(student[j].clas,student[j+1].clas)>0){
struct Message temp;
temp=student[j];student[j]=student[j+1];student[j+1]=temp;
}
else if(strcmp(student[j].clas,student[j+1].clas)==0&&student[j].score<student[j+1].score){
struct Message temp;
temp=student[j];student[j]=student[j+1];student[j+1]=temp;
}
}
}
PRINT(sum);
}
Loading…
Cancel
Save