首页 > 其他分享 >实验5

实验5

时间:2022-12-27 11:56:22浏览次数:36  
标签:min int sum level ++ STU 实验

task3.c

#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;
    // 调用fun对学生成绩记录进行处理
    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);
    system("pause");
    return 0;
}
int fun(STU a[], int n, STU h[]) {
    int b = 0, i;
    double result=0,ave;
    for (i = 0; i < 10; i++) 
    {
        a[i].sum = a[i].s1 * 0.7 + a[i].s2 * 0.3;
        result = result + a[i].sum;
    }
    ave = result / 10.0;
    for (i = 0; i < 10; i++)
    {
        if (a[i].sum >= ave) 
        {
            strcpy(h[b].level, "均分以上");
            strcpy(h[b].num, a[i].num);
            h[b].s1 = a[i].s1;
            h[b].s2 = a[i].s2;
            h[b].sum=a[i].sum;
            b++;
        }
    }
    return b;
}

task4.c

#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;
}
void fun(STU a[], int n) 
{
    int i,max,min,j;
    for (i = 0; i < N; i++) 
        a[i].sum = a[i].maths + a[i].computer + a[i].english;
    max = a[0].sum;
    min = a[0].sum;
    for (j = 0; j < N; j++)
    {
        if (a[j].sum > max) 
            max = a[j].sum;
        if (a[j].sum < min)
            min = a[j].sum;
    }
    for (i = 0; i < N; i++) 
    {
        if (a[i].sum==max)
            strcpy(a[i].level, "优秀");
        else if (a[i].sum==min)
            strcpy(a[i].level, "不及格");
        else
            strcpy(a[i].level, "合格");
    }
}

task5.c

 

#include <stdio.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);

    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 find_min_list(STU s[], STU t[], int n) {
    int count = 0, min = 100;
    for (int i = 0; i < N; i++)
    {
        if (s[i].score < min)
            min = s[i].score;
    }
    for (int i = 0; i < N; i++)
        if (s[i].score == min)
            t[count++] = s[i];
    return count;
}

 

标签:min,int,sum,level,++,STU,实验
From: https://www.cnblogs.com/wangrongxin240/p/17007693.html

相关文章

  • 实验5
    #include<stdio.h>#include<string.h>#defineN3typedefstructstudent{intid;//学号charname[20];//姓名......
  • 实验6
    #include<stdio.h>#include<stdlib.h>intmain(){chara[2][100]={"nuist2022-nuist2023","FIFAWorldCup2022"};FILE*fp;inti,n=0;charch;......
  • 实验5 结构体应用编程
    1.实验任务1//P286例8.17//对教材上的程序作了微调整,把输出学生信息单独编写成一个函数模块//打印不及格学生信息和所有学生信息程分别调用#include<stdio.h>......
  • 《DFZU2EG_4EV MPSoc之FPGA开发指南》第三十三章 OV5640摄像头HDMI显示实验​
    OV5640摄像头HDMI显示实验​在OV5640摄像头RGB-LCD显示实验中,成功地在LCD屏上实时显示出了摄像头采集的图像。本章将使用FPGA开发板实现对OV5640的数字图像采集并在HDMI显示......
  • 实验内容:NTP的客户端实现
           ......
  • 实验六
    任务4#define_CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>intmain(){charch;intcount=0;FILE*fp;fp=fopen("D:\\data......
  • 实验五
    任务3#include<stdio.h>#include<string.h>#defineN100typedefstruct{charnum[10];//学号ints1;//期末成绩ints2;......
  • 实验6 文件应用编程
    #include<stdio.h>#defineN7#defineM80typedefstruct{charname[M];//书名charauthor[M];//作者}Book;intmain(){Bookx[N]={{"《雕塑家》","......
  • 实验6
    实验6#include<stdio.h>#include<stdlib.h>intmain(){chara[2][100]={"nuist2022-nuist2023","FIFAWorldCup2022"};FILE*fp;inti,n=0;cha......
  • 实验5 结构体应用编程
    #include<stdio.h>#include<string.h>#defineN3typedefstructstudent{intid;charname[20];charsubject[20......