【计算机类职业资格】初级程序员下午试题-71及答案解析.doc

上传人:arrownail386 文档编号:1330130 上传时间:2019-10-17 格式:DOC 页数:11 大小:48.50KB
下载 相关 举报
【计算机类职业资格】初级程序员下午试题-71及答案解析.doc_第1页
第1页 / 共11页
【计算机类职业资格】初级程序员下午试题-71及答案解析.doc_第2页
第2页 / 共11页
【计算机类职业资格】初级程序员下午试题-71及答案解析.doc_第3页
第3页 / 共11页
【计算机类职业资格】初级程序员下午试题-71及答案解析.doc_第4页
第4页 / 共11页
【计算机类职业资格】初级程序员下午试题-71及答案解析.doc_第5页
第5页 / 共11页
点击查看更多>>
资源描述

1、初级程序员下午试题-71 及答案解析(总分:90.00,做题时间:90 分钟)一、B试题一/B(总题数:1,分数:15.00)1.阅读以下说明和流程图,回答问题将解答填入对应栏。 说明 下面的流程图,用来完成求字符串 t在 s中最右边出现的位置。其思路是:做一个循环,以 s的每一位作为字符串的开头和 t比较,如果两字符串的首字母是相同的,则继续比下去,如果一直到 t的最后一个字符也相同,则说明在 s中找到了一个字符串 t;如果还没比较到 t的最后一个字符,就已经出现字符串不等的情况,则放弃此次比较,开始新一轮的比较。当在 s中找到一个字符串 t时,不应停止寻找(因为要求的是求 t在 s中最右边

2、出现位置),应先记录这个位置 pos,然后开始新一轮的寻找,若还存在相同的字符串,则更新位置的记录,直到循环结束,输出最近一次保存的位置。如果 s为空或不包含 t,则返回-1。 注:返回值用 pos表示。 问题 将流程图的(1)(5)处补充完整。(分数:15.00)_二、B试题二/B(总题数:1,分数:15.00)2.阅读以下函数说明和 C语言函数,将应填入U (n) /U处的字句写在对应栏内。 说明 1 函数 void fun(char*w,char x,int*n)用来在 w数组中插入 x,w 数组中的数已按由小到大顺序存放,n 指存储单元中存放数组中数据的个数,插入后数组中的数仍有序。

3、C函数 1 void fun(char*W,char x,int*n) int i,P; p=0; w*n=x; while(xwp)U (1) /U; for(i=*n,ip;i-)wi=U (2) /U; wp=x; +*n; 说明 2 函数 void revstr(char*s)将字符串 s逆置。例如:字符串“abcde”,经过逆置后变为“edcba”。 C函数 2 void revstr(char*s) char*p,c; if(s=NULL)return; p=U (3) /U; /*p指向字符串 s的最后一个有效字符 */ while(sp) / *交换并移动指针 */ C=*s;

4、 U (4) /U=*p; U (5) /U=c; (分数:15.00)填空项 1:_三、B试题三/B(总题数:1,分数:15.00)3.阅读以下函数说明和 C语言函数,将应填入U (n) /U处的字句写在对应栏内。 说明 已知r1.n是 n个记录的递增有序表,用折半查找法查找关键字为 k的记录。若查找失败,则输出“failure“,函数返回值为 0;否则输出“success”,函数返回值为该记录的序号值。 C 函数 int binary search(struct recordtype r,int n,keytype k) intmid,low=1,hig=n; while(low=hig)

5、 mid=U (1) /U; if(krmid.key)U (2) /U; else if(k=rmid.key) printf(“succesS/n“); U (3) /U; elseU (4) /U; printf(“failure/n“); U (5) /U; (分数:15.00)填空项 1:_四、B试题四/B(总题数:1,分数:15.00)4.阅读以下函数说明和 C语言函数,将应填入U (n) /U处的字句写在对应栏内。 说明 本程序实现对指定文件内的单词进行计数。其中使用二叉树结构来保存已经读入的不同单词,并对相同单词出现的次数进行计数。此二叉树的左孩子结点的字符串值小于父结点的字符

6、串值,右孩子结点的字符串值大于父结点的字符串值。函数 getword(char*filename,char *word)是从指定的文件中得到单词。char*strdup(char*S)是复制 S所指向的字符串,并返回复制字符串的地址。 C程序 #include stdio.h#include ctype.h#include string.h#define MAXWORD 100 struct node char*word; int count; struct node*left; struct node*right; struct node*addtree(struct node*P,char

7、*w) int cond; if(p=NULL) /*向树中插入结点 */ P=(struct node*)malloc(sizeof(struct node); P-word=strdup(w); P-count=1; U (1) /U; elseif(oond=strcmp(w,p-word)=0)U (2) /U; else if(cond0)p-left=U (3) /U; else p-right=U (4) /U; return p; main() Struct node*root; char wordMAXWORD; root=NULL; filename=“example.da

8、t“; while(getword(filename,word)!=EOF) root=U (5) /U; (分数:15.00)填空项 1:_五、B试题五/B(总题数:1,分数:15.00)5.阅读以下说明和 C+程序,将应填入U (n) /U处的字句写在对应栏内 说明 以下程序的功能是计算三角形、矩形和正方形的面积并输出。 程序由 4个类组成:类 Triangle,Rectangle 和 Square分别表示三角形、矩形和正方形;抽象类 Figure提供了一个纯虚拟函数 getArea(),作为计算上述三种图形面积的通用接口。 C+程序 #includeiostream.h #include

9、math.h class Figure public: virtual double getArea()=0; /纯虚拟函数 ; class Rectangle:U (1) /U protected: double height; double width; public: Rectangle(); Rectangle(double height,double width) This-height=height; This-width=width; double getarea() returnU (2) /U; ; class Square:U (3) /U public: square(d

10、ouble width) U (4) /U; ; class triangle:U (5) /U double la; double lb; double lc; public: triangle(double la,double lb,double lc) this-la=la;thiS-ib;this-lc; double getArea() double s=(la+lb+lc)/2.0; return sqrt(s*(s-la)*(s-lb)*(s-lc); ; viod main() figure*figures3= new triangle(2,3,3),new Rectangle

11、(5,8),new Square(5); for(int i=0; i3;i+) cout“figures“i“area=“(figures)-getarea()endl; ;(分数:15.00)填空项 1:_六、B试题六/B(总题数:1,分数:15.00)6.阅读以下说明和 Java程序,将应填入U (n) /U处的字句写在对应栏内 说明 以下程序的功能时三角形、矩形和正方形的面积输出。 程序由 5个类组成:areatest 是主类,类 Triangle,Rectangle 和 Square分别表示三角形、矩形和正方形,抽象类 Figure提供了一个计算面积的抽象方法。 Java程序 pub

12、lic class areatest public static viod main(string args) FigureFigures= New triangle(2,3,3),new rectangle(5,8),new square(5) ; for(int i=0; iFigures.length;i+) system.out.println(Figures+“area=“+Figures.getarea(); public abstract class figure public abstract double getarea(); public class rectangle e

13、xtends U(1) /U double height; double width; public rectangle (double height,double width) this.height=height; this.width=width; public string tostring() return“rectangle:height=“+height+“,width=“+width+“:“; public double getarea() returnU (2) /U public class square exendsU (3) /U public square(doubl

14、e width) U (4) /U; public string tostring() return“square:width=“+width“:“; public class triangle entendsU (5) /U double la; double lb; double lc; public triangle(double la,double lb,double lc) this.la=la;this.lb=lb;this.lc=lc; public string tostring()( return“triangle:sides=“+la+“,“+lb+“,“+lc+“:“;

15、public double get area() double s=(la+lb+lc)/2.0; return mathsqrt(s *(s-la)*(s-lb)*(s-lc); (分数:15.00)填空项 1:_初级程序员下午试题-71 答案解析(总分:90.00,做题时间:90 分钟)一、B试题一/B(总题数:1,分数:15.00)1.阅读以下说明和流程图,回答问题将解答填入对应栏。 说明 下面的流程图,用来完成求字符串 t在 s中最右边出现的位置。其思路是:做一个循环,以 s的每一位作为字符串的开头和 t比较,如果两字符串的首字母是相同的,则继续比下去,如果一直到 t的最后一个字符也相

16、同,则说明在 s中找到了一个字符串 t;如果还没比较到 t的最后一个字符,就已经出现字符串不等的情况,则放弃此次比较,开始新一轮的比较。当在 s中找到一个字符串 t时,不应停止寻找(因为要求的是求 t在 s中最右边出现位置),应先记录这个位置 pos,然后开始新一轮的寻找,若还存在相同的字符串,则更新位置的记录,直到循环结束,输出最近一次保存的位置。如果 s为空或不包含 t,则返回-1。 注:返回值用 pos表示。 问题 将流程图的(1)(5)处补充完整。(分数:15.00)_正确答案:()解析:pos=-1; (2) si!=/0; (3) sj=tk; (4) k0; (5) pos=i;

17、 解析 本试题考查流程图。 题目中说明,如果 s中不包含 t,则返回-1,由流程图可以看出,如果(2)的条件不满足,流程图会直接跳到最后 Returnpos,所以,在开始进行查找之前,就要先将 pos置-1,所以(1)填入“pos=-1”。循环开始,(2)保证的条件应该是 si不是空的,即(2)填入“si!=/0”。下面就开始进行比较,由于要输出的是最右边出现的位予,所以当第一次比较到相同的字符时不能输出,只要暂时把保存着,即(5)填入“pos=i”,然后进行下一次循环,当又出现相同的字符串时,就将 pos的值更新,如果一直到最后都没有再次出现相同的字符串,就把 pos输出。当比较到第一个相同

18、的字符时,要继续比较下去,看是不是t和 s的每一个字符全相同,所以(3)应填入“sj=tk”。在什么情况下能说明 t和 s完全相同呢?就是当 t一直比较到最后一个字符即空格时,并且 k大于 0(因为如果 k等于 0,则说明第一个字母就不相同,根本没有开始比较),所以(4)应填入“k0”。二、B试题二/B(总题数:1,分数:15.00)2.阅读以下函数说明和 C语言函数,将应填入U (n) /U处的字句写在对应栏内。 说明 1 函数 void fun(char*w,char x,int*n)用来在 w数组中插入 x,w 数组中的数已按由小到大顺序存放,n 指存储单元中存放数组中数据的个数,插入后

19、数组中的数仍有序。 C函数 1 void fun(char*W,char x,int*n) int i,P; p=0; w*n=x; while(xwp)U (1) /U; for(i=*n,ip;i-)wi=U (2) /U; wp=x; +*n; 说明 2 函数 void revstr(char*s)将字符串 s逆置。例如:字符串“abcde”,经过逆置后变为“edcba”。 C函数 2 void revstr(char*s) char*p,c; if(s=NULL)return; p=U (3) /U; /*p指向字符串 s的最后一个有效字符 */ while(sp) / *交换并移动指

20、针 */ C=*s; U (4) /U=*p; U (5) /U=c; (分数:15.00)填空项 1:_ (正确答案:p+ (2) wi-1 (3) s+strlen(s)-1 (4) *s+或*(s+))解析:(5) *p-或 *(p-)解析 函数 1的 fun()中的 while循环是为了找到 x的插入位置,因此(1)填“p+”,for 循环是移动数组中的元素,因此(2)填“wi-1”。 对于函数 2,设字符串的长度为 n,则该函数的思想为将 *(s+j)与 *(s+n-1+i)对换,i=0n/2。采用指针来实现,s 为起始地址,p 定位为最后一个字符的位置,所以空(3)应填“s+str

21、len(s)-1”;采用 *s与*p交换后为 s+与 P-。即空(4)填“ *s+”或“ *(s+)”,空(5)填“ *p-”或“ *(p-)”。三、B试题三/B(总题数:1,分数:15.00)3.阅读以下函数说明和 C语言函数,将应填入U (n) /U处的字句写在对应栏内。 说明 已知r1.n是 n个记录的递增有序表,用折半查找法查找关键字为 k的记录。若查找失败,则输出“failure“,函数返回值为 0;否则输出“success”,函数返回值为该记录的序号值。 C 函数 int binary search(struct recordtype r,int n,keytype k) intm

22、id,low=1,hig=n; while(low=hig) mid=U (1) /U; if(krmid.key)U (2) /U; else if(k=rmid.key) printf(“succesS/n“); U (3) /U; elseU (4) /U; printf(“failure/n“); U (5) /U; (分数:15.00)填空项 1:_ (正确答案:(low+hig)/2 (2) hig=mid-1 (3) returnmid (4) low=mid+1 (5) return 0)解析:解析 折半查找法也就是二分法:初始查找区间的下界为 1,上界为 len,查找区间的中

23、界为k=(下界+上界)/2。所以(1)应填“(low+hig)/2”。中界对应的元素与要查找的关键字比较。当 krmid.key时,(2)填“hig=mid-1”;当 k=rmid.key时,(3)填“return mid”;当 krmid.key 时,(4)填“low=mid+1”。如果 lowhig 时循环终止时,仍未找到需查找的关键字,那么根据题意返回 0,即空(5)填“return 0”。四、B试题四/B(总题数:1,分数:15.00)4.阅读以下函数说明和 C语言函数,将应填入U (n) /U处的字句写在对应栏内。 说明 本程序实现对指定文件内的单词进行计数。其中使用二叉树结构来保存

24、已经读入的不同单词,并对相同单词出现的次数进行计数。此二叉树的左孩子结点的字符串值小于父结点的字符串值,右孩子结点的字符串值大于父结点的字符串值。函数 getword(char*filename,char *word)是从指定的文件中得到单词。char*strdup(char*S)是复制 S所指向的字符串,并返回复制字符串的地址。 C程序 #include stdio.h#include ctype.h#include string.h#define MAXWORD 100 struct node char*word; int count; struct node*left; struct n

25、ode*right; struct node*addtree(struct node*P,char*w) int cond; if(p=NULL) /*向树中插入结点 */ P=(struct node*)malloc(sizeof(struct node); P-word=strdup(w); P-count=1; U (1) /U; elseif(oond=strcmp(w,p-word)=0)U (2) /U; else if(cond0)p-left=U (3) /U; else p-right=U (4) /U; return p; main() Struct node*root;

26、char wordMAXWORD; root=NULL; filename=“example.dat“; while(getword(filename,word)!=EOF) root=U (5) /U; (分数:15.00)填空项 1:_ (正确答案:p-left=p-right=NULL (2) p-count+ (3) addtree(p-left,w))解析:(4) addtree(p-right,w) (5) addtree(root,word) 解析 在用二叉树结构来保存指定文件内的单词时,采用递归调用。首先在树中创建一个结点,因此空(1)填“p-left=p-right=NULL

27、”。如果要插入的字符串已经存在,则计数值加 1,即空(2)填“p-count+”;如果要插入的字符串小于此结点上字符串的值,则再次调用此函数,即空(3)填“addtree(p-left,w)”;如果要插入的字符串大于此结点上字符串的值,则再次调用函数为空(4),即“addtree(p-right,w)”。在主函数中调用空(5),即“addtree(root,word)”。五、B试题五/B(总题数:1,分数:15.00)5.阅读以下说明和 C+程序,将应填入U (n) /U处的字句写在对应栏内 说明 以下程序的功能是计算三角形、矩形和正方形的面积并输出。 程序由 4个类组成:类 Triangle

28、,Rectangle 和 Square分别表示三角形、矩形和正方形;抽象类 Figure提供了一个纯虚拟函数 getArea(),作为计算上述三种图形面积的通用接口。 C+程序 #includeiostream.h #includemath.h class Figure public: virtual double getArea()=0; /纯虚拟函数 ; class Rectangle:U (1) /U protected: double height; double width; public: Rectangle(); Rectangle(double height,double wi

29、dth) This-height=height; This-width=width; double getarea() returnU (2) /U; ; class Square:U (3) /U public: square(double width) U (4) /U; ; class triangle:U (5) /U double la; double lb; double lc; public: triangle(double la,double lb,double lc) this-la=la;thiS-ib;this-lc; double getArea() double s=

30、(la+lb+lc)/2.0; return sqrt(s*(s-la)*(s-lb)*(s-lc); ; viod main() figure*figures3= new triangle(2,3,3),new Rectangle(5,8),new Square(5); for(int i=0; i3;i+) cout“figures“i“area=“(figures)-getarea()endl; ;(分数:15.00)填空项 1:_ (正确答案:public Figure (2) height *width (3) public Rectangle)解析:(4) this-height=

31、this-width=width (5) public Figure解析 本题考查 C+编程中的几个重要概念。 Figure类是一个抽象类,其他三个类 rectangle、square、triangle 都要直接或间接继承该类,所以(1)(5)处应为“public Figure”。(2)处是要计算矩形面积,矩形面积等于长乘以宽,所以(2)处应为“height* width”。正方形是一个特殊的矩形,所以可以继承矩形类,所以(3)处应为“publicRectangle”,(4)处应为“this-height=this-width=width”。六、B试题六/B(总题数:1,分数:15.00)6.

32、阅读以下说明和 Java程序,将应填入U (n) /U处的字句写在对应栏内 说明 以下程序的功能时三角形、矩形和正方形的面积输出。 程序由 5个类组成:areatest 是主类,类 Triangle,Rectangle 和 Square分别表示三角形、矩形和正方形,抽象类 Figure提供了一个计算面积的抽象方法。 Java程序 public class areatest public static viod main(string args) FigureFigures= New triangle(2,3,3),new rectangle(5,8),new square(5) ; for(i

33、nt i=0; iFigures.length;i+) system.out.println(Figures+“area=“+Figures.getarea(); public abstract class figure public abstract double getarea(); public class rectangle extends U(1) /U double height; double width; public rectangle (double height,double width) this.height=height; this.width=width; pub

34、lic string tostring() return“rectangle:height=“+height+“,width=“+width+“:“; public double getarea() returnU (2) /U public class square exendsU (3) /U public square(double width) U (4) /U; public string tostring() return“square:width=“+width“:“; public class triangle entendsU (5) /U double la; double

35、 lb; double lc; public triangle(double la,double lb,double lc) this.la=la;this.lb=lb;this.lc=lc; public string tostring()( return“triangle:sides=“+la+“,“+lb+“,“+lc+“:“; public double get area() double s=(la+lb+lc)/2.0; return mathsqrt(s *(s-la)*(s-lb)*(s-lc); (分数:15.00)填空项 1:_ (正确答案:Figure (2) height *width (3) rectangle (4) super(width,width))解析:(5) Figure解析 本题考查 Java编程。 Figure类是一个抽象类,其他三个类 rectangle、square、triangle 都要直接或间接继承该类,所以(1) (5)处应为“Figure”。(2)处是要计算矩形面积,矩形面积等于长乘以宽,所以(2)处应为“height*width”。正方形是一个特殊的矩形,所以可以继承矩形类,所以(3)处应为“rectangle”,(4)处应为“super(width,width)”。

展开阅读全文
相关资源
猜你喜欢
  • BS CECC 22000-1993 Harmonized system of quality assessment for electronic components - Generic specification - Radio frequency coaxial connectors (Parts I II and III)《电子元器件用质量评定协调体.pdf BS CECC 22000-1993 Harmonized system of quality assessment for electronic components - Generic specification - Radio frequency coaxial connectors (Parts I II and III)《电子元器件用质量评定协调体.pdf
  • BS CECC 22110-1983 Harmonized system of quality assessment for electronic components sectional specification radio frequency coaxial connectors series SMA《电子元器件用质量评估协调体系 分规范 射频同轴连接.pdf BS CECC 22110-1983 Harmonized system of quality assessment for electronic components sectional specification radio frequency coaxial connectors series SMA《电子元器件用质量评估协调体系 分规范 射频同轴连接.pdf
  • BS CECC 22111-1983 Specification for harmonized system of quality assessment for electronic components - Blank detail specification radio frequency coaxial connections series SMA《电.pdf BS CECC 22111-1983 Specification for harmonized system of quality assessment for electronic components - Blank detail specification radio frequency coaxial connections series SMA《电.pdf
  • BS CECC 22121-1981 Specification for harmonized system of quality assessment for electronic components - Blank detail specification radio frequency coaxial connectors series BNC《电子.pdf BS CECC 22121-1981 Specification for harmonized system of quality assessment for electronic components - Blank detail specification radio frequency coaxial connectors series BNC《电子.pdf
  • BS CECC 23100-801-1998 Harmonized system of quality assessment for electronic components - Capability detail specification single and double-sided printed boards with plain holes《电.pdf BS CECC 23100-801-1998 Harmonized system of quality assessment for electronic components - Capability detail specification single and double-sided printed boards with plain holes《电.pdf
  • BS CECC 23200-801-1998 Harmonized system of quality assessment for electronic components - Capability detail specification single and double-sided printed boards with plated throug.pdf BS CECC 23200-801-1998 Harmonized system of quality assessment for electronic components - Capability detail specification single and double-sided printed boards with plated throug.pdf
  • BS CECC 23300-801-1998 Harmonized system of quality assessment for electronic components - Capability detail specification multi-layer printed boards《电子元器件用质量评估协调体系 性能详细规范 多层印刷电路板》.pdf BS CECC 23300-801-1998 Harmonized system of quality assessment for electronic components - Capability detail specification multi-layer printed boards《电子元器件用质量评估协调体系 性能详细规范 多层印刷电路板》.pdf
  • BS CECC 23600-801-1998 Harmonized system of quality assessment for electronic components - Capability detail specification flex-rigid multilayer printed boards with through connect.pdf BS CECC 23600-801-1998 Harmonized system of quality assessment for electronic components - Capability detail specification flex-rigid multilayer printed boards with through connect.pdf
  • BS CECC 23700-801-1998 Harmonized system of quality assessment for electronic components - Capability detail specification flex-rigid double-sided printed boards with through conne.pdf BS CECC 23700-801-1998 Harmonized system of quality assessment for electronic components - Capability detail specification flex-rigid double-sided printed boards with through conne.pdf
  • 相关搜索

    当前位置:首页 > 考试资料 > 职业资格

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1