下列程序中需要清理动态分配的数组,划线处应有的语句是_______。
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( );
______
}
第1题:
下列程序中划线处正确的语句是( )。#include <iostream>using namespace std;class Base{public:void fun() { cout<<"Base:: fun"<<end1; }};class Derived: public Base{ void fun() { _______________________ //显试调用基类的函数 fun() cout <<"Derived:: fun"<<end1;};
A.fun();
B.Base. fun();
C.Base:: fun();
D.Base->fun();
第2题:
在下列的程序的横线处填上适当的语句,使该程序的输出为12。
include<iostream.h>
using namespace std;
class Base
{
public:
int a,b;
Base(int i){a=i;}
};
class Derived:public Base
{
int a;
public:
Derived(int x):Base(x),b(x+1){};
void show()
{
第3题:
按解释中的要求在下列程序划线处填入的正确语句是:() #include <iostream.h> class Base{ public: void fun() {cout<<"Base::fun"<<endl;} }; class Derived:public Base{ public: void fun() { _______________________//在此空格处调用基类的函数fun() cout<<"Derived::fun"<<endl;} };
A.fun();
B.Base.fun();
C.Base::fun();
D.Base->fun();
第4题:
下列程序编译错误,是由于划线处缺少某个语句,该语句是______。
include<iostream.h>
class A
{
private:
int numl;
public:
A( ):numl(0){}
A(int i):numl(i){}
};
class B
{
private:
int num2;
public:
B( ):num2(0){}
B(int i):num2(i){}
int my_math(A obj1, B obj2);
};
int B::my_math(A obj1,B obj2)
{
return(obj1.numl+obj2.num2);
}
void main(void)
{
A objl(4);
B obj,obj2(5);
cout<<"obj1+obj2:"<<obj.my_math(obj1,obj2);
}
第5题:
下列程序不能通过编译,应该在划线部分填写的语句是______。
include<iostream.h>
include<stdlib.h>
double Func(int a,int b,char ch)
{
double x;
switch(ch)
{
case'+':
x=double(a)+b;
break;
case '-':
x=double(a)-b;
break;
case '*':
x=double(a)*b;
break;
case'/':
if(B)x=double(a)/b;
else
exit(1);
break;
default:
exit(1);
}
______
}
void main( )
{
cout<<Func(32,6,'-')<<",";
cout<<Func(32,6, '*')<<",";
cout<<Func(32,6,'/')<<endl;
}