【计算机类职业资格】二级C语言-50及答案解析.doc

上传人:eastlab115 文档编号:1325393 上传时间:2019-10-17 格式:DOC 页数:3 大小:34KB
下载 相关 举报
【计算机类职业资格】二级C语言-50及答案解析.doc_第1页
第1页 / 共3页
【计算机类职业资格】二级C语言-50及答案解析.doc_第2页
第2页 / 共3页
【计算机类职业资格】二级C语言-50及答案解析.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

1、二级 C 语言-50 及答案解析(总分:71.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:1.00)1.请补充函数 fun(),该函数的功能是:从a到z统计一个字符串中所有字母字符各自出现的次数,结果保存在数组 alf 中。注意:不区分大小写,不能使用字符串库函数。 例如,输入:“Aabc+5*c”,结果为:a=2, b=l,c2。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 run 的横线上填入所编写的若干表达式或语句。 试题程序: #includeconioh #includestdioh #define N 100 void

2、 fun(char *tt,int alf) int i char *p=tt; for(i=0;i26;i+) U U /U /U; while(*p) if(*p=A int i; /*found* str=p; for(i=0; im; i+)ai=*; do ai=*p; /*found* i+; while(*p); /*found* ai=0; strcpy(str, a); void main() int m; char str so; system(“CLS“); printf(“/nEnter a string: “); gets(str); printf(“/nThe st

3、ring: %s/n“, str); printf(“/nEnter n(number of *): “); scanf(“%d“, proc(str, m); printf(“/nThe string after inster: %s/n“, str); (分数:30.00)填空项 1:_三、B编程题/B(总题数:1,分数:40.00)3.某学生的记录由学号、8 门课成绩和平均分组成,学号和 8 门课的成绩已在主函数中给出。请编写fun()函数,它的功能是:求出该学生的平均分放在记录的 ave 成员中。请自己定义正确的形参。 例如,若学生的成绩是 85.5,76,69.5,85,91,72,

4、64.5, 87.5,则他的平均分应当是 78.875。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #define N 8 typedef struct char num 10; double sN; double ave; STREC; void fun() main() STREC s=“GA005“,85.5,76,69.5,85,91, 72,64.5,87.5); int i; fun ( i+) printf(“%4.1f/n“, s.si); /*输

5、出各科成绩*/ printf(“/nave=%7.3f/n“,s.ave); /*输出平均分*/ (分数:40.00)_二级 C 语言-50 答案解析(总分:71.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:1.00)1.请补充函数 fun(),该函数的功能是:从a到z统计一个字符串中所有字母字符各自出现的次数,结果保存在数组 alf 中。注意:不区分大小写,不能使用字符串库函数。 例如,输入:“Aabc+5*c”,结果为:a=2, b=l,c2。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 run 的横线上填入所编写的若干表达式

6、或语句。 试题程序: #includeconioh #includestdioh #define N 100 void fun(char *tt,int alf) int i char *p=tt; for(i=0;i26;i+) U U /U /U; while(*p) if(*p=A int i; /*found* str=p; for(i=0; im; i+)ai=*; do ai=*p; /*found* i+; while(*p); /*found* ai=0; strcpy(str, a); void main() int m; char str so; system(“CLS“)

7、 printf(“/nEnter a string: “); gets(str); printf(“/nThe string: %s/n“, str); printf(“/nEnter n(number of *): “); scanf(“%d“, proc(str, m); printf(“/nThe string after inster: %s/n“, str); (分数:30.00)填空项 1:_ (正确答案:(1)错误:str=p; 正确:p=str; (2)错误:i+; 正确:i+; P+; (3)错误:ai=0; 正确:ai=/0;)解析:解析 由函数 proc 可知,变量 p

8、 是指向字符串的指针,初始化应为字符串首地址。因此,“str=p;”应改为“p=str;”将 p 指向的字符串中的每一个字符插在 m 个*之后并存放在字符串数组 a中。因此,“i+;”应改为“i+;p+;”操作完成后要为字符串数组添加结束符因此“ai=0;”应改为“ai=/0”。三、B编程题/B(总题数:1,分数:40.00)3.某学生的记录由学号、8 门课成绩和平均分组成,学号和 8 门课的成绩已在主函数中给出。请编写fun()函数,它的功能是:求出该学生的平均分放在记录的 ave 成员中。请自己定义正确的形参。 例如,若学生的成绩是 85.5,76,69.5,85,91,72,64.5,

9、87.5,则他的平均分应当是 78.875。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #define N 8 typedef struct char num 10; double sN; double ave; STREC; void fun() main() STREC s=“GA005“,85.5,76,69.5,85,91, 72,64.5,87.5); int i; fun ( i+) printf(“%4.1f/n“, s.si); /*输出各科成绩*

10、/ printf(“/nave=%7.3f/n“,s.ave); /*输出平均分*/ (分数:40.00)_正确答案:(void fun(STREC *p) int i; p-ave=0.0; for(i=0;iN;i+) p-ave=p-ave+p-si; /*求各门成绩的总和*/ p-ave=p-ave/N; /*求平均分*/ )解析:解析 本题考查自己定义形参的相关知识点,程序流程是这样的,在 fun()函数中求出平均分后,返回到主函数时平均分也要带回,所以只能定义一个指针类型的形参 STREC *p,此时,引用成员的方式可以是用指向运算符即 p-ave 和 p-si,当然,也可用(*p).ave 和(*p).si。

展开阅读全文
相关资源
猜你喜欢
  • ISO 797-1973 Aluminium and aluminium alloys Determination of silicon Gravimetric method《铝和铝合金 硅含量的测定 重量法》.pdf ISO 797-1973 Aluminium and aluminium alloys Determination of silicon Gravimetric method《铝和铝合金 硅含量的测定 重量法》.pdf
  • ISO 7973-1992 Cereals and milled cereal products determination of the viscosity of flour method using an amylograph《谷物和精制谷物制品 面粉粘度的测定 (淀粉)糊化力测定法》.pdf ISO 7973-1992 Cereals and milled cereal products determination of the viscosity of flour method using an amylograph《谷物和精制谷物制品 面粉粘度的测定 (淀粉)糊化力测定法》.pdf
  • ISO 7975-2006 Passenger cars - Braking in a turn - Open-loop test method《乘用车 转向时制动 开环试验法》.pdf ISO 7975-2006 Passenger cars - Braking in a turn - Open-loop test method《乘用车 转向时制动 开环试验法》.pdf
  • ISO 7976-1-1989 Tolerances for building methods of measurement of buldings and building products part 1 methods and instruments《建筑公差 建筑物和建筑制品的测量方法 第1部分 方法和仪器》.pdf ISO 7976-1-1989 Tolerances for building methods of measurement of buldings and building products part 1 methods and instruments《建筑公差 建筑物和建筑制品的测量方法 第1部分 方法和仪器》.pdf
  • ISO 7976-2-1989 Tolerances for building methods of measurement of buildings and building products part 2 position of measuring points《建筑公差 建筑物和建筑制品的测量方法 第2部分 测点.pdf ISO 7976-2-1989 Tolerances for building methods of measurement of buildings and building products part 2 position of measuring points《建筑公差 建筑物和建筑制品的测量方法 第2部分 测点.pdf
  • ISO 7980-1986 Water quality Determination of calcium and magnesium Atomic absorption spectrometric method《水质 钙和镁的测定 原子吸收光谱法》.pdf ISO 7980-1986 Water quality Determination of calcium and magnesium Atomic absorption spectrometric method《水质 钙和镁的测定 原子吸收光谱法》.pdf
  • ISO 7983-1988 Woodworking machines single blade circular sawing machines with travelling table nomenclature and acceptance conditions《木工机械 带移动工作台木工圆锯机 术语及验收条件》.pdf ISO 7983-1988 Woodworking machines single blade circular sawing machines with travelling table nomenclature and acceptance conditions《木工机械 带移动工作台木工圆锯机 术语及验收条件》.pdf
  • ISO 7984-1988 Woodworking machines technical classification of woodworking machines and auxiliary machines for woodworking《木工机械 木工机床及辅机的分类》.pdf ISO 7984-1988 Woodworking machines technical classification of woodworking machines and auxiliary machines for woodworking《木工机械 木工机床及辅机的分类》.pdf
  • ISO 7986-1997 Hydraulic fluid power - Sealing devices - Standard test methods to assess the performance of seals used in oil hydraulic reciprocating application.pdf ISO 7986-1997 Hydraulic fluid power - Sealing devices - Standard test methods to assess the performance of seals used in oil hydraulic reciprocating application.pdf
  • 相关搜索

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

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