首页 > 其他分享 >实验5

实验5

时间:2022-12-21 19:55:29浏览次数:30  
标签:min int sum level STU 实验 include

test3

#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 100
typedef struct {
char num[10]; // 学号
int s1; // 期末成绩
int s2; // 平时成绩
double sum; // 总评
char level[10]; // 等级
} STU;
int fun(STU a[], int n, STU h[]);
int main() {
STU s[N]={ {"GA05", 85, 76},
{"GA03", 76, 90},
{"GA02", 69, 90},
{"GA04", 85, 56},
{"GA01", 91, 95},
{"GA07", 72, 80},
{"GA08", 64, 45},
{"GA06", 87, 98},
{"GA015", 85, 86},
{"GA013", 91, 97} };
STU h[N]; // 保存均分以上学生记录
int i, k, n = 10;
k = fun(s, n, h);
printf("There are :\n");
for(i = 0; i < k; i++)
printf("%s %d %d %.2f %s\n", h[i].num, h[i].s1, h[i].s2, h[i].sum,
h[i].level);
return 0;
}
int fun(STU[] a,intt n,STU[] b){
    int i = 0;
    double sum = 0;
    int res = 0;
    for(i = 0;i<n;i++){
        a[i].sum = a[i].s1*0.7+a[i].s2*0.7;
    }
    for(i = 0;i<n;i++){
        sum += a[i].sum;
    }
    sum = sum *1.0/n;
    for(i = 0 ;i<n;i++){
        if(a[i].sum>sum){
            res++;
        }
    }
    return res;
}

 

 test4

#include <stdio.h>
#include <string.h>
#include<stdlib.h>
#define N 5

typedef struct student {
    char name[10];
    int num;
    int maths;
    int computer;
    int english;
    int sum;
    char level[10];
} STU;

void fun(STU a[], int n);  // 函数声明

int main() {
    STU s[6*N]={ {"A001", 1, 34, 67, 80},
                 {"B003", 3, 78, 87, 90},
                 {"A002", 2, 90, 98, 99},
                 {"B002", 4, 56, 78, 98},
                 {"A005", 5, 35, 67, 79} };
    int i;

    fun(s, N);
    for(i = 0; i < N; i++)
      printf("%s %d %d %d %d %d %s\n", s[i].name, s[i].num, s[i].maths, s[i].computer, s[i].english, s[i].sum, s[i].level);
    system("pause");
    return 0;
}

// 函数定义
// 功能:对包含n条学生成绩记录的数组a进行处理:
// 计算三门课程总分、总分最大值、总分最小值,并设置等级:
// 总分与总分最大值相等的同学的等级设置为优秀
// 总分与总分最小值相等的同学的等级设置为不及格
// 其余同学的等级设置为合格
void fun(STU a[], int n) {
    // 待补足
    // xxx
int i, j, max = 0, min = 300;
    for (i = 0; i < n; i++)
    {
        a[i].sum = a[i].maths + a[i].computer + a[i].english;
        if (max < a[i].sum)
            max = a[i].sum;
        if (min > a[i].sum)
            min = a[i].sum;
    }
    for (j = 0; j < n; j++)
    {
        if (a[j].sum == max)
            strcpy(a[j].level, "优秀");
        else if (a[j].sum == min)
            strcpy(a[j].level, "不及格");
        else
            strcpy(a[j].level, "合格");
    }
}

 

 tset5

#include <stdio.h>
#include<stdlib.h>
#define N 5
// 定义结构体类型struct student, 并定义STU为其别名
typedef struct student {
long no;
char name[20];
int score;
} STU;
// 函数声明
void input(STU s[], int n);
int find_min_list(STU s[], STU t[], int n);
void output(STU s[], int n);
int main() {
STU stu[N], min_list[N];
int count;
printf("录入%d个学生信息\n", N);
input(stu, N);
printf("\n统计最低分人数和学生信息...\n");
count = find_min_list(stu, min_list, N);
printf("\n一共有%d个最低分,信息如下:\n", count);
output(min_list, count);
system("pause");
return 0;
}
// 输入n个学生信息,存放在结构体数组s中
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);
}
// 输出结构体s中n个元素信息
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);
}
// 在结构体数组s中,查找最低分学生的记录,将其存入结构体数组t中
// 形参n是结构体数组s中元素个数
// 函数返回最低分的学生人数
int find_min_list(STU s[], STU t[], int n) {
int i,j=0;
STU min;
min=s[0];
for(i=0;i<n;i++)
{
    if(s[i].score<min.score)
        min=s[i];
}
for(i=0;i<n;i++)
    if(min.score==s[i].score)
        t[j++]=s[i];
return j;
}

 

标签:min,int,sum,level,STU,实验,include
From: https://www.cnblogs.com/shenyuhao/p/16997005.html

相关文章

  • 实验6
    #include<stdio.h>intmain(){charch;FILE*fp;fp=fopen("data4.txt","r");if(fp==NULL){printf("failtoopenfile");re......
  • 实验五
    #include<stdio.h>#include<string.h>#include<stdlib.h>#defineN100typedefstruct{charnum[10];//学号ints1;//期末成......
  • 实验5
    task3#include<stdio.h>#include<stdlib.h>#include<string.h>#defineN100typedefstruct{charnum[10];//学号ints1;//......
  • 实验五
    实验任务3#define_CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<string.h>#include<stdlib.h>#defineN100typedefstruct{charnum[10];//学号......
  • 火山引擎 DataTester 为企业降本增效:1 个人也能成为一支 A/B 实验团队
    更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群今年天猫电商、京东均表示交易规模与2021年持平,跟往年急剧增长的销售额相比,今年的双......
  • 实验6
    task4#include<stdio.h>intmain(){FILE*fp;fp=fopen("C:\\Users\\user\\Documents\\data4.txt","r");if(feof(fp)){printf("failtoopenth......
  • 火山引擎 DataTester 为企业降本增效:1 个人也能成为一支 A/B 实验团队
    更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群 今年天猫电商、京东均表示交易规模与2021年持平,跟往年急剧增长的销售额相比,今......
  • 实验五 结构体应用编程
    实验任务三task3.c#include<stdio.h>#include<string.h>#include<stdlib.h>#defineN100typedefstruct{charnum[10];//学号ints1;//期末成绩ints2;/......
  • 实验五
    task3#include<stdio.h>#include<string.h>#include<stdlib.h>#defineN100typedefstruct{charnum[10];//学号ints1;//期末成绩ints2;//平时成绩dou......
  • 实验5
    实验任务3#include<stdio.h>#include<string.h>#include<stdlib.h>#defineN100typedefstruct{charnum[10];//学号ints1;//期末成绩ints2......