1 #include <iostream>
2 using namespace std;
3
4 class Fraction{
5 private:
6 int m;
7 int d;
8 public:
9 Fraction():m(0),d(1){
10 cout<<"Fraction()"<<endl;
11 }
12 Fraction(int m, int d):m(m),d(d){
13 cout<<"Fraction(int, int)"<<endl;
14 }
15 void set(int m, int d){
16 this->m=m;
17 this->d=d;
18 }
19 void frac(){
20 int g=m>d ? m : d;
21 for(int i=g; i>0; i--){
22 if(m%i==0 && d%i==0){
23 m/=i;
24 d/=i;
25 }
26 }
27 }
28 void show(){
29 cout<<"m="<<m<<", d="<<d<<endl;
30 }
31 ~Fraction(){
32 cout<<"~Fraction"<<endl;
33 }
34
35 };
36
37 int main(){
38 Fraction f1(10,20), f2;
39
40 f1.frac();
41 f1.show();
42
43 f2.set(3,4);
44 f2.frac();
45 f2.show();
46 system("pause");
47 }
48