#include <iostream.h>
class operation{
float num;
float deno;
public:
operation(float numerateur=1, float denominateur=1);
friend operation operator+(operation fct1, operation fct2);
friend operation operator-(operation fct1, operation fct2);
friend operation operator* (operation fct1, operation fct2);
friend operation operator/(operation f1, operation f2);
void affiche();
};
operation::operation (float numerateur, float denominateur){
num= numerateur;
deno=denominateur;
}
operation operator+ (operation fct1, operation fct2){ //ressemble a constructeur par
copie
operation res;
res.deno= fct1.deno*fct2.deno;
res.num=(fct1.num*fct2.deno)+(fct2.num*fct1.deno);
return res;
}
operation operator- (operation fct1, operation fct2){ //ressemble a constructeur par
copie
operation res;
res.deno= fct1.deno*fct2.deno;
res.num=(fct1.num*fct2.deno)-(fct2.num*fct1.deno);
return res;
}
operation operator* (operation fct1, operation fct2){ //ressemble a constructeur par
copie
operation res;
res.deno= fct1.deno*fct2.deno;
res.num=fct1.num*fct2.num;
return res;
}
operation operator/(operation f1, operation f2) {
operation res;
if(f2.num == 0) {
res.num = 0;
res.deno = 1;
cout << "division par 0 pas possible" << endl;
}
else {
res.deno = f1.deno * f2.num;
res.num = f1.num * f2.deno;
}
return res;
}
// opposé ???????
void operation::affiche(){
cout<<num<<" / "<<deno<<endl;
}
void main(){
operation a(2,3);
operation b(1,2);
operation c;
c=a+b;
c.affiche();
c=a-b;
c.affiche();
c=a*b;
c.affiche();
c=a/b;
c.affiche();
}