[计算机类试卷]软件水平考试(初级)程序员下午(应用技术)模拟试卷42及答案与解析.doc
《[计算机类试卷]软件水平考试(初级)程序员下午(应用技术)模拟试卷42及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]软件水平考试(初级)程序员下午(应用技术)模拟试卷42及答案与解析.doc(9页珍藏版)》请在麦多课文档分享上搜索。
1、软件水平考试(初级)程序员下午(应用技术)模拟试卷 42及答案与解析 1 阅读以下说明和流程图,回答问题将解答填入对应栏。 说明 下面的流程图,用来完成计算一组数组中的中值,其方法是:将数组中的一个值与其他值比较,并计算大于等于被比较数的数值的个数,以及小于等于被比较数的数值的个数,如果两数都大于 n/2,则已经找到了中值,否则继续之前的步骤。 注:流程中循环开始的说明按照 “循环变量:循环初值,循环终值,增量 ”格式描述; 问题 将流程图的 (1) (5)处补充完整。 2 阅读以下函数说明和 C语言函 数,将应填入 (n)处的字句写在对应栏内。 说明 1 函数 void fun(char*w
2、,char x,int*n)用来在 w数组中插入 x, w数组中的数已按由小到大顺序存放, n指存储单元中存放数组中数据的个数,插入后数组中的数仍有序。 C函数 1 void fun(char*W,char x,int*n) int i,P; p=0; w*n=x; while(x wp) (1) ; for(i=*n,i p;i-)wi=(2); wp=x; +*n; 说明 2 函数 void revstr(char*s)将字符串 s逆置。例如:字符串 “abcde”,经过逆置后变为“edcba”。 C函数 2 void revstr(char*s) char*p,c; if(s=NULL)
3、return; p=(3); /*p指向字符串 s的最后一个有效字符 */ while(s p) /*交换并移动指针 */ C=*s; (4)=*p; (5)=c; 3 阅读以下函数说明和 C语言函数,将应填入 (n)处的字句写在对应栏内。 说明 已知 r1.n是 n个记录的递增有序表,用折半查找法查找关键字为 k的记录。若查找失败,则输出 “failure“,函数返回值为 0;否则输出 “success”,函数返回值为该记录的序号值。 C函数 int binary search(struct recordtype r,int n,keytype k) intmid,low=1,hig=n;
4、while(low =hig) mid=(1); if(k rmid.key) (2); else if(k=rmid.key) printf(“succesSn“); (3); else (4); printf(“failuren“); (5); 4 阅读以下函数说明和 C语言函数,将应填入 (n)处的字句写 在对应栏内。 说明 本程序实现对指定文件内的单词进行计数。其中使用二叉树结构来保存已经读入的不同单词,并对相同单词出现的次数进行计数。此二叉树的左孩子结点的字符串值小于父结点的字符串值,右孩子结点的字符串值大于父结点的字符串值。函数getword(char*filename, char
5、*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*w) int cond; if(p=NULL) /*向树中插入结点 */ P=(struct no
6、de*)malloc(sizeof(struct node); P- word=strdup(w); P- count=1; (1) ; elseif(oond=strcmp(w,p- word)=0) (2) ; else if(cond 0)p- left=(3); else p- right=(4); return p; main() Struct node*root; char wordMAXWORD; root=NULL; filename=“example.dat“; while(getword(filename,word)!=EOF) root=(5); 5 阅读以下说明和 C+
7、程序,将应填入 (n)处的字句写在对应栏内。 说明 下面程序输出一个矩形面积,以及矩形区域上的假想的作物产量。 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_actual_crop(void) (1) ; int get_ideal_crop(void) (2) ;) ; Class lot
8、_size int length; int width; (3) 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)return (4) ; int get_data2(void)freturn (5) ; int main() Los_size small, medium; small.set(5,5,5,25); medium.set(10,10,10,50); c
9、out “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 are$“ medium.get_data2() “n“; cout “and ideal crops are$“ medium.get_
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 软件 水平 考试 初级 程序员 下午 应用技术 模拟 42 答案 解析 DOC
