};
voidshow(A&a)
{
intk=50;
a.fun(k);
}
intmain()
{
Aa;
Bb;
cout<<"Callingshow(a).\n";
show(a);
cout<<"Callingshow(b).\n";
show(b);
return0;
}
10.#include
classClass
{
public:
staticintvar;
Class()
{
var++;
}
};
intClass:
:
var=1;
voidmain()
{
cout<<″Class:
:
var=″<:
var<Classcl;
cout<<″cl.var=″<Classc2,c3;
cout<<″c2.var=″<}
程序改错题
1.classA{
private:
intnum;
public:
A();
intgetint(){returnnum;}
void~A();
};
2.#include
classT
{protected:
inta;
public:
T(intm){p=m;}
};
voidmain()
{Tt(10);
cout<}
3.classA
{
public:
A(intx,inty)
{
X=x;Y=y;
}
……
private:
intX,Y;
}
classB:
publicA
{
public:
B(intp,intq)
{
P=p;
Q=q;
}
privare:
intP,Q;
};
4.#include
voidmain()
{inti,*p;
i=5;
p=i;
cout<<*p<}
5.#include
voidmain()
{inti
(2),j(5);
int*constp=&i;
cout<<*p<p=&j;
cout<<*p<}
6.#include
intmain(){
intx=1,y=2;
constint*p=&x;
*p=y;
cout<<*p<return0;}
7.#include
classpoint
{private:
floatx;
public:
voidf(floata){x=a;}
voidf(){x=0;}
friendfloatmax(point&a,point&b);
};
floatmax(point&a,point&b)
{return(a.x>b.x)?
a.x:
b.x;}
voidmain(){
pointa,b;
a.f(2.0);b.f(4.0);
cout<}
8.#include
classA
{
private:
intx,y;
public:
A(inta=3,b=4);
voidShow();
};
A:
:
A(inta,intb)
{
x=a;
y=b;
}
voidA:
:
Show()
{
cout<<″x=″<cout<<″y=″<}