Software Engineering Project --WebCalculator

Project introduction

Creating a web calculator involves several steps, including designing the user interface, implementing calculation logic, and processing user input.This is a software engineering project. Here is some information about the project.

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 AssignmentCreate a calculator with a visual interface
MU STU ID and FZU STU ID21126909_832102210

In addition to this, I also uploaded my own code on GitHub, here is the link : https://github.com/westflog/calculator.git

Work Procedure

PSP

Personal Software Process StagesEstimated Time(minutes)Actual Time(minutes)
Planning3040
• Estimate3040
Development550550
• Analysis4030
• Design Specification5030
• Design Review2010
• Coding Standard1520
• Design180140
• Coding200240
• Code Review3020
• Test1510
Reporting150110
• Test Report6060
• Size Measurement3020
• Postmortem & Process Improvement Plan6030
Sum730700

Problem-solving ideas

When I got to know the project, I knew I had to learn something about visualization and some of the code that made up the calculator.So I learn and use Hyper Text Markup Language (HTML), Cascading Style Sheets (CSS), Java Script (JS) to bulid the calculator.In addition, I also need to look up relevant knowledge on the Internet to complete this task.Finally, our calculator can be presented in a web page.

Code

Since there are three different languages, I’ll show them in three pieces of code.
HTML PART:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div class="con clear">
        <input type="text" id="input" value="0" disabled>
         <div class="divs" id="div1">7</div>
        <div class="divs" id="div2">8</div>
        <div class="divs" id="div3">9</div>
        <div class="divs" id="div4">-</div>
        <div class="divs" id="div5">4</div>
        <div class="divs" id="div6">5</div>
        <div class="divs" id="div7">6</div>
        <div class="divs" id="div8">+</div>
        <div class="divs" id="div9">1</div>
        <div class="divs" id="div10">2</div>
        <div class="divs" id="div11">3</div>
        <div class="divs" id="div12">*</div>
        <div class="divs" id="div13">C</div>
        <div class="divs" id="div14">0</div>
        <div class="divs" id="div15">=</div>
        <div class="divs" id="div16">/</div>
    </div>
</body>
</html>

CSS PART:

<style>
    .con {
        border: 1px solid #000000;
        width: 500px;
        height: 600px;
        text-align: center;
        position: relative;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        margin: auto;
    }

   .con>div {
            width: 100px;
            height: 100px;
            border: 1px solid #000000;
            box-shadow: 2px 2px 2px #CCCCCC;
            float: left;
            margin: 11px;
            text-align: center;
            font-size: 40px;
            line-height: 100px;
            user-select: none;
        }
 
        .con>input {
            width: 90%;
            height: 30px;
            line-height: 30px;
            font-size: 25px;
            text-align: right;
            margin-top: 20px;
            margin-bottom: 20px;
            box-shadow: 3px 3px 3px #CCCCCC;
            outline: none;
            padding: 5px 10px;
            background-color: white;
            border: 1px solid #000000;
        }
 

    .clear::after {
        content: "";
        clear: both;
        display: block;
        height: 0;
        visibility: hidden;
        overflow: hidden;
    }

    .clear {
        zoom: 1;
    }
</style>

JAVA PART:

<script>
    var input = document.getElementById("input");
    var current = "", first = "", type = "";

    for (var i = 1; i < 17; i++) {
        var div = document.getElementById("div" + i);
        div.onclick = function () {
            if (isNaN(this.innerHTML)) {
                switch (this.innerHTML) {
                    case "+":
                        type = "+";
                        first = current;
                        current = "";
                        break;
                    case "-":
                        type = "-";
                        first = current;
                        current = "";
                        break;
                    case "*":
                        type = "*";
                        first = current;
                        current = "";
                        break;
                    case "/":
                        type = "/";
                        first = current;
                        current = "";
                        break;
                    case "=":
                        if (type === "+") input.value = Number(first) + Number(current);
                        if (type === "-") input.value = first - current;
                        if (type === "*") input.value = first * current;
                        if (type === "/") input.value = first / current;
                        first = "";
                        current = "";
                        type = "";
                        break;
                    case "C":
                        input.value = "0";
                        break;
                }
            } else {
                current += this.innerHTML;
                input.value = Number(current) + "";
            }
        }
    }
</script>

A general explanation of the code

HTML section:
div class=“con clear” : This is a container div that contains the layout of the entire calculator, using the.con and.clear classes.
input type=“text” id=“input” value=“0” disabled : This is an input box used to display user input and calculation results. It is set to disabled to prevent user manual input.
Numeric buttons and operator buttons: Through a series of div elements with the class name.divs, each with a unique id, used for event handling in JavaScript.

CSS section:
Style definition: CSS is used to define the style of an element, including appearance, size, shading, and so on.

JavaScript section:
Event handling: JavaScript is used to handle button click events. Each number and operator button has a corresponding event handler that executes the corresponding logic based on the user’s click.
Computational logic: Depending on user input, computational logic includes the processing of addition, subtraction, multiplication, and division, as well as empty and equal logic.

FLowchart

Calculation process:

Created with Raphaël 2.3.0 input Input Input symbol and number Get the result yes

Results display

Results display


As we can see from the video demonstration, our calculator can perform simple addition, subtraction, multiplication and division operations.

Summary

The goal of this project is to implement a simple version of the web calculator, it needs to implement the visualization and related functions of the calculator, it uses HTML, CSS and javascript to build and beautify the web page,HTML is responsible for the network structure, CSS is responsible for the layout and beautification,JS is responsible for the behavior of the web page, programming In the course, I learned how to build and perfect my own web front end. In documenting my own code base using Github and writing my own blog documenting the development process using CSDN, I learned how to fully prepare, design, summarize, and review my own projects.But in addition, I am also constantly finding things that can be improved, such as there may be an error in the code, namely input.value=“0”; It should be placed outside the switch statement to ensure that the empty operation is not overwritten. You can move it outside of the switch statement, like this:

switch (this.innerHTML) {
    // ...
    case "=":
        // ...
        break;
    case "C":
        input.value = "0";
        break;
}

I am still improving my project, so through this project, I will also be more strict with myself in daily tasks

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值