Frac operator -();

frac operator -(frac &);

frac operator *(frac &);

frac operator / (frac &)

 

Файл fractionR.cpp – файл реализации

frac frac::operator +(frac &c)

{return frac (p*c.q+q*c.p, q*c.q);}

bool frac::operator <(frac &c)

{return (p*c.q < c.p*q)? true:false;}

frac frac::operator - ()

{return frac (-p, q);}

frac frac::operator - (frac &c)

{return frac (p*c.q-q*c.p, q*c.q);}

frac frac::operator * (frac &c)

{return frac (p*c.p, q*c.q);}

frac frac::operator /(frac &c)

{return frac (p*c.q, q*c.p);}

 

 

// fractiongl.cpp – продолжение 2

x=b*c; x.show();

operator *(frac& [{4/3}])

Do reduce()...

Reduce()={8/9}

frac (int a, unsigned int b)

Destructor ~frac() for {8/9}

{8/9}

 

t=a+x; t.show();

operator +(frac &[{8/9}])

Do reduce()...

Reduce()={25/18}

frac (int a, unsigned int b)

Destructor ~frac() for {25/18}

{25/18}

x=c/d; x.show();

x=b-x; x.show();

x=t*x; x.show();

x=(a+b*c)*(b-c/d);

operator /(frac & [{2/5}])

Do reduce()...

Reduce()={10/3}

frac (int a, unsigned int b)

operator -(frac & [{10/3}])

Do reduce()...

Reduce()={-8/3}

frac (int a, unsigned int b)

operator *(frac& [{4/3}])

Do reduce()...

Reduce()={8/9}

frac (int a, unsigned int b)

operator +(frac &[{8/9}])

Do reduce()...

Reduce()={25/18}

frac (int a, unsigned int b)

operator *(frac& [{-8/3}])

Do reduce()...

Reduce()={-100/27}

frac (int a, unsigned int b)

Destructor ~frac() for {-100/27}

Destructor ~frac() for {25/18}

Destructor ~frac() for {8/9}

Destructor ~frac() for {-8/3}

Destructor ~frac() for {10/3}

x={-100/27}

__________________________________

Файлfraction.h

Дружественные функции:

- не представляют свойств класса, но входят в его интерфейс, и имеют доступ к его полям;

- определяются внутри класса со словом friend;

- на него не распространяются спецификаторы доступа;

- ей не передается this;

- описание алгоритма – вне класса, не повторяется слово friend, нет операции frac:: .

friend ostream & operator <<(ostream &,const frac &);

};

 

Файл fractionR.cpp – файл реализации

 

ostream & operator <<(ostream &f,const frac &c)

{ f<<"{"<<c.p<<'/'<<c.q<<"}";

return f; }

Лекция 9.

//MyDinMasHead.h

 

#include <iostream>

#include <fstream>