自考新教材-p143_2

源程序:

#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;
}

运行结果:

 

posted @ 2020-02-06 19:28  bobo哥  阅读(163)  评论(0编辑  收藏  举报