首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC6打开考生文件夹下的源程序文件modi1.cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为: This is a greart! Hello Hello 注意:错误的语句在//******error
使用VC6打开考生文件夹下的源程序文件modi1.cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为: This is a greart! Hello Hello 注意:错误的语句在//******error
admin
2019-05-14
40
问题
使用VC6打开考生文件夹下的源程序文件modi1.cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为:
This is a greart!
Hello
Hello
注意:错误的语句在//******error******的下面,修改该语句即可。
1 #include<iostream.h>
2 class CMyClass
3 {
4 public:
5 void display1()
6 {
7 cout<<’’This is great!’’<<end1;
8 }
9 void display2()
10 {
11 //********error********
12 char str[5]=’’Hello’’;
13 cout<<str<<end1;
14 }
15 //******error******
16 void display3(char string)
17 {
18 //******error******
19 cout<<string<<end1
20 }
21 };
22 void main()
23 {
24 CMyClass myclass;
25 myclass.display1();
26 myclass.display2();
27 myclass.display3(’’Heiio’’);
28 }
选项
答案
(1)char str[6]=’’Helio’’; 或char str[]=’’Hello’’; (2)void display3(char*string) 或void display3(char string[]) (3)cout<<string<<end1;
解析
类CMyClass有3个成员函数:display1()、display2()和display3(),display1()和display2()不带参数,display3()带有参数,函数功能分别向屏幕打印输出不同的字符串。
(1)”Hello”字符串的长度为5,存放在字符数组中的话,字符数组的长度至少为6,因为字符数组的最后一个字符为NULL,故第1个标识下字符数组长度为5太短,应改成“char str[6]=’’Hello’’;”或“char str[]=”Hello”;”。
(2)char string表示string为一个char变量,代表一个字符而不是一串字符,程序要求输出一串字符显然字符变量做不到,应该为字符指针或字符数组,故第2个标识下应改为“void display3(char*string)”或“void display3(char string[])”。
(3)编译程序发现第3标识下有错误,观察程序可知第3个标识下语句结束没有分号,而C++语句必须以分号结束,应加上分号,即第3表示下应改为“cout<<string<< end1];”。
转载请注明原文地址:https://kaotiyun.com/show/fE8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
补充完整下面的类定义:classXCH{char*a;public:XCH(char*aA){//构造函数a=newchar[strlen(aA)+1];strcpy(a,aA);
有如下程序:#include<iostream>usingnamespaeestd;classAnimal{public:virtualchar*getType()const{return"Anim
下面的函数利用递归实现了求1+2+3+…+n的功能:intsum(intn){if(n==0)return0;elsereturnn+saln(n-1);}在执行SUm(10)的过程中,递归调用s
有如下程序段:intx=1,y=2,z=3;x=x^z:y=y^z;z=x^y:cout<<x<<y<<z;这个程序段的输出结果是______。
下列情况中,不会调用拷贝构造函数的是()。
如果有以下定义及初始化:inta=3,*p=&a;则由此可以推断,*p的值是()。
有如下程序:#include<iostream>usingnamespacestd;voidfun(int&x,inty){intt=x;x=y;y=t;}intmain(){inta[2]={
有如下程序:#include<iostream>usingnamespacestd;classBase{public;intm,n;};classDerived1:______Base{};
程序中有如下语句:for(inti=0;i<5;i++)cout<<*(p+i)<<",";能够依次输出int型一维数组DATA的前5个元素。由此可知,变量p的定义及初始化语句是______。
有如下程序:#include<iostream>voidfun(int&x,inty){intt=x;x=y;y=t;}intmain(){inta[2]={23,42};fun(a[1],a
随机试题
CPU的中文名称是
危险化学品的储存设施与以下()场所、区域之间要符合国家规定的距离标准。
对预防过敏性哮喘效果较好的药是
A.阿米巴病B.结核C.菌痢D.伤寒易发生肠粘连、肠腔狭窄的疾病是
产后出血的定义是下列何项
下列各项中;年度终了需要转入“利润分配——末分配利润”科口的有()
设函数则下列结论错误的是().
Scientistshavediscoveredapowerfulantibioticinthebloodstreamofgiantpandasthatcandestroybacteria.TheChineserese
Thefamilynameisthe______inChina.
Themorningaftermyteachercame,sheledmeintoherroomandgavemeadoll.WhenIhadplayedwithitalittlewhile,MissS
最新回复
(
0
)