⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 floatnm.h

📁 适合初学者学习以及程序员回顾
💻 H
字号:
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -