From b98027ba9a9df40d922b696763251448a728eb29 Mon Sep 17 00:00:00 2001 From: plwhm8ti7 <1736991355@qq.com> Date: Sun, 12 Nov 2023 09:42:34 +0800 Subject: [PATCH] ADD file via upload --- 6.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 6.cpp diff --git a/6.cpp b/6.cpp new file mode 100644 index 0000000..ed674cc --- /dev/null +++ b/6.cpp @@ -0,0 +1,61 @@ +#include +int main() +{ +struct data + { + long int num; + long int clas; + char name[20]; + float grade1; + float grade2; + float grade3; + }; + struct data stud[3]={10001,11,"zhang",99.5,88.5,89.5,10002,12,"yang",77.9,56.5,87.5,10003,11,"liang",92.5,99.0,60.5}; + struct data stu;//{10001,11,"zhang",99,88,89}; + printf("请输入待修改的学生信息\n"); + scanf("%ld %ld %s %f %f %f",&stu.num,&stu.clas,&stu.name,&stu.grade1,&stu.grade2,&stu.grade3); + for(int i=0;i<3;i++) + { + if(stu.num==stud[i].num) + { + stud[i].grade1=stu.grade1; + stud[i].grade2=stu.grade2; + stud[i].grade3=stu.grade3; + } + break; + } + struct data temp; + for(int i=0;i<3;i++) + { + for(int j=i+1;j<3;j++) + { + if(stud[i].clas>stud[j].clas) + { + temp=stud[i]; + stud[i]=stud[j]; + stud[j]=temp; + } + } + } + for(int i=0;i<3;i++) + { + for(int j=i+1;j<3;j++) + { + if(stud[i].num>stud[j].num&&stud[i].clas==stud[j].clas) + { + temp=stud[i]; + stud[i]=stud[j]; + stud[j]=temp; + } + } + } + for(int i=0;i<3;i++) + { + if(i>0&&stud[i].clas==stud[i-1].clas) + printf(" %ld %s %3.1f %3.1f %3.1f",stud[i].num,stud[i].name,stud[i].grade1,stud[i].grade2,stud[i].grade3); + else printf("%d %ld %s %3.1f %3.1f %3.1f",stud[i].clas,stud[i].num,stud[i].name,stud[i].grade1,stud[i].grade2,stud[i].grade3); + if(stud[i].num==stu.num) printf(" modified"); + printf("\n"); + } + return 0; + }