问题
填空题
有以下程序:
#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;
则该程序的输出结果为: 【13】 。
答案
参考答案:Smith:30 D
解析: 本题考核类与对象的操作。主函数中定义类person的对象 demo,并赋初值(30,"smith")。然后调用成员函数display()输出赋值结果,即Smitch:30。程序结束时demo对象的析构函数被调用,再输出“D”。