Compare commits
No commits in common. 'main' and 'develop' have entirely different histories.
@ -1,165 +0,0 @@
|
|||||||
#include "ExpressionEvaluator.h"
|
|
||||||
|
|
||||||
void ExpressionEvaluator::skipSpaces() {
|
|
||||||
while (index < expr.size() && isspace(expr[index])) {
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double ExpressionEvaluator::parseNumber() {
|
|
||||||
skipSpaces();
|
|
||||||
size_t start = index;
|
|
||||||
|
|
||||||
// 处理负数
|
|
||||||
if (expr[index] == '-' && (index == 0 || expr[index-1] == '(')) {
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (index < expr.size() && (isdigit(expr[index]) || expr[index] == '.')) {
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string numStr = expr.substr(start, index - start);
|
|
||||||
return stod(numStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
double ExpressionEvaluator::parseFunction() {
|
|
||||||
skipSpaces();
|
|
||||||
std::string funcName;
|
|
||||||
|
|
||||||
// 提取函数名
|
|
||||||
while (index < expr.size() && isalpha(expr[index])) {
|
|
||||||
funcName += expr[index];
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
skipSpaces();
|
|
||||||
if (index >= expr.size() || expr[index] != '(') {
|
|
||||||
throw std::runtime_error("函数后缺少左括号");
|
|
||||||
}
|
|
||||||
index++; // 跳过 '('
|
|
||||||
|
|
||||||
double arg = parseExpression();
|
|
||||||
|
|
||||||
skipSpaces();
|
|
||||||
if (index >= expr.size() || expr[index] != ')') {
|
|
||||||
throw std::runtime_error("函数后缺少右括号");
|
|
||||||
}
|
|
||||||
index++; // 跳过 ')'
|
|
||||||
|
|
||||||
// 计算函数值
|
|
||||||
if (funcName == "sin") {
|
|
||||||
return sin(arg * M_PI / 180.0); // 假设是角度制
|
|
||||||
} else if (funcName == "cos") {
|
|
||||||
return cos(arg * M_PI / 180.0);
|
|
||||||
} else if (funcName == "tan") {
|
|
||||||
return tan(arg * M_PI / 180.0);
|
|
||||||
} else if (funcName == "sqrt") {
|
|
||||||
if (arg < 0) throw std::runtime_error("负数不能开平方");
|
|
||||||
return sqrt(arg);
|
|
||||||
} else {
|
|
||||||
throw std::runtime_error("未知函数: " + funcName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double ExpressionEvaluator::parsePower() {
|
|
||||||
double left = parsePrimary();
|
|
||||||
|
|
||||||
skipSpaces();
|
|
||||||
while (index < expr.size() && expr[index] == '^') {
|
|
||||||
index++;
|
|
||||||
double right = parsePrimary();
|
|
||||||
left = pow(left, right);
|
|
||||||
skipSpaces();
|
|
||||||
}
|
|
||||||
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
double ExpressionEvaluator::parsePrimary() {
|
|
||||||
skipSpaces();
|
|
||||||
if (index >= expr.size()) {
|
|
||||||
throw std::runtime_error("表达式不完整");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (expr[index] == '(') {
|
|
||||||
index++; // 跳过 '('
|
|
||||||
double result = parseExpression();
|
|
||||||
skipSpaces();
|
|
||||||
if (index >= expr.size() || expr[index] != ')') {
|
|
||||||
throw std::runtime_error("缺少右括号");
|
|
||||||
}
|
|
||||||
index++; // 跳过 ')'
|
|
||||||
return result;
|
|
||||||
} else if (isalpha(expr[index])) {
|
|
||||||
return parseFunction();
|
|
||||||
} else if (isdigit(expr[index]) ||
|
|
||||||
(expr[index] == '-' && (index == 0 || expr[index-1] == '('))) {
|
|
||||||
return parseNumber();
|
|
||||||
} else {
|
|
||||||
throw std::runtime_error("无效的表达式");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double ExpressionEvaluator::parseTerm() {
|
|
||||||
double left = parsePower();
|
|
||||||
|
|
||||||
skipSpaces();
|
|
||||||
while (index < expr.size()) {
|
|
||||||
QChar op = expr[index];
|
|
||||||
if (op != '*' && op != '/') break;
|
|
||||||
|
|
||||||
index++;
|
|
||||||
double right = parsePower();
|
|
||||||
|
|
||||||
if (op == '*') {
|
|
||||||
left *= right;
|
|
||||||
} else {
|
|
||||||
if (right == 0) throw std::runtime_error("除零错误");
|
|
||||||
left /= right;
|
|
||||||
}
|
|
||||||
|
|
||||||
skipSpaces();
|
|
||||||
}
|
|
||||||
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
double ExpressionEvaluator::parseExpression() {
|
|
||||||
double left = parseTerm();
|
|
||||||
|
|
||||||
skipSpaces();
|
|
||||||
while (index < expr.size()) {
|
|
||||||
QChar op = expr[index];
|
|
||||||
if (op != '+' && op != '-') break;
|
|
||||||
|
|
||||||
index++;
|
|
||||||
double right = parseTerm();
|
|
||||||
|
|
||||||
if (op == '+') {
|
|
||||||
left += right;
|
|
||||||
} else {
|
|
||||||
left -= right;
|
|
||||||
}
|
|
||||||
|
|
||||||
skipSpaces();
|
|
||||||
}
|
|
||||||
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
double ExpressionEvaluator::evaluate(const std::string& expression) {
|
|
||||||
expr = expression;
|
|
||||||
index = 0;
|
|
||||||
|
|
||||||
double result = parseExpression();
|
|
||||||
|
|
||||||
skipSpaces();
|
|
||||||
if (index < expr.size()) {
|
|
||||||
throw std::runtime_error("表达式包含额外字符");
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,112 +0,0 @@
|
|||||||
#include "UserManager.h"
|
|
||||||
UserManager::UserManager(){
|
|
||||||
currentEmail = "";
|
|
||||||
currentPassword = "";
|
|
||||||
users.clear();
|
|
||||||
std::ifstream ifile("account.txt");
|
|
||||||
std::string line;
|
|
||||||
while(getline(ifile, line))
|
|
||||||
{
|
|
||||||
std::stringstream ss(line);
|
|
||||||
std::string email, password;
|
|
||||||
ss>>email>>password;
|
|
||||||
users.push_back({QString::fromStdString(email),QString::fromStdString(password)});
|
|
||||||
}
|
|
||||||
ifile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
UserManager::~UserManager(){}
|
|
||||||
|
|
||||||
bool UserManager::login(const QString& email, const QString& password){
|
|
||||||
for(const auto& user : users){
|
|
||||||
if(user.email == email && user.password == password)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString UserManager::generateRegistrationCode() {
|
|
||||||
const QString chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
||||||
QString code="";
|
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
code += chars[rand() % chars.length()];
|
|
||||||
}
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UserManager::isEmailRegistered(const QString& email) {
|
|
||||||
for (const auto& user : users) {
|
|
||||||
if (user.email == email) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UserManager::isValidEmail(const QString& email) {
|
|
||||||
std::regex pattern(R"([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})");
|
|
||||||
std::string str = email.toStdString();
|
|
||||||
return regex_match(str, pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UserManager::isValidPassword(const QString& password) {
|
|
||||||
if (password.length() < 6 || password.length() > 10) return false;
|
|
||||||
|
|
||||||
bool hasUpper = false, hasLower = false, hasDigit = false;
|
|
||||||
std::string str = password.toStdString();
|
|
||||||
for (char c : str) {
|
|
||||||
if (isupper(c)) hasUpper = true;
|
|
||||||
if (islower(c)) hasLower = true;
|
|
||||||
if (isdigit(c)) hasDigit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasUpper && hasLower && hasDigit;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UserManager::addNewUser(){
|
|
||||||
User newUser;
|
|
||||||
newUser.email = currentEmail;
|
|
||||||
newUser.password = currentPassword;
|
|
||||||
users.push_back(newUser);
|
|
||||||
std::fstream file("account.txt");
|
|
||||||
file<<currentEmail.toStdString()<<" "<<currentPassword.toStdString()<<std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UserManager::setCurrentPassword(const QString& s) {
|
|
||||||
currentPassword = s;
|
|
||||||
for (auto& u : users) {
|
|
||||||
if(u.email==currentEmail)
|
|
||||||
{
|
|
||||||
u.password=s;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void UserManager::changeCurrentPassword(const QString& s){
|
|
||||||
setCurrentPassword(s);
|
|
||||||
std::ifstream file("account.txt");
|
|
||||||
std::ofstream tfile("temp.txt");
|
|
||||||
std::string line;
|
|
||||||
while(getline(file,line))
|
|
||||||
{
|
|
||||||
std::stringstream ss(line);
|
|
||||||
std::string email, password;
|
|
||||||
ss>>email>>password;
|
|
||||||
tfile<<email<<" ";
|
|
||||||
if(email != s)
|
|
||||||
{
|
|
||||||
tfile<<password;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tfile<<s.toStdString();
|
|
||||||
}
|
|
||||||
tfile<<std::endl;
|
|
||||||
}
|
|
||||||
file.close();
|
|
||||||
tfile.close();
|
|
||||||
remove("account.txt");
|
|
||||||
rename("temp.txt","account.txt");
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,39 +0,0 @@
|
|||||||
#ifndef USERMANAGER_H
|
|
||||||
#define USERMANAGER_H
|
|
||||||
//用户管理
|
|
||||||
#include <QString>
|
|
||||||
#include <QVector>
|
|
||||||
#include <regex>
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
struct User {
|
|
||||||
QString email;
|
|
||||||
QString password;
|
|
||||||
};
|
|
||||||
|
|
||||||
class UserManager{
|
|
||||||
private:
|
|
||||||
QVector<User> users;
|
|
||||||
QString currentEmail, currentPassword;
|
|
||||||
public:
|
|
||||||
UserManager();
|
|
||||||
~UserManager();
|
|
||||||
|
|
||||||
bool login(const QString& email, const QString& password);
|
|
||||||
QString generateRegistrationCode();
|
|
||||||
bool isEmailRegistered(const QString& email);
|
|
||||||
bool isValidEmail(const QString& email);
|
|
||||||
bool isValidPassword(const QString& password);
|
|
||||||
void addNewUser();
|
|
||||||
QString getCurrentEmail() { return currentEmail; }
|
|
||||||
QString getCurrentPassword() { return currentPassword; }
|
|
||||||
void setCurrentEmail(const QString& s){ currentEmail=s; };
|
|
||||||
void setCurrentPassword(const QString& s);
|
|
||||||
void changeCurrentPassword(const QString& s);
|
|
||||||
|
|
||||||
QVector<User> getUsers() { return users; }
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // USERMANAGER_H
|
|
||||||
@ -1 +0,0 @@
|
|||||||
123 123
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
QMAKE_CXX.QT_COMPILER_STDCXX = 201703L
|
|
||||||
QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION = 13
|
|
||||||
QMAKE_CXX.QMAKE_GCC_MINOR_VERSION = 1
|
|
||||||
QMAKE_CXX.QMAKE_GCC_PATCH_VERSION = 0
|
|
||||||
QMAKE_CXX.COMPILER_MACROS = \
|
|
||||||
QT_COMPILER_STDCXX \
|
|
||||||
QMAKE_GCC_MAJOR_VERSION \
|
|
||||||
QMAKE_GCC_MINOR_VERSION \
|
|
||||||
QMAKE_GCC_PATCH_VERSION
|
|
||||||
QMAKE_CXX.INCDIRS = \
|
|
||||||
C:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0/include/c++ \
|
|
||||||
C:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0/include/c++/x86_64-w64-mingw32 \
|
|
||||||
C:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0/include/c++/backward \
|
|
||||||
C:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0/include \
|
|
||||||
C:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0/include-fixed \
|
|
||||||
C:/Qt/Tools/mingw1310_64/x86_64-w64-mingw32/include
|
|
||||||
QMAKE_CXX.LIBDIRS = \
|
|
||||||
C:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0 \
|
|
||||||
C:/Qt/Tools/mingw1310_64/lib/gcc \
|
|
||||||
C:/Qt/Tools/mingw1310_64/x86_64-w64-mingw32/lib \
|
|
||||||
C:/Qt/Tools/mingw1310_64/lib
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue