fraction.h

来自「实现了分数之间的四则运算」· C头文件 代码 · 共 57 行

H
57
字号
#ifndef FRACTION_H
#define FRACTION_H

#include <iostream>
using namespace std;

int count(int a);  //cout the digit numbers of an integer

class fraction
{
    friend ostream &operator<<( ostream &, const fraction &); 
    friend istream &operator>>( istream &, fraction &); 
    friend fraction operator+(const fraction &, const fraction &);
    friend fraction operator-(const fraction &, const fraction &);
    friend fraction operator*(const fraction &, const fraction &);
    friend fraction operator/(const fraction &,fraction &);
    friend bool operator>(const fraction &, const fraction &);
    friend bool operator>=(const fraction &, const fraction & );
    friend bool operator<(const fraction &, const fraction &);
    friend bool operator<=(const fraction &, const fraction &);
    friend bool operator==(const fraction &, const fraction &);
    friend bool operator!=(const fraction &, const fraction &);

  public:
         fraction(int,int); //defacult constructor
         ~fraction(); //destructor
         void simplify();
         void reciprocal();  //function to get the reciprocal   
         void set_denominator(int);
         void set_numerator(int);
         void set_fraction(int,int);       
         int get_numerator();
         int get_denominator();
         int digit_number();
protected:
          int denominator;
          int numerator;           
           
}
;
class Integer : public fraction
{
    friend ostream &operator<<( ostream &, const Integer &); 
    friend int operator+( Integer &, Integer &);
    friend int operator-( Integer &, Integer &);
    friend int operator*( Integer &, Integer &);
    friend fraction operator/(const Integer &, Integer &);

    
   
public:
       Integer(int);
       int digit_number();
}
;
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?