下列程序运行结果是 。 class AA { int a; public: AA(int i) { a=i; cout<<"aa="<<a<<endl;} virtual ~aa() { bb="<<b<<endl;} ~BB() { cout<<" ~bb="<<b<<endl;} }; void main() { AA *pa=new AA(8); delete pa; AA *pb=new BB(6,9); delete pb; }<br><p class=" answer">
8、若定义了一个类,该类只能用作基类,而不能定义该类的对象,这种类被称为 。
第1题
9、下列程序运行结果是 。(考点:纯虚函数和抽象类) class Pet{ char name[10]; public: Pet(char*name){strcpy(this->name, name);} const char*getName()const {return name;} virtual void call()const=0; }; class Dog: public Pet{ public: Dog(char*name):Pet(name){} void call()const{cout<<"汪汪叫";} }; cat:public pet{ public: cat(char*name):pet(name){} void int main(){ pet*pet1="new" dog("哈克"), *pet2="new" cat("吉米");>getName();pet1->call(); cout<<end1;>getName();pet2->call(); cout<<end1; return 0;>
第2题
a=b a<>C
注意:部分源程序已存在文件testl7_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数Compare的花括号中填写若干语句。
文件testl7_2.cpp的内容如下:
include<iostream.h>
include<stdlib.h>
class AA {
int *a;
int n;
int MS;
public:
void InitAA(int aa[], int nn, int ms)
{
if(nn>ms)
{
cout<<"Error!"<<end1;
exit(1);
}
MS=ms;
n=nn;
a=new int[MS];
for(int i=0; i<n; i++) a[i]=aa[i];
}
int Compare(AA b);
};
int AA::Compare(AA b)
{
}
void main()
{
AA a,b,c;
int x[]={1,2,3,4,5};
int y[]={1,2,3,6,7};
int z[]={1,2,5,7,9};
a. InitAA(x,3,5);
b. InitAA(y,3,5);
c. InitAA(z,3,5);
if (a.Compare(b))
cout<<"a=b"<<end1;
else
cout<<"a<>b"<<end1;
if (a.Compare(c))
cout<<"a=c"<<end1;
else
cout<<"a<>c"<<end1;
}
第3题
A.print();
B.print(); }
C.11B.12
D.21D.22
第4题
A.11
B.12
C.21
D.22
第5题
#include(iostream. h>
class A
{
int num;
public:
A(int i){num=i;}
A(A &a){num=a. num++;}
void print(){cout<
};
void main()
{
A a(1),b(a);
a. print();
b.print();
A.11
B.12
C.21
D.22
第6题
#include "stdio.h"
typedef struct aa
{ int a;
struct aa *next; } M;
void set(M *k,int i,int *b)
{ int j,d=0;
for(j=1;j <i;j++)
{ k[j-1].next=&k[j];
k[j-1].a=b[d++]; }
k[j].a=b[d]; }
main()
{ M k[5],*p;
int d[5]={23,34,45,56,67};
set(k,5,d);
p=k+1;
printf("%d\n",table); }
则下面的表达式在table处,能使程序执行后,打印输出数据45的是
A.p->next->a
B.++p->a
C.(*p).a++
D.p++->a
第7题
#include<iostream>
usingnamespacestd;
classA
{private:
inta:
public:
A(inti)
{a=i;}
voiddisp()
{cout<<a<<",";));
classB
(private:
intb;
public:
B(intj)
{b=j;}
voiddisp()
{cout<<b<<",";}};
classC:publicB,publicA
{private:
intC;
public:
c(intk):A(k-2),B(k+2)
{c=k;
}
voiddisp()
{
a::disp();
B::disp();
COUt<<c<<endl;
}
};
intmain()
{
Cobj(10);
obj.disp();
return0;
}
程序执行后的输出结果是( )。
A.10,10,10
B.10,12,14
C.8,10,12
D.8,12,10
第8题
A.2
B.3
C.4
D.5
第9题
下列程序运行结果是 。 class people{ int x , y ; public : people( ){ cout << "default constructor \n"; x=y=0 ; cout << " One \n" ; } people( int i ){ x=i ; y=0 ; cout << "constructor \n"; cout << " Two \n" ; } ~people( ) { cout << "destructor \n" ; } void print( ) { cout << x << setw(5) << y << endl ; } } ; void main( ) { people *ptr ; ptr=new people[2] ; ptr[0]=people( ) ; ptr[1]=people(3) ; for( int i=0 ; i<2 ; i++) ptr[i].print( ) delete [ ]ptr }>
第10题
A.运行时出错
B.E2一C16一
C.C4一Cl6一
D.E2一E4—
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!