Back-end separation calculator programming

832101228梁伟权 2023-10-09 16:20:05
The Link Your Classhttps://bbs.csdn.net/forums/ssynkqtd-04
The Link of Requirement of This Assignmenthttps://bbs.csdn.net/topics/617332156
The Aim of This AssignmentBack-end separation calculator programming
MU STU ID and FZU STU IDMU:21125546    FZU:832101228

contents

   I. Introduction

   II. PSP table

   III. Problem-solving ideas

   IV. Design and implementation

   V. Code description 

   VI. Displaying result functions

   VII. Summary 

I. Introduction

       This blog will show how I use the WeChat mini program to build an calculator which including  addition, subtraction, multiplication, division and clear functions. I will introduce some relevant background and design process and code description, and finally a product display in the next part.

II. PSP table

Personal Software Process StagesEstimated Time(minutes)Actual Time(minutes)
planning单元格单元格
Estimate4060
Development\\
Analysis3025
Design Spec1010
Design Review510
Coding Standard23
Design2015
Coding180200
Code Review6080
Test1010
Reporting//
Test Report4060
Size Measurement108
Postmortem & Process Improvement Plan1015
Sum417491

III. Problem-solving ideas

       First of all, we need to make a visual interface, for which I chose the most familiar Wechat mini program to make. But I didn't know how to start an event when I clicked a button in the interface, so I chose to look for a tutorial on Bilibili. Then, the logic writing part, simple operations I choose to write myself. The more complicated trigonometric functions and exponential operations can not solve so far. One of the backspace function at first did not think of a solution, and then I wanted to use the string to remove the end of the character to achieve, so I looked for the use of slice function on the Internet to solve the problem.

IV.

Design and implementation

  1. Front-end
    I use wxss designer to design the surface. I create 2 windows, which are the calculator and history. Style sheet is used to make the interface more beautiful.
    In the calculator, perform different functions according to different click events. For example, digits and dot are different from operators. There are also other function buttons.

  2. Back-end
    I used to use mysql to connect the database directly but failed many times. So to be replaced I use wxjs to connect the database.
    The table is manipulated bt executing sql statements.
    Next is the process.
    When calculator is open, clear the table “history” in the database “calculator”.
    When users push “=”, expression is sented to the table “history” in the database"calculator".
    When users push “ANS”, read the latest field in the table and display it in the lineEdit.
    When users push “history”, the window of history is shown and showEvent is triggered. In the showEvent, database is connected and the latest 10 fields of the table are read in turn and then displayed in the lineEdits in the window one by one.

3.Flowchart

img

V. Code description

  1. The following is the mini program's back-end program codes.
// pages/index/index.js
Page({
  data: {
    num1:"",
    numStr:"0",
    op:""
  },
  clear(){
    this.setData({numStr:"0"});
  },
  op(e){
    var v = e.currentTarget.dataset.op;
    this.setData({
      op:v,
      num1:this.data.numStr,
      numStr:""
    });
  },
  cal(){
    if(!this.data.num1 || !this.data.op || !this.data.numStr){
      wx.showToast({
        title: '计算条件不完整',icon:"none"
      });
      return;
    }
    var rs = 0;
    var v1 = parseFloat(this.data.num1);
    var v2 = parseFloat(this.data.numStr);
    switch(this.data.op){
      case "+":
        rs = v1+v2;
        break;
      case "/":
        rs = v1/v2;
        break;
      case "×":
        rs = v1*v2;
        break;
      case "-":
        rs = v1-v2;
        break;
      case "%":
        rs = v1%v2;
        break;
    }
    this.setData({
      numStr:rs
    });
  },
  numBtn(e){
    var v = e.currentTarget.dataset.num;
    this.setData({
      numStr: this.data.numStr == "0" ? v: this.data.numStr + v
    });
  },
  click(e){
    var index = e.currentTarget.dataset.index;
    if(index == 0){
       var num1=this.data.num1;
       var num1=data.substr(0,num1.length-1);
       this.setData({
         num1:num1
       })
    }
  }
})


  1. The following is the mini program's preceding code. 
.info{
  min-height: 380rpx;
  display: flex;
  align-content: flex-end;
  text-align: right;
  flex-direction: column;
  justify-content: flex-end;
  background-color: #eee;
  font-size: 64rpx;
}
.op{
  text-align: right;
  background-color: #eee;
}
.btns{
  border-left: solid 1px #ccc;
  border-right: solid 1px #ccc ;
}
.btns > view{
  display: flex;
}
.btns > view>view{
  flex: 1;
  text-align: center;
  height: 150rpx;
  line-height: 150rpx;
  outline: solid 1px #ccc;
}


Above is the code part, I learned a small program front and back end links. 

VI. Displaying result functions

 

 

VII. Summary

      In this assignment, I designed a calculator with a visual interface using Wechat developer tools. Here are the steps and procedures for me to complete this assignment:

(1) download a Wechat developer tools: I registered an account and passed the platform audit.

(2) Create the main window: I used the build-in library to create a main window and set the title and size of the window.

(3) Create display: I created a text box on the main window to display the calculation result and the expression entered by the user.

(4) Create buttons: I used the  to create a series of buttons for the user to enter numbers and operators.

(5) Add button function: I added corresponding function for each button, such as when clicking the number button, the corresponding number will be displayed on the display screen; When you click the operator button, the corresponding operator is displayed on the display.

(6) Implement the calculation function: I use the "switch case" conditional judgment statement to evaluate the expression entered by the user and display the result on the display screen.

(7) Testing and debugging: I tested the calculator and fixed some possible bugs.

By doing this assignment, I learned how to use Wechat developer tools and some programming knowledge to design a calculator with a simple visual interface. I learned the basic concepts and techniques of front and back end development and improved my programming skills. 

...全文
103 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

176

社区成员

发帖
与我相关
我的任务
社区描述
梅努斯软件工程
软件工程 高校 福建省·福州市
社区管理员
  • LinQF39
  • Jcandc
  • chjinhuu
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧