zoukankan      html  css  js  c++  java
  • 实现简单的计算器(计算功能模块实现)

     1 #ifndef EXECUTE_H
     2 #define EXECUTE_H
     3 #include <QString>
     4 
     5 class execute
     6 {
     7 public:
     8     execute();
     9     void setnum1(int num);
    10     void setnum2(int num);
    11     void setflag(QString flag);
    12     QString doexe();
    13 private:
    14     int num1;
    15     int num2;
    16     QString flag;
    17 };
    18 
    19 #endif // EXECUTE_H
     1 #include "execute.h"
     2 
     3 execute::execute()
     4 {
     5     num1=0;
     6     num2=0;
     7 }
     8 
     9 void execute::setnum1(int num){
    10     this->num1 = num;
    11 }
    12 
    13 void execute::setnum2(int num){
    14     this->num2 = num;
    15 }
    16 
    17 void execute::setflag(QString flag){
    18     this->flag = flag;
    19 }
    20 
    21 QString execute::doexe(){
    22     int result = 0;
    23     if(this->flag == "+"){
    24         result = this->num1+this->num2;
    25     }else if (this->flag == "-") {
    26         result = this->num1-this->num2;
    27     }else if (this->flag == "*") {
    28         result = this->num1*this->num2;
    29     }else if (this->flag == "/") {
    30         if(this->num2 == 0){
    31             return "ERROR";
    32         }else {
    33             result = this->num1*this->num2;
    34         }
    35     }else {
    36         result = this->num1;
    37     }
    38     return QString::number(result);
    39 }
    内在的趣味,表面的繁琐
  • 相关阅读:
    第一次讲课
    请允许我悄悄的爱你一次好吗 zz
    装.NET实在是一种折磨,
    第一次听课
    路,在何方?
    UNION和UNION ALL 的区别
    利用jquery操作select下拉列表框
    理解 collate Chinese_PRC_CI_AS
    sql 中 case when 实例
    sql 中 case when 实例(2)
  • 原文地址:https://www.cnblogs.com/data1213/p/10800575.html
Copyright © 2011-2022 走看看