当前位置: > 热点>正文

c语言课后答案(谭浩强(第三版)C语言的课后答案 要第13章)

2023-03-07 04:00:56 互联网 热点

这先要看你去掌握什么方面的的自动化测试脚本了,自动化测试工具例如:RFT的脚本包括java与.net,并将已排序的学生数据存入一个新文件stu-sort中,你需要自动化测试脚本编写教程,这个方面不是单存的自动化测试脚本了,因为CLI的自动化测试就是应用脚本去模拟人工输入命令行,结合各种自动化测试理念去构建适合自己的自动化测试框架,求自动化测试脚本编写教程。

谭浩强(第三版)C语言的课后答案 要第13章

第十三章 13.4从键盘输入一个字符串,将其中的小写字母全部转换成大写字母,然后输出到一个磁盘文件“test”中保存。输入的字符串以“!”结束。 解:#include 《stdio.h》 main() { File *fp; Char str; Int I=0; If((fp=fopen(“test”,”w”)==NULL) {printf(“Can not open the file\n”); exit(0); } printf(“Input a string:\n”); gets(str); while(str[i]!=’!’) {if (str[i]》=’a’&&str[i]《=’z’) str[i]=str[I-32]; fputc(str[i],fp); I++; } fclose(fp); fp=fopen(“test”,”r”); fgets(str,strlen(str)+1,fp); printf(“%s\n”,str); fclose(fp); } 13.5有两个磁盘文件”A”和”B”,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列),输出到一个新文件”C”中。 解:#include《stdio.h》 main() { FILE *fp; Int I,j,n,i1; Char c,t ,ch; If((fp=fopen(“a1”,”r”))==NULL) {printf(“can not open the file\n”); exit(0); } printf(“\n file A:\n”); for(I=0;(ch=fgetc(fp)!=EOF;I++) {c[i]=ch; putchar(c[i]); } fclose(fp); i1=I; if((fp=fopen(“b1”,”r”))==NULL) {printf(“\n can not ipen the file”); exit(0); } printf(“\n file B:\n”); for(I=i1;(ch=fgenc(fp))!=EOF;I++) {c[i]=ch; putchar(c[i]); } fclose(fp); n=I; for(i=0;I《n;I++) for(j=I+1;j《n;j++) if(c[i]》c[j]) {t=c[i]; c[i]=c[j]; c[j]=t; printf(“\n file C:\n”); fp=fopen(“c1”,”w”); for(I=0;I《n;I++) {putc(c[i],fp); putchar(c[i]); } fclose(fp); } 13.6有5个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号、姓名、三门课成绩),计算出平均成绩,将原有数据和计算出的平均分数存放在磁盘文件stud中。 解: #include《stdio.h》 struct student {char num; char name; int score; float ave; }stu; main() {int I,j,sum; FILE *fp; For(I=0;I《5;I++) {printf(“\n input score of student%d:\n”,I+1); printf(“NO.:”); scanf(“%s”,stu[i].num); printf(“name:”); scanf(“%s”,stu[i].name); sum=0; for(j=0;j《3;j++) {printf(“score %d :”j+1); scanf(“%d”,&stu[i].score[j]); sum+=stu[i].score[j]; } stu[i].ave=sum/3.0 } fp=fopen(“stud”,”w”); for(I=0;I《5;I++) if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1) printf(“File write error\n”); fclose(fp); fp=fopen(“stud”,”r”); for(I=0;I《5;I++) {fread(&stu[i],sizeof(struct student),1,fp); printf(“%s,%s,%d,%d,%d,%6.2f\n”,stu[i].num,stu[i].name,stu[i].score, stu[i].score, stu[i].score ,stu[i].ave); } } 13.7将上题stud文件中的学生数据按平均分进行排序处理,并将已排序的学生数据存入一个新文件stu-sort中。 解: #include 《stdio.h》 #define N 10 struct student {char num; char name; int score; float ave; }st[N],temp; main() { FILE *fp; Int I,j,n; If((fp=fopen(“stud”,”r”))==NULL) {printf(“can not open the file”); exit(0); } printf(“\n file ‘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《st[j].ave) {temp=st[i]; st[i]=st[j]; st[j]=temp; } printf(“\nnow:”); fp=fopen(“stu-sort”,”w”); for(I=0;I《n;I++) {fwrite(&st[i],sizeof(struct student),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.8将上题以排序的学生成绩文件进行插入处理。插入一个学生的3门课成绩,程序先计算新插入学生的平均成绩,然后将它按平均成绩高低顺序插入,插入后建立一个新文件。 解:#include 《stdio.h》 struct student {char num; char name; int score; float ave; }st,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, &s. score, &s. score); s.ave=(s.score+s.score+s.score)/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,s.score,s.score,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《stdio.h》 struct student {char num; char name; int score; float ave; }st,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+&s.score+&s.score, &s.score); s.ave=( s.score+ s.score+ s.score)/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,s.score s.score 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《stdio.h》 struct emploee {char num; char name; char sex; int age; char addr; int salary; char health; char class; }en; struct emp {char name; int salary; }em-case; 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《I;j++) {if(fwrite(&en_case[j],sizeof(struct emp),1,fp2)!=1) printf(“error!”); printf(“\n %12s%10d”,em_case[j].name,em_case[j].salary); } printf(“\n*******************************************”); fclose(fp1); fclose(fp2); } 13.11从上题的“职工工资文件”中删区一个职工的数据,再存回原文件。 解:#incude 《stdio.h》 #incude 《string.h》 struct emploee {char name; int salary; }emp; main() {FILE *fp; int I,j,n,flag; char name; int salary; if((fp=fopen(“emp_salary”,”rb”))==NULL) {printf(“can not open file.”); exit(0); } printf(“\n original data:”); for(I=0;fead(&emp[i],sizeof(struct emploee),1,fp)!=0;I++) printf(“\n %8s %7d”,emp[i].name,emp[i].salary); fclose(fp); n=I; printf(“\n input name deleted:”); scanf(“%s”,name); for(flag=1,I=0;flag&&I《n;I++) {if(strcmp(name,emp[i].name)==0) {for(j=I;j《n-1;j++) {strcmp(name,emp[i].name)==0 {for(j=I;j《n-1;j++) {strcpy(emp[j].name,emp[j+1].name); emp[j].salary=emp[j+1].salary; } flag=0; } } if(!flag) n=n-1; else printf(“\n Now,the content of file:\n”); fp=fopen(“emp-dalary”,”wb”); for(I=p;I《n;I++) fwrite(&emp[i],sizeof(struct emploee),1,fp); fclose(fp); fp=fopen(“emp_salary”,”r”); for(I=0;fread(&emp[i],sezeof(struct emploee),1,fp)!=0;I++) printf(“\n%8s%7d”,emp[i].name,emp[i].salary); fclose(fp); } 13.12 从键盘输入若干行字符(每行长度不等),输入后把它们存储到一磁盘文件中。再从该文件中读入这些数据,将其中小写字母转换成大写字母后在显示屏上输出。 解: #include《stdio.h》 main() {int I,flag; char str,c; FILE *fp; Fp=fopen(“text”,”w”); Flag=1; While(flag==1) {printf(“\n Input string:\n”); ges(str); fprintf(fp,”%s”,str); printf(“\nContinue?”); c=getchar(); if((c==’N’)||(c==’n’)) flag=0; getchar(); } fcolse()fp; fp=fopen(“text”,”r”); while(fscanf(fp,”%s”,str)!=EOF) {for(I=0;str[i]!=’\0’;I++) if((str[i]》=’a’)&& (str[i]《=’z’)) str[i]-=32; printf(“\n%s\n”,str); } fclose(fp); }

c语言中 顺序表的选择排序是什么

选择排序(Selection sort)是一种简单直观的排序算法。工作原理是每一次从待排序的数据元素中选出最小(或最大)的一个元素,存放在序列的起始位置,直到全部待排序的数据元素排完。 以下是一个实现选择排序的例子:12345678910111213 #define SWAP(x, y, t) ((t) = (x), (x) = (y), (y) = (t)) //将list中的n个数据,通过选择排序算法排序。void selete_sort(int list, int n){ int i, j, min, temp; for (i = 0; i 《 n - 1; i++){ min = i; for (j = i + 1; j 《 n; j++)//找出最小元素的下标。 if (list[j] 《 list[min]) min = j; SWAP(list[i], list[min], temp);//交换最小元素到当前起始位置。

求自动化测试脚本编写教程,别就说让我去学各式语言,详细点

你好我是从事自动化测试方面的1、自动化测试脚本,包括下面几个方面1)CLI自动化测试,其应用脚本技术,包括tcl、phython、ruby,你学好一门自动化测试脚本即可,因为CLI的自动化测试就是应用脚本去模拟人工输入命令行,建议学习一下phython,因为其强大的社区,还有不亚于高级语言的编程思想。2)工具方面,自动化测试工具例如:RFT的脚本包括java与.net;QPT的脚本为VB等。你有一定的编程基础的话,就不要停留在工具试用方面,而是要去重点学习一下其工具思想。你没有基础的话,你就从其RFT与QTP的帮助文档看起,里面都有关于这些功能的API的。3)自动化测试框架,这个方面不是单存的自动化测试脚本了,而是利用编程技巧,结合各种自动化测试理念去构建适合自己的自动化测试框架,则就要求一定高度的编程技巧和各种知识了。你需要自动化测试脚本编写教程,这先要看你去掌握什么方面的的自动化测试脚本了,我可以提供你教程,但关键先看你的需求这样,推荐你一个博客, 是专注自动化测试的博客。你先看看,我觉得你对自动化测试认识不深,你先把自动化测试弄得有点小明白,再去看看。你需要什么,你的方向是什么:51tesing上的“散步的SUN”的博客,这是我的博客,你可以在百度里面直接输入“散步的SUN”就是其博客了。上面有各种关于自动化测试方面的知识,希望对你又帮助吧。 或者对自动化测试有兴趣的,可以发短消息或者邮件我吧(test_sunny@hotmail.com),有机会一起学习探讨下

C语言编程软件名字叫什么

Visual C++6.0。

Microsoft Visual C++是微软公司的C++开发工具,具有集成开发环境(IDE,1998年后,集成到了Visual Studio开发环境),可提供编辑C语言,C++以及C++/CLI等编程语言。VC++集成了便利的除错工具,特别是集成了微软Windows视窗操作系统应用程序接口、三维动画DirectX API,Microsoft .NET框架。

它不但具有程序框架自动生成、灵活方便的类管理、代码编写和界面设计集成交互操作、可开发多种程序等优点,而且通过的设置就可使其生成的程序框架支持数据库接口、OLE2.0,WinSock网络。

扩展资料

Visual C++使用注意事项

VC++ 6.0占用的系统资源比较少,打开工程、编译运行都比较快,能够直接新建.cpp文件编译运行,所以赢得很多软件开发者的青睐。但因为它先于C++标准推出,所以对C++标准的支持不太好。

for语句中声明的变量i,对于VC++ 6.0来说,出了for循环仍能使用。但很显然这与C++标准对于变量生存期的规定不符合。

参考资料来源:百度百科—Microsoft Visual C++ 6.0

测试

版权声明: 本站仅提供信息存储空间服务,旨在传递更多信息,不拥有所有权,不承担相关法律责任,不代表本网赞同其观点和对其真实性负责。如因作品内容、版权和其它问题需要同本站联系的,一经查实,本站将立刻删除。