Simple class.

Simple class.

class

See version :

Pas de dépendances

Download :

#include <cstdlib>
#include <iostream>

using namespace std;

/* --------------------------- */

int pgcd (int m, int n)            // Algorithme d'Euclide (pour les matheux)
{
  if (n==0) return m;
  else return pgcd( n, m % n);
}

/* ---------------------------- */

class Fraction
{
private:
    int num;
    int denom;
public:
    Fraction(int,int);
    void Simplifie();
    void Affiche();
};

Fraction::Fraction(int n,int d)
{
    num=n;
    denom=d;
}

void Fraction::Simplifie()
{
    int p=pgcd(num,denom);
    num/=p;
    denom/=p;
}

void Fraction::Affiche()
{
    cout << num << "/" << denom << endl;
}

/* ------------------------------ */

int main()
{
    int n,d;
    cout << "entrez numerateur, puis denominateur" << endl;
    cin >> n;
    cin >> d;
    Fraction f(n,d);
    f.Simplifie();
    cout << "Votre fraction simplifiee" << endl;
    f.Affiche();
    system("PAUSE");
    return 0;
}




Explanations

	No explanations yet.