Computer practice of front and back end separation

1.introduction of the assignment

In this task, we need to improve the previous calculator, including adding the residual function and the way to view the history of the calculation, we use python for the back end, html for the front end

github here is the code of front-end and back end

2.1assignment table

cause for this assignmethttps://bbs.csdn.net/forums/ssynkqtd-04
Assignment Requirements https://bbs.csdn.net/topics/617378696
Objectives of This AssignmentAdded new algorithms and history
MU STU ID and FZU STU ID21124353(MU)832101320(FZU)

2.2PSP table

Personal Software Process StagesEstimated Time(minutes)Actual Time(minutes)
Planning
• Estimate2015
Development
• Analysis4030
• Design Spec2020
• Design Review1515
• Coding Standard2020
• Design1515
• Coding10090
• Code Review2010
• Test1010
Reporting
• Test Repor130120
• Size Measurement55
• Postmortem & Process Improvement Plan1515
Sum410365

3.Problem-solving ideas

In this assignment, we need to consider how to separate the front-end and back-end code, add the remainder operation to the quadratic operation, how to build and connect the database, and how to pass the history, which mainly involves the back end.
For front-end and back-end code separation, we need to use python and html methods to pass the arithmetic process of the calculator by using data in the front-end and back-end. Finally, the front end receives the information and the back end processes it and feeds it back to the front end, and saves the history to the database

For the data processing method, we need to process the input i.e. the calculation, and then display the result as the output.

Finally, calculators should have different functions to calculate data, such as addition, subtraction, multiplication, division, and taking the remainder and have history database.

4 code of the assignment

4.1Front-end code

This part deals with the frame and keys of the calculator。

<!DOCTYPE html>
<html>
<head>
    <title>Calculator</title>
    <style>
        .button {
            width: 50px;
            height: 50px;
            font-size: 20px;
        }
    </style>
    <script src="calculator.js"></script>
</head>
<body>
    <h1>Calculator</h1>
    <input type="text" id="result" disabled><br> <!-- 结果显示框,禁用输入 -->
    <table>
        <tr>
            <td><button class="button" onclick="appendValue(7)">7</button></td>
            <td><button class="button" onclick="appendValue(8)">8</button></td>
            <td><button class="button" onclick="appendValue(9)">9</button></td>
            <td><button class="button" onclick="appendValue('+')">+</button></td>
        </tr>
        <tr>
            <td><button class="button" onclick="appendValue(4)">4</button></td>
            <td><button class="button" onclick="appendValue(5)">5</button></td>
            <td><button class="button" onclick="appendValue(6)">6</button></td>
            <td><button class="button" onclick="appendValue('-')">-</button></td>
        </tr>
        <tr>
            <td><button class="button" onclick="appendValue(1)">1</button></td>
            <td><button class="button" onclick="appendValue(2)">2</button></td>
            <td><button class="button" onclick="appendValue(3)">3</button></td>
            <td><button class="button" onclick="appendValue('*')">*</button></td>
        </tr>
        <tr>
            <td><button class="button" onclick="appendValue(0)">0</button></td>
            <td><button class="button" onclick="appendValue('.')">.</button></td>
            <td><button class="button" onclick="appendValue('%')">%</button></td> <!-- 求余数运算符按钮 -->
            <td><button class="button" onclick="appendValue('/')">/</button></td>
        </tr>
        <tr>
            <td colspan="4"><button class="button" onclick="clearResult()">C</button></td> <!-- 清除按钮,占据4-->
        </tr>
        <tr>
            <td colspan="4"><button class="button" onclick="calculate()">=</button></td> <!-- 等号按钮,占据4-->
        </tr>
    </table>

    <h2>History</h2>
    <ul id="history"></ul> <!-- 历史记录列表 -->

    <script>
        // JavaScript代码
        // ...
    </script>
</body>
</html>

4.2Back-end code

interface plane :calculator.html
from flask import Flask, render_template, request

app = Flask(__name__)

history = []  # 存储历史记录的列表

@app.route('/')
def index():
    return render_template('calculator.html')

@app.route('/calculate', methods=['POST'])
def calculate():
    expression = request.form['expression']
    try:
        result = eval(expression)  # 使用eval函数计算表达式的结果
        history.append(f'{expression} = {result}')  # 将表达式和结果添加到历史记录
        if len(history) > 10:  # 保持历史记录最多10条
            history.pop(0)
        return {'result': result}
    except Exception as e:
        return {'error': str(e)}

@app.route('/history')
def get_history():
    return {'history': history}

if __name__ == '__main__':
    app.run(debug=True)

5. flow chart

请添加图片描述

6.display of the result

在这里插入图片描述

Summary

In this assignment,It is really much more difficult than the last experiment, which is not just visualization, but the separation of the front and back ends. Some students may use the database to store historical records, so the difficulty is much more complicated than the calculation results last time. Therefore, I learned a lot of knowledge in this task, including front-end construction and back-end editing, and interactive interaction between the two, so as to complete this task

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值