Giter VIP home page Giter VIP logo

calculator's Introduction

计算器

主要界面

  • 1.mainwindow (主窗口,设置菜单栏等)
  • 2.choosepage (选择功能界面)

image-20230506163012445.

  • 3.normalpage (标准计算器界面)

image.

  • 4.sciencepage (科学计算器界面)

image.

  • 5.programmerpage (程序员界面)

imageimage

  • 6.datepage日期计算界面
后端

c++没有封装bignums库, 因此数字计算采用高精度算法任意精度算术 - 维基百科C++高精度算法_c++高精度计算_江河湖海 的博客-CSDN博客

封装一个有理数Rational类

class Rational
{
    QVector<int8_t> mInteger; // 整数部分, 使用signed char 来代表每个数字
    QVector<int8_t> mDecimal; // 小数部分
    
    // 并且将主要的运算符全部重载
    bool operator>(const Rational &A)const;                    //重载大于号
    bool operator>=(const Rational &A)const;                   //重载大于等于号
    bool operator<(const Rational &A)const;                    //重载小于号
    bool operator<=(const Rational &A)const;                   //重载小于等于号
    bool operator==(const Rational &A)const;                   //重载等于号
    bool operator!=(const Rational &A)const;                   //重载不等于号
    Rational operator+(const Rational &A)const;               //重载加法
    Rational operator-(const Rational &A)const;               //重载减法
    Rational operator*(const Rational &A)const;               //重载乘法
    Rational operator/(const Rational &A)const;               //重载除法
}

核心算法

void rantionalAdd(const Rational &A,const Rational &B,Rational &Res)const;                           //高精度加法
void rantionalSubtract(const Rational &A,const Rational &B,Rational &Res)const;                      //高精度减法
void rantionalMultiply(const Rational &A,const Rational &B,Rational &Res)const;                      //高精度乘法
void rantionalDivide(const Rational &A,const Rational &B,Rational &Res,int32_t precision)const;      //高精度除法

QString getNumber()const;                                   //输出高精度数为字符串
QString getDecimal()const;                                  //单独获取小数部分
QString getInteger()const;                                  //获取整数部分

表达式运算算法

使用常规的中缀转后缀然后运算得出结果

计算出结果后,以科学计算器页面为例

页面逻辑:点击计算器按钮生成一个表达式(Expression),获取控件text()文本然后发送到CalEngine

然后通过CalEngine计算出结果后更新当前输入框的内容为计算结果

前端

mainwindow窗口

image.

sciencepage

image.

致谢

https://github.com/EMILIIIIA/ExpressionCalculator

calculator's People

Contributors

wustghj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.