【计算机类职业资格】初级程序员下午试题-16及答案解析.doc
《【计算机类职业资格】初级程序员下午试题-16及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】初级程序员下午试题-16及答案解析.doc(11页珍藏版)》请在麦多课文档分享上搜索。
1、初级程序员下午试题-16 及答案解析(总分:18.00,做题时间:90 分钟)一、B试题一/B(总题数:1,分数:3.00)1.阅读以下说明和流程图回答问题,将解答填入对应栏。 说明 “直接插入法”排序是一种 N2运算量的例程,只能用在 N 较小的时候,其方法是:挑出第二个数将它按与第一个数大小的顺序插入,然后挑出第三个数将它按大小顺序插入到前两个数中,如此下去,一直到最后一个也插入。 注:流程中循环开始的说明按照“循环变量:循环初值,循环终值,增量”格式描述。 问题 将流程图的(1)(5)处补充完整。(分数:3.00)填空项 1:_二、B试题二/B(总题数:1,分数:3.00)2.阅读以下函
2、数说明和 C 语言函数,将应填入U (n) /U处的字句写在对应栏内。 说明 1 函数int factors(int n)的功能是判断整数 n(n=2)是否为完全数。如果 n 是完全数,则函数返回 0,否则返回-1。 所谓“完全数”是指整数 n 的所有因子(不包括 n)之和等于 n 自身。例如:28 的因子为1,2,4,7,14,而 28=1+2+4+7+14,因此 28 是“完全数”。 C 函数 1 int factors(int n) int i,S; for(i=l,s=0;i=n/2;i+) if(n%i=O) U(1) /U; if(U (2) /U)return 0; rerurn
3、 -1; 说明 2 函数 int maxint(int a,int k)的功能是用递归方法求指定数组中前 k 个元素的最大值,并作为函数值返回。 C 函数 2 int maxint(int a,int k) int t; if(U (3) /U)return U(4) /U; t=maxint(a+1, U(5) /U)j return(a0t) ? a0 :t; (分数:3.00)填空项 1:_三、B试题三/B(总题数:1,分数:3.00)3.阅读以下函数说明和 C 语言函数,将应填入U (n) /U处的字句写在对应栏内。 说明 该程序从正文文件 test.txt 中读入一批整数,并将它们按
4、照递增的顺序存放在一个链表中。其中,函数struct Link*insertChain(struct Link*head,structLink*k)用来寻找结点 k 在链表 head 中的插入位置,并插入该结点。 C 程序 #include stdio.h#include stdlib.h struct Link int number; struct Link *next; struct Link *insertChain(struct Link *head,struct Link *k); VOid main() struct Link *ptr, *head; FILE *fd; int
5、hum; if(fd=fopen(“test.txt“,“r“)=NULL) print(“Cannot open this file!/n“); return; head=NULL; while(fscanf(fd,“%d“,hum)=1) ptr=U (1) /U; if(!ptr) return; ptr-number=hum; ptr-next=NULL; head=insertChain(head,ptr); U (2) /U; return; struct Link *insertChain(struct Link *head,struct Link *k) struct Link
6、 *ptr,*u; ptr=head; while(ptr k k-numberptr-number) u=ptr; U(3) /U if(ptr = head) head=k; else U(4) /U; U(5) /U; return head; (分数:3.00)填空项 1:_四、B试题四/B(总题数:1,分数:3.00)4.阅读以下函数说明和 C 语言函数,将应填入U (n) /U处的字句写在对应栏内。 说明 这是一个模拟渡口管理的算法。某汽车轮渡口,过江渡船每次能载 10 辆车过江。过江车辆分为客车类和火车类,上船有如下规定:同类车先到先上船,客车先于货车上渡船,且每上 4 辆客车,
7、才允许上一辆货车;若等待客车不足 4 辆,则以货车代替,若无货车等待则允许客车都上船。 程序中用到的函数有 enqueue(queue*sq,elemtype *x)在队列 sq 中入队一个元素x;outqueue(queue *sq,elemtype *x)在队列 sq 中出队一个元素,并将其值赋给 x;empty(queue *sq)判断队列 sq 是否为空队,若为空,返回 1;否则返回 0。 C 程序 #includestdio.h void pass() queue bus,truct; /*bus 表示客车队列,truck 表示货车队列*/ char ch; int n,tag; /
8、 * n 为车号,tag 为标志,tag=0 表示客车,tag=1 表示货车 */ intcount=0,countbus=0,counttruck=0; / *分别表示上渡船汽车数、客车数、货车数 */ while(1) printf(“输入命令: /n“); Scanf(“%c“, switch(ch) casee: caseE: printf(“车号: /n“); Scanf(“%d“, printf(“客车/货车(0/1): /n“); scanf(“%d“, if(U (1) /U) enqueue( else enqueue( break; casei: caseI: while(
9、count10) if(U (2) /U printf(“上船的车号为: /n“); count+; U(3) /U; eise if(U (4) /U) /*货车出队 */ countbus=0; outqueue( printf(“上船的车号为: /n“); count+; counttruck+; else if(empty( outqueue( printf(“没有 10 辆车排队轮渡/n“); count+; countbus+; else printf(“没有 10 辆车排队轮渡/n“); retUrn; break; caseq: caseQ:break; if(ch=q | c
10、h=Q) break; (分数:3.00)填空项 1:_五、B试题五/B(总题数:1,分数:3.00)5.阅读以下说明和 C+程序,将应填入U (n) /U处的字句写在对应栏内。 说明 下面程序输出一个矩形面积,以及矩形区域上的假想的作物产量。 C+程序 #include iostream.h class crop_assessment int actual_crop; int ideal_crop; public: void set(int in_actual,int in_ideal) actual crop=in_actual; ideal_crop=in_ideal; int get_
11、actual_crop(void)U (1) /U; int get_ideal_crop(void)U (2) /U;) ; Class lot_size int length; int width; U (3) /U crop; public: void set(int 1,int w,int a,int i) length=1; width=w; crop.set(a,i); int get_area(void)return length*width; int get_data(void)returnU (4) /U; int get_data2(void)freturnU (5) /U
12、; int main() Los_size small,medium; small.set(5,5,5,25); medium.set(10,10,10,50); cout“For a small lot of area“smallget_area()“/n”;cout“the actual crops are$“small.get_data2()“/n“;cout“and ideal crops are$”small.get_data()“/n“;cout“For a medium Lot of area“medium.get area():/n”;cout“the actual crops
13、 are$“medium.get_data2()“/n“;cout“and ideal crops are$“medium.get_data()“/n“;return 0;(分数:3.00)填空项 1:_六、B试题六/B(总题数:1,分数:3.00)6.阅读以下说明和 Java 程序,将应填入U (n) /U处的字句写在对应栏内。 说明 下面程序输出一个矩形面积,以及矩形区域上的假想的作物产量。 Java 程序 public class MainJava public static void main(String args) Lot_size small=new Lot_size(); Lo
14、t_size medium=new Lot_size(); small.set(5,5,5,25); medium.set(10,10,10,50); System.out.println(“For a small lot of area“ +small.get_area()+“/n“); System.out.println(“the actual crops are $“ +small.get_data2()+“/n“); System.out.println(“and ideal crops are $“ +small.get data()+“/n“); System.out.print
15、ln(“For a medium lot of area“ +medium.get_area()+“/n”); System.out.println(“the actual crops are $“ +medium.get_data2()+“/n“); System.out.println (“and ideal crops are $“ +medium.get_data()+“/n“); class Crop_assessment private int actual_crop; private int ideal_crop; public void set(int in_actual,in
16、t in ideal) actual_crop=in_actual; ideal_crop=in_ideal; public int get_actual_crop()return U(1) /U; public int get_ideal_crop()(return U(2) /U;class Lot_size private int length; private int width; private Crop_assessment crop=U (3) /U; public void set(int 1,int W,int a,int i) length=1; width=W; crop
17、.set(a,i); public int get_area()return length*width; public int get_data()freturnU (4) /U; public int get_data2()(returnU (5) /U;(分数:3.00)填空项 1:_初级程序员下午试题-16 答案解析(总分:18.00,做题时间:90 分钟)一、B试题一/B(总题数:1,分数:3.00)1.阅读以下说明和流程图回答问题,将解答填入对应栏。 说明 “直接插入法”排序是一种 N2运算量的例程,只能用在 N 较小的时候,其方法是:挑出第二个数将它按与第一个数大小的顺序插入,然后
18、挑出第三个数将它按大小顺序插入到前两个数中,如此下去,一直到最后一个也插入。 注:流程中循环开始的说明按照“循环变量:循环初值,循环终值,增量”格式描述。 问题 将流程图的(1)(5)处补充完整。(分数:3.00)填空项 1:_ (正确答案:1,n-1,1; (2) aj; (3) ajai; (4) ai+1=ai; (5) ai+1=a;)解析:解析 本题目考查流程图。 题目中已经给出了直接插入法排序的算法,由于该算法是从数组中第二个数起,取出并与前面的数进行排序,直到数组中最后一个数排序完成,所以,循环变量初值为 1,终值为 N-1,增量为 1,按照题目中要求的格式,则为“1,N-1,1
19、”。 由题目中的算法可知,我们要将取出来的数同排在其前面的数做比较,并插入,所以,首先要把取出来的数赋给一个变量,即(2)填入“aj”。然后从第 j-1 个数开始,如果 aiaj,那么我们就将 aiN 移一位,以便空出一个位置来插入 aj,所以(4)填入“ai+1=ai”这样一直进行到 aiaj或者 i0,这时,我们就找到了 aj要插入的位置,可以将 aj插入,即(3)填入“ajai”,(5)填入“ai+1=a”。二、B试题二/B(总题数:1,分数:3.00)2.阅读以下函数说明和 C 语言函数,将应填入U (n) /U处的字句写在对应栏内。 说明 1 函数int factors(int n)
20、的功能是判断整数 n(n=2)是否为完全数。如果 n 是完全数,则函数返回 0,否则返回-1。 所谓“完全数”是指整数 n 的所有因子(不包括 n)之和等于 n 自身。例如:28 的因子为1,2,4,7,14,而 28=1+2+4+7+14,因此 28 是“完全数”。 C 函数 1 int factors(int n) int i,S; for(i=l,s=0;i=n/2;i+) if(n%i=O) U(1) /U; if(U (2) /U)return 0; rerurn -1; 说明 2 函数 int maxint(int a,int k)的功能是用递归方法求指定数组中前 k 个元素的最大
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 初级 程序员 下午 试题 16 答案 解析 DOC
