1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
#include <iostream>
#include "Frac.h"
using namespace std;
// cout <<
ostream& operator<<( ostream &flux, Frac const& frac)
{
frac.afficher(flux);
return flux;
}
//Liste des fonctions
Frac add(Frac frac1, Frac frac2 ,Frac frac3)
{
frac3 = frac1 + frac2;
return frac3;
}
Frac sub(Frac frac1, Frac frac2, Frac frac3)
{
frac3 = frac1 - frac2;
return frac3;
}
Frac mult(Frac frac1, Frac frac2, Frac frac3)
{
frac3 = frac1 * frac2;
return frac3;
}
Frac div(Frac frac1, Frac frac2, Frac frac3)
{
frac3 = frac1 / frac2;
return frac3;
}
void valeurexacte(Frac eg)
{
int rep(0);
cout <<"Souhaitez-vous avoir la valeur exacte de cette fraction?";
cin >> rep;
switch (rep)
{
case 1:
cout << endl;
cout << "La voici: " << eg.getm_valeurexacte() << endl;
break;
case 2:
//Oh no you deedn't!
break;
}
}
int main()
{
int choixOperation(1);
int denom(1);
int num(1);
Frac fracresult;
cout << endl;
do
{
cout << "0 - Quitter" << endl;
cout << "1 - Additionner" << endl;
cout << "2 - Soustraire" << endl;
cout << "3 - Multiplier" << endl;
cout << "4 - Diviser" << endl;
cin >> choixOperation;
switch (choixOperation){
case 0:
return 0;
break;
case 1:{
cout <<"Entrez la valeur du numerateur de la premiere fraction a additionner: ";
cin >> num;
cout << endl;
cout <<"Le denominateur maintenant: ";
cin >> denom;
cout << endl;
Frac frac1(num, denom);
Frac frac2(3, 4);
add(frac1, frac2, fracresult);
cout << frac1 <<" + "<< frac2 <<" = "<< fracresult << endl;
valeurexacte(fracresult);
break;}
case 2:{
Frac frac1;
Frac frac2(5, 4);
sub(frac1, frac2, fracresult);
cout << fracresult;
valeurexacte(fracresult);
break;}
case 3:{
Frac frac1;
Frac frac2(5, 4);
mult(frac1, frac2, fracresult);
cout << frac1;
valeurexacte(fracresult);
break;}
case 4:{
Frac frac1;
Frac frac2(5, 4);
div(frac1, frac2, fracresult);
cout << fracresult;
valeurexacte(fracresult);
break;}
default:
cout << "Tapez un nombre entre 0 et 4." << endl;
break;
}
}
while (choixOperation !=0);
return 0;
}
|