试验七

博客提及按部就班做了很多关于ex2的内容,还涉及exit(0),并给出了转载来源https://www.cnblogs.com/hx-123/p/11079428.html 。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ex2

  1 #include <stdio.h>
  2 #include <string.h>
  3 const int N = 10;
  4 
  5 // 定义结构体类型struct student,并定义其别名为STU 
  6 typedef struct student {
  7     long int id;
  8     char name[20];
  9     float objective;    /*客观题得分*/
 10     float subjective;    /*操作题得分*/
 11     float sum;
 12     char level[10];    
 13 }STU; 
 14 
 15 // 函数声明
 16 void input(STU s[], int n);
 17 void output(STU s[], int n);
 18 void process(STU s[], int n);
 19 
 20 int main() {
 21     STU stu[N];
 22     
 23     printf("录入%d个考生信息: 准考证号,姓名,客观题得分(<=40),操作题得分(<=60)\n", N); 
 24     input(stu, N);
 25     
 26     printf("\n对考生信息进行处理: 计算总分,确定等级\n");
 27     process(stu, N);
 28     
 29     printf("\n打印考生完整信息: 准考证号,姓名,客观题得分,操作题得分,总分,等级\n");
 30     output(stu, N); 
 31     
 32     return 0;
 33 } 
 34 
 35 // 从文本文件examinee.txt读入考生信息:准考证号,姓名,客观题得分,操作题得分
 36 void input(STU s[], int n) {
 37     // 补足代码
 38     FILE *fp;
 39     int i;
 40     
 41     fp = fopen("examinee.txt", "r"); 
 42     if (fp == NULL) {
 43         printf("fail to open examinee.txt\n");    
 44     } 
 45     
 46     for(i=0; i<n; i++){ 
 47         fscanf(fp, "%d %s %f %f", &s[i].id, s[i].name, &s[i].objective, &s[i].subjective);
 48                                                                                
 49     } 
 50     fclose(fp);
 51 }
 52 
 53 // 对考生信息进行处理:计算总分,排序,确定等级
 54 void process(STU s[], int n) {
 55     // 补足代码
 56     STU t;
 57     int i;
 58     
 59     for(i=0; i<n; i++)
 60     {
 61         s[i].sum=s[i].objective+s[i].subjective;
 62     }
 63     
 64     for(i=0; i<n; i++)
 65       for(j=0;j<n-i-1;j++)
 66         if(s[j].sum<s[j+1].sum)
 67          {
 68           t=s[j];
 69           s[j]=s[j+1];
 70           s[j+1]=t;
 71          }
 72 
 73  for(i=0;i<n;i++)
 74     {
 75         if((i+1)<=n*0.1)
 76           strcpy(s[i].level,"优秀"); 
 77         else if((i+1)>n*0.1&&(i+1)<=n*0.5)
 78           strcpy(s[i].level,"合格");
 79         else
 80           strcpy(s[i].level,"不合格");    
 81     }
 82 }
 83 
 84 // 输出考生完整信息: 准考证号,姓名,客观题得分,操作题得分,总分,等级
 85 // 不仅输出到屏幕上,还写到文本文件result.txt中 
 86 void output(STU s[], int n) {
 87     // 补足代码
 88      FILE *fp;
 89      int i;
 90     
 91     fp = fopen("result.txt", "w"); 
 92     if (fp == NULL) {
 93         printf("fail to open result.txt\n");   
 94     } 
 95     
 96     for(i=0; i<n; i++) {
 97         printf("%d %s %.2lf %.2lf %.2lf %s\n", s[i].id, s[i].name, s[i].objective, s[i].subjective, s[i].sum, s[i].level);
 98         fprintf(fp, "%d %s %.2lf %.2lf %.2lf %s\n", s[i].id, s[i].name, s[i].objective, s[i].subjective, s[i].sum, s[i].level);
 99     }
100     
101     fclose(fp);
102 }

前面按部就班了很多东西

包括exit(0)

自己太low了

 

转载于:https://www.cnblogs.com/hx-123/p/11079428.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值