floatnm.h

来自「适合初学者学习以及程序员回顾」· C头文件 代码 · 共 53 行

H
53
字号
// FloatNM.h

#ifndef FLOATNM_H
#define FLOATNM_H
#include <iomanip>
#include <iostream>
#include <math.h>
using std::cin;
using std::cout;
using std::endl;

class Float
{
  friend Float
    operator+(const Float& Left,
              const Float& Right);
  friend Float
    operator*(const Float& Left,
              const Float& Right);
  friend Float
    operator^(const Float& Left,
              const Float& Right);
  friend Float&
    operator+=(Float& Left,
               const Float& Right);
  private:
    float F;
  public:
  Float(float x) : F(x) {}
  Float(): F(0) {}
  // 定义 转换运算子 float
  operator float() {return F;}
};
  // 定义 operator+()
Float operator +
 (const Float& Left, const Float& Right)
  {return Float(Left.F + Right.F);}
  // 定义 operator*()
Float operator *
 (const Float& Left, const Float& Right)
  {return Float(Left.F * Right.F);}
  // 定义 operator^()
Float operator ^
 (const Float& Left, const Float& Right)
  {return Float(pow(Left.F, Right.F));}
  // 定义 operator+=()
Float& operator +=
 (Float& Left, const Float& Right)
{
   Left.F += Right.F;
   return Left;
}
#endif

⌨️ 快捷键说明

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