fenshu

fenshu - #include <iostream.h> #include...

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

View Full Document Right Arrow Icon
#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);}
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online