Course for This Assignment | MU - SE2301 |
---|---|
Assignment Requirements | https://bbs.csdn.net/topics/617378696 |
Objectives of This Assignment | Added new algorithms and history |
MU STU ID and FZU STU ID | 21126232 832102108 |
GitHub Code |
Personal Software Process Stages | Estimated Time(minutes) | Actual Time(minutes) |
---|---|---|
Planning | 50 | 50 |
• Estimate | 50 | 50 |
Development | 400 | 420 |
• Analysis | 50 | 50 |
• Design Spec | 40 | 30 |
• Design Review | 35 | 40 |
• Coding Standard | 35 | 40 |
• Design | 70 | 90 |
• Coding | 180 | 180 |
• Code Review | 90 | 70 |
• Test | 80 | 80 |
Reporting | 55 | 65 |
• Test Repor | 10 | 10 |
• Size Measurement | 15 | 15 |
• Postmortem & Process Improvement Plan | 30 | 40 |
Sum | 505 | 535 |
-
Introduction
This is a Front and rear end separated calculator -
Frontend
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
<style>
input[type="text"], input[type="button"] {
width: 50px;
height: 50px;
font-size: 18px;
}
</style>
</head>
<body>
<table>
<tr>
<td><input type="text" id="display" readonly></td>
</tr>
<tr>
<td><input type="button" value="1" onclick="appendToDisplay('1')"></td>
<td><input type="button" value="2" onclick="appendToDisplay('2')"></td>
<td><input type="button" value="3" onclick="appendToDisplay('3')"></td>
<td><input type="button" value="+" onclick="appendToDisplay('+')"></td>
</tr>
<tr>
<td><input type="button" value="4" onclick="appendToDisplay('4')"></td>
<td><input type="button" value="5" onclick="appendToDisplay('5')"></td>
<td><input type="button" value="6" onclick="appendToDisplay('6')"></td>
<td><input type="button" value="-" onclick="appendToDisplay('-')"></td>
</tr>
<tr>
<td><input type="button" value="7" onclick="appendToDisplay('7')"></td>
<td><input type="button" value="8" onclick="appendToDisplay('8')"></td>
<td><input type="button" value="9" onclick="appendToDisplay('9')"></td>
<td><input type="button" value="*" onclick="appendToDisplay('*')"></td>
</tr>
<tr>
<td><input type="button" value="0" onclick="appendToDisplay('0')"></td>
<td><input type="button" value="." onclick="appendToDisplay('.')"></td>
<td><input type="button" value="=" onclick="calculate()"></td>
<td><input type="button" value="/" onclick="appendToDisplay('/')"></td>
</tr>
<tr>
<td><input type="button" value="ans" onclick="appendToDisplay(getAns())"></td>
</tr>
</table>
<script>
function appendToDisplay(value) {
document.getElementById('display').value += value;
}
function calculate() {
try {
document.getElementById('display').value = eval(document.getElementById('display').value);
} catch (error) {
document.getElementById('display').value = 'Error';
}
}
function getAns() {
return document.getElementById('display').value;
}
</script>
</body>
</html>
- Backend
from flask import Flask, request, jsonify
app = Flask(__name)
history = []
@app.route('/add', methods=['POST'])
def add():
data = request.get_json()
result = data['num1'] + data['num2']
history.append(f"{data['num1']} + {data['num2']} = {result}")
return jsonify({"result": result})
@app.route('/subtract', methods=['POST'])
def subtract():
data = request.get_json()
result = data['num1'] - data['num2']
history.append(f"{data['num1']} - {data['num2']} = {result}")
return jsonify({"result": result})
@app.route('/multiply', methods=['POST'])
def multiply():
data = request.get_json()
result = data['num1'] * data['num2']
history.append(f"{data['num1']} * {data['num2']} = {result}")
return jsonify({"result": result})
@app.route('/divide', methods=['POST'])
def divide():
data = request.get_json()
if data['num2'] == 0:
return jsonify({"error": "Division by zero"})
result = data['num1'] / data['num2']
history.append(f"{data['num1']} / {data['num2']} = {result}")
return jsonify({"result": result})
@app.route('/history', methods=['GET'])
def get_history():
return jsonify({"history": history[-10:]})
if __name__ == '__main__':
app.run()
-
Display
-
Summary
This assignment improve the ability of coding in both frontend and backend.