fenshu

fenshu - #include &lt;iostream.h&gt; #include...

This preview shows pages 1–2. Sign up to view the full content.

#include <iostream.h> #include <math.h> //abs() #include <stdlib.h> //exit(0) class fraction { friend ostream &operator<<( ostream & o,const fraction & f); friend istream &operator>>( istream & i, fraction & f); public: p static int n; //¾²Ì¬Êý¾Ý³ÉÔ±µÄ³õÊ¼»¯·ÅÔÚÀàÌåÍâ s static int gcd(int m,int n1); //º¯Êý¶¨ÒåÇ°¼ÓÉÏstatic s fraction(int fz=0,int fm=1); //º¯ÊýµÄÄ¬ÈÏÐ´ÔÚÉùÃ÷ÖÐ { fenzi=f.fenzi ;fenmu=f.fenmu ; n++; } ~fraction(){ }// n--; } ~ fraction operator+(fraction f) { //return fraction(fenzi*f.fenmu +fenmu*f.fenzi,fenmu*f.fenmu); fraction f1; f1.fenzi =fenzi*f.fenmu +fenmu*f.fenzi; f1.fenmu =fenmu*f.fenmu; return f1; } private: int fenzi,fenmu; //Ò»°ãÊý¾Ý³ÉÔ±µÄ³õÊ¼»¯·ÅÔÚ¹¹Ôìº¯Êý }; int fraction::n=0; //ÀàÌåÍâ³õÊ¼»¯µÄÊ±ºò²»Òª¼ÓÉÏstatic i fraction::fraction(int fz,int fm)//º¯ÊýµÄÄ¬ÈÏ²»¿ÉÐ´ÔÚ¶¨ÒåÖÐ { if(fm==0){cout<<"·ÖÄ¸²»ÔÊÐíÎª0"<<endl;exit(0);}

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

fenshu - #include &lt;iostream.h&gt; #include...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online