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 }
    内在的趣味,表面的繁琐
  • 相关阅读:
    梦断代码阅读笔记一
    进度一
    LOJ#6031. 「雅礼集训 2017 Day1」字符串
    cf700E. Cool Slogans
    BZOJ1014: [JSOI2008]火星人prefix
    BZOJ2716: [Violet 3]天使玩偶
    cf1080F. Katya and Segments Sets
    BZOJ1354: [Baltic2005]Bus Trip
    灭绝树题集
    How Many Substrings?
  • 原文地址:https://www.cnblogs.com/data1213/p/10800575.html
Copyright © 2011-2022 走看看