Front-End and Back-End Separated Calculator

2024-03-07 03:40

本文主要是介绍Front-End and Back-End Separated Calculator,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

  • Introduction
  • 1.Personal Information
  • 2.PSP Table
  • 3.Planning and Executing Stages
    • 3.1 Frontend Design
    • 3.2Frontend codes
    • 3.3 Backend Design
    • 3.4 Backend codes
    • 4.Calculator Display
  • Personal Learnings


Introduction

The significance of this project lies in its practical implications. It enabled the application of knowledge in HTML, CSS, and JavaScript to design an intuitive user interface. Simultaneously, it provided insights into the back-end, involving the creation of an Express.js server to handle calculation requests and responses. The project not only enhanced development skills but also promoted effective communication between the front-end and back-end, highlighting the role of data exchange in web applications.


1.Personal Information

The Link Your Classhttps://bbs.csdn.net/forums/ssynkqtd-04
The Link of Requirement of This Assignmenththttp://t.csdnimg.cn/janAWtps://bbs.csdn.net/topics/617332156
The Aim of This AssignmentFront-End and Back-End Separated Calculator
MU STU ID and FZU STU ID21125554_832101230

2.PSP Table

Personal Software Process StagesEstimated Time(minutes)Actual Time(minutes)
Planning2030
• Estimate2010
Development260240
• Analysis600720
• Design Spec2020
• Design Review1010
• Coding Standard3030
• Design180120
• Coding500520
• Code Review60120
• Test12060
Reporting60100
• Test Repor6020
• Size Measurement6030
• Postmortem & Process Improvement Plan6030
Sum20002030

3.Planning and Executing Stages

3.1 Frontend Design

The front-end code, represented by calculator.html, is responsible for creating the user interface of the visual calculator. It consists of HTML elements such as input fields, buttons, and associated JavaScript functions for user interactions.

  • The <input> element with the id="display" is used to display both the user input and the calculation results.
  • Numeric buttons (e.g., 0-9) and arithmetic operator buttons (+, -, *, /) are presented for user input. These buttons have onclick attributes to trigger JavaScript functions.
  • Special operation buttons for trigonometric functions (sin, cos, tan) and exponentiation (EXP) are available, allowing users to perform advanced calculations.
  • The calculateResult() function is executed when the “=” button is clicked, which computes the result of the expression entered by the user and displays it.
  • The clearDisplay() function clears the input field when the “C” button is clicked.
  • The displayHistory() function retrieves and displays the last ten historical records from the back-end when the “History” button is clicked. The results are shown in the ans field, providing users with a history of previous calculations.

3.2Frontend codes

<!DOCTYPE html>
<html>
<head><title>可视化计算器</title>
</head>
<body><h2>计算器</h2><input id="display" type="text" readonly><br><button onclick="appendToDisplay('7')">7</button><button onclick="appendToDisplay('8')">8</button><button onclick="appendToDisplay('9')">9</button><button onclick="appendToDisplay('+')">+</button><button onclick="appendToDisplay('4')">4</button><button onclick="appendToDisplay('5')">5</button><button onclick="appendToDisplay('6')">6</button><button onclick="appendToDisplay('-')">-</button><button onclick="appendToDisplay('1')">1</button><button onclick="appendToDisplay('2')">2</button><button onclick="appendToDisplay('3')">3</button><button onclick="appendToDisplay('×')">*</button><button onclick="appendToDisplay('0')">0</button><button onclick="appendToDisplay('.')">.</button><button onclick="calculateResult()">=</button><button onclick="clearDisplay()">C</button><button onclick="appendToDisplay('÷')">/</button><button onclick="calculateSin()">sin</button><button onclick="calculateCos()">cos</button><button onclick="calculateTan()">tan</button><button onclick="appendToDisplay('EXP')">EXP</button><br><button onclick="displayHistory()">历史记录</button><input id="ans" type="text" readonly>
</body>
<script>
</script>
</html>

3.3 Backend Design

The back-end code, written in Node.js with Express.js, serves as the server responsible for handling calculation requests and managing historical data.

  • The /calculate route, which handles POST requests, receives mathematical expressions from the front-end. It then uses JavaScript’s eval function to compute the results and stores both the input expression and the result in a history array. If the expression is invalid, it responds with a 400 error to the front-end.
  • The /history route, designed for GET requests, provides the front-end with the ten most recent historical records from the history array.
  • A history array is used to keep track of previously calculated expressions and their results.
  • The server is set to listen on port 3000.

3.4 Backend codes

const express = require('express');
const bodyParser = require('body-parser');
const app = express();app.use(bodyParser.json());const history = [];app.post('/calculate', (req, res) => {const expression = req.body.expression;try {const result = eval(expression);history.push({ expression, result });res.json({ result });} catch (error) {res.status(400).json({ error: "Invalid expression" });}
});app.get('/history', (req, res) => {const lastTen = history.slice(Math.max(history.length - 10, 0));res.json(lastTen);
});app.listen(3000, () => {console.log('3000');
});

4.Calculator Display

https://pic.imgdb.cn/item/65353dbcc458853aef1c3b54.gif
在这里插入图片描述

在这里插入图片描述


Personal Learnings

Finishing this calculator task provided me with valuable front-end and back-end development experience, reinforced my problem-solving skills, familiarized me with the field of web development, and ignited my interest in continued learning and exploration. It was a highly beneficial learning journey that will help me make progress in the software development domain.

这篇关于Front-End and Back-End Separated Calculator的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/782275

相关文章

Flink Back Pressure

什么是 Back Pressure 如果看到任务的背压警告(如 High 级别),这意味着 生成数据的速度比下游算子消费的的速度快。以一个简单的 Source -> Sink 作业为例。如果能看到 Source 有警告,这意味着 Sink 消耗数据的速度比 Source 生成速度慢。Sink 正在向 Source 施加反压。 许多情况都会导致背压。例如,GC导致传入数据堆积,或者数据源在发送数

阅读笔记--Guiding Attention in End-to-End Driving Models

作者:Diego Porres1, Yi Xiao1, Gabriel Villalonga1, Alexandre Levy1, Antonio M. L ́ opez1,2 出版时间:arXiv:2405.00242v1 [cs.CV] 30 Apr 2024 这篇论文研究了如何引导基于视觉的端到端自动驾驶模型的注意力,以提高它们的驾驶质量和获得更直观的激活图。 摘 要   介绍

[C++11#46](三) 详解lambda | 可变参数模板 | emplace_back | 默认的移动构造

目录 一.lambda 1. 捕捉列表 2. 底层原理 二. 可变参数模板 1. 递归函数方式展开参数包 2. 数组接收方式展开参数包 3. 运用 4.emplace_back 5.移动构造和拷贝构造 强制生成 default 一.lambda 可调用类的对象 函数指针--少用 void(*ptr) (int x) 仿函数--构造类 重载 operator() 对象

vector中的push_back()和emplace_back()的区别、以及使用场景

目录 前言 1. 基本区别 2. 性能差异 3. 构造参数传递 4. 使用场景总结 前言 push_back() 更适合在已经有对象实例的情况下使用。emplace_back() 则更适合需要在容器内部直接构造对象的场景,特别是在性能敏感的情况下。 1. 基本区别 push_back(): 作用:将一个已构造的对象或临时对象复制或移动到容器的末尾。使用场景:适合在

Basic Calculator 总结

Basic Calculator 思路:stack中间存数,遇见+,-都当符号位,push num或者-num进去;最后相加;重要的是如何处理括号,那么这里一种方法是用递归调用;count左右括号,如果为0,那么就是一个反括号的位置了,那么 //(      ) //j......i; substring(j + 1, i); 这题的通用解法,可以扩展到二三题; class Solutio

FISCO BCOS Webase front 智能合约 参数不合适

一、字符串得用双引号,不能用单引号 ❌ 'hello world' ['1', '2'] ✅ "hello world" ["1", "2"]   二、引号是否对齐补齐了 ❌ ["1, "2"]

C++ emplace emplace_back是什么 替代 insert

在C++开发过程中,我们经常会用STL的各种容器,比如vector,map,set等,这些容器极大的方便了我们的开发。在使用这些容器的过程中,我们会大量用到的操作就是插入操作,比如vector的push_back,map的insert,set的insert。这些插入操作会涉及到两次构造,首先是对象的初始化构造,接着在插入的时候会复制一次,会触发拷贝构造。但是很多时候我们并不需要两次构造带来效率的

网络编程-echo-back-server-上

echo-back-server 是在学习 TCP/IP 网络编程时惯常使用、实现的一个服务端。它的所要实 现的业务逻辑很简单:服务端在收到客户端发来的数据之后,原样将数据再发回给客户端。这 也是它为什么叫 echo-back-server ( 回声服务器 ) 的原因。 1. 客户端的实现 1.1 说明 echo-back-server 的实现 ( 及其后续的迭代升级 ) 服务端是重点,而客

vector的push_back

push_back是vector的一个方法,表示将一个元素存储到容器的末尾。 具体用法可以参考如下程序段: vector< int > line   // 定义一个容器line(可以简单理解为一个数组,只是数组大小可变)for(int i = 0 ; i < 10 ; i ++)  {  line.push_back(i);  // 将i的值依次存放到容器line的末尾,即对容

Transaction rolled back

出现这个问题的原因是查询跟插入一个事务了,因此在插入事务或者查询事务回滚的时候冲突了。把这两个分开来,查询归查询,插入归插入。