打卡

#include<iostream>
using namespace std;
class Time
{
private:
int min,hour;
public:
Time(int a=0,int b=0)
{
min=b;
hour=a;
}
int hu()
{
int hu=hour*60+min;
return hu;
}
friend int operator -(Time &x,Time &y)
{
int c=y.hu()-x.hu();
return c;
}
};
int main()
{
int a1,a2,b1,b2;
while(cin>>a1>>b1>>a2>>b2)
{
if(a1==0&&a2==0&&b1==0&&b2==0)
{
break;
}
else
{
Time p1(a1,b1);
Time p2(a2,b2);
int o=p1-p2;
cout<<o<<endl;
}
}
return 0;
}

#include<iostream>
using namespace std;
class Complex
{
public:
Complex(double r=0, double i=0):real(r), imag(i){}
Complex operator+(Complex &a) const;
Complex operator-=(Complex &a);
friend Complex operator-(Complex &a,Complex &b);
void Display() const;
private:
double real;
double imag;
};
Complex Complex::operator+(Complex &a) const
{
return Complex(real+a.real,imag+a.imag);
}
Complex Complex::operator-=(Complex &a)
{
real=real-a.real;
imag=imag-a.imag;
return Complex(real,imag);
}
Complex operator-(Complex &a,Complex &b)
{
return Complex(a.real-b.real,a.imag-b.imag);
}
void Complex::Display() const
{
cout << "(" << real << ", " << imag << ")" << endl;
}

int main()
{
double r, m;
cin >> r >> m;
Complex c1(r, m);
cin >> r >> m;
Complex c2(r, m);
Complex c3 = c1+c2;
c3.Display();
c3 = c1-c2;
c3.Display();
c3 -= c1;
c3.Display();
return 0;
}

posted @ 2023-04-21 10:58  ruangong  阅读(40)  评论(0)    收藏  举报