此题为判断题(对,错)。
第1题:
有以下程序:
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;
}
则该程序的输出结果为:【 】。
第2题:
使用VC6打开考生文件夹下的工程test28_3。此工程包含一个test28_3.cpp,其中定义了类Person,但该类的定义并不完整。请按要求完成下列操作,将程序补充完整。
(1)定义类Person的私有数据成员forename、surname 和 money,forename 和 surname都是char型的指针数据,money是double型的数据。请在注释“//**1**”之后添加适当的语句。
(2)完成类Person的带三个参数的构造函数Person(char *f, char *s,double m),分别为forename和surname申请新的空间来存储参数f和s指针指向的内容,注意空间的大小,最后把参数m的值赋给money,请在注释“//**2**”之后添加适当的语句。
(3)完成类Person的析构函数的定义,把forename和surname指向的空间释放,请在注释“//**3**”之后添加适当的语句。
(4)完成类Person的成员函数display的定义,使其以格式“forname surname has money”的形式输出内容,请在注释“//**4*。”之后添加适当的语句。
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
输出结果如下:
Richard Berk has 1000.56
源程序文件test28_3.cpp清单如下:
include <iostream.h>
include <string.h>
class Person
{
private:
//** 1 **
double money;
public:
Person(char *f, char *s, double m);
~Person();
void display();
};
Person::Person(char *f, char *s, double m)
{
//** 2 **
strcpy(forename, f);
surname = new char[strlen(s)+1];
strcpy(surname, s);
money=m;
}
Person: :-Person ()
{
//** 3 **
}
void Person:: display ( )
{
//** 4 **
}
void main ( )
{
Person p("Richard", "Berk", 1000.56);
p.display ( );
}
第3题:
3.—__________ 1 go out for a while?
—No,you __________ You must finish your homework first.
A. Must,needn't
B. Can,may
C. May,mustn't
D. May,must
第4题:
A.Must; needn’t
B.Can; can’t
C.May; mustn’t
D.Can; mustn’t
第5题:
下列程序中需要清理动态分配的数组,划线处应有的语句是_______。
include<iostream.h>
class person
{
int age,tall;
public:
person( ){age=0;tall=40;cout<<"A baby is born."<<endl;}
person(int i){age=i;tall=40;cout<<"A old person."<<endl;}
person(int i,int j){age=i;tall=j;cout<<"a old person with tall."<<endl;)
~person( ){cout<<"person dead."<<endl;}
void show( )
{
cout<<"age="<<age<<",tall="<<tall<<endl;
}
};
void main( )
{
person*ptr;
ptr=new person[3];
ptr[0]=person( );
ptr[1]=person(18);
ptr[2]=person(20,120);
for(int i=0;i<3;i++)
ptr[i].show( );
______
}
第6题:
37. —There's somebody at the door._________ it be Jim?
—No ,It __________be him. It's just seven o'clock.It’s too early.
A. May; can't
B. Will; won't
C. May; mustn’t
D Must; may not