zoukankan      html  css  js  c++  java
  • 实验七

    实验任务3

    正确,生成

    正确,直观可读

    实验任务4

    子任务1:正确输出,生成,不直观可读

    子任务2:

    #include <stdio.h> 
    #include <stdlib.h>
    
    #define N 10
    
    typedef struct student {
        int num;
        char name[20];
        int score;
    }STU;
    
    int main() {
        FILE *fin, *fout;
        STU st[N];
        int i;
        
        fin = fopen("file4.dat", "rb");
        if( !fin ) {  
            printf("fail to open file4.dat
    ");
            exit(0);
        }
        
    fread(st,sizeof(STU),10,fin);
    
    fclose(fin);
    
        for(i=0; i<N; i++) 
            printf("%-6d%-10s%3d
    ", st[i].num, st[i].name, st[i].score);
        
        
        return 0;
    }

    实验任务5:

    #include <stdio.h>
    #include <string.h>
    const int N = 10;
    
    // 定义结构体类型struct student,并定义其别名为STU 
    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); 
        input(stu, N);
        
        printf("
    对考生信息进行处理: 计算总分,确定等级
    ");
        process(stu, N);
        
        printf("
    打印考生完整信息: 准考证号,姓名,客观题得分,操作题得分,总分,等级
    ");
        output(stu, N); 
        
        return 0;
    } 
    
    // 从文本文件examinee.txt读入考生信息:准考证号,姓名,客观题得分,操作题得分
    void input(STU s[], int n) {
        FILE*fp;
        fp=fopen("examinee.txt","r");
        for(int i=0;i<N;i++)
        fscanf(fp,"%ld %s %f %f",&s[i].id,s[i].name,&s[i].objective,&s[i].subjective);
        fclose(fp);
        
    
    }
    
    // 输出考生完整信息: 准考证号,姓名,客观题得分,操作题得分,总分,等级
    // 不仅输出到屏幕上,还写到文本文件result.txt中 
    void output(STU s[], int n) {
        FILE*fin;
        fin=fopen("result.txt", "w");
        for(int i=0;i<N;i++)
        {
            printf("%ld		 %s		  %.2f		 %.2f		 %.2f	 %s
    ",s[i].id,s[i].name,s[i].objective,s[i].subjective,s[i].sum,s[i].level);
            fprintf(fin,"%ld		 %s		  %.2f		 %.2f		 %.2f	 %s
    ",s[i].id,s[i].name,s[i].objective,s[i].subjective,s[i].sum,s[i].level);
        }
        fclose(fin);
    }
    
    // 对考生信息进行处理:计算总分,排序,确定等级
    void process(STU s[], int n) {
        for (int i = 0; i < n; i++) {
            s[i].sum = s[i].objective + s[i].subjective;
            if (s[i].sum < 90) {
                strcpy(s[i].level, "不合格");
            }
            else if (s[i].sum <= 95) {
                strcpy(s[i].level, "合格");
            }
            else {
                strcpy(s[i].level, "优秀");
            }
        }
        for (int i = 0; i < n - 1; i++) {
            STU temp ;
            for (int j = 0; j < n-1-i; j++) {
                if (s[j].sum < s[j + 1].sum) {
                    temp = s[j];
                    s[j] = s[j + 1];
                    s[j + 1] = temp;
                }
            }
        }
    }

  • 相关阅读:
    docker镜像制作及上传到远端镜像仓库
    mysql索引进阶
    电子商务需要用到香港服务器吗?
    golang module goland 配置代理
    nginx做linux服务时,日志有权限提示没权限(nginx: [emerg] open() "/home/www/log/error.log" failed)
    Yaml 、Json 、Dict 之间的转化
    CodeSmith .NET三层架构模板
    C#获取26个英文字母
    基于PCASClass.js和layui.js的城市三级联动
    MySQL变量的使用
  • 原文地址:https://www.cnblogs.com/ruanfandd/p/14198316.html
Copyright © 2011-2022 走看看