高分求做C++练习题

2025-03-23 07:28:27
推荐回答(2个)
回答1:

(B)11.
Which
is
the
running
result
of
following
program?
int
i=100;
int
fun(
)
{static
int
i=10;
return
++i;
}
void
main()
{
fun();
cout<}
A.10,100
B.12,100
C.12,12
D.11,100
(A)12.
Data
encapsulation
is
to
combine
a
set
of
data
and
operations
based
on
the
data
together
,
to
form
a
entity(实体),
the
entity
is
called
A.
class
B.
object
C.
function
D.
block
(B)13.
If
we
have
the
class
definition:
class
SAMPLE
{
int
n;
public:
SAMPLE(int
i=0):n(i){}
void
setValue(int
n0);
};
Which
is
the
right
definition
for
member
function
setValue?
A.SAMPLE::setValue(int
n0){n=n0;}
B.void
SAMPLE::setValue(int
n0){n=n0;}
C.void
setValue(int
n0){n=n0;}
D.setValue(int
n0){n=n0;}
(C)14.
Which
operator
can
not
be
overloaded
in
C++
?
A.
&&
B.
[
]
C.
::
D.
New
(D)15.
InC++,which
function
is
used
for
dynamic
binding?
A.inline
function
B.overloading
function
C.template
function
D.virtual
function
(B)16.
Which
is
correct
in
the
following
template
description?
A.
template
T1
;T2;T3>
B.
template
T1,T2,T3>
C.
template
T1,
class
T2,class
T3>
D.
template
T1,T2,T3>
(B)17.
Which
statement
is
wrong
in
the
following
class
definition?
class
Sample
{
public:
Sample(int
val);
//(1)
~Sample();
//(2)
Sample();
//(3)
private:
int
a=2.5;
//(4)
};
A.(1)(2)(3)(4)
B.(4)
C.(3)
D.(1)(2)(3)
(B)18.
Which
of
the
following
is
not
member
function?
A.static
member
function
B.friend
C.constructor
D.destructor
(D)19.
Which
is
the
running
result
of
following
program?
#include
using
namespace
std;
class
A
{
public:
A(
)
{
cout
<<
"A";
}
};
class
B
{
public:
B(
)
{
cout
<<
"B"
;}
};
class
C
:
public
A
{
B
b;
public:
C(
)
{
cout
<<"C";
}
};
int
main(
)
{
C
obj;
return
0;
}
A.
CBA
B.
BAC
C.
ACB
D.
ABC
(B)20.If
we
have
the
class
defination:
class
XA{
int
x;
public:
XA(int
n){
x=n;}
};
class
XB:
public
XA{
int
y;
public:
XB(int
a,int
b);
};
Which
is
the
correct
constructor
defination
for
XB
?
A.XB::XB(inta,intb):x(a),y(b){
}
B.XB::XB(inta,intb):XA(a),y(b){
}
C.XB::XB(inta,intb):x(a),XB(b){
}
D.XB::XB(inta,intb):XA(a),XB(b){
}

回答2:

(B)11. Which is the running result of following program?
int i=100;
int fun( )
{static int i=10;
return ++i;
}
void main()
{
fun();
cout<}
A.10,100 B.12,100 C.12,12 D.11,100

(A)12. Data encapsulation is to combine a set of data and operations based on the data together , to form a entity(实体), the entity is called
A. class B. object C. function D. block

(B)13. If we have the class definition:
class SAMPLE
{
int n;
public:
SAMPLE(int i=0):n(i){}
void setValue(int n0);
};
Which is the right definition for member function setValue?
A.SAMPLE::setValue(int n0){n=n0;}
B.void SAMPLE::setValue(int n0){n=n0;}
C.void setValue(int n0){n=n0;}
D.setValue(int n0){n=n0;}

(C)14. Which operator can not be overloaded in C++ ?
A. && B. [ ] C. :: D. New

(D)15. InC++,which function is used for dynamic binding?
A.inline function B.overloading function C.template function D.virtual function

(B)16. Which is correct in the following template description?
A. template B. template
C. template D. template

(B)17. Which statement is wrong in the following class definition?
class Sample
{
public:
Sample(int val); //(1)
~Sample(); //(2)
Sample(); //(3)
private:
int a=2.5; //(4)
};
A.(1)(2)(3)(4) B.(4) C.(3) D.(1)(2)(3)

(B)18. Which of the following is not member function?
A.static member function B.friend C.constructor D.destructor

(D)19. Which is the running result of following program?
#include
using namespace std;
class A {
public:
A( ) { cout << "A"; }
};
class B {
public:
B( ) { cout << "B" ;}
};
class C : public A {
B b;
public:
C( ) { cout <<"C"; }
};
int main( ) { C obj; return 0; }
A. CBA B. BAC C. ACB D. ABC

(B)20.If we have the class defination:
class XA{
int x;
public:
XA(int n){ x=n;}
};
class XB: public XA{
int y;
public:
XB(int a,int b);
};
Which is the correct constructor defination for XB ?
A.XB::XB(inta,intb):x(a),y(b){ }
B.XB::XB(inta,intb):XA(a),y(b){ }
C.XB::XB(inta,intb):x(a),XB(b){ }
D.XB::XB(inta,intb):XA(a),XB(b){ }