176
社区成员
发帖
与我相关
我的任务
分享| The Link Your Class | https://bbs.csdn.net/forums/ssynkqtd-04 |
|---|---|
| The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/617378696 |
| The Aim of This Assignment | The front and back end design of the calculator |
| MU STU ID and FZU STU ID | 832101101_21126585 |
Github:GIT
The result is obtained by directly evaluating the string using the eval() function.
Java Script
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JAVA-CAL-1</title>
<script type="text/javascript">
var str;
var str1;
var result=0;
var isequal = false;
var issign = false;
function get_sign(){
issign = true;
}
function Delete_sign(){
if(issign){
Press_Delete();
}
}
function C()
{
str = document.getElementById("numId");
str.value = "";
}
function Press_Delete(){
str = document.getElementById("numId");
var length=str.value.length;
str.value = str.value.substr(0,length-1);
}
function check_equal(){
if(isequal){
C();
isequal = false;
}
}
function Press_Sign(sign)
{
check_equal();
str = document.getElementById("numId");
Delete_sign();
if(str.value == ""){
str.value = str.value + "0";
}
str.value = str.value + sign;
get_sign();
}
function Press_Num(num)
{
check_equal();
issign=false;
str = document.getElementById("numId");
str.value = str.value + num;
}
function Ans(){
str.value = str.value + result;
}
function Press_Result()
{
isequal = true;
Delete_sign();
str=document.getElementById("numId");
str.value = str.value.replace( /log/g , 'Math.log');
str.value = str.value.replace( /e/g , 'Math.E');
try{
result = eval(str.value);
str.value = result;
}catch{
str.value="error";
}

Fore and aft ends
let calculation = str.innerText;
const data = {
calculation: calculation,
value: value
};
xhr.send(JSON.stringify(data));
const xhr = new XMLHttpRequest();
xhr.open('POST', 'http://127.0.0.1:9000/post', true);
xhr.setRequestHeader('Content-type', 'application/json');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
const response = xhr.responseText;
console.log(response);
} else {
console.error( xhr.status);
}
}
};
function His(){
const xhr = new XMLHttpRequest();
xhr.open('GET', 'http://127.0.0.1:9000/get', true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
Data = JSON.parse(xhr.responseText);
array = Data["data"];
console.log(array);
HIS.innerText = "";
for (i = 0; i < array.length; i++) {
HIS.innerText += array[i] + '\n';
}
}
}}};
from flask import Flask, request, jsonify
from flask_cors import CORS
import pymysql
import datetime
app = Flask(__name__)
CORS(app)
db = pymysql.connect(
host="localhost",
user="root",
password="194066089",
database="mysql"
)
@app.route('/post', methods=['POST'])
def hello_world():
try:
data = request.get_json()
expression = data.get('calculation')
result = data.get('value')
print(str(calculation) + "=" + str(value))
cursor = db.cursor()
sql = "INSERT INTO calculations (calculation, value) VALUES (%s, %s)"
values = (calculation, value)
cursor.execute(sql, values)
db.commit()
cursor.close()
except Exception as e:
print("Error:", e)
@app.route('/get', methods=['GET'])
def get_calculation_data():
try:
cursor = db.cursor()
sql = "SELECT expression, result FROM calculations ORDER BY id DESC LIMIT 10"
cursor.execute(sql)
data = cursor.fetchall()
cursor.close()
history_data = [{"calculation": item[0], "value": item[1]} for item in data]
return jsonify({"data": history_data})
except Exception as e:
print("Error:", e)
if __name__ == '__main__':
app.run(host='localhost', port=9000)
The .replace() function replaces the original computation notation with the Math language.
Example:
str.value = str.value.replace( /log/g , 'Math.log');
str.value = str.value.replace( /e/g , 'Math.E');

```
Other special computation symbols can be designed in the same way. Some special arithmetic rules may require some custom functions. The back-end design still needs to be learned.
| Personal Software Process Stages | Estimated Time(minutes) | Actual Time(minutes) |
|---|---|---|
| Planning | 10 | 10 |
| • Estimate | 10 | 10 |
| Development | 10 | 10 |
| • Analysis | 5 | 5 |
| • Design Spec | 20 | 20 |
| • Design Review | 5 | 5 |
| • Coding Standard | 50 | 60 |
| • Design | 30 | 30 |
| • Coding | 100 | 300 |
| • Code Review | 60 | 100 |
| • Test | 20 | 40 |
| Reporting | 60 | 60 |
| • Test Repor | 40 | 40 |
| • Size Measurement | 5 | 5 |
| • Postmortem & Process Improvement Plan | 10 | 10 |
| Sum | 435 | 705 |
I think this mission is unfriendly to people who aren't familiar with front and back end design. Self-learning takes a lot of time, and part of the environment configuration makes some of the frameworks difficult to use. But I did learn something.