c++试题

  • 格式:doc
  • 大小:71.50 KB
  • 文档页数:9
class Point
{
int x_,y_;
public:
point():x_(0),y_(0){}
point(int x,int y=0):x_(x),y_(y){}
};
If we define as follow:
point a(2),b{3},*c{4};
then how many times is the constructor called?(C)
A.const char*p=”ABCD”;
B.char const *p=”ABCD”;
C.char *const p=”ABCD”;
D.const char*const p=”ABCD”;
14. In the followingexpression, Whichmeaning of operator"+"is different(C)
complex&operator+=(complex a){
re+=a.re;
im+=a.im;
return *this;
}
};
Ostream&operator<<(Ostream& s,constcomplex& z)
{return s<<’(‘<<z.real()<<’,’<<z.image()<<’)’; }
#include<iostream>
using name space std;
class complex{
double re,im;
public:
complex(double r,double i) : re(r),im(i) { }
double real()const{return re;}
double image()const{return im;}
A.127B.11C.10D.13
6. x=2.5,y=4.7,a=7,b=2, (x||y) && (a||b)=?(D)
A.2 B. 1 C. 0 D.7
7.Which is the running result of following program?( )
#include<iostream>
}
~base(){cout<<"destructing base classes"<<endl;}
};
class sub:public base
{
public:
sub()
{
cout<<"constructing sub class"<<endl;
}
~sub(){cout<<"destructing sub class"<<endl;}
i=ii;
g();
}
void h(){
cout<<"i="<<i;
}
};
void main()
{
B d1(45);
d1.g();
d1.h();
}
4.#include <iostream>
using namespace std;
class Howmany
{
public:
Howmany(int temp)
A.s.p=5 B.s->p=5C.s.*p=5D.*s.p=5
12. We have a class as follow:
class SAMPLE
{
int n;
public:
SAMPLE(int i=0):n(i){}
void setValue(int n0);
};
Which is the correct definition of setValue( )
while (k>=6) k=k-1;
A.endless circle B. 0C.5D.4
9.What is the output of the following program?(D)
#include <iostream>
using namespace std;
void func() {
static int i = 1;
A.5.0+2.0 and 5.0+2
B.5.0+2.0 and5+2.0
C.5.0+2.0 and 5+2
D.5+2.0 and 5.0+2
15. Which is the incorrect declaration of friend function of operatoroverloaded (B)
4. Which is the correct definition of pure virtual function? (C)
A.virtual void vf(int);
B.void vf(int)=0;
C.Virtual viod vf()=0
D.Virtual void yf(int){}
5.sizeof(“Hello World!”)=(D)
A.2B.3 C.4 D.5
18.Which is the result of thefollowingprogram?( )
#include<iosteram>
using namespace std;
class A {
pubic:
A( ) { cout << "A"; }
};
class B { public:B( ) { cout << "B" }};
A.x%=4B.k/=4C.k%=4D.x/=3
3.If we have
int i=10;
const int m=20;
Which is the correct definition for reference?(D)
A.int &r=&i; B.int &r=m;
C.int &r;D.int &r=i;
private:
static int n;
};
int test::n=1;
int main()
{
test*p=new test;
delete p;
cout<<”n=”<<test::getNum() <<endl;
return 0;
}
A.n=0B.n=1C.n=2D.n=3
17. We have a class as follow:
cout<<"in function f()"<<endl;
}
void main()
{
Howmany a(1);
f(a);
}
5.#include <iostream>
using namespace std;
class MyStudent
{
int id;
public:
MyStudent();
MyStudent(int);
class Num {
T x;
public:
Num() {}
Num(T x) {this->x=x;}
Num<T;T> &x2) {
static Num<T> temp;
temp.x=x+x2.x;
return temp;
}
void disp() {cout<<"x="<<x;}
{
p1=temp;
cout<<"constructor"<<endl;
}
Howmany(Howmany&s){
p1=s.p1+1;
cout<<"copy"<<endl;
}
~Howmany(){
cout<<"destructor"<<endl;
}
protected:
int p1;
};
voidf(Howmany f){
void Display();
};
MyStudent::MyStudent ()
{
id=0;
}
MyStudent::MyStudent(int m)
{
id=m;
}
void MyStudent::Display()
{
cout<<"Display a id :"<<id<<endl;
A.friendFranction operator+(franction,franction);
B.friendFranction operator-(franction);
C.friendFranction&operator=(franction&,franction);
D.friendFranction&operator+=(franction&,franction);
for(i=0;i<6;i++)
a[i]=i;
for(i=0;i<2;i++)