Calculator

Information table

Link of Class https://bbs.csdn.net/forums/ssynkqtd-04
Link of Requirement of This Assignmenthttps://bbs.csdn.net/topics/617332156
Aim of This AssignmentImplement web version calculator
MU STU ID and FZU STU ID  21126232_832102108

link of github: BillyKulu/web-calculator (github.com)

PSP Form

Personal Software Process StagesEstimated Time (minutes)Actual Time (minutes)
Planning (Total)400600
Estimate and Preparation400600
Development (Total)320390
Analysis3040
Design Spec1020
Design Review1030
Coding Standard1010
Design7040
Coding100150
Code Review6070
Test3030
Reporting (Total)120100
Test Report00
Size Measurement00
Postmortem & Process Improvement Plan120100
Sum8401090

 

Problem-Solving:

We need to implement basic calculator functions. These include addition, subtraction, multiplication, division, and clearing the display. Then implement more complex functions such as exponentiation, trigonometric functions, and more. Finally Implement an event-driven system to handle user input.   Create a main application window with a display. Add buttons for digits, basic operations, implement functions to handle button clicks, then display.

Design and implementation process

We will create a simple GUI using tkinter. Organize the code into functions for each calculator operation. Implement an event-driven system to handle user input.
Implementation:Create a main application window with a display. Add buttons for digits, basic operations. Implement functions to handle button clicks. Display the results in the GUI.

Code:

<!DOCTYPE html>
<html>
<head>
    <title>Simple Web Calculator</title>
    <style>
        body {
            text-align: center;
        }
        .calculator {
            width: 300px;
            margin: 0 auto;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            box-shadow: 0px 0px 5px 0px #aaa;
        }
        input[type="text"] {
            width: 100%;
            margin-bottom: 10px;
            padding: 5px;
            font-size: 18px;
        }
        button {
            width: 50px;
            height: 50px;
            font-size: 18px;
            margin: 5px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <h2>Simple Web Calculator</h2>
    <div class="calculator">
        <input type="text" id="display" readonly>
        <br>
        <button onclick="appendToDisplay('1')">1</button>
        <button onclick="appendToDisplay('2')">2</button>
        <button onclick="appendToDisplay('3')">3</button>
        <button onclick="appendToDisplay('+')">+</button>
        <br>
        <button onclick="appendToDisplay('4')">4</button>
        <button onclick="appendToDisplay('5')">5</button>
        <button onclick="appendToDisplay('6')">6</button>
        <button onclick="appendToDisplay('-')">-</button>
        <br>
        <button onclick="appendToDisplay('7')">7</button>
        <button onclick="appendToDisplay('8')">8</button>
        <button onclick="appendToDisplay('9')">9</button>
        <button onclick="appendToDisplay('*')">*</button>
        <br>
        <button onclick="appendToDisplay('0')">0</button>
        <button onclick="clearDisplay()">C</button>
        <button onclick="calculate()">=</button>
        <button onclick="appendToDisplay('/')">/</button>
    </div>

    <script>
        function appendToDisplay(value) {
            document.getElementById("display").value += value;
        }

        function clearDisplay() {
            document.getElementById("display").value = "";
        }

        function calculate() {
            try {
                const result = eval(document.getElementById("display").value);
                document.getElementById("display").value = result;
            } catch (error) {
                document.getElementById("display").value = "Error";
            }
        }
    </script>
</body>
</html>

Result function:

Summary:

In this blog post, we've outlined the steps to create a calculator with a visual interface.   We started by defining our project's requirements and specifications, discussed problem-solving ideas, and presented the code implementation for basic functionality.  

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值