有以下程序:
include <iostream>
include <string>
using nameSpace std;
class person
{
int age;
Char * name;
public:
person ( int i, Char * str )
{
int j;
j = strlen( str ) + 1;
name = new char[ j ];
strcpy( name, str );
age = i;
}
~person()
{
delete name;
cout<<"D";
}
void display()
{
cout<<name<<":"<<age;
}
};
int main()
{
person demo( 30,"Smith" );
demo.display();
return 0;
}
则该程序的输出结果为:【 】。
第1题:
有以下程序: #include 〈iostream〉 #include 〈string〉 using namespace std; class visited { private: int number; char *name; public: static int glob; void set mes(char *a); }; void visited::set mes(char *a) { name=new char[strlen(A) +1]; strcpy(name,A) ; number=++glob; } int visited::glob-O; int main() { visited person[10]; int i; char str[8]; for(i=0;i<5;i++) { cin>>str; person[i] .set mes(str); } cout<
A.5
B.4
C.3
D.2
第2题:
以下程序的运行结果是【 】。
include<iostream>
include<string>
using namespace std;
void main(){
chara[10]="China",b[]="Chin",c[]="ese";
cout<<strlen(strcat(strcpy(a,b),c))<<endl;
}
第3题:
【填空题】写出下面程序执行后的运行结果。 #include <iostream> #include <string> using namespace std; char* ss____ { char*p, t; p = s + 1; t = *s; while ____ { *____ = *p; p++; } *____ = t; return s; } void main____ { char *p, str[10]="abcdefgh"; p = ss____; cout << p; }
第4题:
有以下程序: #include <iostream> #include <string> using namespace std; class base { private: char baseName[10]; public: base ( ) { strcpy (baseName, "Base"); } virtual char *myName() {
A.DerivedBase
B.BaseBase
C.DerivedDerived
D.BaseDerived
第5题:
有以下程序,程序运行的结果是 ______。 #include<iostream.h> #include<string.h> void main(){ char x[]= "C++" ,y[10]= "C++" ; cout<<sizeof(x)/sizeof(char)<<“,”<<sizeof(y)/sizeof(char); }
A.3 3
B.4 4
C.4 10
D.10 10