SHARE
TWEET

Untitled

a guest Jan 24th, 2020 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* TP essai création de classe Rational */
  2. #include <iostream>
  3.  
  4. class Rational {
  5.     friend Rational operator+ (Rational a, Rational b);
  6.     friend Rational operator* (Rational a, Rational b);
  7. private:
  8.     int num;
  9.     int denom;
  10. public:
  11.     Rational(int n, int d): num(n),denom(d) {
  12.         print();
  13.     }
  14.     void print() {
  15.         std::cout<<num<<'/'<<denom<<std::endl;
  16.     }
  17.  
  18.     Rational add(Rational a) {
  19.         return Rational(num*a.denom+denom*a.num,denom*a.denom);
  20.         }
  21.  
  22.     Rational mult(Rational a) {
  23.         return Rational(num*a.num,denom*a.denom);
  24.         }
  25.  
  26.     double eval(){
  27.        
  28. };
  29.  
  30. inline Rational operator+ (Rational a, Rational b) {
  31.     return Rational(a.num*b.denom+a.denom*b.num,a.denom*b.denom);
  32. }
  33.  
  34. inline Rational operator* (Rational a, Rational b) {
  35.     return Rational(a.num*b.num,a.denom*b.denom);
  36. }
  37. int main() {
  38.     Rational r(1,2);
  39.     Rational t(3,5);
  40.     Rational v=r.add(t);
  41.     Rational w=t.mult(r);
  42.         Rational z=r+w;
  43.     Rational u=t*v;
  44.     t.print(); /*3/5*/
  45.     std::cout<<"coucou"<<"\n";
  46.         std::cout<<"salutcava"<<"\n";
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top