如下程序编译时发生错误,错误的原因是show函数实现语句错误,则正确的语句应该为______。
include<iostream.h>
class test
{
private:
int hum;
public:
test(int);
void show( );
};
test::test(int n){num=n;}
test::show( ){cout<<num<<endl;}
void main( )
{
test T(10):
T.show( );
}
第1题:
下面程序错误的语句是
① #include<iostream.h>
② void main( )
③ {
④ int * p=new int[1] ;
⑤ p=9;
⑥ cout < < * p < <endl;
⑦ delete[ ] p;
⑧ }
A.④
B.⑤
C.⑥
D.⑦
第2题:
A.内联函数必须在定义处加上inline关键字,否则就是普通的函数
B.内联函数必须是一个小函数,不能包含循环、switch等语句
C.一个函数中如果包含循环、switch等语句,则将其定义为内联函数时编译器会报错
D.在编译程序时,系统会直接将调用内联函数的地方用内联函数中的语句体做等价替换,从而省去运行程序时函数调用所额外消耗的时间
第3题:
对于已经被定义过可能抛出异常的语句,在编译时()。
A.必须使用try/catch语句处理异常
B.如果程序错误,则必须使用try/catch语句处理异常
C.不使用try/catch语句会出现编译错误
D.不使用try/catch语句不会出现编译错误
第4题:
有如下程序:
#include<iostream>
using namespace std;
class Instrument{
public:
virtual void Display()=0;
};
class Piano:public Instrument {
public:
void Display(){/*函数体程序略*/}
};
int main(){
Instrument s;
Instrument *p=0;
//…;
return 0;
}
下列叙述中正确的是
A.语句“Instrument *p=0;”编译时出错
B.语句“Instrument s;”编译时出错
C.类Piano中的Display函数不是虚函数
D.类Instrument是一个虚基类
第5题:
下面程序有注释的语句中,错误的语句是( )。 #include <iostream> using namespace std; class A{ int a; public: void show A(){cout<<"this is A!";} }; class B:public A{ int b; public: void show B(){cout<< "this is B!";} }; void main(){ A ia,*piA; B ib,*piB; piA=ia; //第一个测试语句 piA=&ib; //第二个测试语句 piA->showA(); //第三个测试语句 piA->showB(); //第四个测试语句 }
A.第一个测试语句
B.第二个测试语句
C.第三个测试语句
D.第四个测试语句
第6题:
下面的程序在编泽时产生错误,其出错原因是( )。 #include<stdio.h> main() {int 1_case;float printF; printf("请输入2个数:"); scanf ("%d%f",&1_case,&printF); printf("%d%f\n",1_case,printF); }
A.定义语句出错,1_case不能作为变量名
B.定义语句出错,printF不能用作用户自定义标识符
C.定义语句无错,scanf不能作为输入函数使用
D.定义语句无错,printf不能输出1_case的值
第7题:
A.语句1错误,语句2和语句3正确
B.语句2正确,语句1和语句3错误
C.语句3正确,语句1和语句2错误
D.语句1正确,语句2和语句3错误
第8题:
以下函数findmin拟实现在数组中查找最小值并作为函数值返回,但程序中有错导致不能实现预定功能。
造成错误的原因是( )。
A)定义语句int i,min;中vain未赋初值
B)赋值语句min=MAN;中,不应给min赋MAX值
C)语句if(min D)赋值语句min=MAX;放错了位置
第9题:
有如下程序: #include<iostreanl> using namespace std; class MyClass{ public: MyClass(int x):val(x){ } void Set(int x){val=x;} void Print( )eonst{eout<<"val="<<val<<'\t';} private: int val; }; int main( ){ eonst MyClass objl(10); MyClass obj2(20); objl.Print(); //语句1 obj2.Print( ); //语句2 objl.Set(20); //语句3 obj2.Set(30); //语句4 return 0; } 其主函数中错误的语句是
A.语句1
B.语句2
C.语句3
D.语句4
第10题:
请在如下程序中的空格处填写正确的语句:
include <iostream>
using namespace std;
class Base {
public:
void fun() {cout<<"Base fun"<<endl; }
};
class Derived: public Base {
public:
void fun() {
【 】; //调用基类的函数fun()
cout<<"Derived fun "<<endl;
}
};
第11题:
编译语句int aInt=66666不会出现编译错误。
第12题:
④
③
②
①
第13题:
有以下程序
main( )
{ char a,b,c,*d;
a='\';b='\xbc';
c='\0xab';d="\0127";
cout<<a<<b<<c<<*d<<endl;
}
编译时出现错误,以下叙述中正确的是
A.程序中只有a='\';语句不正确
B.b='\xbc';语句不正确
C.d="\0127";语句不正确
D.a='\';和c='\0xab';语句都不正确
第14题:
main函数中发生编译错误的语句是______。
include<iostream.h>
class A
{
public:
int a;
const int b;
A( ):a(10),b(20){}
void fun( )const
{
cout<<"a="<<a<<"\tb="<<b<<endl;
}
};
void main( )
{
A obj1;
const A*ptr=new A;
ptr=&obj1;
ptr->a=100;
ptr->fun( );
}
第15题:
有如下程序:
#include<iostream>
using namespace std;
class Music{
public:
void setTitle(char*str){strcpy(title,str);}
protected:
char type[10];
private:
char title[20];
};
class Jazz:public Music{
public:
void set(char*str){
strcpy(type,”Jazz”); //①
strcpy(title,str); //②
}
};
下列叙述中正确的是
A.程序编译正确
B.程序编译时语句①出错
C.程序编译时语句②出错
D.程序编译时语句①和②都出错
第16题:
阅读以下程序:该程序在编译时产生错误,原因是( )。
A.定义语句出错,Case是关键字,不能用作用户自定义标识符
B.定义语句出错,printF不能用作用户自定义标识符
C.定义语句无错,sCanf不能作为输入函数使用
D.定义语句无错,printf不能输出Case的值
第17题:
下列程序编译时发现pb->f(10);语句出现错误,其原因是______。
include<iostream.h>
class Base
{
public:
void f(int x){cout<<"Base:"<<x<<endl;)
};
class Derived:public Base
{
public:
void f(char*str){cout<<"Derived:"<<str<<endl;}
};
void main(void)
{
Derived*pd=new Derived;
Pd->f(10);
}
第18题:
有如下程序:
Private type stu
X as string
Y as integer
End type
Private Sub Command1_Click()
Dim a as stu
a.x=”ABCD”
a.Y=12345
print a
End Sub
程序运行时出现错误,错误的原因是
A)Type定义语句没有放在标准模块中
B)变量声明语句有错
C)赋值语句不对
D)输出语句print不对
第19题:
现有如下程序段,此程序段编译有错误,则程序段的错误出在 #include<stdio.h> main() { int a=30,b=40,c=50,d; d=a>30? b:c; swish(d) { case a: Printf("%d,",a); case b: printf("%d,",b); case c: printf("%d,",c); default printf("#");}}
A.default:printf("#");这个语句
B.d=a>30? b:c;这个语句
C.case a:printf("%d,",a);case b:printf("%d,",b);case c:printf("%d,",c);这三个语句
D.switch(d)这个语句
第20题:
有如下程序: Private Type stu X As String Y As Integer End Type Private Sub Command1 Click( ) Dim a As stu X="ABCD" Y=12345 Print a End Sub 程序运行时出现错误,错误的原因是( )。
A.Type定义语句没有放在标准模块中
B.变量声明语句有错
C.赋值语句不对
D.输出语句Print不对
第21题:
下面程序错误的语句是
①#include<iostream.h>
②void main()
③{
④ int * p=new int[1]
⑤ p=9
⑥ cout<<* p<<end1;
⑦ delete []p;
⑧}
A.④
B.⑤
C.⑥
D.⑦
第22题:
下面关于文件包含语句说法错误的是()。
第23题:
在包含文件时,如果没有找到文件,include语句会发生警告信息,程序继续运行。
在包含文件时,如果没有找到文件,require语句会发生致命错误,程序停止运行。
“./”表示当前目录,“../”表示当前目录的上级目录。
在包含文件时,被包含的文件路径必须是从盘符开始的路径。