From f8d04452444991802473b0f28df644b132e5e085 Mon Sep 17 00:00:00 2001 From: hnu202326010401 <2263510185@qq.com> Date: Tue, 30 Sep 2025 15:41:40 +0800 Subject: [PATCH 01/11] ADD file via upload --- src/account.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/account.cpp diff --git a/src/account.cpp b/src/account.cpp new file mode 100644 index 0000000..b1ee00b --- /dev/null +++ b/src/account.cpp @@ -0,0 +1,24 @@ +#include"account.h" + +Authenticator::Authenticator(){ + users = { + User("张三1","123","小学"), + User("张三2","123","小学"), + User("张三3","123","小学"), + User("李四1","123","初中"), + User("李四2","123","初中"), + User("李四3","123","初中"), + User("王五1","123","高中"), + User("王五2","123","高中"), + User("王五3","123","高中"), + }; +} + +User* Authenticator::authenticate(const std::string& username,const std::string& password){ + for(User& user : users){ + if(user.UserName == username&&user.Password == password){ + return &user; + } + } + return nullptr; +} \ No newline at end of file -- 2.34.1 From f27aeb2bf9d33243841b05c8bf8c08031b352c45 Mon Sep 17 00:00:00 2001 From: hnu202326010401 <2263510185@qq.com> Date: Tue, 30 Sep 2025 15:42:27 +0800 Subject: [PATCH 02/11] ADD file via upload --- src/account.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/account.h diff --git a/src/account.h b/src/account.h new file mode 100644 index 0000000..586bfe6 --- /dev/null +++ b/src/account.h @@ -0,0 +1,15 @@ +#ifndef ACCOUNT_H +#define ACCOUNT_H + +#include"case.h" +#include + +class Authenticator{ + private: + std::vector users; + public: + User* authenticate(const std::string& username,const std::string& password); + Authenticator(); +}; + +#endif \ No newline at end of file -- 2.34.1 From a5801b7808860eda217ae934dd4d382872632093 Mon Sep 17 00:00:00 2001 From: hnu202326010401 <2263510185@qq.com> Date: Tue, 30 Sep 2025 15:42:49 +0800 Subject: [PATCH 03/11] ADD file via upload --- src/case.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/case.h diff --git a/src/case.h b/src/case.h new file mode 100644 index 0000000..6ee5bcb --- /dev/null +++ b/src/case.h @@ -0,0 +1,25 @@ +#ifndef CASE_H +#define CASE_H + +#include + +class User{ +public: + std::string UserName; + std::string Password; + std::string UserType; + + User(const std::string& uname,const std::string& pwd,const std::string& type) + :UserName(uname),Password(pwd),UserType(type){} +}; + +class Question{ +public: + int id; + std::string content; + + Question(int ID,const std::string& cont) + :id(ID),content(cont){} +}; + +#endif \ No newline at end of file -- 2.34.1 From d099adf73f2308b3221d3edfee14c2b10461482f Mon Sep 17 00:00:00 2001 From: hnu202326010401 <2263510185@qq.com> Date: Tue, 30 Sep 2025 15:42:59 +0800 Subject: [PATCH 04/11] ADD file via upload --- src/filemanage.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/filemanage.cpp diff --git a/src/filemanage.cpp b/src/filemanage.cpp new file mode 100644 index 0000000..5cc7ed2 --- /dev/null +++ b/src/filemanage.cpp @@ -0,0 +1,67 @@ +#include"filemanage.h" +#include"tool.h" +#include +#include +#include +#include + +Filemanage::Filemanage(const std::string&dir):baseDir(dir){ + createDir(baseDir); +} + +void Filemanage::createDir(const std::string& path){ + _mkdir(path.c_str()); +} + +std::string Filemanage::getUserFolder(const std::string& username){ + std::string userFolder = baseDir + "/" + username; + createDir(userFolder); + return userFolder; +} + +std::string Filemanage::saveQuestions(const std::string& username,const std::vector questions){ + std::string userFolder = getUserFolder(username); + std::string filename = tool::getCurrentTime() + ".txt"; + std::string filepath = userFolder + "/" + filename; + + std::ofstream userpath(filepath); + if(!userpath.is_open()){ + std::cout<<"无法创建文件"< Filemanage::getQuestions(const std::string&username){ + std::setproductedQuestion; + std::string userFolder = getUserFolder(username); + DIR* dirstream = opendir(userFolder.c_str()); + struct dirent* dir; + while((dir = readdir(dirstream)) != NULL){ + std::string filename = dir->d_name; + if(filename.length() > 4&&filename.substr(filename.length() - 4) == ".txt"){ + std::string filepath = userFolder + "/" + filename; + std::ifstream userpath; + userpath.open(filepath); + if(userpath.is_open()){ + std::string OneQuestion; + while(getline(userpath,OneQuestion)){ + OneQuestion = tool::EreaseEmpty(OneQuestion); + if(!OneQuestion.empty()&&OneQuestion.find('.') != std::string::npos){ + int dotnum = OneQuestion.find('.'); + OneQuestion = OneQuestion.substr(dotnum + 1,OneQuestion.size() - dotnum - 1); + productedQuestion.insert(OneQuestion); + } + } + } + userpath.close(); + } + } + closedir(dirstream); + return productedQuestion; +} -- 2.34.1 From bdcb6e4415f26124c96ef739161f7bbcda9e39bb Mon Sep 17 00:00:00 2001 From: hnu202326010401 <2263510185@qq.com> Date: Tue, 30 Sep 2025 15:43:11 +0800 Subject: [PATCH 05/11] ADD file via upload --- src/filemanage.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/filemanage.h diff --git a/src/filemanage.h b/src/filemanage.h new file mode 100644 index 0000000..935acc9 --- /dev/null +++ b/src/filemanage.h @@ -0,0 +1,20 @@ +#ifndef FILEMANAGE_H +#define FILEMANAGE_H + +#include"case.h" +#include +#include +#include + +class Filemanage{ +private: + std::string baseDir; + std::string getUserFolder(const std::string& username); + void createDir(const std::string& path); +public: + Filemanage(const std::string& dir = "examquestions"); + std::setgetQuestions(const std::string&username); + std::string saveQuestions(const std::string& username,const std::vector questions); +}; + +#endif \ No newline at end of file -- 2.34.1 From b845619019132ba04c895e24488f07a978c401a3 Mon Sep 17 00:00:00 2001 From: hnu202326010401 <2263510185@qq.com> Date: Tue, 30 Sep 2025 15:43:25 +0800 Subject: [PATCH 06/11] ADD file via upload --- src/main.cpp | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 src/main.cpp diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..b52d390 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,133 @@ +#include +#include +#include"account.h" +#include"case.h" +#include"filemanage.h" +#include"question_product.h" +#include"tool.h" + +class ExamSystem{ +private: + Authenticator authenticator; + Filemanage fileManage; + QuestionProduction questionProduction; + User* currentUser; + bool IsUser = false; + void SystemLogin(); + void SystemProductQuestions(); + void handleSwitchType(const std::string& newtype); + void ProductQuestion(int num); +public: + void systemRun(); +}; + +void ExamSystem::systemRun(){ + std::cout<<"====欢迎使用中小学卷子自动生成系统===="< tokens = tool::split(Input); + if(tokens.size() != 2){ + std::cout<UserType<<"数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):"; + IsUser = true; + } +} + +void ExamSystem::SystemProductQuestions(){ + std::string Input; + getline(std::cin,Input); + if(Input == "-1"){ + currentUser = nullptr; + IsUser = false; + return ; + } + + std::regex switchPattern("切换为(\\S+)"); + std::smatch match; + + if(std::regex_match(Input,match,switchPattern)){ + std::string newType = match[1].str(); + handleSwitchType(newType); + return ; + } + + if(!tool::isNumber(Input)){ + std::cout<<"请输入有效的数字(10~30)"<30){ + std::cout<<"题目数量范围应为10~30"< Levels = {"小学","初中","高中"}; + bool isLevel = false; + + for(std::string Level:Levels){ + if(Level == newtype){ + isLevel = true; + } + } + + if(!isLevel){ + std::cout<<"请输入小学、初中和高中三个选项中的一个"<UserType = newtype; + std::cout<<"准备生成"<UserType<<"数学题目,请输入生成题目数量:"; +} + +void ExamSystem::ProductQuestion(int num){ + std::cout<<"正在生成"<UserType<<"数学题目,请耐心等待ovo"< hadquestion = fileManage.getQuestions(currentUser->UserName); + std::vector newquestions; + int id = 1; + while(id <= num){ + Question tempQuestion = questionProduction.questionProduction(id,currentUser->UserType); + int QuestionNum = hadquestion.size(); + hadquestion.insert(tempQuestion.content); + if(QuestionNum != hadquestion.size()){ + newquestions.push_back(tempQuestion); + id++; + } + } + std::string filename = fileManage.saveQuestions(currentUser->UserName,newquestions); + std::cout<<"试卷已成功生成并保存"<UserType<<"数学题目,保存至 "< Date: Tue, 30 Sep 2025 15:43:39 +0800 Subject: [PATCH 07/11] ADD file via upload --- src/question_product.cpp | 115 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/question_product.cpp diff --git a/src/question_product.cpp b/src/question_product.cpp new file mode 100644 index 0000000..392ed9f --- /dev/null +++ b/src/question_product.cpp @@ -0,0 +1,115 @@ +#include"question_product.h" +#include +#include + +int QuestionProduction::randnum(int min,int max){ + int num = (rand()%(max - min + 1)) + min; + return num; +} + +Question QuestionProduction::questionProduction(int questionId,const std::string& usertype){ + int operationnum = randnum(1,5); + std::vector operations; + + for(int i = 0;i < operationnum;i++){ + operations.push_back(randnum(1,100)); + } + + if(usertype == "小学"){ + return primaryProduction(questionId,operations); + }else if(usertype == "初中"){ + return juniorProduction(questionId,operations); + }else if(usertype == "高中"){ + return seniorProduction(questionId,operations); + } +} + + +Question QuestionProduction::primaryProduction(int questionId,const std::vector&operation){ + if(operation.size() == 1){ + std::string expression = std::to_string(operation[0]); + return Question(questionId,expression); + } + + std::string expression = std::to_string(operation[0]); + + for(int i = 1;i < operation.size();i++){ + std::string op = primaryWay[randnum(0,primaryWay.size() - 1)]; + bool ifbracket = randnum(0,1); + if(ifbracket){ + expression = "(" + expression + " " + op + " " + std::to_string(operation[i]) + ")"; + }else{ + expression = expression + " " + op + " " + std::to_string(operation[i]); + } + } + + return Question(questionId,expression); +} + +Question QuestionProduction::juniorProduction(int questionId,const std::vector&operation){ + std::string expression = std::to_string(operation[0]); + bool ifSpecialop = false; + + for(int i = 1;i < operation.size();i++){ + if(randnum(0,1) == 1){ + if(randnum(0,1) == 1){ + expression = "√" + expression; + }else{ + expression = "(" + expression + ")?"; + } + ifSpecialop = true; + } + std::string op = primaryWay[randnum(0,primaryWay.size() - 1)]; + bool ifbracket = randnum(0,1); + if(ifbracket){ + expression = "(" + expression + " " + op + " " + std::to_string(operation[i]) + ")"; + }else{ + expression = expression + " " + op + " " + std::to_string(operation[i]); + } + } + + if(!ifSpecialop){ + if(randnum(0,1) == 1){ + expression = "√" + expression; + }else{ + expression = "(" + expression + ")?"; + } + } + + return Question(questionId,expression); +} + +Question QuestionProduction::seniorProduction(int questionId,const std::vector&operation){ + std::string expression = std::to_string(operation[0]); + bool ifTrigonometric = false; + + for(int i = 1;i < operation.size();i++){ + if(randnum(0,1)){ + std::vectortrigFuns = {"sin","cos","tan"}; + std::string trigFun = trigFuns[randnum(0,2)]; + expression = trigFun + "(" + expression + ")"; + ifTrigonometric = true; + }else if(randnum(0,2) == 0){ + if(randnum(0,1) == 1){ + expression = "√" + expression; + }else{ + expression = "(" + expression + ")?"; + } + } + std::string op = primaryWay[randnum(0,primaryWay.size() - 1)]; + bool ifbracket = randnum(0,1); + if(ifbracket){ + expression = "(" + expression + " " + op + " " + std::to_string(operation[i]) + ")"; + }else{ + expression = expression + " " + op + " " + std::to_string(operation[i]); + } + } + + if(!ifTrigonometric){ + std::vectortrigFuns = {"sin","cos","tan"}; + std::string trigFun = trigFuns[randnum(0,2)]; + expression = trigFun + "(" + expression + ")"; + } + + return Question(questionId,expression); +} -- 2.34.1 From f8e40c1151d1ab57a5ea2a2c52bec96636dfde2f Mon Sep 17 00:00:00 2001 From: hnu202326010401 <2263510185@qq.com> Date: Tue, 30 Sep 2025 15:44:51 +0800 Subject: [PATCH 08/11] ADD file via upload --- src/question_product.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/question_product.h diff --git a/src/question_product.h b/src/question_product.h new file mode 100644 index 0000000..0b8aed3 --- /dev/null +++ b/src/question_product.h @@ -0,0 +1,23 @@ +#ifndef QUESTION_PRODUCT_H +#define QUESTION_PRODUCT_H + +#include"case.h" +#include +#include + +class QuestionProduction{ + private: + std::vectorprimaryWay = {"+","-","*","/"}; + std::vectorjuniorWay = {"+","-","*","/","虏","鈭"}; + std::vectorseniorWay = {"+","-","*","/","虏","鈭","sin","cos","tan"}; + + Question primaryProduction(int questionId,const std::vector&operation); + Question juniorProduction(int questionId,const std::vector&operation); + Question seniorProduction(int questionId,const std::vector&operation); + public: + Question questionProduction(int questionId,const std::string& usertype); + int randnum(int min,int max); +}; + + +#endif \ No newline at end of file -- 2.34.1 From 8c5f749e2d9ff22e615bf34517612b01d0017482 Mon Sep 17 00:00:00 2001 From: hnu202326010401 <2263510185@qq.com> Date: Tue, 30 Sep 2025 15:45:00 +0800 Subject: [PATCH 09/11] ADD file via upload --- src/tool.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/tool.cpp diff --git a/src/tool.cpp b/src/tool.cpp new file mode 100644 index 0000000..2659168 --- /dev/null +++ b/src/tool.cpp @@ -0,0 +1,58 @@ +#include"tool.h" +#include +#include + + +std::vectortool::split(const std::string& str){ + std::istringstream iss(str); + std::vector tokens; + std::string token; + std::istringstream tokenStream(str); + + while(std::getline(tokenStream,token,' ')){ + tokens.push_back(token); + } + + return tokens; +} + +bool tool::isNumber(const std::string& str){ + if(str.empty()){ + return false; + } + + int start = 0; + if(str[0] == '-'){ + if(str.size() == 1){ + return false; + } + start = 1; + } + + for(int i = start;i < str.size();i++){ + if(!isdigit(str[i])){ + return false; + } + } + + return true; +} + +std::string tool::getCurrentTime(){ + time_t now = time(0); + tm* ltm = localtime(&now); + char buffer[80]; + strftime(buffer,80,"%Y-%m-%d-%H-%M-%S",ltm); + std::string nowTime = buffer; + return nowTime; +} + +std::string tool::EreaseEmpty(const std::string& question){ + int start = question.find_first_not_of("\t\n\r"); + int end = question.find_last_not_of("\t\n\r"); + if(start == std::string::npos||end == std::string::npos){ + return ""; + } + + return question.substr(start,end - start + 1); +} \ No newline at end of file -- 2.34.1 From 8078392b38d8084d8894e697ad5f853b499fa379 Mon Sep 17 00:00:00 2001 From: hnu202326010401 <2263510185@qq.com> Date: Tue, 30 Sep 2025 15:45:09 +0800 Subject: [PATCH 10/11] ADD file via upload --- src/tool.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/tool.h diff --git a/src/tool.h b/src/tool.h new file mode 100644 index 0000000..9555959 --- /dev/null +++ b/src/tool.h @@ -0,0 +1,17 @@ +#ifndef TOOL_H +#define TOOL_H + +#include +#include + +namespace tool{ + std::vectorsplit(const std::string& str); + + bool isNumber(const std::string& str); + + std::string getCurrentTime(); + + std::string EreaseEmpty(const std::string& question); +} + +#endif \ No newline at end of file -- 2.34.1 From a7c45bde3f83d45f55ba4d6f585d90a78638663e Mon Sep 17 00:00:00 2001 From: hnu202326010401 <2263510185@qq.com> Date: Tue, 30 Sep 2025 15:52:20 +0800 Subject: [PATCH 11/11] ADD file via upload --- doc/璇存槑鏂囨。.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 doc/璇存槑鏂囨。.md diff --git a/doc/璇存槑鏂囨。.md b/doc/璇存槑鏂囨。.md new file mode 100644 index 0000000..abd88c6 --- /dev/null +++ b/doc/璇存槑鏂囨。.md @@ -0,0 +1,3 @@ +windows骞冲彴 +鏃犲弬鏁拌缃 +缂栫爜GBK \ No newline at end of file -- 2.34.1