下面程序的执行结果是( )。 #include<iostream> using namespace std; class building { public: building() {} building(unsigned stories, float breadths, float lengths) { story = stories; breadth = breadths; length = lengths;} void getstory(void) { cout<<"story is:"<<story<<endl;} void getarea(void) { area = length*breadth*story;cout<<"area is:"<<area<<endl;} private: unsigned story; float length; float breadth; float area; }; void main(void) { building b1,b2;building b3(10u,16.6,58.8); b1.getstory(); b1.getarea(); b2.getstory(); b2.getarea(); b3.getstory(); b3.getarea();}
A.story is:0 area is:0 story is:0 area is:0 story is:10 area is:9760.8
B.story is:null area is:null story is:null area is:null story is:10 area is:9760.8
C.前两个对象输出的结果是不定的,后一个对象的结果正确
D.前两个对象没有初值,因此程序编译时出错
第1题:
下面程序的结果是 ______。 #include<iostream.h> class A{ public: virtual void fun()=0{}; }; class B:public A{ public: void fun () {cout<< "new file" ;} }; class C: public A{ public: void fun (){cout<<"open file"<< " " } }; class D: public A{ public: void fun () {cout<< "save file\n" ;} }; void main() { A a,*p; B b; C c; D d; p=&c; p->fun (); p=&b; p->fun (); p=&d; p->fun(); }
A.new file open file save file
B.new file new file new file
C.编译出错
D.open file new file save file
第2题:
下面程序的输出结果是( )。 #include <iostream> using namespace std; class A { public: A( ) {cout<<"A";} } class B { public: B() {coat<<"B" ;} } class C: public A { public: B b; C() {cout<<"C";} } void mian(){ C c; }
A.CBA
B.ABC
C.ACB
D.BCA
第3题:
下面程序的结果是 #include<iostream.h> class A { int a; public: A( ):a(1){} void showa( ){cout<<a;} }; class B { int a; public: B( ) :a(2) {}
A.1
B.2
C.3
D.程序有错误
第4题:
下面程序执行的结果是【 】
include<iostream>
using namespace std;
class A{
public:
static int x;
A(inty){cout<<x+y;}
};
int A::x=2;
void main(){
A a(5);
}
第5题:
以下程序的执行结果是______。
include<iostream.h>
class A
{
int a:
public:
void seta(int x) {a=x;}
void showa() {cout<<a<<end1;}
};
class B
{
int b;
public:
void setb(int x) {b=x;}
void showb(){cout<<b<<end1;}
};
第6题:
下面程序的结果是 #include<iostream.h> class A { public: A( ) {cout<<"construtA"<<endl;} virtual~A( ) {cout<<"destructA"<<endl;}}; class B:public A {}; class C:public A {}; c
A.constructA destructA
B.constructA constructA destructA destructA
C.constructA constructA constructA destructA destructA destructA
D.constructA onstructA constructA constructA destructA destructA destructA destructA
第7题:
下面程序的执行结果是【 】。
include<iostream>
include<iomanip>
using namespace std;
void main()
{
cout<<setfill('x')<<setw(10);
cout<<"Hello"<<endl;
}
第8题:
下面程序的结果是 #include<iostream.h> class A { public: A(){cout<<"construtA" <<endl;} virtual ~A() {cout << "destructA" <<endl;}}; class B:public A { }; class C:public A { }; class D:public B,public C { }; void main() { Dd;}
A.constructA
B.constructA
C.constmctA
D.constmctA destructA constructA constmctA constructA destructA constructA constructA destructA destructA constructA destructA dest
第9题:
下面程序的执行结果是______。
include<iostream.h>
include<iomanip.h>
using namespace std;
void main()
{
cout<<setfill('x')<<setw(10);
cout<<"Hello"<<endl;
}