Virtual Calculator

目录

1.Introduction

2.Basic Information 

3.General display

4.PSP Table

5.Description Of Problem-Solving Ideas

6.Design And Implementation Process

7.summary


 1.Introduction

This blog mainly contains a simple visual calculator that I designed using wechat developer tools. It can realize the basic addition, subtraction, multiplication and division of four operations and some basic trigonometric function calculation. In the following introduction there is a visual demonstration of the small program, as well as the design process and detailed code of each part.

2.Basic Information 

The Link Your Classhttps:https://bbs.csdn.net/forums/ssynkqtd-04
The Link of Requirement of This Assignmenthttps:https://bbs.csdn.net/topics/617332156
The Aim of This AssignmentCreate a calculator with a visual interface.
MU STU ID and FZU STU ID21126160(MU)/832101311(FZU)

 Link to the finished project code:https://github.com/luckyLucy999/calculator1/tree/index.wxss

 3.General display

The picture above is the development interface of a visual calculator using wechat developer tools.

The above dynamic diagram shows the function of analog calculator to achieve addition, subtraction, multiplication, division, trigonometric functions, and regression. 

4.PSP Table

Personal Software Process StagesEstimated Time(minutes)Actual Time(minutes)
Planning4550
• Estimate4550
Development355445
• Analysis3035
• Design Spec3020
• Design Review2530
• Coding Standard4025
• Design4060
• Coding100155
• Code Review5070
• Test4050
Reporting200158
• Test Repor8088
• Size Measurement5030
• Postmortem & Process Improvement Plan7040
Sum600653

 5.Description Of Problem-Solving Ideas

①Define project requirements

In this project, first clear the project calculator needs to achieve the function: to achieve addition, subtraction, multiplication and division of four operations, decimal points and trigonometric functions of some basic calculation functions.

②How To Achieve

After reading a lot of materials and learning through Bilibili, Jianshu, CSDN and other related materials, I decided to use the wechat developer tools and use the JavaScript of wechat mini program to write this project. Since it is the first time for me to contact this kind of project, I have learned a lot of materials to complete this project.

6.Design And Implementation Process

The design of the calculator is divided into the following parts:

app.json、wxml、wxss、js

①app.json file writing
This is a configuration file. pages is the page path of the configuration applet; window is the window style that configures the applet. The app.json file can realize the Settings of the page, window and other functions of the small program, and configure the debugging and permissions of the small program.

{
  "pages":[
    "pages/index/index"
  ],
  "window":{
    "backgroundTextStyle":"light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "CALCULATOR",
    "navigationBarTextStyle":"black"
  },
  "debug":true
}

②wxml file writing

This is a file that is mainly used to write the structural part of the small program page. This file is used to create the buttons for the calculator interface and to design the buttons' styles, values, and touch event handlers. With these buttons and logic, the function of a simple calculator is realized.

<view class='button'>
     <view class='showkindow'>{{screenNum}}</view> 
    <view capture-bind:touchstart="compute">
     <view>
       <button data-val='clear' hover-class='shadow' class='bottomw bottom1'>AC</button>
       <button data-val='back' hover-class='shadow' class='bottomw bottom1'>DEL</button>
       <button data-val='#' hover-class='shadow' class='bottomw bottom1'>#</button>
       <button data-val='÷' hover-class='shadow' class='bottomw bottom'>÷</button>
     </view>
     <view>
       <button data-val='sin' hover-class='shadow' class='bottomw bottom1'>sin</button>
       <button data-val='cos' hover-class='shadow' class='bottomw bottom1'>cos</button>
       <button data-val='tan' hover-class='shadow' class='bottomw bottom1'>tan</button>
       <button data-val='±' hover-class='shadow' class='bottomw bottom'>±</button>
     </view>
       <view>
       <button data-val='7' hover-class='shadow' class='bottomw'>7</button>
       <button data-val='8' hover-class='shadow' class='bottomw'>8</button>
       <button data-val='9' hover-class='shadow' class='bottomw'>9</button>
       <button data-val='x' hover-class='shadow' class='bottomw bottom'>x</button>
     </view>
       <view>
       <button data-val='4' hover-class='shadow' class='bottomw'>4</button>
       <button data-val='5' hover-class='shadow' class='bottomw'>5</button>
       <button data-val='6' hover-class='shadow' class='bottomw'>6</button>
       <button data-val='-' hover-class='shadow' class='bottomw bottom'>-</button>
     </view>
       <view>
       <button data-val='1' hover-class='shadow' class='bottomw'>1</button>
       <button data-val='2' hover-class='shadow' class='bottomw'>2</button>
       <button data-val='3' hover-class='shadow' class='bottomw'>3</button>
       <button data-val='+' hover-class='shadow' class='bottomw bottom'>+</button>
     </view>
       <view>
       <button data-val='1' hover-class='shadow' class='bottomw bottom2'>0</button>
       <button data-val='.' hover-class='shadow' class='bottomw'>.</button>
       <button data-val='=' hover-class='shadow' class='bottomw bottom'>=</button>
     </view>
    </view>
</view>

③wxss file writing

This file is used to write small program page style file. This file allows you to create beautiful styles for your applet pages. Set the shape and color of the key, the color of the background and the color and font of the numeric text, and the shadow Settings after the button is pressed.

.button{
  width:100%;
  height: 700px;
  background:black;
}
.showkindow{
  color: #fff;
  width: 100%;
  height:125px;
  font-size: 50px;
  text-align:right;
}

.bottomw{
  width: 90px;
  height:90px;
  display:block;
  float:left;
  border-radius: 50%;
  line-height: 90px;
  text-align: center;
  margin-left: 3px;
  margin-top: 5px;
  color:black;
  background:white;
  font-weight: bold;
  font-size: 30px;
}
.bottom{
  background:lightsalmon;
}
.bottom1{
  background: #969494;
  color:#000;
}
.bottom2{
  width: 180px;
  border-radius: 40px;
}
.shadow{
  background:rgba(0, 0, 0, 0.075);
}

④js file writing

This file is a scripting language for writing small program logic, and can manipulate page elements, manipulate data, and so on. Through the writing of this file to achieve a simple calculator function, to achieve addition, subtraction, multiplication and division of four operations and trigonometric functions and other basic calculations.

//index.js

const app = getApp()

Page({

  /**
   * Initial data for the page
   */
  data: {
    screenNum: 0,//The number displayed on the screen
    currentNum: '',//The number of current inputs
    storage: 0,//Stored number
    operator: '',//operator
    off: false,
  },

  compute: function (e) {
    var btn_num = e.target.dataset.val;
    var obj = this;
    if (!isNaN(btn_num)) {
      if (obj.data.off == true) {
        obj.data.currentNum = ''
        obj.data.off = false;
      }
      obj.data.currentNum += btn_num
      obj.data.currentNum = Number(obj.data.currentNum);
      obj.data.currentNum = obj.data.currentNum.toString();
    } else {
      switch (btn_num) {
        case '+':
        case '-':
        case 'x':
        case '÷':
        case '=':
        
// Stores the number on the current screen and the current operator to a variable

          if (obj.data.storage == 0) {
            obj.data.storage = obj.data.currentNum;
            obj.data.operator = btn_num;
          } else {
            if (obj.data.off != true) {
              if (obj.data.operator == '+') {
                obj.data.currentNum = Number(obj.data.storage) + Number(obj.data.currentNum)
              } else if (obj.data.operator == '-') {
                obj.data.currentNum = Number(obj.data.storage) - Number(obj.data.currentNum)
              } else if (obj.data.operator == 'x') {
                obj.data.currentNum = Number(obj.data.storage) * Number(obj.data.currentNum)
              } else if (obj.data.operator == '÷') {
                obj.data.currentNum = Number(obj.data.storage) / Number(obj.data.currentNum)
              }
            }
            obj.data.storage = obj.data.currentNum;
            obj.data.operator = btn_num;
          }

          obj.data.off = true;
          break;
        case 'clear':
          obj.data.storage = 0;
          obj.data.currentNum = '0';
          obj.data.operator = '';
          break;
        case 'back':
          obj.data.currentNum = obj.data.currentNum.slice(0, -1);
          if (obj.data.currentNum == '') {
            obj.data.currentNum = '0';
          }
          break;
        case '.':
          if (obj.data.currentNum.indexOf('.') == -1) { // Check whether.
            obj.data.currentNum += btn_num
          }
          break;
          case 'sin':
  obj.data.currentNum = Math.sin(parseFloat(obj.data.currentNum)).toString();
  break;
case 'cos':
  obj.data.currentNum = Math.cos(parseFloat(obj.data.currentNum)).toString();
  break;
case 'tan':
  obj.data.currentNum = Math.tan(parseFloat(obj.data.currentNum)).toString();
  break;

      }
    }
    obj.setData({
      screenNum: obj.data.currentNum
    })
  },

})

The following diagram is a flowchart for designing a calculator.

 7.summary

        This project aims to use wechat developer tools and JavaScript to create a visual calculator and implement basic addition, subtraction, multiplication, division and other advanced functions such as trigonometric functions. Through this project, I learned a lot about project implementation and how to design and program on wechat developer tools. The process of making the calculator let me understand the development process of wechat small program, including creating projects, configuring pages, writing logic code and so on. I learned how to use wechat developer tools for project debugging and release. And master the small program page componentized development and the use of common components. I learned to write the page structure through WXML, set the page style through WXSS, and write the page logic through JS. In the course of this project, I encountered various problems, such as abnormal page display, logic errors, etc. By reviewing documentation, searching for solutions, and debugging code, I learned how to quickly locate and resolve problems. This has improved my problem-solving skills.
        In general, by making calculator projects through wechat developer tools, I not only gained practical experience in wechat mini program development, but also improved my programming ability and problem solving ability. These gains will be helpful to my future technology development and project implementation.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值