77范文网 - 专业文章范例文档资料分享平台

C语言课后习题答案-第四版- 谭浩强(14)

来源:网络收集 时间:2021-02-21 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

计算机教程

le ‘stud’:”); for(I=0;fread(&st[i],sizef(struct student),1,fp)!=0;I++) {printf(“\n%8s%8s”,st[i].num,,st[i].name); for(j=0;j<3;j++) printf(“%8d”,st[i].score[j]); printf(“%10.f”,st[i].ave); fclose(fp); n=I; for(I=0;I<n;I++) for(j=I+1;j<n;j++) if(st[i].ave struct student {char num[10]; char name[8]; int score[3]; float ave; }st[10],s; main() {FILE *fp, * fp1 ; int I,j,t,n; printf(“\n NO.:”); scanf(“%s”,s.num); printf(“name:”); scanf(“%s”,s.name); printf(“score1,score2,score3:”); scanf(“%d,%d,%d”,&s. score[0], &s. score[1], &s. score[2]); s.ave=(s.score[0]+s.score[1]+s.score[2])/3.0; if((fp=fopen(“stu_sort”,”r”))==NULL) {printf(“can not open file.”); exit(0); } printf(“original data:\n”); for(I=0;fread(&st[i],sizeof(struct student),1,fp)!=0;I++) {printf(“\n%8s%8s”,st[i].num,st[i].name); for(j=0;j<3;j++) printf(“%8d”,st[i].score[j]); printf(“%10.2f”,st[i].ave); } n=I; for(t=0;st[t].ave>s.ave&&t<n;t++); printf(“\nnow:\n”); fp1=fopen(“sort1.dat”,”w”); for(I=p;j<t;I++) {fwrite(&st[i],sizeof(stuct student),1,fp1); print(“\n%8s%8s”,st[i],num,st[i].name); for(j=0;j<3;j++) ptintf(“%8d”,st[i].score[j]); printf(“%10.2f”,st[i].ave); } fwrite(&s,sizeof(struct student),1,fp1); printf(“\n%8s%7s%7d%7d%7d%10.2f”,s.num,s.name,s.score[0],s.score[1],s.score[2],s.ave); for(I=t;I<n;I++) {fwrite(&st[i],sizeof(struct student),1,fp1);

    printf(“\n %8s%8s”,st[i].num,st[i].name); for(j=0;j<3;j++) printf(“%8d”,st[i].score[j]); printf(“10.2f”,st[i].ave); fclose(fp); fclose(fp1); } 13.9上题结果仍存入原有的stu_sort文件而不另建立新文件。 解: #include struct student {char num[10]; char name[8]; int score[3]; float ave; }st[10],s; main() {FILE *fp, *fp1; int I ,j,t,n; printf(“\nNO.:”); scanf(“%s”,s.num); printf(“name:”); scanf(“%s“,s.name); printf(“score1,score2,score3:”); scanf(“%d%d%d”,&s.score[0]+&s.score[1]+&s.score[1], &s.score[2]); s.ave=( s.score[0]+ s.score[1]+ s.score[2])/3.0; if((fp=fopen(“stu=sort”,”r”))==NULL) {printf(“can not open the file.”); exit(0); } printf(“original data:\n”); for(I=0;fread(&st[i],sizeof(struct student),1,fp)!=0;I++) {printf(“\n%8s%8s”,st[i].num,st[i].name); for(j=0;j<3;j++) printf(“%8d”,st[i].score[j]); printf(“%10.2f”,st[i].ave); } fclose(fp); n=I; for(t=0;st[t].ave>s.ave+&&t<n;t++); ptintf(“\nnow:\n”); fp=fopen(“stu_sort”,”w”); for(I=0;I<t;I++) {fwrite(&st[i],sizeof(struct student),1,fp); printf(“\n%9s%8s%8d%8d%8d%10.2f”,s.num,s.name,s.score[0],s.score[1] s.score[2] s.ave); for(I=t;I<n;I++) {fwrit(&sr[i],sizeof(struct srudent),1,fp); printf(“\n %8s%8s”,st[i].num,st[i].name); for(j=0;j<3;j++) printf(“%8d”,st[i].score[j]); printf(“%10.2f”,st[i].ave); } fclose(fp); } 13.10 有一磁盘文件emploee,内存放职工的数据。每个职工的数据包括:职工姓名、职工 号、性别、年龄、住址、工资、健康状况、文化程度。要求将职工名和工资的信息单独抽 出来另建一个简明的职工工资文件。 解:#include

    struct emploee {char num[6]; char name[10]; char sex[2]; int age; char addr[20]; int salary; char health[8]; char class[10]; }en[10]; struct emp {char name[10]; int salary; }em-case[10]; main() {FILE *fp1, *fp2; int I,j; if ((fp1=fopen(“emploee”,”r”))==NULL) {printf(“can not open the file.”); exit(0); } printf(“\n NO. name sex age addr salary health class\n”); for(I=0;fread(&em[i],sizeof(struct emploee),1,fp1)!=p;I++) {printf(“\n%4s%8s%4s%6s%10s%6s%10s%8s”,em[i].num,em[i].name,em[i].sex, em[i].age, em [i].addr, em[i].salary, em[i].health, em[i].class); strcpy(em_case[i].name, em[i].name); em_case[i].salary=en[i].salary; } printf(“\n\n*****************************************”); if((fp2=fopen(“emp_salary”,”wb”))==NULL) {printf(“can not open the file.”); exit(0);} for(j=0;j #incude  struct emploee {char name[10]; int salary; }emp[20]; main() {FILE *fp; int

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库C语言课后习题答案-第四版- 谭浩强(14)在线全文阅读。

C语言课后习题答案-第四版- 谭浩强(14).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/jiaoyu/1186241.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: