首页 > 其他分享 >五月二十五日实验

五月二十五日实验

时间:2023-06-08 19:45:17浏览次数:34  
标签:min int sum level ++ 二十五日 STU 实验 五月

实验一

实验二

实验三

实验四

#include <stdio.h>
#include<string.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);
return 0;
}
// 函数定义
// 功能:对包含n条学生成绩记录的数组a进行处理:
// 计算总评成绩,统计等级为"均分以上"的学生记录保存到数组h中,并返回其人数
int fun (STU a[], int n, STU h[]) {
    int i;
    int k = 0;
    double ave = 0.0;
    for(i = 0; i < n; i++) {
        a[i].sum = a[i].s1*0.7 + a[i].s2*0.3;
        ave += a[i].sum;
    }
    ave /= n;
    for(i = 0; i < n; i++)
        if(a[i].sum > ave)
            h[k++] = a[i];
    return k;
}

实验图片:

实验五

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

return 0;
}
void fun(STU a[], int n) {
    int i;
    int max, min;

    for(i = 0; i < n; i++)
        a[i].sum = a[i].maths + a[i].computer + a[i].english;

    max = min = a[0].sum;

    for(i = 1; i < n; i++)
        if(a[i].sum > max)
            max = a[i].sum;

    for(i = 1; i < n; i++)
        if(a[i].sum < min)
            min = a[i].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,"合格");
    }
}

实验图片:

实验六

#include <stdio.h>
#define N 5

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 i;
    int min = s[0].score;
    int k = 0;
    for(i = 1; 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;
}

实验图片:

标签:min,int,sum,level,++,二十五日,STU,实验,五月
From: https://www.cnblogs.com/xhw354405545/p/17467470.html

相关文章

  • 实验6
    task1_1源代码:1fromturtleimport*23defmove(x,y):4'''画笔移动到坐标(x,y)处'''5penup()6goto(x,y)7pendown()89defdraw(n,size=100):10'''绘制边长为size的正n边形'''......
  • 实验七
    任务三#include<stdio.h>#include<stdlib.h>intmain(){FILE*fp;charch;intchar_count=0;fp=fopen("data4.txt","r");if(fp==NULL){printf("Couldnotopenfiledata4.txt.\n&q......
  • 实验7
    任务4源代码#include<stdio.h>#include<string.h>intmain(){FILE*fp;inti,num=0;chars[7][80];fp=fopen("data4.txt","r");if(fp==NULL){printf("failtoopenfp\n");......
  • 实验6 turtle绘图与python库应用编程体验
    task1-1fromturtleimport*defmove(x,y):penup()goto(x,y)pendown()defdraw(n,size=100):foriinrange(n):fd(size)left(360/n)defmain():pensize(2)pencolor('red')move(-200,0)draw......
  • 实验七
    实验任务4程序代码:#include<stdio.h>#include<string.h>#include<stdlib.h>intmain(){FILE*fp;charstr[100];inti,k=0,flag;while((fp=fopen("data4.txt","r"))==NULL)printf("failtoopen&quo......
  • 实验7
    实验任务4实验代码#include<stdio.h>#include<stdlib.h>#include<string.h>constintN=5,M=100;intmain(){charch[M];intn=0; FILE*fp; fp=fopen("data4.txt","r"); while(!feof(fp))......
  • 实验7
    #11#12classAccount:3def__init__(self,name,account_number,initial_amount=10):4self._name=name5self._card_no=account_number6self._balance=initial_amount78defdeposit(self,amount):9'......
  • 实验七
    classAccount:def__init__(self,name,account_number,initial_amount=10):self._name=nameself._card_no=account_numberself._balance=initial_amountdefdeposit(self,account):self._balance+=accountdefwithdraw(s......
  • 实验六
    task11fromturtleimport*2defmove(x,y):3penup()4goto(x,y)5pendown()6defdraw(n,size=100):7foriinrange(n):8fd(size)9left(360/n)10defmain():11pensize(2)12pencolor('red......
  • 实验七
    任务一1classAccount:2'''一个模拟银行账户的简单类'''3def__init__(self,name,account_number,initial_amount=10):4'''构造新账户'''5self._name=name6self._card_no......