实验六

Part1

#include 
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)
    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)
printf("%ld %s %d\n", s[i].no, s[i].name, s[i].score);
}
int findMinlist(STU s[], STU t[], int n) {
    int i,j,min=s[0].score;
    for(i=0;i)
    {
        if(s[i].score<min)
            min=s[i].score;
    }
    i=0;
    for(j=0;j)
    {
        if(s[j].score==min)
            t[i++]=s[j];
    }
    return i;
}

实验六_第1张图片

#include 
#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)
        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)
        printf("%ld %s %.2f %.2f %.2f %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)
        s[i].sum=s[i].subjective+s[i].objective;
    for(j=0;j1;j++)
    {
        for(k=0;k1;k++)
        {
            if(s[k].sum1].sum)
            {
                temp=s[k];s[k]=s[k+1];s[k+1]=temp;
            }
        }
    }
    i=0;
    for(i=0;i)
    {
        if(i==0)
            strcpy(s[i].level,"优秀");
        else if(i>=1&&i<=4)
            strcpy(s[i].level,"合格");
        else if(i>=5&&i<=9)
            strcpy(s[i].level,"不合格");
    }
}

实验六_第2张图片

Part2共用体是构造数据类型,也叫联合体
它使几个不同类型的变量共占一段内存(相互覆盖),每次只有一个能使用.
结构体则不然, 每个成员都会有存储空间的,可以一起用.(搜索得到)

Part3枚举用于描述包含固定值的数据,不能直接输入输出,把一个int型数值赋值给一个枚举类型的变量需要使用强制(显式)转换,枚举值可以赋给整形变量。

你可能感兴趣的:(实验六)