网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

阅读以下说明和C语言程序,将应填入(n)处的字句写在对应栏内。

【说明】

以字符流形式读入一个文件,从文件中检索出6种C语言的关键字,并统计、输出每种关键字在文件中出现的次数。本程序中规定:单词是一个以空格或'\t'、'\n'结束的字符串。其中6种关键字在程序中已经给出。

【程序】

include <stdio.h>

include <stdlib.h>

FILE *cp;

char fname[20], buf[100];

int NUM;

struct key

{ char word[10];

int count;

}keyword[]={ "if", 0, "char", 0, "int", 0,

"else", 0, "while", 0, "return", 0};

char *getword (FILE *fp)

{ int i=0;

char c;

while((c=getc(fp))!= EOF &&(1));

if(c==EOF)

return (NULL);

else

buf[i++]=c;

while((c=fgetc(fp))!=EOF && c!="&& c!='\t' && c!='\n' )

buf[i++]=c;

buf[i]='\0';

return(buf);

}

void lookup(char *p)

{ int i;

char *q, *s;

for(i=0; i<NUM; i++)

{ q=(2);

s=p;

while(*s && (*s==*q))

{ (3))

if((4))

{ keyword[i].count++;

break;

}

}

return;

}

void main()

{ int i;

char *word;

printf("lnput file name:");

scanf("%s", fname);

if((cp=fopen(fname, "r"))==NULL)

{ printf("File open error: %s\n", fname);

exit(0);

}

NUM=sizeof(keyword)/sizeof(struct key);

while((5))

lookup(word);

fclose(cp);

for(i=0;i<NUM;i++)

printf("keyword:%-20s count=%d\n",keyword[i].word,keyword[i].count);

}


参考答案

更多 “ 阅读以下说明和C语言程序,将应填入(n)处的字句写在对应栏内。【说明】以字符流形式读入一个文件,从文件中检索出6种C语言的关键字,并统计、输出每种关键字在文件中出现的次数。本程序中规定:单词是一个以空格或'\t'、'\n'结束的字符串。其中6种关键字在程序中已经给出。【程序】include <stdio.h>include <stdlib.h>FILE *cp;char fname[20], buf[100];int NUM;struct key{ char word[10];int count;}keyword[]={ "if", 0, "char", 0, "int", 0,"else", 0, "while", 0, "return", 0};char *getword (FILE *fp){ int i=0;char c;while((c=getc(fp))!= EOF (1));if(c==EOF)return (NULL);elsebuf[i++]=c;while((c=fgetc(fp))!=EOF c!=" c!='\t' c!='\n' )buf[i++]=c;buf[i]='\0';return(buf);}void lookup(char *p){ int i;char *q, *s;for(i=0; i<NUM; i++){ q=(2);s=p;while(*s (*s==*q)){ (3))if((4)){ keyword[i].count++;break;}}return;}void main(){ int i;char *word;printf("lnput file name:");scanf("%s", fname);if((cp=fopen(fname, "r"))==NULL){ printf("File open error: %s\n", fname);exit(0);}NUM=sizeof(keyword)/sizeof(struct key);while((5))lookup(word);fclose(cp);for(i=0;i<NUM;i++)printf("keyword:%-20s count=%d\n",keyword[i].word,keyword[i].count);} ” 相关考题
考题 ●试题八阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】以下程序的功能是:从键盘上输入一个字符串,把该字符串中的小写字母转换为大写字母,输出到文件test.txt中,然后从该文件读出字符串并显示出来。【程序】#includestdio.hmain(){FILE*fp;charstr[100];inti=0;if((fp=fopen("text.txt" (1) ))==NULL){printf("can't open this file.\n");exit(0);}printf("input astring:\n");gest(str);while(str[i]){if(str[i]=′a′ && str[i]=′z′)str[i]= (2) ;fputc(str[i], (3) );i++;}fclose(fp);fp=fopen("test.txt", (4) );fgets(str,100,fp);printf("%s\n",str);(5) ;}

考题 阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。【说明】StringEditor类的功能是:已知一个字符串,返回将字符串中的非字母字符都删除后的字符串。public (1) {public static String removeNonLetters( (2) ){StringBuffer aBuffer=(3);char aCharacter;for(int i=0; i<original.length();i++){aCharacter=(4);if(Character.isLetter(aCharacter))aBuffer.append( (5) );}return new String(aBuffer);}}public class StringEditorTester{public static void main(String args[]){String riginal="Hi!, My Name is Mark, 234I think you are my classmate?!!";System.out.println(StringEditor.removeNonLetters(original));}}

考题 阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。【程序2.1说明】已知一个排好序的数组,现输入一个数,要求按原来的顺序规律,将它插入到数组中。【程序2.1】include <stdioh>define N 100void main(){float a[N+l],x;int i,p;printf("输入已经排好序的数列: ");for(i=0; i<N; i++)scanf(%f",a[i]);printf("输入要插入的数:");scanf("%f",x);for(i=0,p=N; i<N; i++)if(x<a[i]){(1)break;}for(i=N-1; i>=p; i--)(2)(3)for(i=0; i<=N; i++)prinff("%f\t",a[i]);}【程序2.2说明】本程序用变量count统计文件中字符的个数。【程序2.2】include <stdio.h>include <stdlib.h>void main(){FILE *fp;long count=0;if((fp=fopen("letter.txt","r"))==NULL){printf("can not open file\n");exit(0);}while(!feof(fp)){(4)count++;}printf("count=%d\n",count);(5)}

考题 阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。【说明】已知头指针分别为La和lb的有序单链表,其数据元素都是按值非递减排列。现要归并La和Lb得到单链表Lc,使得Lc中的元素按值非递减排列。程序流程图如下所示:

考题 阅读下列函数说明和C代码,将应填入(n)处的字句写在对应栏内。【说明】以下程序的功能是:从键盘上输入一个字符串,把该字符串中的小写字母转换为大写字母,输出到文件test.txt中,然后从该文件读出字符串并显示出来。【程序】include < stdio. h >main( ){ FILE * fp;char str[100]; int i=0;if((fp=fopen("text.txt"(1))) ==NULL){ printf("can't open this file. \n") ;exit(0) ;}printf(" input astring: \n" ); gest(str);while( str[i] ){ if(str[i] >='a' str[i] <='z')str[i]=(2);fputc(str[i],(3));i++;}fclose(fp);fp=fopen(" test.txt",(4));fgets(str, 100, fp);printf("%s\n" ,str);(5);}

考题 阅读以下说明及Visual Basic程序代码,将应填入(n)处的字句写在对应栏内。【说明】以下程序为求行列式X(5,5)的值S。【Visual Basic代码】Private Function col ( byval x ( 5,5 ) as integer ) as longdim fesult as longdim temp as longdim I as integerdim j as integerdim k as imegerresult = 0for I = to 5(1)for j = 1 to 5if I+j>6 thenk= ( 1+j ) mod 5elsek=1endiftemp=temp*x ( k,j )(2)result=(3)(4)(5)End function

考题 阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。[说明]完成以下中序线索化二叉树的算法。[函数]Typedef int datatype;Typedef struct node {Int ltag, rtag;Datatype data;*lchild,* rchild;}bithptr;bithptr pre;void inthread ( p );{if{inthread ( p->lchild );if ( p->lchild==unll ) (1);if ( P->RCHILD=NULL) p->rtag=1;if (2){if (3) pre->rchild=p;if ( p->1tag==1 )(4);}INTHREAD ( P->RCHILD );(5);}}

考题 阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。[说明]设学生某次考试的成绩按学号顺序逐行存放于某文件中,文件以单行句点“.”为结束符。下面的流程图读取该文件,统计出全部成绩中的最高分max和最低分min。

考题 阅读下列说明和流程图,将应填入(n)的字句写在对应栏内。【说明】下列流程图(如图4所示)用泰勒(Taylor)展开式sinx=x-x3/3!+x5/5!-x7/7!+…+(-1)n×x2n+1/(2n+1)!+…【流程图】计算并打印sinx的近似值。其中用ε(>0)表示误差要求。

考题 阅读以下说明和c++码,将应填入(n)处的字名写在的对应栏内。[说明] 以下函数完成求表达式的值,请填空使之完成此功能。float sum ( float x ){ float s=0.0;int sign = 1;(1);for(inti=1;(2); i+ +){t=t*x;s=s+(3);sign = - sign;(4);}

考题 阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。【说明】给定函数fun的功能是:将从键盘上输入的每个单词的第一个字母转换为大写字母,输入时各单词必须用空格隔开,用“.”结束输入。【函数】int fun(char *c,int status){if((1)=='')return 1;else{if((2)(3)(4))(5)='A'-'a';return 0;}}main(){int flag=1;char ch;printf("请输入一字符串,用点号结束输入!\n");do {ch=getchar();flag=fun(ch,flag);putchar(ch);}while(ch!='.');printf("\n");}

考题 阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。【说明】编写程序,生成一个新文本文件,它由一个已知文本文件的所有偶数行组成。要求已知文本文件名和新文本文件名均从键盘输入。请填空完善程序。【C语言程序】include<stdio.h>main(){FILE *oldf,*newf;char ch,fname[20];int i;do{printf("Enter name of existed text file to be read:");scanf("%s",fname);if((oldf=fopen(fname,"r"))==NULL)printf("File %s can't open!\n",fname);}while(oldf==NULL);do{printf("Enter mane of new text file to be written:");scanf("%s",fname);if(((1)==NULL)printf("File %s can't open!\n",fname);}while((2));i=1;while(!feof(oldf)){while((ch=fgetc(oldf))!=(3)){if(i%2==(4))fputc(ch,newf);}fputc('\n',newf);(5);}fclose(oldf);fclose(newf);}

考题 阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。【程序2.1说明】求所有满足如下条件的三位数:它除以11得的商等于它各位数字的平方和。例如 550,除以11商为50,50=52+52+02。【程序2.1】void main(){int i, j,n,s;for(i=100;i<=999;i++){n=i;j=n/11;s=0;while((1)){(2)n/=10;}if((3))printf("%d\t",i);}}【程序2.2说明】本程序输入一字符串,将其中的大写字母改变成小写字母。【程序2.2】void main(){int i=0;char s[120];scanf("%s",s);while((4)){if((5))s[i]=s[i]- 'A'+'a';i++;}printf("%s\n",s);}

考题 阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。【说明】下面程序完成从键盘读入一个字符串,然后采用parseInt方法将其转换为一个相应的整数。import java.io.*;public class testThrows{public static (1) readString() (2) IOException{int ch;String r="";boolean done=false;while((3)){ch=System.in.read();if(ch<0 || ch=0xd) //处理回车符中第一个符号done=true;elser=r+(char)ch;}return r;}public static void main(Stling args[]){String str;(4) {str=readString();} (5) (IOException e){System.out.println("error");return;}System.out.println("input integer: "+Integer.parselnt(str));}}

考题 阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写在对应栏内。【说明】阅读下面几段C++程序回答相应问题。比较下面两段程序的优缺点。①for (i=0; i<N; i++ ){if (condition)//DoSomething…else//DoOtherthing…}②if (condition) {for (i =0; i<N; i++ )//DoSomething}else {for (i=0; i <N; i++ )//DoOtherthing…}

考题 阅读下列程序说明和C程序,将应填入(n)处的字句写在对应栏内。[函数2.1说明]下面程序的功能是计算x和y的最小公倍数。[函数2.1]main(){ int m,n,d,r;seanf("%d %d",m,n);if(m<n) {r=m;m=n;n=r;}(1);while (d%n! =0) (2);printf("%d\n",d);}[函数2.2说明]下述程序接收键盘输入,直到句点“.”时结束。输入的字符被原样输出,但连续的空格输入将转换成一个空格。[函数2.2]include <stdio.h>main(){ char c,preChar='\0';c = getchar();while(c! = '.'){if((3)) putchar(c);else if(preChar! =' ') putchar(c);(4);c=(5);}}

考题 阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。[说明]下面的流程图用于计算一个英文句子中最长单词的长度(即单词中字母个数)MAX。假设该英文句子中只含字母、空格和句点“.”,其中句点表示结尾,空格之间连续的字母串称为单词。[流程图]

考题 阅读下列说明和流程图,将应填入(n)处的语句写在对应栏内。【说明】设学生(学生数少于50人)某次考试的成绩按学号顺序逐行存放于某文件中,文件以单行句点“.”为结束符。下面的流程图用于读取该文件,并把全部成绩从高到低排序到数组B[50]中。【流程图】

考题 ●试题二阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】该程序运行后,输出下面的数字金字塔【程序】includestdio.hmain (){char max,next;int i;for(max=′1′;max=′9′;max++){for(i=1;i=20- (1) ;++i)printf(" ");for(next= (2) ;next= (3) ;next++)printf("%c",next);for(next= (4) ;next= (5) ;next--)printf("%c",next);printf("\n");}}

考题 试题三(共 15 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。

考题 图2-1是基于软交换的网络分层模型。请将选项应填入(n)处的字句写在答题纸对应的解答栏内。

考题 (a)智能网概念模型中分布功能平面模型如下图所示,请根据此图将应填入(n)处的 字句写在答题纸的对应栏内。

考题 ()阅读下列说明和C语言程序,将应填入 (n)处的语句写在答题纸的对应栏内。[说明]下面程序是一个带参数的主函数,其功能是显示在命令行中输入的文本文件内容。[C语言函数]#include"stdio.h"main(argc,argv) int argc; char *argv[]; { (1) ; if((fp=fopen(argv[1],”r’’))== (2) ) { printf(”file not open!\n”);exit(0);} while( (3) ) putchar( (4) ); (5); }

考题 图6-1是下一代网络的体系结构简图,请根据此简图将应填入(n)处的字句写在答题纸的对应栏内。

考题 阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。 【C++代码】 #include using namespace std; class invoice{ public: (1){ cout

考题 阅读下列说明和图,回答问题,将解答填入答题纸的对应栏内。 阅读以下说明和C函数,将应填入 (n) 处的语句或语句成分写在答题纸的对应栏内。 【说明1】 函数deldigit(char *s) 的功能是将字符串s中的数字字符去掉,使剩余字符按原次序构成一个新串,并保存在原串空间中。其思路是:先申请一个与s等长的临时字符串空间并令t指向它,将非数字字符按次序暂存入该空间,最后再拷贝给s。 【C函数】 char *t = (char *)malloc( (1) ); /*申请串空间*/ int i, k = 0; if (!t) return; for(i = 0; i =’0’ if ( (4) ) { ch = *s; *s = *(s+len-1); *(s+len-1) = ch; reverse( (5) ); }}

考题 阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】 某文件管理系统中定义了类OfficeDoc和DocExplorer,当类OfficeDoc发生变化时,类DocExplorer的所有对象都要更新其自身的状态,现采用观察者(Observer)设计模式来实现该需求,所设计的类图如图6-1所示。

考题 阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。 【说明】 某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种 类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。