自考新教材-p142_3(1)

源程序:

#include <iostream>
using namespace std;
class point
{
private:
float x;
public:
void f(float a)
{
x = a;
}
void f()
{
x = 0;
}
friend float max(point &a,point &b);
};

float max(point &a, point &b)
{
return (a.x > b.x) ? a.x : b.x;
}

int main()
{
point a, b;
a.f(2.2);
b.f(3.3);
cout << max(a, b) << endl;
system("pause");
return 1;
}

运行结果:

 

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