实验六

实验1

#include<stdio.h>#include<stdlib.h>#include<string.h> #define N 4       typedef struct student {    int id;                char name[20];            char subject[20];       float perf;           float mid;            float final;         float total;           char level[10];   } STU;void input(STU[],int );         void calc(STU[],int);        int fail(STU[],STU [],int);     void sort(STU[],int);        void print(STU[], int);        int main() {    STU st[N],fst[N];      int k;         printf("录入学生成绩信息:\n");    input(st,N);        printf("\n成绩处理...\n");    calc(st,N);        k = fail(st,fst,N);    sort(st, N);    printf("\n学生成绩排名情况:\n");    print(st, N);        printf("\n不及格学生信息:\n");    print(fst, k);        return 0;} void input(STU s[],int n) {      int i;      for(i=0;i<n;i  )      scanf("%d %s %s %f %f %f",&s[i].id,s[i].name,s[i].subject,&s[i].perf,&s[i].mid,&s[i].final);}void calc(STU s[],int n) {    int i;    for(i=0;i<n;i  ) {            s[i].total=s[i].perf*0.2 s[i].mid*0.2 s[i].final*0.6;                if(s[i].total>=90)          strcpy(s[i].level,"优");          else if(s[i].total>=80 && s[i].total<90)          strcpy(s[i].level,"良");        else if(s[i].total>=70 && s[i].total<80)          strcpy(s[i].level,"中");         else if(s[i].total>=60 && s[i].total<70)          strcpy(s[i].level,"及格");        else          strcpy(s[i].level,"不及格");             }}int fail(STU s[],STU t[],int n) {      int i,k=0;            for(i=0;i<n;i  )          if(s[i].total<60)            t[k  ]=s[i];                return k;}void sort(STU s[],int n) {    int i,j;    STU temp;        for(i=0;i<n-1;i  )      for(j=0;j<n-1-i;j  )        if(s[j].total<s[j 1].total) {            temp = s[j];            s[j] = s[j 1];            s[j 1] = temp;        }}void print(STU s[], int n) {   int i;      printf("-----------------\n");   printf("学号 姓名 考试科目 平时成绩 期中成绩  期末成绩 总评成绩  成绩等级\n");   for(i=0;i<n;i  )      printf("] s s %5.1f %5.1f %5.1f %5.1f s\n",s[i].id,s[i].name,s[i].subject,s[i].perf,s[i].mid,s[i].final,s[i].total,s[i].level);}

实验2

#include <stdio.h>const int N=5;typedef struct student {    long no;    char name[20];    int score;     }STU;void input(STU s[], int n);int findMinlist(STU s[], STU t[], int n);void output(STU s[], int n);int main() {    STU stu[N], minlist[N];    int count;        printf("录入%d个学生信息\n", N);    input(stu, N);        printf("\n统计最低分人数和学生信息...\n");    count = findMinlist(stu, minlist, N);        printf("\n一共有%d个最低分,信息如下:\n", count);    output(minlist, count);         return 0;} void input(STU s[], int n) {    int i;    for(i=0; i<n; i  )         scanf("%ld %s %d", &s[i].no, s[i].name, &s[i].score);} void output(STU s[], int n) {    int i;    for(i=0; i<n; i  )        printf("%ld %s %d\n", s[i].no, s[i].name, s[i].score); } int findMinlist(STU s[], STU t[], int n) {    int min=100,i,k=0;        for(i=0;i<n;i  )        if(s[i].score<min)            min=s[i].score;        for(i=0;i<n;i  )        if(s[i].score==min){            t[k  ]=s[i];        }        return k;}

实验3

#include <stdio.h> #include <string.h>const int N = 10;typedef struct student {    long int id;    char name[20];    float objective;       float subjective;      float sum;    char level[10];    }STU; void input(STU s[], int n);void output(STU s[], int n);void process(STU s[], int n);int main() {    STU stu[N];        printf("录入%d个考生信息: 准考证号,姓名,客观题得分(<=40),操作题得分(<=60)\n", N);     input(stu, N);        printf("\n对考生信息进行处理: 计算总分,确定等级\n");    process(stu, N);        printf("\n打印考生完整信息: 准考证号,姓名,客观题得分,操作题得分,总分,等级\n");    output(stu, N);         return 0;} void input(STU s[], int n) {    int i;    for(i=0;i<n;i  )    scanf("%ld %s %f %f",&s[i].id,s[i].name,&s[i].objective,&s[i].subjective); }void output(STU s[], int n) {    int i;    for(i=0;i<n;i  )    printf("%5ld s %5.1f %5.1f %5.1f s\n",s[i].id,s[i].name,s[i].objective,s[i].subjective,s[i].sum,s[i].level);    }void process(STU s[], int n) {    int i,j,k;    STU temp;             for(i=0;i<n;i  )         s[i].sum=s[i].objective s[i].subjective;            for(i=0;i<n-1;i  )        for(j=i 1;j<n;j  )            if(s[j].sum>s[i].sum){                temp=s[i];                s[i]=s[j];                s[j]=temp;            }                    for(i=0;i<n;i  ){        if(i==0)          strcpy(s[i].level,"优秀");         else if(i>0&&i<=4)          strcpy(s[i].level,"合格");        else          strcpy(s[i].level,"不合格");    }}

来源:https://www.icode9.com/content-4-795951.html

(0)

相关推荐