源程序:

#include <iostream>
using namespace std;

class point
{
private:
float x, y;
public:
void f1(float a, float b)
{
x = a;
y = b;
}
point()
{
x = 0;
y = 0;
}
void getx()
{
cout << x << endl;
}
void gety()
{
cout << y << endl;
}
friend void print(point);
};
void print(point a)
{
cout << a.x << "," << a.y << endl;
}
int main()
{
point a;
a.f1(3.0,5.0);
print(a);
system("pause");
return 1;
}

运行结果:

自考新教材-p143_2_#include