You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<iostream>
#include<regex>
#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<<"====欢迎使用中小学卷子自动生成系统===="<<std::endl;
while(1){
if(!IsUser){
SystemLogin();
}else{
SystemProductQuestions();
}
}
};
void ExamSystem::SystemLogin(){
std::cout<<"请输入账号 密码登录:";
std::string Input;
getline(std::cin,Input);
Input = tool::EreaseEmpty(Input);
if(Input.empty()){
return ;
}
std::vector<std::string> tokens = tool::split(Input);
if(tokens.size() != 2){
std::cout<<std::endl<<"请输入正确的用户名、密码:";
return ;
}
currentUser = authenticator.authenticate(tokens[0],tokens[1]);
if(currentUser == nullptr){
std::cout<<std::endl<<"请输入正确的用户名、密码:";
return ;
}else{
std::cout<<std::endl<<"准备生成"<<currentUser->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"<<std::endl;
return ;
}
int count = stoi(Input);
if(count < 10||count >30){
std::cout<<"题目数量范围应为10~30"<<std::endl;
return ;
}
ProductQuestion(count);
}
void ExamSystem::handleSwitchType(const std::string& newtype){
std::vector<std::string> Levels = {"小学","初中","高中"};
bool isLevel = false;
for(std::string Level:Levels){
if(Level == newtype){
isLevel = true;
}
}
if(!isLevel){
std::cout<<"请输入小学、初中和高中三个选项中的一个"<<std::endl;
return ;
}
currentUser->UserType = newtype;
std::cout<<"准备生成"<<currentUser->UserType<<"数学题目,请输入生成题目数量:";
}
void ExamSystem::ProductQuestion(int num){
std::cout<<"正在生成"<<num<<""<<currentUser->UserType<<"数学题目请耐心等待ovo"<<std::endl;
std::set<std::string> hadquestion = fileManage.getQuestions(currentUser->UserName);
std::vector<Question> 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<<"试卷已成功生成并保存"<<std::endl;
std::cout<<"成功生成"<<num<<""<<currentUser->UserType<<"数学题目,保存至 "<<filename<<" 文件内"<<std::endl;
}
int main(){
ExamSystem system;
system.systemRun();
return 0;
}