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

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

1、二级 C+-39及答案解析(总分:100.00,做题时间:90 分钟)一、B1改错题/B(总题数:1,分数:30.00)使用 VC+6.0打开考生文件夹下的源程序文件 1.cpp,该程序运行时有错误,请改正错误,使得程序输出:Hellotest注意:不要改动 main函数,不能增加或删除行,也不能更改程序的结构,错误的语句在/*error*的下面。试题程序:#includeiostream/*error*template(T)void fun(T t)std:cout“test“std:end1;/*error*templateboolvoid fun(bool t)std:cout(t?“H

2、ello“:“Hi“)std:end1;int main()/*error*bool flag=TRUE;fun(flag);fun(int)flag);return 0;(分数:30.00)填空项 1:_填空项 1:_填空项 1:_二、B2简单应用题/B(总题数:1,分数:40.00)1.请使用“答题”菜单或使用 VC6打开考生文件夹 proj2下的工程 proj2,函数 void Insert(node*q)使程序能够完成如下功能:从键盘输入一行字符,调用该函数建立反序的无头结点的单链表,然后输出整个链表。 注意:请勿修改主函数 main和其他函数中的任何内容,只需在画线处编写适当代码,也

3、不能删除或移动/*found*。 /源程序 proj2.cpp #includeiostream using namespace std; struct node char data; node*link: *head; /链表首指针 void Insert(node*q) /将节点插入链表首部 /*found* _; head=q; int main() char ch; node *p; head=NULL: cout“Please input the string“endl; while(ch=cin.get()!=/n) /*found* _;/用 new为节点 p动态分配存储空间 p

4、data=ch; /*found* _; /在链表首部插入该节点 p=head; while(p!=NULL) coutp-data; p=p-link; coutendl; return 0: (分数:40.00)_三、B3综合应用题/B(总题数:1,分数:30.00)2. 试题源程序文件清单如下: #includeiostream #includeiornanip using namespace std; class MiniString public: friend ostream return output; friend istream /用于输入的临时数组 temp0=/0; /

5、初始为空字符串 inputsetw(100)temp; int inten= strlen(temp); /输入字符串长度 if(inten! =0) s.length= inten; /赋长度 if(s.sPtr!=0) deletes.sPtr; /避免内存泄露 s.sPtr=new chars.length+1; strcpy(s.sPtr,temp); /如果 s不是空指针,则复制内容 else s.sPtr0=/0; /如果 s是空指针,则为空字符串 return input; /*333* /*666* private: int length; /字符串长度(不超过 100个字符)

6、 char*sPtr; /指向字符串的起始地址 ; /proj3. cpp #includeiostream #includeiomanip using namespace std; #include “proj3.h“ int main() void writeToFile(char*); MiniString strl(“Happy“); coutstrl“/n“; writeToFile(“K:/K01/61010002/“); return 0: (分数:30.00)_二级 C+-39答案解析(总分:100.00,做题时间:90 分钟)一、B1改错题/B(总题数:1,分数:30.00)

7、使用 VC+6.0打开考生文件夹下的源程序文件 1.cpp,该程序运行时有错误,请改正错误,使得程序输出:Hellotest注意:不要改动 main函数,不能增加或删除行,也不能更改程序的结构,错误的语句在/*error*的下面。试题程序:#includeiostream/*error*template(T)void fun(T t)std:cout“test“std:end1;/*error*templateboolvoid fun(bool t)std:cout(t?“Hello“:“Hi“)std:end1;int main()/*error*bool flag=TRUE;fun(fla

8、g);fun(int)flag);return 0;(分数:30.00)填空项 1:_ (正确答案:应改为“templateclass T”。)解析:填空项 1:_ (正确答案:删除“templatebool”。)解析:填空项 1:_ (正确答案:应改为“bool flag=true;”。)解析:解析 C+中的模板类格式为 templateclass T,所以第 1处的语句“template(T)”应修改为“templateclass T”。在第 2处的“void fun(bool t)”函数中,t 变量为布尔型变量,是 C+中的基础变量,不是模板变量,没有使用到模板类,所以删除第 2处的模板

9、类型定义语句。第 3处的“bool flag=TRUE;”是声明布尔型变量 flag,并将其值赋为逻辑真。而 TRUE并不是合法值,C+中区分大小写,所以逻辑真值应为 true,即“bool flag=true;”。二、B2简单应用题/B(总题数:1,分数:40.00)1.请使用“答题”菜单或使用 VC6打开考生文件夹 proj2下的工程 proj2,函数 void Insert(node*q)使程序能够完成如下功能:从键盘输入一行字符,调用该函数建立反序的无头结点的单链表,然后输出整个链表。 注意:请勿修改主函数 main和其他函数中的任何内容,只需在画线处编写适当代码,也不能删除或移动/*

10、found*。 /源程序 proj2.cpp #includeiostream using namespace std; struct node char data; node*link: *head; /链表首指针 void Insert(node*q) /将节点插入链表首部 /*found* _; head=q; int main() char ch; node *p; head=NULL: cout“Please input the string“endl; while(ch=cin.get()!=/n) /*found* _;/用 new为节点 p动态分配存储空间 p-data=ch;

11、 /*found* _; /在链表首部插入该节点 p=head; while(p!=NULL) coutp-data; p=p-link; coutendl; return 0: (分数:40.00)_正确答案:(1)node*head; 2)p=new node(); 3)p-link=head; head=p;)解析:1)后面有 head=q;,显然有个变量头指针没定义,所以在该行应该定义一个头指针 head。 2)为指针 p分配内存空间。 3)将新结点插入到链表中,链表的指针顺序不能搞错,应该是先将 p-link 指向head指向的地址,然后将 head指针指向 p。三、B3综合应用题/

12、B(总题数:1,分数:30.00)2. 试题源程序文件清单如下: #includeiostream #includeiornanip using namespace std; class MiniString public: friend ostream return output; friend istream /用于输入的临时数组 temp0=/0; /初始为空字符串 inputsetw(100)temp; int inten= strlen(temp); /输入字符串长度 if(inten! =0) s.length= inten; /赋长度 if(s.sPtr!=0) deletes.

13、sPtr; /避免内存泄露 s.sPtr=new chars.length+1; strcpy(s.sPtr,temp); /如果 s不是空指针,则复制内容 else s.sPtr0=/0; /如果 s是空指针,则为空字符串 return input; /*333* /*666* private: int length; /字符串长度(不超过 100个字符) char*sPtr; /指向字符串的起始地址 ; /proj3. cpp #includeiostream #includeiomanip using namespace std; #include “proj3.h“ int main() void writeToFile(char*); MiniString strl(“Happy“); coutstrl“/n“; writeToFile(“K:/K01/61010002/“); return 0: (分数:30.00)_正确答案:()解析:解析 默认构造函数 MiniString (const char*s=“)中,需要用类的数据成员 char*sPtr动态分配足够的存储空间来接收 s所指向的字符串,可采用 strlen()函数求字符串长度,但分配空间时需要加1。在析构函数中应该将 sPtr指向的存储空间释放。

展开阅读全文
相关资源
猜你喜欢
  • ASTM D8004-2015 2838 Standard Test Method for Fuel Dilution of In-Service Lubricants Using Surface Acoustic Wave Sensing《使用表面声波检测测定所用润滑油的燃料稀释性的标准试验方法》.pdf ASTM D8004-2015 2838 Standard Test Method for Fuel Dilution of In-Service Lubricants Using Surface Acoustic Wave Sensing《使用表面声波检测测定所用润滑油的燃料稀释性的标准试验方法》.pdf
  • ASTM D8005-2015 0339 Standard Test Method for Color of Clear Liquids (Platinum-Cobalt Scale)《透明液体色度的标准试验方法 (铂钴色度标尺)》.pdf ASTM D8005-2015 0339 Standard Test Method for Color of Clear Liquids (Platinum-Cobalt Scale)《透明液体色度的标准试验方法 (铂钴色度标尺)》.pdf
  • ASTM D8005-2018 1250 Standard Test Method for Color of Clear Liquids (Platinum-Cobalt Scale)《透明液体颜色的标准试验方法(铂钴刻度)》.pdf ASTM D8005-2018 1250 Standard Test Method for Color of Clear Liquids (Platinum-Cobalt Scale)《透明液体颜色的标准试验方法(铂钴刻度)》.pdf
  • ASTM D8006-2016 7663 Standard Guide for Sampling and Analysis of Residential and Commercial Water Supply Wells in Areas of Exploration and Production (E& P) Operations《勘探与开发 (E&.pdf ASTM D8006-2016 7663 Standard Guide for Sampling and Analysis of Residential and Commercial Water Supply Wells in Areas of Exploration and Production (E& P) Operations《勘探与开发 (E&.pdf
  • ASTM D8007-2015 6799 Standard Test Method for Wale and Course Count of Weft Knitted Fabrics《测定纬编针织物的横纵密度的标准试验方法》.pdf ASTM D8007-2015 6799 Standard Test Method for Wale and Course Count of Weft Knitted Fabrics《测定纬编针织物的横纵密度的标准试验方法》.pdf
  • ASTM D8007-2015e1 1690 Standard Test Method for Wale and Course Count of Weft Knitted Fabrics《纬编针织物经纬密度的标准试验方法》.pdf ASTM D8007-2015e1 1690 Standard Test Method for Wale and Course Count of Weft Knitted Fabrics《纬编针织物经纬密度的标准试验方法》.pdf
  • ASTM D8008-2015 4608 Standard Practice for Representative Field Sampling of Traffic Paints《路标代表性现场取样的标准实施规程》.pdf ASTM D8008-2015 4608 Standard Practice for Representative Field Sampling of Traffic Paints《路标代表性现场取样的标准实施规程》.pdf
  • ASTM D8009-2015 4202 Standard Practice for Manual Piston Cylinder Sampling for Volatile Crude Oils Condensates and Liquid Petroleum Products《利用活塞式液压缸对挥发性原油 凝析物和液态石油产品进行人工取样的标准实施规程》.pdf ASTM D8009-2015 4202 Standard Practice for Manual Piston Cylinder Sampling for Volatile Crude Oils Condensates and Liquid Petroleum Products《利用活塞式液压缸对挥发性原油 凝析物和液态石油产品进行人工取样的标准实施规程》.pdf
  • ASTM D8010-2015 4225 Standard Practice for Determination of Water Soluble Alkali Content in Coal《用于测定煤炭中水溶性碱含量的标准实施规程》.pdf ASTM D8010-2015 4225 Standard Practice for Determination of Water Soluble Alkali Content in Coal《用于测定煤炭中水溶性碱含量的标准实施规程》.pdf
  • 相关搜索

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

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