[计算机类试卷]国家二级C++机试(操作题)模拟试卷165及答案与解析.doc

上传人:priceawful190 文档编号:497227 上传时间:2018-11-28 格式:DOC 页数:5 大小:30KB
下载 相关 举报
[计算机类试卷]国家二级C++机试(操作题)模拟试卷165及答案与解析.doc_第1页
第1页 / 共5页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷165及答案与解析.doc_第2页
第2页 / 共5页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷165及答案与解析.doc_第3页
第3页 / 共5页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷165及答案与解析.doc_第4页
第4页 / 共5页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷165及答案与解析.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级 C+机试(操作题)模拟试卷 165 及答案与解析 一、基本操作题 1 给定程序中,函数 fun的功能是:将 a所指 35矩阵中第 k列的元素左移到第 0列,第 k列以后的每列元素行依次左移,原来左边的各列依次绕到右边。 例如,有下列矩阵: 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 若 k为 2,程序执行结果为 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 请在程序的中括号处填入正确的内容并把中括号删除,使程序得出正确的结果。 注意:部分源程序在文件 BLANKl C中。 不得增行或删行,也不得更改程序的结构 ! 试题程序: #inclucle #def

2、ine M 3 #define N 5 void fun(int(*a)N, int k) int i, j, p, temp; *found* for(p=1; p #include #include int fun(float x, int n) *found* int j, c=0; float xa=0 0; for(j=0; jxa) c+; return c; main() float x100=193 199, 195 673, 195 757, 196 051, 196 092, 196 596, 196 579, 196 763; system(“cls“); printf(

3、 d n“, fun(x, 8); 三、综合应用题 3 请编写函数 fun,其功能是:将一个数字字符串转换为一个整数 (不得调用 C语言 提供的将字符串转换为整数的函数 )。例如,若输入字符串 “一 1234”,则函数把它转换为整数值一 1234。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include #include long fun(char*p) void main() char s6; long n; printf(“Enter a string: n“); gets(S); n=f

4、un(S); printf(“ id n“, n); 国家二级 C+机试(操作题)模拟试卷 165 答案与解析 一、基本操作题 1 【正确答案】 (1)k(2)N一 1 (3)temp 【试题解析】 填空 1:外循环 p的值为数组移动的次数,试题要求第 k 列左移,则需要移动的次数为 k,所以应填 k。 填空 2:矩阵共 N列,所以应填 N一 1。 填空 3:临时变量 temp 中存放的值为数组最左边元素的值,需要把 temp 放到数组的末 尾,即放到 aiN 1中,所以应填 temp。 二、简单应用题 2 【正确答案】 (1)int j, c=0; float xa=0 0; (2)if(x

5、j=xa) 【试题解析】 (1)本题着重考查考生对 C语言基本语法以及比较运算符的掌握情况。 (2)本题中的第一个错误:在 C语言中, 应威对出现,所以程序中的语句 “int j, c=0; float xa=0 0; “应改为 “int j, c=0; float xa=0 0; ”或相同作用的语句; 三、综合应用题 3 【正确答案】 long fun(char*p) long n=0; int flag=1; if(*p=-) *负数时置 flag为一 1*c p+; flag=一 1; else if(*p=+) *正数时置 flag为 1* p+; while(*p!= 0) n=n*10+*p一 0; *将字符串转成相应的整数 * p+; return n*flag; 【试题解析】 if语句的作用是判断该字符串为正数还是 负数, while循环的作用是将字符串转成相应的整数。注意: *p 是一个字符 (例如 9、 4),并不是一个数,要将其转成相应的数字需令其减去 0(不是 0),即 *p 一 0就得到 *p这个字符的相应数字,例如 0一 0=0、 8一 0=8 等。必须在程序的前面加#include,函数 atol的作用是将字符串转换成长整型数,它是一个库函数。

展开阅读全文
相关资源
猜你喜欢
  • BS ISO 6020-3-2015 en_1078  Hydraulic fluid power Mounting dimensions for single rod cylinders 16 MPa (160 bar) series Compact series with bores from 250 mm to 500 mm《液压流体动力.16MPa(160bar)系.pdf BS ISO 6020-3-2015 en_1078 Hydraulic fluid power Mounting dimensions for single rod cylinders 16 MPa (160 bar) series Compact series with bores from 250 mm to 500 mm《液压流体动力.16MPa(160bar)系.pdf
  • BS ISO 6104-2005 en_4059  Superabrasive products - Rotating grinding tools with diamond or cubic boron nitride - General survey designation and multilingual nomenclature《高强度磨料制品.金刚石.pdf BS ISO 6104-2005 en_4059 Superabrasive products - Rotating grinding tools with diamond or cubic boron nitride - General survey designation and multilingual nomenclature《高强度磨料制品.金刚石.pdf
  • BS ISO 6117-2005 en_8336  Road vehicles - Elastomeric boots for drum-type hydraulic brake wheel cylinders using a non-petroleum base hydraulic brake fluid (service temperature 100 C max.)《道.pdf BS ISO 6117-2005 en_8336 Road vehicles - Elastomeric boots for drum-type hydraulic brake wheel cylinders using a non-petroleum base hydraulic brake fluid (service temperature 100 C max.)《道.pdf
  • BS ISO 614-2012 en_8589  Ships and marine technology Toughened safety glass panes for rectangular windows and side scuttles Punch method of non-destructive strength testing《船舶和海洋技术 舷.pdf BS ISO 614-2012 en_8589 Ships and marine technology Toughened safety glass panes for rectangular windows and side scuttles Punch method of non-destructive strength testing《船舶和海洋技术 舷.pdf
  • BS ISO 6162-1-2012 en_5574  Hydraulic fluid power Flange connections with split or one-piece flange clamps and metric or inch screws Flange connectors ports and mounting surfaces .pdf BS ISO 6162-1-2012 en_5574 Hydraulic fluid power Flange connections with split or one-piece flange clamps and metric or inch screws Flange connectors ports and mounting surfaces .pdf
  • BS ISO 6358-1-2013 en_9874  Pneumatic fluid power Determination of flow-rate characteristics of components using compressible fluids General rules and test methods for steady-state flow《气压.pdf BS ISO 6358-1-2013 en_9874 Pneumatic fluid power Determination of flow-rate characteristics of components using compressible fluids General rules and test methods for steady-state flow《气压.pdf
  • BS ISO 6362-6-2012 en_2338  Wrought aluminium and aluminium alloys Extruded rods bars tubes and profiles Round square rectangular and hexagonal tubes Tolerances on shape and dimensions《锻造铝和.pdf BS ISO 6362-6-2012 en_2338 Wrought aluminium and aluminium alloys Extruded rods bars tubes and profiles Round square rectangular and hexagonal tubes Tolerances on shape and dimensions《锻造铝和.pdf
  • BS ISO 639-4-2010 en_1543  Codes for the representation of names of languages - General principles of coding of the representation of names of languages and related entities and application guidel.pdf BS ISO 639-4-2010 en_1543 Codes for the representation of names of languages - General principles of coding of the representation of names of languages and related entities and application guidel.pdf
  • BS ISO 6432-2015 en_3486  Pneumatic fluid power Single rod cylinders 1 000 kPa (10 bar) series bores from 8 mm to 25 mm Basic and mounting dimensions《气动流体动力.单杆汽缸.1100kPa(10bar)系列..pdf BS ISO 6432-2015 en_3486 Pneumatic fluid power Single rod cylinders 1 000 kPa (10 bar) series bores from 8 mm to 25 mm Basic and mounting dimensions《气动流体动力.单杆汽缸.1100kPa(10bar)系列..pdf
  • 相关搜索

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

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