我只实现了Win32 Console Application,MFC你自己可以把下面的代码套进去就可以了。
class Complex
{
friend Complex operator* (const Complex & c1, const Complex & c2);
friend Complex operator/ (const Complex & c1, const Complex & c2);
friend Complex operator- (const Complex & c1);
friend istream & operator>> (istream& in, Complex& c);
friend ostream & operator<< (ostream& in, Complex& c);
private:
double real;
double imag;
public:
Complex(double r=0, double i=0):real(r), imag(i){}
Complex(const Complex & com1);
~Complex();
Complex operator+ (const Complex & c);
Complex operator- (const Complex & c);
};
Complex::Complex(const Complex & c1)
{
real = c1.real;
imag = c1.imag;
}
Complex::~Complex()
{
cout << "(" << real << ", " << imag << ")砆猂疼" << endl;
}
Complex Complex::operator+ (const Complex & c)
{
return Complex(real+c.real, imag+c.imag);
}
Complex Complex::operator- (const Complex & c)
{
return Complex(real-c.real, imag-c.imag);
}
Complex operator* (const Complex & c1, const Complex & c2)
{
return Complex(c1.real*c2.real-c1.imag*c2.imag, c1.imag*c2.real+c1.real*c2.imag);
}
Complex operator/ (const Complex & c1, const Complex & c2)
{
return Complex((c1.real*c2.real+c1.imag*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag),
(c1.imag*c2.real-c1.real*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag));
}
Complex operator- (const Complex & c1)
{
return Complex(0-c1.real, 0-c1.imag);
}
istream & operator >>(istream& in, Complex& c)
{
in.ignore();
in >> c.real;
in.ignore(2);
in >> c.imag;
return in;
}
ostream & operator<< (ostream& out, Complex& c)
{
out << "(" << c.real << ", " << c.imag << ")" << endl;
return out;
}
void main()
{
Complex c;
cout << c;
Complex c1(1,2);
cout << c1;
Complex c2(c1);
cout << c2;
Complex c3;
cin >> c3;
Complex c4 = c1 + c3;
cout << c4;
Complex c5 = c1 - c3;
cout << c5;
Complex c6 = c1 * c3;
cout << c6;
Complex c7 = c1 / c3;
cout << c7;
Complex c8 = -c1;
cout << c8;
}
#include
using namespace std;
class CLOCK{
private:
int chour;int cminute;int csecond;int hour;int minute;int second;
public:
CLOCK(int = 0,int = 0,int = 0);
void SETALARM(int ,int ,int );
void RUN();
void SHOWTIME();
};
CLOCK::CLOCK(int chour,int cminute,int csecond)
{
自己学着写程序,有错误,大伙可以帮忙debug
复数类的实现,网上可以搜到很多源代码
自己稍微加工一下就可以完成这个作业了