第二次作业

发布时间 2023-12-05 18:39:32作者: 傻乎辉

第二次作业

一、实验目的

 

1.掌握软件开发的基本流程

 

2.掌握常用的软件开发方式和工具。

 

二、实验内容

1.设计一个包含登录界面的计算器软件,该软件可以实现第一次作业中的全部功能,同时可以保存用户的历史计算记录(保存数据最好使用数据库)。

 

三、实验要求

 

1.完成软件的UI设计、使用Visio设计软件中所涉及的所有流程图。

2.选择合适的集成开发环境和工具完成计算器软件的开发

3.将开发好软件进行测试并截图

4.将本次实验过程写成实验报告提交在本次作业的链接中

5.关键代码部分以代码块格式粘贴在实验报告正文中

6.软件架构以及开发技术不限

四、实验过程

1:ui前端登录界面流程图

 

2:前端实现代码

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录页面</title>
  <style>
        body {
            margin: 0;
            padding: 0;
            background-image: url('1.jpg');
            background-size: cover;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            color: white;
        }

        h1 {
            font-size: 2em;
        }

        form {
            display: flex;
            flex-direction: column;
            align-items: center;
            background: rgba(0, 0, 0, 0.5);
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
        }

        label {
            margin-bottom: 10px;
        }

        input {
            padding: 8px;
            margin-bottom: 15px;
            border: 1px solid white;
            border-radius: 5px;
        }

        button {
            padding: 10px;
            
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        button:hover {
            background-color: #45a049;
        }

        #errorMessage {
            color: red;
            display: none;
        }

        #successMessage {
            color: green;
            display: none;
        }

        #registerButton {
            position: absolute;
            bottom: 10px;
            left: 10px;
            padding: 10px;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        #registerButton:hover {
            background-color: #2980b9;
        }
    </style>
</head>
<body>

<h1>登录页面</h1>

<form id="loginForm">
  <label for="username">用户名:</label>
  <input type="text" id="username" name="username" required>

  <label for="password">密码:</label>
  <input type="password" id="password" name="password" required>

  <button type="button" onclick="validateLogin()">登录</button>

  <p id="errorMessage">用户名或密码错误,登录失败</p >
  <p id="successMessage">登录成功!</p >
</form>

<button id="registerButton" onclick="register()">注册</button>

<script>
        function validateLogin() {
            var username = document.getElementById('username').value;
            var password = document.getElementById('password').value;

            if (username === '李亚骏' && password === '123') {
                document.getElementById('errorMessage').style.display = 'none';
                document.getElementById('successMessage').style.display = 'block';
            } else {
                document.getElementById('errorMessage').style.display = 'block';
                document.getElementById('successMessage').style.display = 'none';
            }
        }

        function register() {
            alert('注册按钮被点击');
        }
    </script>

</body>
</html>

 

3:登录界面(登录测试)

 

 

 

 

 

 

3:计算器实现流程图

 

4:计算器实现代码

(第一次作业)

5:历史记录保存类实现

定义一个类CalculatorHistory保存历史记录

 

import sqlite3

 

class CalculatorHistory:

def __init__(self, db_name):

self.db_name = db_name

self.conn = sqlite3.connect(db_name)

self.cursor = self.conn.cursor()

self.cursor.execute('''CREATE TABLE IF NOT EXISTS history

(id INTEGER PRIMARY KEY AUTOINCREMENT,

expression TEXT,

result TEXT)''')

 

def add_expression(self, expression, result):

self.cursor.execute("INSERT INTO history (expression, result) VALUES (?, ?)",

(expression, result))

self.conn.commit()

 

def get_history(self):

self.cursor.execute("SELECT * FROM history")

return self.cursor.fetchall()

 

def __del__(self):

self.conn.close()

 

6:计算器运行图