如下程序编译时发生错误,错误的原因是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
main()
{ int a=30,b=40,c=50,d;
d=a >30?b:c;
switch(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)这个语句
第2题:
下面程序错误的语句是
① #include<iostream.h>
② void main( )
③ {
④ int * p=new int[1] ;
⑤ p=9;
⑥ cout < < * p < <endl;
⑦ delete[ ] p;
⑧ }
A.④
B.⑤
C.⑥
D.⑦
第3题:
阅读以下程序
#include <stdio.h>
main()
{ int case; float printF;
printf(" 请输入 2 个数 : ");
scanf("%d %f",&case,&printF);
printf("%d %f\n",case,printF);
}
该程序编译时产生错误,其出错原因是
A) 定义语句出错, case 是关键字,不能用作用户自定义标识符
B) 定义语句出错, printF 不能用作用户自定义标识符
C) 定义语句无错, scanf 不能作为输入函数使用
D) 定义语句无错, printf 不能输出 case 的值
第4题:
对于已经被定义过可能抛出异常的语句,在编译时()。
A.必须使用try/catch语句处理异常
B.如果程序错误,则必须使用try/catch语句处理异常
C.不使用try/catch语句会出现编译错误
D.不使用try/catch语句不会出现编译错误
第5题:
A.内联函数必须在定义处加上inline关键字,否则就是普通的函数
B.内联函数必须是一个小函数,不能包含循环、switch等语句
C.一个函数中如果包含循环、switch等语句,则将其定义为内联函数时编译器会报错
D.在编译程序时,系统会直接将调用内联函数的地方用内联函数中的语句体做等价替换,从而省去运行程序时函数调用所额外消耗的时间
第6题:
下面程序错误的语句是 ①#include < iostream.h> ②void main( 0 ③{ ④ int * p = new int[1] ; ⑤ p =9; ⑥ cout <<*p <<end1; ⑦ delete [ ] p; ⑧ }
A.④
B.⑤
C.⑥
D.⑦
第7题:
有以下程序
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';语句都不正确
第8题:
下列关于语句的描述中,错误的是()。
A.C++程序中的函数是由若干条语句组成的
B.每条语句都要实现某种操作
C.条件语句是用来实现分支操作的
D.循环语句是用来在一定条件下重复执行某段程序的
第9题:
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( );
}
第10题:
有如下程序:
#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.程序编译时语句①和②都出错