#include<iostream>usingnamespace std;classA{public:A(int x =0,int y =0):x(x),y(y){}voidshow()const;booloperator>(A& a);private:int x, y;};bool A::operator>(A& a){return((x*x+y*y)>(a.x*a.x+a.y*a.y));}intmain(){int x,y,p,q;while(cin >> x >> y >> p >> q, x||y||p||q){
A a1(x, y);
A a2(p, q);
cout <<((a1 > a2)?"true":"false")<< endl;}return0;}
7-4 分数加法运算重载 (10 分)
#include<iostream>#include<algorithm>usingnamespace std;classFS{private:int fz;int fm;intgcd(int x,int y){if(x < y)swap(x, y);while(y){int z = x % y;
x = y;
y = z;}return x;}public:FS(){}FS(int z,int m):fz(z),fm(m){}voidset(int x,int y){fz=x; fm=y;}voidshow()const{
cout <<fz<<"z"<<fm<<"m"<<endl;}
FS operator+(const FS &f){int y = fm * f.fm;int x = fz * f.fm + f.fz * fm;int d =gcd(x,y);
x = x / d, y = y / d;if(y <0){
x =-x, y =-y;}returnFS(x,y);}};intmain(){int n, p, q;char a,b;
cin >> n;while(n--){
cin >> q >> a >> p >> b;
FS f(q, p);
cin >> q >> a >> p >> b;
FS g(q, p);
f = f + g;
f.show();}return0;}
7-5 分钟秒钟的时间相减 (10 分)
#include<iostream>#include<cstdio>#include<algorithm>usingnamespace std;classTime{private:int hour, minute;public:Time(){}Time(int h,int m):hour(h),minute(m){};
Time operator-(const Time& t){if(t.minute <= minute){this->minute -= t.minute;this->hour -= t.hour;}else{this->minute =this->minute +60- t.minute;this->hour -=(t.hour +1);}return*this;}voidshowMinutes()const{
cout << hour*60+ minute <<endl;}};intmain(){int h1, m1, h2, m2;while(scanf("%02d %02d %02d %02d",&h1,&m1,&h2,&m2)){if(!h1 &&!m1 &&!h2 &&!m2)break;
Time f(h1, m1);
Time g(h2, m2);
g = g - f;
g.showMinutes();}return0;}