What does the following function return?
char foo(void)
{
unsigned int a = 6;
iht b = -20;
char c;
(a+b > 6) ? (c=1): (c=0);
return c;
}
第1题:
有如下程序:
include<iostream>
using namespaee std;c lass Animal{
public:
virtual char*getType( )const{return"Animal";}
virtual char*getVoice( )const{return"Voice";}
};
class Dog:public Animal{
public:
char*getType( )const{return"Dog";}
char*getVoice( )eonst{return"Woof";}
};
void type(Animal&A) {cout<<a.getType( );}
void speak(Animal A) {eout<<a.getVoice( );}
int main( ){
Dog d;type(D) ;cout<<"speak";speak(D) ;cout< return 0;
}
程序的输出结果是______。
第2题:
( 27 )有如下程序:
#include<iostream>
#include<cstring>
using namespace std;
class XCD{
char* a;
int b;
public:
XCD ( char* aa, int bb ) {
a=new char[strlen ( aa ) +1];
strcpty ( a,aa ) ;
b=bb;
}
Char* Geta () {return a; )
int Getb () { return b;}
};
int main () {
char *pl="abcd" , *p2="weirong" ;
int dl=6, d2=8;
XCD x ( pl,dl ) , Y ( p2 , d2 ) ;
cout<<strien ( x .Geta ( ) ) +y. Getb () +endl;
return 0;
}
运行时的输出结果是
A ) 12
B ) 16
C ) 14
D ) 11

第3题:
若下面程序运行时输出结果为
1,A,10.1
2,B,3.5
include <iostream>
using namespace std;
int main()
{
void test(int, char, doubie【 】);
test(1, 'A', 10.1 );
test(2, 'B');
return 0;
}
void test(int a, char b, double c)
{
cout<<a<<','<<b<<','<<c<<endl;
}
第4题:
有以下程序 #include <iostream> #include <string> using namespace std; class base { private: char baseName[10]; public: base () { strcpy(baseName,"Base"); } virtual char *myName() { return baseName; } char *className() { return baseName; } }; class Derived : public base { private: char derivedName[10]; public: Derived() { strcpy(derivedName,"Derived"); } char *myName() { return derivedName; } char *className() { return derivedName; } }; void showPtr(base &p) { cout<<p.myName () <<" "<<p.className (); } int main () { base bb; Derived dd; showPtr(dd); return 0; } 运行后的输出结果为
A.Derived Base
B.Base Base
C.Derived Derived
D.Base Derived
第5题:
下列程序的输出结果是【 】。
include<iostream>
include<cstring>
using namespace std;
void fun(const char *s,char &c){c=s[strlen(s)/2];}
int main()
{
char str[]="ABCDE";
char ch=str[1];
fun(str,ch);
cout<<ch;
return 0;
}
第6题:
有如下程序:
#include<iostream>
#include<cstring>
using namespace std;
class XCD{
char*a;
int b;
public:
XCD(char;l:aa,int bB){
a=flew char[strlen(aA)+1];
strcpy(a,aA);
b=bb;
}
char*lE Geta(){return a;}
int Getb(){return b;}
};
int main(){
char*pl=”abcd”.*p2=”weirong”;
int dl=6,d2=8;
XCD x(pl;d1),Y(p2,d2);
cout<<strlen(X.Gem())+Y.Getb()<<endl;
return 0;
}、
运行时的输出结果是
A.12
B.16
C.14
D.11
第7题:
以下程序的执行结果为【 】。
include<iostream>
using namespace std;
void overload(int num)
{
cout<<num<<end1;
}
void overload(char ch)
{
char c=ch+1;
cout<<c<<end1;
}
int main()
{
overload('X');
return 0;
}
第8题:
如下程序的输出结果是 #include<lostream> #include<cstring> using namespace std; class XCD{ char*a; int b; public: XCD(char*aa,int bB) { a=new char[strlen(aA) +1]; strcpy(a,aA) ; b=bb; } char*Geta( ){return a;} int Getb( ){return b;} }; int main( ){ char*pl="abcd",*p2="weirong": int dl,6,d2=8; XCD x(pl,d1),y(p2,d2); cout<<strlen(x.Geta( ))+y.Getb( )<<endl; return 0; }
A.12
B.16
C.14
D.11
第9题:
有以下程序: #include void fun(char(*p)[6]) { int i; for(i=0;i<4;i++)printf("%c",p[i][i]); printf("\n"); } main( ) { char s[6][6]={"ABCDE","abcde","12345","FGHIJ","fghij","54321"}; fun(s); } 程序的运行结果是( )。
A.Aa1F
B.Ab3I
C.ABCD
D.fghij
第10题:
下列程序的输出结果是______。
include<iostream.h>
int CalcDigital(char*str)
{
if(str= =NULL)
return 0;
int num_of_digital=0;
for(int i=0;str{i]!=0x0;i++)
if(str[i]<='9'&& str[i]>='0')
num_of_digital++;
return num_of_digital;
}
void main( )
{
char a[]="Beijing20080lympic";
cout<<CalcDigital(a)<<endl;
}
第11题:
10. interface Foo { int bar(); } 11. public class Sprite { 12. public int fubar( Foo foo) { return foo.bar(); } 13. public void testFoo() { 14. fubar( 15. // insert code here 16.); 17. } 18. } Which code, inserted at line 15, allows the class Sprite to compile?()
第12题:
ABDCBDCB
ABCDABCD
Compilation fails.
An exception is thrown at runtime.
第13题:
[说明1]
函数void convelt(chal *a,int n)是用递归方法将一个正整数n按逆序存放到一个字符数组a中,例如,n=123,在a中的存放为'3'、'2'、'1'。
[C函数1]
void convert(char *a,int n)
{ int i;
if((i=n/10)!=0; convert( (1) ,i);
*a= (2) ;
}
[说明2]
函数int index(char *s,char *t)检查字符串s中是否包含字符串t,若包含,则返回t在s中的开始位置(下标值),否则返回-1。
[C函数2]
int index(char *s,char *t)
{ int i,j=0;k=0;
for(i=0;s[i]!:'\0';i++)
( for( (3) ;(t[k]!='\0')&&(s[j]!='\0')&&( (4) );j++,k++);
if( (5) ) return(i);
}
return(-1);
}
第14题:
( 12 )有如下程序:
#include <iostream>
using namespace std
class Animal{
public:
virtual char* getType () const { return "Animal" ; }
virtual char* getVoice () const { return "Voice" ; }
};
Class Dog : public Animal {
public:
char* getType ( ) const {return "Dog" ; }
char* getVoice ( ) const {return "Woof"}
};
void type ( Animal& a ) {cout<<a.getType ( ) ; }
void speak ( Animal a ) {cout<<a.getVoice ( ) ; }
int main ( ) {
Dog d; type ( d ) ; cout<<" speak" ; speak ( d ) ; cout<<endi;
return 0;
}
运行时的输出结果是【 12 】 。
第15题:
有以下程序 #include <stdio.h> int fun(char s[]) { int n=O; while(*s<='9'&&*s>='0') { n=10*n+*s-'0'; s++; } return (n); } main() { char s[10]={ '6', '1', '*', '4', '*', '9', '*', '0', '*'}; printf("%d\n",fun(s)); }
A.9
B.61490
C.61
D.5
第16题:
有如下程序:
nclude<iostream>
using namespace std;
class Animal{
public:
virtual char*getType()const{return“Animal”;}
virtual char*getVoice()const{return“Voice”;}
};
class Dog:public Animal{
public:
char*getType()const{rgturn“Dog”;}
char*getVoice()const{retum“Woof”;}
};
void type(Animal&A){cout<<a.getType();}
void speak(AnimalA){cout<<a.getVoice();}
int main(){
Dog d.type(D);tout<<“speak”;speak(D);cout<<endl;
return 0;
}
运行时的输出结果是【 】
第17题:
下列程序的输出结果是______。
include <iostream.h>
include <cstring.h>
using namespace std;
void fun(const char*s,char &C) {c=s[strlen (s)/2];}
int main {)
{
char str [] ="ABCDE";
char ch=str[1];
fun(str,sh);
cout<<Ch;
return 0;
}
第18题:
以下程序的输出结果是( )。 #include<iostream.h> int fun (char*s) { char *p=s; while (*p!='\0,) p++: return (p-s): } void main() { cout<<fun (" ABCDEF ")<<endl: }
A.3
B.6
C.8
D.0
第19题:
下面程序输出的结果是( )。 #include<iostream> using namespace std; int fuc (char *x); int main(){ cout<<fuc("hello")<<endl; return 0; } int fuc(char *x){ char *y=x; while(*y! ='\0')y++; return(y-x); }
A.5
B.6
C.0
D.语法错误,不能输出结果
第20题:
在下面程序运行 #include<iostream.h> int func(char s[]){ int length=0; while(*(s+length))length++; return length; } void main(){ char a[10], *ptr=a; cin>>ptr; cout<<fune(ptr)<<end1; } 如果输入字符串Hello!并回车,则输出结果为 ______。
A.4
B.7
C.6
D.5
第21题:
有以下程序 #include<iostream.h> int f(iht n) { if(n==1) return 1; else return f(n-1)+1;} void main( ) { iht i,j=0; for(i=1;i<3;i++)j+=f(i); cout < < j;} 程序运行后的输出结果是
A.4
B.3
C.2
D.1
第22题:
阅读以下说明和C语言程序,将应填入(n)处的字句写在对应栏内。
【说明】
以字符流形式读入一个文件,从文件中检索出6种C语言的关键字,并统计、输出每种关键字在文件中出现的次数。本程序中规定:单词是一个以空格或'\t'、'\n'结束的字符串。其中6种关键字在程序中已经给出。
【程序】
include <stdio.h>
include <stdlib.h>
FILE *cp;
char fname[20], buf[100];
int NUM;
struct key
{ char word[10];
int count;
}keyword[]={ "if", 0, "char", 0, "int", 0,
"else", 0, "while", 0, "return", 0};
char *getword (FILE *fp)
{ int i=0;
char c;
while((c=getc(fp))!= EOF &&(1));
if(c==EOF)
return (NULL);
else
buf[i++]=c;
while((c=fgetc(fp))!=EOF && c!="&& c!='\t' && c!='\n' )
buf[i++]=c;
buf[i]='\0';
return(buf);
}
void lookup(char *p)
{ int i;
char *q, *s;
for(i=0; i<NUM; i++)
{ q=(2);
s=p;
while(*s && (*s==*q))
{ (3))
if((4))
{ keyword[i].count++;
break;
}
}
return;
}
void main()
{ int i;
char *word;
printf("lnput file name:");
scanf("%s", fname);
if((cp=fopen(fname, "r"))==NULL)
{ printf("File open error: %s\n", fname);
exit(0);
}
NUM=sizeof(keyword)/sizeof(struct key);
while((5))
lookup(word);
fclose(cp);
for(i=0;i<NUM;i++)
printf("keyword:%-20s count=%d\n",keyword[i].word,keyword[i].count);
}
第23题:
public class Delta { static boolean foo(char c) { System.out.print(c); return true; } public static void main( String[] argv ) { int i =0; for ( foo(‘A’); foo(‘B’)&&(i<2); foo(‘C’)){ i++ ; foo(‘D’); } } } What is the result?()