当前位置: 首页 > news >正文

实验报告7

实验4

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>signed main() {FILE *fp;fp=fopen("data4.txt","r");if(fp==NULL){printf("fail to open file to read\n");return 0;}int n=0,nl=0;char c=fgetc(fp);while(c!=EOF){// putchar(c);if(c=='\n'){nl++;}else{if(c!=' '&&c!=EOF){n++;}}c=fgetc(fp);}fclose(fp);// printf("\n");printf("行数:%d\n",nl+1);printf("字符数(不计空白字符):%d\n",n);return 0;
}

image

实验5

#include <stdio.h>
#include <string.h>#define N 10typedef struct {long id;            // 准考证号char name[20];      // 姓名float objective;    // 客观题得分float subjective;   // 操作题得分float sum;          // 总分char result[10];    // 考试结果
} STU;// 函数声明
void read(STU st[], int n);
void write(STU st[], int n);
void output(STU st[], int n);
int process(STU st[], int n, STU st_pass[]);int main() {STU stu[N], stu_pass[N];int cnt;double pass_rate;printf("从文件读入%d个考生信息...\n", N);read(stu, N);printf("\n对考生成绩进行统计...\n");cnt = process(stu, N, stu_pass);printf("\n通过考试的名单:\n");output(stu, N);   // 输出所有考生完整信息到屏幕write(stu, N);    // 输出考试通过的考生信息到文件pass_rate = 1.0 * cnt / N;printf("\n本次等级考试通过率: %.2f%%\n", pass_rate*100);return 0;
}// 把所有考生完整信息输出到屏幕上
// 准考证号,姓名,客观题得分,操作题得分,总分,结果
void output(STU st[], int n) {int i;printf("准考证号\t姓名\t客观题得分\t操作题得分\t总分\t\t结果\n");for (i = 0; i < n; i++)printf("%ld\t\t%s\t%.2f\t\t%.2f\t\t%.2f\t\t%s\n", st[i].id, st[i].name, st[i].objective, st[i].subjective, st[i].sum, st[i].result);
}// 从文本文件examinee.txt读入考生信息:准考证号,姓名,客观题得分,操作题得分
void read(STU st[], int n) {int i;FILE *fin;fin = fopen("examinee.txt", "r");if (!fin) {printf("fail to open file\n");return;}for (i = 0; i < n; i++)fscanf(fin, "%ld %s %f %f", &st[i].id, st[i].name, &st[i].objective, &st[i].subjective);fclose(fin);
}// 把通过考试的考生完整信息写入文件list_pass.txt
// 准考证号,姓名,客观题得分,操作题得分,总分,结果
void write(STU s[], int n) {// 待补足// xxxFILE *fout;fout=fopen("list_pass.txt","w");if(fout==NULL){printf("fail to open file to write\n");return;}fprintf(fout,"准考证号\t姓名\t客观题得分\t操作题得分\t总分\t\t结果\n");for(int i=0;i<n;i++){if(strcmp(s[i].result,"通过")==0){fprintf(fout,"%ld\t\t%s\t%.2f\t\t%.2f\t\t%.2f\t\t%s\n",s[i].id,s[i].name,s[i].objective,s[i].subjective,s[i].sum,s[i].result);}}fclose(fout);
}// 对考生信息进行处理:计算每位考生考试总分、结果;统计考试通过的人数
int process(STU st[], int n, STU st_pass[]) {// 待补足// xxxFILE *f;int count=0;f=fopen("examinee.txt","r");if(f==NULL){printf("fail to open file\n");return 0;}for(int i=0;i<=n;i++){st[i].sum=st[i].objective+st[i].subjective;if(st[i].sum>=60){strcpy(st[i].result,"通过");count++;}else{strcpy(st[i].result,"不通过");}}fclose(f);return count;
}

image

image

实验6

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
struct Stu{long id;char name[100];char class[100];
}a[114514],b[114514];
int h[114514];
signed main() {srand((unsigned int)time(NULL));time_t rawtime;struct tm * timeinfo;time(&rawtime);timeinfo = localtime(&rawtime);char str[20];strftime(str, sizeof(str),"%Y%m%d.txt",timeinfo);FILE *fin, *fout;fout=fopen(str,"w");fin=fopen("list.txt","r");int i=0;while(fscanf(fin,"%ld %s %s",&a[i].id,a[i].name,a[i].class)!=EOF){i++;}int n=i;for(int j=1;j<=5;){int t=rand()%n;while(!h[t]){h[t]=1;b[j++]=a[t];}t=rand()%n;}for(int j=1;j<=5;j++){for(int k=j+1;k<=5;k++){if(b[j].id>b[k].id){struct Stu t=b[j];b[j]=b[k];b[k]=t;}}}fclose(fin);printf("----------%s中奖名单----------\n",str);printf("准考证号\t姓名\t班级\n");for(int j=1;j<=5;j++){printf("%ld\t%s\t%s\n",b[j].id,b[j].name,b[j].class);}fprintf(fout,"----------%s中奖名单----------\n",str);fprintf(fout,"准考证号\t姓名\t班级\n");for(int j=1;j<=5;j++){fprintf(fout,"%ld\t%s\t%s\n",b[j].id,b[j].name,b[j].class);}fclose(fout);return 0;
}

image

image

http://www.jsqmd.com/news/139424/

相关文章:

  • 解题报告-P3081 USACO13MAR Hill Walk G
  • [Windows] 时间和倒计时关机小工具V2.0
  • [吾爱大神原创工具] Net Tools-网络运维工具箱
  • [吾爱大神原创工具] Net Tools-网络运维工具箱
  • 实用指南:量子计算入门:Python量子编程基础
  • HTTP请求方法
  • Pinia状态管理实战教程
  • hot100 141.环形链表
  • 实现自定义指令 v-scrollBar,用于动态显示/隐藏滚动条,提升用户体验
  • 巨量AD广告专业服务商:诚信之选带来的行业变革
  • doris中的分区上卷
  • 工商注册服务推荐:选对公司,开启企业省心之旅
  • doris中的Broadcast Join
  • 工商注册服务哪家好?靠谱之选看这里
  • 某机构趁低买入以太坊,持仓超300万枚
  • 2025年好吃的重庆香肠品牌排行,满足不同场合和个人喜好需求 - 讯息观点
  • 启用Qoder编写ztdaq的C#跨专业的平台示例总结
  • ProfiNet转CAN网关优质生产商推荐
  • 2025最新!继续教育必备9个AI论文平台深度测评
  • doris的Bucket Shuffle Join
  • 8个AI论文软件推荐,继续教育学生轻松搞定毕业论文!
  • 2026设计师私藏,正版高清图片素材网站,商用无风险,购买超省心 - 品牌2026
  • 2025年推荐电池厂排行榜,新测评精选电池正规厂商与电池生产企业推荐
  • XZ Utils库后门漏洞深度剖析:CVE-2024-3094的RCE风险与缓解方案
  • 微信小程序vue_uniapp二手书交易平台
  • 全网热议!2025年热门空调安装品牌推荐,助您选择优质的合作伙伴 - 讯息观点
  • 会议精灵:用ModelEngine构建智能办公助手实战记录
  • Doris的Colocation[托管] Join
  • 2026全网精选,商用高清正版图片素材网站合集,无版权风险放心用 - 品牌2026
  • Spring Boot 与 Apache POI 实现复杂嵌套结构 Excel 导出