parent
fd58f1afdc
commit
e9dbffa0d1
@ -0,0 +1,3 @@
|
||||
{
|
||||
"CurrentProjectSetting": null
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
{
|
||||
"ExpandedNodes": [
|
||||
""
|
||||
],
|
||||
"PreviewInSolutionExplorer": false
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,41 @@
|
||||
{
|
||||
"Version": 1,
|
||||
"WorkspaceRootPath": "C:\\Users\\27887\\Desktop\\exam\\",
|
||||
"Documents": [
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\Users\\27887\\Desktop\\exam\\main.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||
"RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:main.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||
}
|
||||
],
|
||||
"DocumentGroupContainers": [
|
||||
{
|
||||
"Orientation": 0,
|
||||
"VerticalTabListWidth": 256,
|
||||
"DocumentGroups": [
|
||||
{
|
||||
"DockedWidth": 200,
|
||||
"SelectedChildIndex": 1,
|
||||
"Children": [
|
||||
{
|
||||
"$type": "Bookmark",
|
||||
"Name": "ST:0:0:{34e76e81-ee4a-11d0-ae2e-00a0c90fffc3}"
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 0,
|
||||
"Title": "main.cpp",
|
||||
"DocumentMoniker": "C:\\Users\\27887\\Desktop\\exam\\main.cpp",
|
||||
"RelativeDocumentMoniker": "main.cpp",
|
||||
"ToolTip": "C:\\Users\\27887\\Desktop\\exam\\main.cpp",
|
||||
"RelativeToolTip": "main.cpp",
|
||||
"ViewState": "AgIAAAAAAAAAAAAAAADwvwAAAAATAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||
"WhenOpened": "2025-09-24T15:15:56.502Z",
|
||||
"EditorCaption": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
@ -0,0 +1,18 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "windows-gcc-x64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"compilerPath": "D:/mingw64/bin/gcc.exe",
|
||||
"cStandard": "${default}",
|
||||
"cppStandard": "${default}",
|
||||
"intelliSenseMode": "windows-gcc-x64",
|
||||
"compilerArgs": [
|
||||
""
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": true,
|
||||
"cwd": "c:/Users/27887/Desktop/exam",
|
||||
"program": "c:/Users/27887/Desktop/exam/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
{
|
||||
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||
"C_Cpp_Runner.cStandard": "",
|
||||
"C_Cpp_Runner.cppStandard": "",
|
||||
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
|
||||
"C_Cpp_Runner.useMsvc": false,
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic",
|
||||
"-Wshadow",
|
||||
"-Wformat=2",
|
||||
"-Wcast-align",
|
||||
"-Wconversion",
|
||||
"-Wsign-conversion",
|
||||
"-Wnull-dereference"
|
||||
],
|
||||
"C_Cpp_Runner.msvcWarnings": [
|
||||
"/W4",
|
||||
"/permissive-",
|
||||
"/w14242",
|
||||
"/w14287",
|
||||
"/w14296",
|
||||
"/w14311",
|
||||
"/w14826",
|
||||
"/w44062",
|
||||
"/w44242",
|
||||
"/w14905",
|
||||
"/w14906",
|
||||
"/w14263",
|
||||
"/w44265",
|
||||
"/w14928"
|
||||
],
|
||||
"C_Cpp_Runner.enableWarnings": true,
|
||||
"C_Cpp_Runner.warningsAsError": false,
|
||||
"C_Cpp_Runner.compilerArgs": [],
|
||||
"C_Cpp_Runner.linkerArgs": [],
|
||||
"C_Cpp_Runner.includePaths": [],
|
||||
"C_Cpp_Runner.includeSearch": [
|
||||
"*",
|
||||
"**/*"
|
||||
],
|
||||
"C_Cpp_Runner.excludeSearch": [
|
||||
"**/build",
|
||||
"**/build/**",
|
||||
"**/.*",
|
||||
"**/.*/**",
|
||||
"**/.vscode",
|
||||
"**/.vscode/**"
|
||||
],
|
||||
"C_Cpp_Runner.useAddressSanitizer": false,
|
||||
"C_Cpp_Runner.useUndefinedSanitizer": false,
|
||||
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||
"C_Cpp_Runner.showCompilationTime": false,
|
||||
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||
"C_Cpp_Runner.msvcSecureNoWarnings": false
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
{
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cppbuild",
|
||||
"label": "C/C++: g++.exe 生成活动文件",
|
||||
"command": "D:\\vscode\\mingw64\\bin\\g++.exe",
|
||||
"args": [
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}\\${fileBasenameNoExtension}.exe"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${fileDirname}"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"detail": "调试器生成的任务。"
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
CXX = g++
|
||||
CXXFLAGS = -std=c++17 -Wall -Wextra -I.
|
||||
LDFLAGS = -pthread
|
||||
SOURCES = src/auth_manager.cpp src/question_generator.cpp src/primary_generator.cpp src/junior_generator.cpp src/senior_generator.cpp src/file_manager.cpp src/session_manager.cpp src/main.cpp
|
||||
TARGET = math_exam_generator
|
||||
|
||||
$(TARGET): $(SOURCES)
|
||||
$(CXX) $(CXXFLAGS) $(SOURCES) $(LDFLAGS) -o $(TARGET)
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET)
|
||||
@ -0,0 +1,43 @@
|
||||
#include "auth_manager.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <unordered_map>
|
||||
|
||||
AuthManager::AuthManager() {
|
||||
// 初始化预设的教师账户信息,包括小学、初中、高中各三个账号
|
||||
accounts_ = {
|
||||
{"张三1", {"123", "primary"}},
|
||||
{"张三2", {"123", "primary"}},
|
||||
{"张三3", {"123", "primary"}},
|
||||
{"李四1", {"123", "junior"}},
|
||||
{"李四2", {"123", "junior"}},
|
||||
{"李四3", {"123", "junior"}},
|
||||
{"王五1", {"123", "senior"}},
|
||||
{"王五2", {"123", "senior"}},
|
||||
{"王五3", {"123", "senior"}}
|
||||
};
|
||||
}
|
||||
|
||||
bool AuthManager::Authenticate(const std::string& username,
|
||||
const std::string& password,
|
||||
std::string* user_type) {
|
||||
// 验证输入不包含非法字符
|
||||
if (username.find(' ') != std::string::npos ||
|
||||
password.find(' ') != std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto it = accounts_.find(username);
|
||||
if (it != accounts_.end() && it->second.first == password) {
|
||||
*user_type = it->second.second;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AuthManager::IsValidUser(const std::string& username,
|
||||
const std::string& password) {
|
||||
std::string user_type;
|
||||
return Authenticate(username, password, &user_type);
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
#include "junior_generator.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
std::vector<std::string> JuniorGenerator::GenerateQuestions(int count,
|
||||
const std::string& username) {
|
||||
current_user_ = username;
|
||||
std::vector<std::string> questions;
|
||||
questions.reserve(count);
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
questions.push_back(GenerateSingleQuestion());
|
||||
}
|
||||
|
||||
return questions;
|
||||
}
|
||||
|
||||
std::string JuniorGenerator::GenerateSingleQuestion() {
|
||||
static const std::vector<char> kOperators = {'+', '-', '*', '/'};
|
||||
const int operand_count = GetRandomNumber(kMinOperands, kMaxOperands);
|
||||
|
||||
std::stringstream ss;
|
||||
bool has_special_operator = false;
|
||||
|
||||
// 第一个操作数可以是普通数字或特殊运算符
|
||||
if (operand_count == 1 || GetRandomNumber(0, 1)) {
|
||||
// 单操作数情况或第一个操作数是特殊运算符
|
||||
if (GetRandomNumber(0, 1)) {
|
||||
ss << "sqrt(" << GetRandomNumber(kMinNumber, kMaxNumber) << ")";
|
||||
} else {
|
||||
ss << GetRandomNumber(1, 10) << "^2";
|
||||
}
|
||||
has_special_operator = true;
|
||||
} else {
|
||||
// 第一个操作数是普通数字
|
||||
ss << GetRandomNumber(kMinNumber, kMaxNumber);
|
||||
}
|
||||
|
||||
// 添加后续操作数
|
||||
for (int i = 1; i < operand_count; ++i) {
|
||||
const char op = GetRandomOperator(kOperators);
|
||||
|
||||
// 随机决定是添加普通数字还是特殊运算符
|
||||
if (!has_special_operator || GetRandomNumber(0, 1)) {
|
||||
if (GetRandomNumber(0, 1)) {
|
||||
ss << " " << op << " sqrt(" << GetRandomNumber(kMinNumber, kMaxNumber) << ")";
|
||||
} else {
|
||||
ss << " " << op << " " << GetRandomNumber(1, 10) << "^2";
|
||||
}
|
||||
has_special_operator = true;
|
||||
} else {
|
||||
ss << " " << op << " " << GetRandomNumber(kMinNumber, kMaxNumber);
|
||||
}
|
||||
}
|
||||
|
||||
// 确保至少有一个特殊运算符
|
||||
if (!has_special_operator) {
|
||||
const char op = GetRandomOperator(kOperators);
|
||||
if (GetRandomNumber(0, 1)) {
|
||||
ss << " " << op << " sqrt(" << GetRandomNumber(kMinNumber, kMaxNumber) << ")";
|
||||
} else {
|
||||
ss << " " << op << " " << GetRandomNumber(1, 10) << "^2";
|
||||
}
|
||||
}
|
||||
|
||||
ss << " = ?";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool JuniorGenerator::MeetsDifficultyRequirements(const std::string& question) {
|
||||
// 使用ASCII字符而不是特殊Unicode字符
|
||||
return question.find("^2") != std::string::npos ||
|
||||
question.find("sqrt") != std::string::npos;
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
#ifndef JUNIOR_GENERATOR_H_
|
||||
#define JUNIOR_GENERATOR_H_
|
||||
|
||||
#include "question_generator.h"
|
||||
|
||||
class JuniorGenerator : public QuestionGenerator {
|
||||
public:
|
||||
std::vector<std::string> GenerateQuestions(int count,
|
||||
const std::string& username) override;
|
||||
bool MeetsDifficultyRequirements(const std::string& question) override;
|
||||
|
||||
private:
|
||||
static constexpr int kMinOperands = 1;
|
||||
static constexpr int kMaxOperands = 5;
|
||||
static constexpr int kMinNumber = 1;
|
||||
static constexpr int kMaxNumber = 100;
|
||||
|
||||
std::string GenerateSingleQuestion();
|
||||
};
|
||||
|
||||
#endif // JUNIOR_GENERATOR_H_
|
||||
@ -0,0 +1,25 @@
|
||||
用户名: 李四1 (lisi1)
|
||||
生成时间: 20250928_181147
|
||||
题目数量: 10
|
||||
==============================
|
||||
|
||||
第1题: sqrt(93) / sqrt(46) * 73 - 32 = ?
|
||||
|
||||
第2题: 75 * 9^2 / sqrt(88) / 35 + 2^2 = ?
|
||||
|
||||
第3题: 60 / sqrt(98) + 41 = ?
|
||||
|
||||
第4题: sqrt(31) = ?
|
||||
|
||||
第5题: 8^2 = ?
|
||||
|
||||
第6题: 94 + sqrt(84) / 16 = ?
|
||||
|
||||
第7题: 18 * 4^2 / 70 - 61 / sqrt(15) = ?
|
||||
|
||||
第8题: sqrt(40) / 1^2 - sqrt(34) / 3^2 = ?
|
||||
|
||||
第9题: 1^2 / 86 / 10^2 + 10^2 / 64 = ?
|
||||
|
||||
第10题: sqrt(1) + sqrt(56) / sqrt(66) / 9 = ?
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
用户名: 张三1 (zhangsan1)
|
||||
生成时间: 20250928_181110
|
||||
题目数量: 10
|
||||
==============================
|
||||
|
||||
第1题: 79 + 88 * 67 - 90 = ?
|
||||
|
||||
第2题: 89 - 97 = ?
|
||||
|
||||
第3题: 64 / 50 - 85 + 51 = ?
|
||||
|
||||
第4题: 81 + 40 = ?
|
||||
|
||||
第5题: 98 + 98 - 17 = ?
|
||||
|
||||
第6题: 10 * 27 * 16 / 12 = ?
|
||||
|
||||
第7题: 94 / 28 + 73 + 84 * 80 = ?
|
||||
|
||||
第8题: 64 / 35 + 51 = ?
|
||||
|
||||
第9题: 62 * 49 = ?
|
||||
|
||||
第10题: 46 * 63 / 13 * 75 = ?
|
||||
|
||||
Binary file not shown.
@ -0,0 +1,42 @@
|
||||
#include "primary_generator.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
std::vector<std::string> PrimaryGenerator::GenerateQuestions(int count,
|
||||
const std::string& username) {
|
||||
current_user_ = username;
|
||||
std::vector<std::string> questions;
|
||||
questions.reserve(count); // 预分配空间提高效率
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
questions.push_back(GenerateSingleQuestion());
|
||||
}
|
||||
|
||||
return questions;
|
||||
}
|
||||
|
||||
std::string PrimaryGenerator::GenerateSingleQuestion() {
|
||||
static const std::vector<char> kOperators = {'+', '-', '*', '/'};
|
||||
const int operand_count = GetRandomNumber(kMinOperands, kMaxOperands);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << GetRandomNumber(kMinNumber, kMaxNumber); // 第一个操作数
|
||||
|
||||
for (int i = 1; i < operand_count; ++i) {
|
||||
const char op = GetRandomOperator(kOperators);
|
||||
ss << " " << op << " " << GetRandomNumber(kMinNumber, kMaxNumber);
|
||||
}
|
||||
|
||||
ss << " = ?";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool PrimaryGenerator::MeetsDifficultyRequirements(const std::string& question) {
|
||||
// 小学题目只需要包含基本运算符:+ - * /
|
||||
return question.find('+') != std::string::npos ||
|
||||
question.find('-') != std::string::npos ||
|
||||
question.find('*') != std::string::npos ||
|
||||
question.find('/') != std::string::npos;
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
#ifndef PRIMARY_GENERATOR_H_
|
||||
#define PRIMARY_GENERATOR_H_
|
||||
|
||||
#include "question_generator.h"
|
||||
|
||||
class PrimaryGenerator : public QuestionGenerator {
|
||||
public:
|
||||
std::vector<std::string> GenerateQuestions(int count,
|
||||
const std::string& username) override;
|
||||
bool MeetsDifficultyRequirements(const std::string& question) override;
|
||||
|
||||
private:
|
||||
static constexpr int kMinOperands = 2;
|
||||
static constexpr int kMaxOperands = 5;
|
||||
static constexpr int kMinNumber = 1;
|
||||
static constexpr int kMaxNumber = 100;
|
||||
|
||||
std::string GenerateSingleQuestion();
|
||||
};
|
||||
|
||||
#endif // PRIMARY_GENERATOR_H_
|
||||
@ -0,0 +1,19 @@
|
||||
#include "question_generator.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <random>
|
||||
|
||||
QuestionGenerator::QuestionGenerator() {
|
||||
rng_.seed(std::chrono::steady_clock::now().time_since_epoch().count());
|
||||
}
|
||||
|
||||
int QuestionGenerator::GetRandomNumber(int min, int max) {
|
||||
std::uniform_int_distribution<int> dist(min, max);
|
||||
return dist(rng_);
|
||||
}
|
||||
|
||||
char QuestionGenerator::GetRandomOperator(const std::vector<char>& operators) {
|
||||
if (operators.empty()) return '+';
|
||||
std::uniform_int_distribution<int> dist(0, operators.size() - 1);
|
||||
return operators[dist(rng_)];
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
#ifndef QUESTION_GENERATOR_H_
|
||||
#define QUESTION_GENERATOR_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <random>
|
||||
|
||||
class QuestionGenerator {
|
||||
public:
|
||||
virtual ~QuestionGenerator() = default;
|
||||
|
||||
// 生成指定数量的数学题目
|
||||
virtual std::vector<std::string> GenerateQuestions(int count,
|
||||
const std::string& username) = 0;
|
||||
|
||||
// 检查题目是否符合难度要求
|
||||
virtual bool MeetsDifficultyRequirements(const std::string& question) = 0;
|
||||
|
||||
protected:
|
||||
QuestionGenerator();
|
||||
|
||||
// 生成指定范围内的随机数
|
||||
int GetRandomNumber(int min, int max);
|
||||
|
||||
// 从运算符列表中随机选择一个运算符
|
||||
char GetRandomOperator(const std::vector<char>& operators);
|
||||
|
||||
std::string current_user_;
|
||||
std::mt19937 rng_;
|
||||
|
||||
private:
|
||||
// 禁用拷贝构造和赋值操作
|
||||
QuestionGenerator(const QuestionGenerator&) = delete;
|
||||
QuestionGenerator& operator=(const QuestionGenerator&) = delete;
|
||||
};
|
||||
|
||||
#endif // QUESTION_GENERATOR_H_
|
||||
@ -0,0 +1,72 @@
|
||||
#include "senior_generator.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
std::vector<std::string> SeniorGenerator::GenerateQuestions(int count,
|
||||
const std::string& username) {
|
||||
current_user_ = username;
|
||||
std::vector<std::string> questions;
|
||||
questions.reserve(count);
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
questions.push_back(GenerateSingleQuestion());
|
||||
}
|
||||
|
||||
return questions;
|
||||
}
|
||||
|
||||
std::string SeniorGenerator::GenerateSingleQuestion() {
|
||||
static const std::vector<char> kOperators = {'+', '-', '*', '/'};
|
||||
static const std::vector<std::string> kTrigFunctions = {"sin", "cos", "tan"};
|
||||
const int operand_count = GetRandomNumber(kMinOperands, kMaxOperands);
|
||||
|
||||
std::stringstream ss;
|
||||
bool has_trig_function = false;
|
||||
|
||||
// 第一个操作数可以是普通数字或三角函数
|
||||
if (operand_count == 1 || GetRandomNumber(0, 1)) {
|
||||
// 单操作数情况或第一个操作数是三角函数
|
||||
const int trig_index = GetRandomNumber(0, kTrigFunctions.size() - 1);
|
||||
ss << kTrigFunctions[trig_index] << "("
|
||||
<< GetRandomNumber(kMinNumber, kMaxAngle) << "°)";
|
||||
has_trig_function = true;
|
||||
} else {
|
||||
// 第一个操作数是普通数字
|
||||
ss << GetRandomNumber(kMinNumber, kMaxNumber);
|
||||
}
|
||||
|
||||
// 添加后续操作数
|
||||
for (int i = 1; i < operand_count; ++i) {
|
||||
const char op = GetRandomOperator(kOperators);
|
||||
|
||||
// 随机决定是添加普通数字还是三角函数
|
||||
if (!has_trig_function || GetRandomNumber(0, 1)) {
|
||||
const int trig_index = GetRandomNumber(0, kTrigFunctions.size() - 1);
|
||||
ss << " " << op << " " << kTrigFunctions[trig_index] << "("
|
||||
<< GetRandomNumber(kMinNumber, kMaxAngle) << "°)";
|
||||
has_trig_function = true;
|
||||
} else {
|
||||
ss << " " << op << " " << GetRandomNumber(kMinNumber, kMaxNumber);
|
||||
}
|
||||
}
|
||||
|
||||
// 确保至少有一个三角函数
|
||||
if (!has_trig_function) {
|
||||
const char op = GetRandomOperator(kOperators);
|
||||
const int trig_index = GetRandomNumber(0, kTrigFunctions.size() - 1);
|
||||
ss << " " << op << " " << kTrigFunctions[trig_index] << "("
|
||||
<< GetRandomNumber(kMinNumber, kMaxAngle) << "°)";
|
||||
}
|
||||
|
||||
ss << " = ?";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool SeniorGenerator::MeetsDifficultyRequirements(const std::string& question) {
|
||||
// 高中题目至少包含一个三角函数
|
||||
return question.find("sin") != std::string::npos ||
|
||||
question.find("cos") != std::string::npos ||
|
||||
question.find("tan") != std::string::npos;
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
#ifndef SENIOR_GENERATOR_H_
|
||||
#define SENIOR_GENERATOR_H_
|
||||
|
||||
#include "question_generator.h"
|
||||
|
||||
class SeniorGenerator : public QuestionGenerator {
|
||||
public:
|
||||
std::vector<std::string> GenerateQuestions(int count,
|
||||
const std::string& username) override;
|
||||
bool MeetsDifficultyRequirements(const std::string& question) override;
|
||||
|
||||
private:
|
||||
static constexpr int kMinOperands = 1;
|
||||
static constexpr int kMaxOperands = 5;
|
||||
static constexpr int kMinNumber = 1;
|
||||
static constexpr int kMaxNumber = 100;
|
||||
static constexpr int kMaxAngle = 90;
|
||||
|
||||
std::string GenerateSingleQuestion();
|
||||
};
|
||||
|
||||
#endif // SENIOR_GENERATOR_H_
|
||||
@ -0,0 +1,40 @@
|
||||
#include "session_manager.h"
|
||||
|
||||
SessionManager::SessionManager()
|
||||
: current_user_(""),
|
||||
current_difficulty_(""),
|
||||
current_generator_(nullptr) {}
|
||||
|
||||
void SessionManager::SetUser(const std::string& username,
|
||||
const std::string& difficulty) {
|
||||
current_user_ = username;
|
||||
SwitchDifficulty(difficulty);
|
||||
}
|
||||
|
||||
bool SessionManager::SwitchDifficulty(const std::string& difficulty) {
|
||||
if (difficulty == "primary") {
|
||||
current_generator_ = &primary_generator_;
|
||||
current_difficulty_ = "小学";
|
||||
} else if (difficulty == "junior") {
|
||||
current_generator_ = &junior_generator_;
|
||||
current_difficulty_ = "初中";
|
||||
} else if (difficulty == "senior") {
|
||||
current_generator_ = &senior_generator_;
|
||||
current_difficulty_ = "高中";
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QuestionGenerator* SessionManager::GetCurrentGenerator() {
|
||||
return current_generator_;
|
||||
}
|
||||
|
||||
std::string SessionManager::GetCurrentDifficulty() const {
|
||||
return current_difficulty_;
|
||||
}
|
||||
|
||||
std::string SessionManager::GetCurrentUser() const {
|
||||
return current_user_;
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
#ifndef SESSION_MANAGER_H_
|
||||
#define SESSION_MANAGER_H_
|
||||
|
||||
#include <string>
|
||||
#include "question_generator.h"
|
||||
#include "primary_generator.h"
|
||||
#include "junior_generator.h"
|
||||
#include "senior_generator.h"
|
||||
|
||||
class SessionManager {
|
||||
public:
|
||||
SessionManager();
|
||||
|
||||
// 设置当前用户和难度
|
||||
void SetUser(const std::string& username, const std::string& difficulty);
|
||||
|
||||
// 切换难度级别
|
||||
bool SwitchDifficulty(const std::string& difficulty);
|
||||
|
||||
// 获取当前题目生成器
|
||||
QuestionGenerator* GetCurrentGenerator();
|
||||
|
||||
// 获取当前难度描述
|
||||
std::string GetCurrentDifficulty() const;
|
||||
|
||||
// 获取当前用户名
|
||||
std::string GetCurrentUser() const;
|
||||
|
||||
private:
|
||||
std::string current_user_;
|
||||
std::string current_difficulty_;
|
||||
QuestionGenerator* current_generator_;
|
||||
|
||||
PrimaryGenerator primary_generator_;
|
||||
JuniorGenerator junior_generator_;
|
||||
SeniorGenerator senior_generator_;
|
||||
|
||||
// 禁用拷贝构造和赋值操作
|
||||
SessionManager(const SessionManager&) = delete;
|
||||
SessionManager& operator=(const SessionManager&) = delete;
|
||||
};
|
||||
|
||||
#endif // SESSION_MANAGER_H_
|
||||
Loading…
Reference in new issue