diff --git a/README.md b/README.md deleted file mode 100644 index ee97a14..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# MathsQuestionSystem - diff --git a/src/Application.cpp b/src/Application.cpp new file mode 100644 index 0000000..9334123 --- /dev/null +++ b/src/Application.cpp @@ -0,0 +1,177 @@ +#include "Application.h" +#include "UserManager.h" +#include "QuestionGenerator.h" +#include "FileManager.h" +#include +#include +#include + +Application::Application() + : user_manager_(NULL), + question_generator_(NULL), + file_manager_(NULL), + question_checker_(NULL), + session_manager_(NULL) { + InitializeComponents(); +} + +Application::~Application() { + Cleanup(); +} + +void Application::InitializeComponents() { + user_manager_ = new UserManager(); + question_generator_ = new QuestionGenerator(); + file_manager_ = new FileManager(); + question_checker_ = new QuestionChecker(file_manager_); + session_manager_ = new SessionManager(user_manager_, + question_generator_, + question_checker_); +} + +int Application::Run() { + DisplayWelcome(); + + while (true) { + if (!session_manager_->IsLoggedIn()) { + HandleLogin(); + continue; + } + + DisplayCurrentStatus(); + DisplayMainMenu(); + + std::string choice; + std::cin >> choice; + + HandleUserChoice(choice); + } + + return 0; +} + +void Application::DisplayWelcome() const { + std::cout << "ÖÐСѧÊýѧ¾í×Ó×Ô¶¯Éú³É³ÌÐò" << std::endl; + std::cout << "=================================" << std::endl; +} + +void Application::HandleLogin() { + std::string username, password; + std::cout << "ÇëÊäÈëÓû§ÃûºÍÃÜÂ루Óÿոñ¸ô¿ª£©: "; + std::cin >> username >> password; + + if (session_manager_->Login(username, password)) { + UserType current_type = session_manager_->GetCurrentUserType(); + std::cout << "µÇ¼³É¹¦£¡µ±Ç°Ñ¡ÔñΪ" << current_type.GetName() << "³öÌâ" << std::endl; + } else { + std::cout << "ÇëÊäÈëÕýÈ·µÄÓû§Ãû¡¢ÃÜÂë" << std::endl; + } +} + +void Application::DisplayMainMenu() const { + std::cout << "\nÇëÑ¡Ôñ²Ù×÷:" << std::endl; + std::cout << "1. Éú³ÉÌâÄ¿" << std::endl; + std::cout << "2. Çл»ÀàÐÍ" << std::endl; + std::cout << "3. Í˳ö³ÌÐò" << std::endl; + std::cout << "-1. Í˳öµ±Ç°Óû§" << std::endl; + std::cout << "ÇëÊäÈëÑ¡Ôñ: "; +} + +void Application::DisplayCurrentStatus() const { + std::cout << "\nµ±Ç°Óû§: " << session_manager_->GetCurrentUsername() << std::endl; + std::cout << "µ±Ç°ÀàÐÍ: " << session_manager_->GetCurrentUserType().GetName() << std::endl; + std::cout << "ÒÑÉú³ÉÌâÄ¿: " << question_checker_->GetUserQuestionCount( + session_manager_->GetCurrentUsername()) << "µÀ" << std::endl; +} + +void Application::HandleGenerateQuestions() { + std::cout << "×¼±¸Éú³É" << session_manager_->GetCurrentUserType().GetName() + << "ÊýѧÌâÄ¿£¬ÇëÊäÈëÉú³ÉÌâÄ¿ÊýÁ¿£¨10-30£©: "; + std::string input; + std::cin >> input; + + if (!IsNumber(input)) { + std::cout << "ÇëÊäÈëÓÐЧµÄÊý×Ö" << std::endl; + return; + } + + int count = StringToInt(input); + if (count < 10 || count > 30) { + std::cout << "ÌâÄ¿ÊýÁ¿Ó¦ÔÚ10µ½30Ö®¼ä" << std::endl; + return; + } + + std::vector questions = session_manager_->GenerateQuestions(count); + + if (file_manager_->SaveQuestions(questions, session_manager_->GetCurrentUsername(), + session_manager_->GetCurrentUserType())) { + std::cout << "³É¹¦Éú³É" << questions.size() << "µÀ²»Öظ´µÄ" + << session_manager_->GetCurrentUserType().GetName() << "ÊýѧÌâÄ¿£¡" << std::endl; + + if (questions.size() < count) { + std::cout << "×¢Ò⣺ÓÉÓÚÌâÄ¿ÖØ¸´£¬Êµ¼ÊÉú³É" << questions.size() + << "µÀÌâÄ¿£¨ÒªÇó" << count << "µÀ£©" << std::endl; + } + } +} + +void Application::HandleSwitchType() { + std::cout << "ÇëÊäÈëÒªÇл»µÄÀàÐÍ£¨Ð¡Ñ§/³õÖÐ/¸ßÖУ©: "; + std::string target_type; + std::cin >> target_type; + session_manager_->SwitchUserType(target_type); +} + +void Application::HandleUserChoice(const std::string& choice) { + if (choice == "1") { + HandleGenerateQuestions(); + } else if (choice == "2") { + HandleSwitchType(); + } else if (choice == "-1") { + session_manager_->Logout(); + std::cout << "ÒÑÍ˳öµ±Ç°Óû§" << std::endl; + } else if (choice == "3") { + std::cout << "¸ÐлʹÓã¬ÔÙ¼û£¡" << std::endl; + std::exit(0); + } else { + std::cout << "ÎÞЧѡÔñ£¬ÇëÖØÐÂÊäÈë" << std::endl; + } +} + +void Application::Cleanup() { + delete session_manager_; + delete question_checker_; + delete file_manager_; + delete question_generator_; + delete user_manager_; +} + +bool Application::IsNumber(const std::string& str) const { + if (str.empty()) return false; + for (size_t i = 0; i < str.length(); ++i) { + char c = str[i]; + if (!std::isdigit(c) && !(i == 0 && c == '-')) { + return false; + } + } + return true; +} + +int Application::StringToInt(const std::string& str) const { + int result = 0; + int sign = 1; + size_t start = 0; + + if (str[0] == '-') { + sign = -1; + start = 1; + } + + for (size_t i = start; i < str.length(); ++i) { + if (str[i] >= '0' && str[i] <= '9') { + result = result * 10 + (str[i] - '0'); + } + } + + return result * sign; +} diff --git a/src/Application.h b/src/Application.h new file mode 100644 index 0000000..b0792c4 --- /dev/null +++ b/src/Application.h @@ -0,0 +1,39 @@ +#ifndef PROJECT_APPLICATION_H_ +#define PROJECT_APPLICATION_H_ + +#include "IUserManager.h" +#include "IQuestionGenerator.h" +#include "IFileManager.h" +#include "QuestionChecker.h" +#include "SessionManager.h" +#include + +class Application { + public: + Application(); + ~Application(); + + int Run(); + + private: + void InitializeComponents(); + void DisplayWelcome() const; + void HandleLogin(); + void DisplayMainMenu() const; + void DisplayCurrentStatus() const; + void HandleGenerateQuestions(); + void HandleSwitchType(); + void HandleUserChoice(const std::string& choice); + void Cleanup(); + + bool IsNumber(const std::string& str) const; + int StringToInt(const std::string& str) const; + + IUserManager* user_manager_; + IQuestionGenerator* question_generator_; + IFileManager* file_manager_; + QuestionChecker* question_checker_; + SessionManager* session_manager_; +}; + +#endif // PROJECT_APPLICATION_H_ diff --git a/src/Application.o b/src/Application.o new file mode 100644 index 0000000..7f417c0 Binary files /dev/null and b/src/Application.o differ diff --git a/src/FileManager.cpp b/src/FileManager.cpp index 83b23b9..bee1d7d 100644 --- a/src/FileManager.cpp +++ b/src/FileManager.cpp @@ -5,41 +5,42 @@ #include #include -using namespace std; - FileManager::FileManager() {} -bool FileManager::saveQuestions(const vector& questions, const string& username, const UserType& type) { - string filename = username + "_" + getCurrentTimestamp() + ".txt"; - - ofstream file(filename.c_str()); - if (!file.is_open()) { - cout << "ÎÞ·¨´´½¨Îļþ: " << filename << endl; - return false; - } - - for (size_t i = 0; i < questions.size(); i++) { - file << (i + 1) << ". " << questions[i] << endl; - if (i < questions.size() - 1) { - file << endl; - } +bool FileManager::SaveQuestions(const std::vector& questions, + const std::string& username, + const UserType& type) { + std::string filename = username + "_" + GetCurrentTimestamp() + ".txt"; + + std::ofstream file(filename.c_str()); + if (!file.is_open()) { + std::cout << "´´½¨Îļþʧ°Ü: " << filename << std::endl; + return false; + } + + for (size_t i = 0; i < questions.size(); ++i) { + file << (i + 1) << ". " << questions[i] << std::endl; + if (i < questions.size() - 1) { + file << std::endl; } - - file.close(); - cout << "ÌâÄ¿Òѱ£´æµ½: " << filename << endl; - return true; + } + + file.close(); + std::cout << "ÌâÄ¿±£´æÖÁ: " << filename << std::endl; + return true; } -vector FileManager::loadExistingQuestions(const string& username) { - return vector(); +std::vector FileManager::LoadExistingQuestions(const std::string& username) { + // TODO: ʵÏÖÀúÊ·ÌâÄ¿¼ÓÔØ + return std::vector(); } -string FileManager::getCurrentTimestamp() const { - time_t now = time(NULL); - struct tm* tstruct = localtime(&now); - - char buf[80]; - strftime(buf, sizeof(buf), "%Y-%m-%d-%H-%M-%S", tstruct); - - return string(buf); +std::string FileManager::GetCurrentTimestamp() const { + std::time_t now = std::time(NULL); + struct std::tm* tstruct = std::localtime(&now); + + char buf[80]; + std::strftime(buf, sizeof(buf), "%Y-%m-%d-%H-%M-%S", tstruct); + + return std::string(buf); } diff --git a/src/FileManager.h b/src/FileManager.h index 88ef391..47ac199 100644 --- a/src/FileManager.h +++ b/src/FileManager.h @@ -1,20 +1,24 @@ -#ifndef FILEMANAGER_H -#define FILEMANAGER_H +#ifndef PROJECT_FILEMANAGER_H_ +#define PROJECT_FILEMANAGER_H_ #include "IFileManager.h" #include #include class FileManager : public IFileManager { -public: - FileManager(); - virtual ~FileManager() {} - - virtual bool saveQuestions(const std::vector& questions, const std::string& username, const UserType& type); - virtual std::vector loadExistingQuestions(const std::string& username); + public: + FileManager(); + virtual ~FileManager() {} + + virtual bool SaveQuestions(const std::vector& questions, + const std::string& username, + const UserType& type); + + virtual std::vector LoadExistingQuestions( + const std::string& username); -private: - std::string getCurrentTimestamp() const; + private: + std::string GetCurrentTimestamp() const; }; -#endif +#endif diff --git a/src/FileManager.o b/src/FileManager.o index 736ef58..9297ed1 100644 Binary files a/src/FileManager.o and b/src/FileManager.o differ diff --git a/src/IFileManager.h b/src/IFileManager.h index 17f11d5..68fa95c 100644 --- a/src/IFileManager.h +++ b/src/IFileManager.h @@ -1,15 +1,20 @@ -#ifndef IFILEMANAGER_H -#define IFILEMANAGER_H +#ifndef PROJECT_IFILEMANAGER_H_ +#define PROJECT_IFILEMANAGER_H_ #include #include #include "UserType.h" class IFileManager { -public: - virtual ~IFileManager() {} - virtual bool saveQuestions(const std::vector& questions, const std::string& username, const UserType& type) = 0; - virtual std::vector loadExistingQuestions(const std::string& username) = 0; + public: + virtual ~IFileManager() {} + + virtual bool SaveQuestions(const std::vector& questions, + const std::string& username, + const UserType& type) = 0; + + virtual std::vector LoadExistingQuestions( + const std::string& username) = 0; }; -#endif +#endif diff --git a/src/IQuestionGenerator.h b/src/IQuestionGenerator.h index 92b674d..7d0441b 100644 --- a/src/IQuestionGenerator.h +++ b/src/IQuestionGenerator.h @@ -1,15 +1,19 @@ -#ifndef IQUESTIONGENERATOR_H -#define IQUESTIONGENERATOR_H +#ifndef PROJECT_IQUESTIONGENERATOR_H_ +#define PROJECT_IQUESTIONGENERATOR_H_ #include #include #include "UserType.h" class IQuestionGenerator { -public: - virtual ~IQuestionGenerator() {} - virtual std::vector generateQuestions(const UserType& type, int count, const std::string& username) = 0; - virtual void addExistingQuestions(const std::vector& questions) = 0; + public: + virtual ~IQuestionGenerator() {} + + virtual std::vector GenerateQuestions(const UserType& type, + int count, + const std::string& username) = 0; + + virtual void AddExistingQuestions(const std::vector& questions) = 0; }; -#endif +#endif diff --git a/src/IUserManager.h b/src/IUserManager.h index 1bb8450..8602ac5 100644 --- a/src/IUserManager.h +++ b/src/IUserManager.h @@ -1,18 +1,20 @@ -#ifndef IUSERMANAGER_H -#define IUSERMANAGER_H +#ifndef PROJECT_IUSERMANAGER_H_ +#define PROJECT_IUSERMANAGER_H_ #include #include "UserType.h" class IUserManager { -public: - virtual ~IUserManager() {} - - virtual bool authenticate(const std::string& username, const std::string& password) = 0; - virtual UserType getCurrentUserType() const = 0; - virtual std::string getCurrentUsername() const = 0; - virtual void logout() = 0; - virtual bool isLoggedIn() const = 0; + public: + virtual ~IUserManager() {} + + virtual bool Authenticate(const std::string& username, + const std::string& password) = 0; + + virtual UserType GetCurrentUserType() const = 0; + virtual std::string GetCurrentUsername() const = 0; + virtual void Logout() = 0; + virtual bool IsLoggedIn() const = 0; }; -#endif +#endif diff --git a/src/Makefile.win b/src/Makefile.win index 8ed1faa..8ce81cd 100644 --- a/src/Makefile.win +++ b/src/Makefile.win @@ -4,8 +4,8 @@ CPP = g++.exe CC = gcc.exe WINDRES = windres.exe -OBJ = QuestionGenerator.o UserManager.o User.o UserType.o FileManager.o main.o QuestionChecker.o SessionManager.o -LINKOBJ = QuestionGenerator.o UserManager.o User.o UserType.o FileManager.o main.o QuestionChecker.o SessionManager.o +OBJ = QuestionGenerator.o UserManager.o User.o UserType.o FileManager.o main.o QuestionChecker.o SessionManager.o Application.o +LINKOBJ = QuestionGenerator.o UserManager.o User.o UserType.o FileManager.o main.o QuestionChecker.o SessionManager.o Application.o LIBS = -L"D:/³ÌÐòÉè¼Æ/Dev-Cpp/MinGW64/lib" -L"D:/³ÌÐòÉè¼Æ/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -static-libgcc INCS = -I"D:/³ÌÐòÉè¼Æ/Dev-Cpp/MinGW64/include" -I"D:/³ÌÐòÉè¼Æ/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"D:/³ÌÐòÉè¼Æ/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" CXXINCS = -I"D:/³ÌÐòÉè¼Æ/Dev-Cpp/MinGW64/include" -I"D:/³ÌÐòÉè¼Æ/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"D:/³ÌÐòÉè¼Æ/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"D:/³ÌÐòÉè¼Æ/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++" @@ -47,3 +47,6 @@ QuestionChecker.o: QuestionChecker.cpp SessionManager.o: SessionManager.cpp $(CPP) -c SessionManager.cpp -o SessionManager.o $(CXXFLAGS) + +Application.o: Application.cpp + $(CPP) -c Application.cpp -o Application.o $(CXXFLAGS) diff --git a/src/QuestionChecker.cpp b/src/QuestionChecker.cpp index f79c414..bc2bb76 100644 --- a/src/QuestionChecker.cpp +++ b/src/QuestionChecker.cpp @@ -4,31 +4,34 @@ QuestionChecker::QuestionChecker(IFileManager* file_manager) : file_manager_(file_manager) {} -bool QuestionChecker::isDuplicate(const std::string& question, const std::string& username) { - // ¼ì²é±¾´Î»á»°ÊÇ·ñÖØ¸´ - if (current_session_questions_.find(question) != current_session_questions_.end()) { - return true; - } +bool QuestionChecker::IsDuplicate(const std::string& question, + const std::string& username) { + // ¼ì²éµ±Ç°»á»°ÖÐÊÇ·ñÖØ¸´ + if (current_session_questions_.find(question) != current_session_questions_.end()) { + return true; + } - std::vector history_questions = file_manager_->loadExistingQuestions(username); - for (std::vector::iterator it = history_questions.begin(); - it != history_questions.end(); ++it) { - if (*it == question) { - return true; - } + // ¼ì²éÀúÊ·ÌâÄ¿ÖÐÊÇ·ñÖØ¸´ + std::vector history_questions = file_manager_->LoadExistingQuestions(username); + for (std::vector::iterator it = history_questions.begin(); + it != history_questions.end(); ++it) { + if (*it == question) { + return true; } - - return false; + } + + return false; } -void QuestionChecker::addGeneratedQuestion(const std::string& question, const std::string& username) { - current_session_questions_.insert(question); +void QuestionChecker::AddGeneratedQuestion(const std::string& question, + const std::string& username) { + current_session_questions_.insert(question); } -void QuestionChecker::clearUserCache(const std::string& username) { - current_session_questions_.clear(); +void QuestionChecker::ClearUserCache(const std::string& username) { + current_session_questions_.clear(); } -int QuestionChecker::getUserQuestionCount(const std::string& username) const { - return current_session_questions_.size(); +int QuestionChecker::GetUserQuestionCount(const std::string& username) const { + return current_session_questions_.size(); } diff --git a/src/QuestionChecker.h b/src/QuestionChecker.h index 05dba9f..581f5ba 100644 --- a/src/QuestionChecker.h +++ b/src/QuestionChecker.h @@ -1,5 +1,5 @@ -#ifndef QUESTIONCHECKER_H -#define QUESTIONCHECKER_H +#ifndef PROJECT_QUESTIONCHECKER_H_ +#define PROJECT_QUESTIONCHECKER_H_ #include #include @@ -7,17 +7,17 @@ #include "IFileManager.h" class QuestionChecker { -public: - QuestionChecker(IFileManager* file_manager); - - bool isDuplicate(const std::string& question, const std::string& username); - void addGeneratedQuestion(const std::string& question, const std::string& username); - void clearUserCache(const std::string& username); - int getUserQuestionCount(const std::string& username) const; + public: + explicit QuestionChecker(IFileManager* file_manager); + + bool IsDuplicate(const std::string& question, const std::string& username); + void AddGeneratedQuestion(const std::string& question, const std::string& username); + void ClearUserCache(const std::string& username); + int GetUserQuestionCount(const std::string& username) const; -private: - IFileManager* file_manager_; - std::set current_session_questions_; + private: + IFileManager* file_manager_; + std::set current_session_questions_; }; -#endif +#endif // PROJECT_QUESTIONCHECKER_H_ diff --git a/src/QuestionChecker.o b/src/QuestionChecker.o index 7785e8f..f9e2857 100644 Binary files a/src/QuestionChecker.o and b/src/QuestionChecker.o differ diff --git a/src/QuestionGenerator.cpp b/src/QuestionGenerator.cpp index d099afb..1bc2cf5 100644 --- a/src/QuestionGenerator.cpp +++ b/src/QuestionGenerator.cpp @@ -4,100 +4,103 @@ #include #include -using namespace std; - QuestionGenerator::QuestionGenerator() { - srand(static_cast(time(NULL))); + std::srand(static_cast(std::time(NULL))); } -vector QuestionGenerator::generateQuestions(const UserType& type, int count, const string& username) { - vector questions; +std::vector QuestionGenerator::GenerateQuestions(const UserType& type, + int count, + const std::string& username) { + std::vector questions; + int generated_count = 0; + + while (generated_count < count) { + std::string question; - for (int i = 0; i < count; ) { - string question; - - if (type == UserType::PRIMARY) { - question = generatePrimaryQuestion(); - } else if (type == UserType::JUNIOR) { - question = generateJuniorQuestion(); - } else if (type == UserType::SENIOR) { - question = generateSeniorQuestion(); - } - - // ²éÖØ£º¼ì²éÊÇ·ñÒÑ´æÔÚ - if (existingQuestions.find(question) == existingQuestions.end()) { - questions.push_back(question); - existingQuestions.insert(question); - i++; - } + if (type.GetValue() == 0) { // PRIMARY + question = GeneratePrimaryQuestion(); + } else if (type.GetValue() == 1) { // JUNIOR + question = GenerateJuniorQuestion(); + } else if (type.GetValue() == 2) { // SENIOR + question = GenerateSeniorQuestion(); } - return questions; + // ²éÖØ£º¼ì²éÊÇ·ñÒÑ´æÔÚ + if (existing_questions_.find(question) == existing_questions_.end()) { + questions.push_back(question); + existing_questions_.insert(question); + ++generated_count; + } + } + + return questions; } -void QuestionGenerator::addExistingQuestions(const vector& questions) { - for (size_t i = 0; i < questions.size(); i++) { - existingQuestions.insert(questions[i]); - } +void QuestionGenerator::AddExistingQuestions(const std::vector& questions) { + // ʹÓô«Í³µü´úÆ÷Ìæ´ú range-based for + for (std::vector::const_iterator it = questions.begin(); + it != questions.end(); ++it) { + existing_questions_.insert(*it); + } } -string QuestionGenerator::generatePrimaryQuestion() { - int operandCount = 2 + rand() % 3; // 2-4¸ö²Ù×÷Êý - stringstream ss; - - for (int i = 0; i < operandCount; i++) { - ss << (rand() % 100 + 1); - if (i < operandCount - 1) { - char ops[] = {'+', '-', '*', '/'}; - ss << " " << ops[rand() % 4] << " "; - } +std::string QuestionGenerator::GeneratePrimaryQuestion() { + int operand_count = 2 + std::rand() % 3; // 2-4¸ö²Ù×÷Êý + std::stringstream ss; + + for (int i = 0; i < operand_count; ++i) { + ss << (std::rand() % 100 + 1); + if (i < operand_count - 1) { + const char ops[] = {'+', '-', '*', '/'}; + ss << " " << ops[std::rand() % 4] << " "; } - ss << " = "; - return ss.str(); + } + ss << " = "; + return ss.str(); } -string QuestionGenerator::generateJuniorQuestion() { - stringstream ss; - - // È·±£ÖÁÉÙÓÐÒ»¸öƽ·½»ò¿ª¸ùºÅ - if (rand() % 2 == 0) { - ss << (rand() % 20 + 1) << "µÄƽ·½"; - } else { - ss << "¸ùºÅ" << (rand() % 100 + 1); - } - - // ¿ÉÄÜÌí¼ÓÆÕͨÔËËã - if (rand() % 2 == 0) { - char ops[] = {'+', '-', '*', '/'}; - ss << " " << ops[rand() % 4] << " " << (rand() % 100 + 1); - } - - ss << " = "; - return ss.str(); +std::string QuestionGenerator::GenerateJuniorQuestion() { + std::stringstream ss; + + // È·±£ÖÁÉÙÓÐÒ»¸öƽ·½»ò¿ª¸ùºÅ + if (std::rand() % 2 == 0) { + ss << (std::rand() % 20 + 1) << "µÄƽ·½"; + } else { + ss << "¸ùºÅ" << (std::rand() % 100 + 1); + } + + // ¿ÉÄÜÌí¼ÓÆÕͨÔËËã + if (std::rand() % 2 == 0) { + const char ops[] = {'+', '-', '*', '/'}; + ss << " " << ops[std::rand() % 4] << " " << (std::rand() % 100 + 1); + } + + ss << " = "; + return ss.str(); } -string QuestionGenerator::generateSeniorQuestion() { - stringstream ss; - - // È·±£ÖÁÉÙÓÐÒ»¸öÈý½Çº¯Êý - const char* trig[] = {"sin", "cos", "tan"}; - ss << trig[rand() % 3] << "(" << (rand() % 100) << "¶È)"; - - // ¿ÉÄÜÌí¼ÓÆÕͨÔËËã - if (rand() % 2 == 0) { - char ops[] = {'+', '-', '*', '/'}; - ss << " " << ops[rand() % 4] << " " << (rand() % 100 + 1); - } - - ss << " = "; - return ss.str(); +std::string QuestionGenerator::GenerateSeniorQuestion() { + std::stringstream ss; + + // È·±£ÖÁÉÙÓÐÒ»¸öÈý½Çº¯Êý + const char* trig[] = {"sin", "cos", "tan"}; + ss << trig[std::rand() % 3] << "(" << (std::rand() % 100) << "¶È)"; + + // ¿ÉÄÜÌí¼ÓÆÕͨÔËËã + if (std::rand() % 2 == 0) { + const char ops[] = {'+', '-', '*', '/'}; + ss << " " << ops[std::rand() % 4] << " " << (std::rand() % 100 + 1); + } + + ss << " = "; + return ss.str(); } -int QuestionGenerator::getRandomNumber(int min, int max) { - return rand() % (max - min + 1) + min; +int QuestionGenerator::GetRandomNumber(int min, int max) { + return std::rand() % (max - min + 1) + min; } -char QuestionGenerator::getRandomOperator() { - char operators[] = {'+', '-', '*', '/'}; - return operators[rand() % 4]; +char QuestionGenerator::GetRandomOperator() { + const char operators[] = {'+', '-', '*', '/'}; + return operators[std::rand() % 4]; } diff --git a/src/QuestionGenerator.h b/src/QuestionGenerator.h index 79784cc..78278d1 100644 --- a/src/QuestionGenerator.h +++ b/src/QuestionGenerator.h @@ -1,26 +1,29 @@ -#ifndef QUESTIONGENERATOR_H -#define QUESTIONGENERATOR_H +#ifndef PROJECT_QUESTIONGENERATOR_H_ +#define PROJECT_QUESTIONGENERATOR_H_ #include "IQuestionGenerator.h" #include #include class QuestionGenerator : public IQuestionGenerator { -public: - QuestionGenerator(); - virtual ~QuestionGenerator() {} - - virtual std::vector generateQuestions(const UserType& type, int count, const std::string& username); - virtual void addExistingQuestions(const std::vector& questions); + public: + QuestionGenerator(); + virtual ~QuestionGenerator() {} + + virtual std::vector GenerateQuestions(const UserType& type, + int count, + const std::string& username); + + virtual void AddExistingQuestions(const std::vector& questions); -private: - std::string generatePrimaryQuestion(); - std::string generateJuniorQuestion(); - std::string generateSeniorQuestion(); - int getRandomNumber(int min, int max); - char getRandomOperator(); - - std::set existingQuestions; + private: + std::string GeneratePrimaryQuestion(); + std::string GenerateJuniorQuestion(); + std::string GenerateSeniorQuestion(); + int GetRandomNumber(int min, int max); + char GetRandomOperator(); + + std::set existing_questions_; }; -#endif +#endif diff --git a/src/QuestionGenerator.o b/src/QuestionGenerator.o index 31fcf19..eda0615 100644 Binary files a/src/QuestionGenerator.o and b/src/QuestionGenerator.o differ diff --git a/src/SessionManager.cpp b/src/SessionManager.cpp index ceb2742..02dda16 100644 --- a/src/SessionManager.cpp +++ b/src/SessionManager.cpp @@ -7,69 +7,70 @@ SessionManager::SessionManager(IUserManager* user_manager, : user_manager_(user_manager), question_generator_(question_generator), question_checker_(question_checker), - current_type_(UserType::PRIMARY), // ʹÓþßÌåµÄUserType³£Á¿³õʼ»¯ + current_type_(UserType::kPrimary), type_switched_(false) {} -bool SessionManager::switchUserType(const std::string& target_type) { - if (target_type == "Сѧ") { - current_type_ = UserType::PRIMARY; - type_switched_ = true; - std::cout << "ÒÑÇл»µ½Ð¡Ñ§³öÌâģʽ" << std::endl; - return true; - } else if (target_type == "³õÖÐ") { - current_type_ = UserType::JUNIOR; - type_switched_ = true; - std::cout << "ÒÑÇл»µ½³õÖгöÌâģʽ" << std::endl; - return true; - } else if (target_type == "¸ßÖÐ") { - current_type_ = UserType::SENIOR; - type_switched_ = true; - std::cout << "ÒÑÇл»µ½¸ßÖгöÌâģʽ" << std::endl; - return true; - } - std::cout << "Çл»Ê§°Ü£¡ÇëÊäÈë'Сѧ'¡¢'³õÖÐ'»ò'¸ßÖÐ'" << std::endl; - return false; +bool SessionManager::SwitchUserType(const std::string& target_type) { + if (target_type == "Сѧ") { + current_type_ = UserType::kPrimary; + type_switched_ = true; + std::cout << "ÒÑÇл»µ½Ð¡Ñ§³öÌâģʽ" << std::endl; + return true; + } else if (target_type == "³õÖÐ") { + current_type_ = UserType::kJunior; + type_switched_ = true; + std::cout << "ÒÑÇл»µ½³õÖгöÌâģʽ" << std::endl; + return true; + } else if (target_type == "¸ßÖÐ") { + current_type_ = UserType::kSenior; + type_switched_ = true; + std::cout << "ÒÑÇл»µ½¸ßÖгöÌâģʽ" << std::endl; + return true; + } + + std::cout << "Çл»Ê§°Ü£¡ÇëÊäÈë'Сѧ'¡¢'³õÖÐ'»ò'¸ßÖÐ'" << std::endl; + return false; } -UserType SessionManager::getCurrentUserType() const { - if (type_switched_) { - return current_type_; - } - return user_manager_->getCurrentUserType(); +UserType SessionManager::GetCurrentUserType() const { + if (type_switched_) { + return current_type_; + } + return user_manager_->GetCurrentUserType(); } -std::string SessionManager::getCurrentUsername() const { - return user_manager_->getCurrentUsername(); +std::string SessionManager::GetCurrentUsername() const { + return user_manager_->GetCurrentUsername(); } -bool SessionManager::isLoggedIn() const { - return user_manager_->isLoggedIn(); +bool SessionManager::IsLoggedIn() const { + return user_manager_->IsLoggedIn(); } -bool SessionManager::login(const std::string& username, const std::string& password) { - type_switched_ = false; - return user_manager_->authenticate(username, password); +bool SessionManager::Login(const std::string& username, const std::string& password) { + type_switched_ = false; + return user_manager_->Authenticate(username, password); } -void SessionManager::logout() { - type_switched_ = false; - user_manager_->logout(); - question_checker_->clearUserCache(getCurrentUsername()); +void SessionManager::Logout() { + type_switched_ = false; + user_manager_->Logout(); + question_checker_->ClearUserCache(GetCurrentUsername()); } -std::vector SessionManager::generateQuestions(int count) { - std::vector valid_questions; - std::string username = getCurrentUsername(); - UserType type = getCurrentUserType(); - - // Ö±½ÓÉú³ÉÌâÄ¿£¬ÒÀÀµQuestionGeneratorÄÚ²¿µÄ²éÖØ - valid_questions = question_generator_->generateQuestions(type, count, username); - - // ¼Ç¼µ½²éÖØÆ÷ - for (std::vector::iterator it = valid_questions.begin(); - it != valid_questions.end(); ++it) { - question_checker_->addGeneratedQuestion(*it, username); - } - - return valid_questions; +std::vector SessionManager::GenerateQuestions(int count) { + std::vector valid_questions; + std::string username = GetCurrentUsername(); + UserType type = GetCurrentUserType(); + + // Ö±½ÓÉú³ÉÌâÄ¿ + valid_questions = question_generator_->GenerateQuestions(type, count, username); + + // ¼Ç¼µ½²éÖØÆ÷ - ʹÓô«Í³µü´úÆ÷ + for (std::vector::iterator it = valid_questions.begin(); + it != valid_questions.end(); ++it) { + question_checker_->AddGeneratedQuestion(*it, username); + } + + return valid_questions; } diff --git a/src/SessionManager.h b/src/SessionManager.h index 51b6957..c09e250 100644 --- a/src/SessionManager.h +++ b/src/SessionManager.h @@ -1,30 +1,33 @@ -#ifndef SESSIONMANAGER_H -#define SESSIONMANAGER_H +#ifndef PROJECT_SESSIONMANAGER_H_ +#define PROJECT_SESSIONMANAGER_H_ #include +#include #include "UserType.h" #include "IUserManager.h" #include "IQuestionGenerator.h" #include "QuestionChecker.h" class SessionManager { -public: - SessionManager(IUserManager* user_manager, IQuestionGenerator* question_generator, QuestionChecker* question_checker); - - bool switchUserType(const std::string& target_type); - UserType getCurrentUserType() const; - std::string getCurrentUsername() const; - bool isLoggedIn() const; - bool login(const std::string& username, const std::string& password); - void logout(); - std::vector generateQuestions(int count); + public: + SessionManager(IUserManager* user_manager, + IQuestionGenerator* question_generator, + QuestionChecker* question_checker); + + bool SwitchUserType(const std::string& target_type); + UserType GetCurrentUserType() const; + std::string GetCurrentUsername() const; + bool IsLoggedIn() const; + bool Login(const std::string& username, const std::string& password); + void Logout(); + std::vector GenerateQuestions(int count); -private: - IUserManager* user_manager_; - IQuestionGenerator* question_generator_; - QuestionChecker* question_checker_; - UserType current_type_; - bool type_switched_; + private: + IUserManager* user_manager_; + IQuestionGenerator* question_generator_; + QuestionChecker* question_checker_; + UserType current_type_; + bool type_switched_; }; -#endif +#endif diff --git a/src/SessionManager.o b/src/SessionManager.o index 2669a07..9fda019 100644 Binary files a/src/SessionManager.o and b/src/SessionManager.o differ diff --git a/src/User.cpp b/src/User.cpp index 13b0178..b11796f 100644 --- a/src/User.cpp +++ b/src/User.cpp @@ -1,8 +1,8 @@ #include "User.h" User::User(const std::string& username, const std::string& password, const UserType& type) - : username(username), password(password), type(type) {} + : username_(username), password_(password), type_(type) {} -bool User::authenticate(const std::string& inputPassword) const { - return password == inputPassword; +bool User::Authenticate(const std::string& input_password) const { + return password_ == input_password; } diff --git a/src/User.h b/src/User.h index ae963ea..8691399 100644 --- a/src/User.h +++ b/src/User.h @@ -1,23 +1,23 @@ -#ifndef USER_H -#define USER_H +#ifndef PROJECT_USER_H_ +#define PROJECT_USER_H_ #include #include "UserType.h" class User { -public: - User(const std::string& username, const std::string& password, const UserType& type); - - std::string getUsername() const { return username; } - std::string getPassword() const { return password; } - UserType getType() const { return type; } - - bool authenticate(const std::string& inputPassword) const; + public: + User(const std::string& username, const std::string& password, const UserType& type); + + std::string GetUsername() const { return username_; } + std::string GetPassword() const { return password_; } + UserType GetType() const { return type_; } + + bool Authenticate(const std::string& input_password) const; -private: - std::string username; - std::string password; - UserType type; + private: + std::string username_; + std::string password_; + UserType type_; }; -#endif +#endif // PROJECT_USER_H_ diff --git a/src/User.o b/src/User.o index 39bb0b7..48e3b48 100644 Binary files a/src/User.o and b/src/User.o differ diff --git a/src/UserManager.cpp b/src/UserManager.cpp index 3e72c09..e27b871 100644 --- a/src/UserManager.cpp +++ b/src/UserManager.cpp @@ -1,53 +1,54 @@ #include "UserManager.h" #include -UserManager::UserManager() : currentUser(NULL), loggedIn(false) { - initializeUsers(); +UserManager::UserManager() : current_user_(NULL), logged_in_(false) { + InitializeUsers(); } -void UserManager::initializeUsers() { - presetUsers.push_back(User("ÕÅÈý1", "123", UserType::PRIMARY)); - presetUsers.push_back(User("ÕÅÈý2", "123", UserType::PRIMARY)); - presetUsers.push_back(User("ÕÅÈý3", "123", UserType::PRIMARY)); - presetUsers.push_back(User("ÀîËÄ1", "123", UserType::JUNIOR)); - presetUsers.push_back(User("ÀîËÄ2", "123", UserType::JUNIOR)); - presetUsers.push_back(User("ÀîËÄ3", "123", UserType::JUNIOR)); - presetUsers.push_back(User("ÍõÎå1", "123", UserType::SENIOR)); - presetUsers.push_back(User("ÍõÎå2", "123", UserType::SENIOR)); - presetUsers.push_back(User("ÍõÎå3", "123", UserType::SENIOR)); +void UserManager::InitializeUsers() { + preset_users_.push_back(User("ÕÅÈý1", "123", UserType::kPrimary)); + preset_users_.push_back(User("ÕÅÈý2", "123", UserType::kPrimary)); + preset_users_.push_back(User("ÕÅÈý3", "123", UserType::kPrimary)); + preset_users_.push_back(User("ÀîËÄ1", "123", UserType::kJunior)); + preset_users_.push_back(User("ÀîËÄ2", "123", UserType::kJunior)); + preset_users_.push_back(User("ÀîËÄ3", "123", UserType::kJunior)); + preset_users_.push_back(User("ÍõÎå1", "123", UserType::kSenior)); + preset_users_.push_back(User("ÍõÎå2", "123", UserType::kSenior)); + preset_users_.push_back(User("ÍõÎå3", "123", UserType::kSenior)); } -bool UserManager::authenticate(const std::string& username, const std::string& password) { - for (size_t i = 0; i < presetUsers.size(); i++) { - if (presetUsers[i].getUsername() == username && - presetUsers[i].authenticate(password)) { - currentUser = &presetUsers[i]; - loggedIn = true; - return true; - } +bool UserManager::Authenticate(const std::string& username, const std::string& password) { + // ʹÓô«Í³µü´úÆ÷Ìæ´ú range-based for + for (std::vector::iterator it = preset_users_.begin(); + it != preset_users_.end(); ++it) { + if (it->GetUsername() == username && it->Authenticate(password)) { + current_user_ = &(*it); // »ñȡָÕë + logged_in_ = true; + return true; } - return false; + } + return false; } -UserType UserManager::getCurrentUserType() const { - if (currentUser) { - return currentUser->getType(); - } - return UserType::PRIMARY; +UserType UserManager::GetCurrentUserType() const { + if (current_user_ != NULL) { // ʹÓà NULL Ìæ´ú nullptr + return current_user_->GetType(); + } + return UserType::kPrimary; } -std::string UserManager::getCurrentUsername() const { - if (currentUser) { - return currentUser->getUsername(); - } - return ""; +std::string UserManager::GetCurrentUsername() const { + if (current_user_ != NULL) { // ʹÓà NULL Ìæ´ú nullptr + return current_user_->GetUsername(); + } + return ""; } -void UserManager::logout() { - currentUser = NULL; - loggedIn = false; +void UserManager::Logout() { + current_user_ = NULL; // ʹÓà NULL Ìæ´ú nullptr + logged_in_ = false; } -bool UserManager::isLoggedIn() const { - return loggedIn; +bool UserManager::IsLoggedIn() const { + return logged_in_; } diff --git a/src/UserManager.h b/src/UserManager.h index a6f0ead..d6dedd4 100644 --- a/src/UserManager.h +++ b/src/UserManager.h @@ -1,27 +1,27 @@ -#ifndef USERMANAGER_H -#define USERMANAGER_H +#ifndef PROJECT_USERMANAGER_H_ +#define PROJECT_USERMANAGER_H_ #include "IUserManager.h" #include #include "User.h" class UserManager : public IUserManager { -public: - UserManager(); - virtual ~UserManager() {} - - virtual bool authenticate(const std::string& username, const std::string& password); - virtual UserType getCurrentUserType() const; - virtual std::string getCurrentUsername() const; - virtual void logout(); - virtual bool isLoggedIn() const; + public: + UserManager(); + virtual ~UserManager() {} + + virtual bool Authenticate(const std::string& username, const std::string& password); + virtual UserType GetCurrentUserType() const; + virtual std::string GetCurrentUsername() const; + virtual void Logout(); + virtual bool IsLoggedIn() const; -private: - std::vector presetUsers; - const User* currentUser; - bool loggedIn; - - void initializeUsers(); + private: + void InitializeUsers(); + + std::vector preset_users_; + const User* current_user_; + bool logged_in_; }; -#endif +#endif // PROJECT_USERMANAGER_H_ diff --git a/src/UserManager.o b/src/UserManager.o index c5daec9..0160180 100644 Binary files a/src/UserManager.o and b/src/UserManager.o differ diff --git a/src/UserType.cpp b/src/UserType.cpp index a5c1dce..2b86e66 100644 --- a/src/UserType.cpp +++ b/src/UserType.cpp @@ -1,5 +1,5 @@ #include "UserType.h" -const UserType UserType::PRIMARY(0, "Сѧ"); -const UserType UserType::JUNIOR(1, "³õÖÐ"); -const UserType UserType::SENIOR(2, "¸ßÖÐ"); +const UserType UserType::kPrimary(0, "Сѧ"); +const UserType UserType::kJunior(1, "³õÖÐ"); +const UserType UserType::kSenior(2, "¸ßÖÐ"); diff --git a/src/UserType.h b/src/UserType.h index cb2ef79..b56b03c 100644 --- a/src/UserType.h +++ b/src/UserType.h @@ -1,28 +1,28 @@ -#ifndef USERTYPE_H -#define USERTYPE_H +#ifndef PROJECT_USERTYPE_H_ +#define PROJECT_USERTYPE_H_ #include class UserType { -public: - static const UserType PRIMARY; - static const UserType JUNIOR; - static const UserType SENIOR; - - UserType() : value(-1), name("δ֪") {} // Ìí¼ÓĬÈϹ¹Ô캯Êý - UserType(const UserType& other) : value(other.value), name(other.name) {} - - std::string getName() const { return name; } - int getValue() const { return value; } - - bool operator==(const UserType& other) const { return value == other.value; } - bool operator!=(const UserType& other) const { return value != other.value; } - -private: - UserType(int val, const std::string& n) : value(val), name(n) {} - - int value; - std::string name; + public: + static const UserType kPrimary; + static const UserType kJunior; + static const UserType kSenior; + + UserType() : value_(-1), name_("Unknown") {} + UserType(const UserType& other) : value_(other.value_), name_(other.name_) {} + + std::string GetName() const { return name_; } + int GetValue() const { return value_; } + + bool operator==(const UserType& other) const { return value_ == other.value_; } + bool operator!=(const UserType& other) const { return value_ != other.value_; } + + private: + UserType(int val, const std::string& n) : value_(val), name_(n) {} + + int value_; + std::string name_; }; -#endif +#endif diff --git a/src/UserType.o b/src/UserType.o index 442f9ae..47d26a1 100644 Binary files a/src/UserType.o and b/src/UserType.o differ diff --git a/src/main.cpp b/src/main.cpp index e327754..b805ffa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,190 +1,6 @@ -#include -#include -#include -#include -#include -#include "IUserManager.h" -#include "IQuestionGenerator.h" -#include "IFileManager.h" -#include "QuestionChecker.h" -#include "SessionManager.h" -#include "UserManager.h" -#include "QuestionGenerator.h" -#include "FileManager.h" - -using namespace std; - -bool isNumber(const string& str); -int stringToInt(const string& str); -void displayWelcome(); -void handleLogin(SessionManager* session_manager); -void displayMainMenu(); -void handleGenerateQuestions(SessionManager* session_manager, IFileManager* file_manager); -void handleSwitchType(SessionManager* session_manager); -void handleUserChoice(SessionManager* session_manager, IFileManager* file_manager, const string& choice); -void cleanupResources(SessionManager* session_manager, QuestionChecker* question_checker, - IFileManager* file_manager, IQuestionGenerator* question_generator, - IUserManager* user_manager); - - -bool isNumber(const string& str) { - if (str.empty()) return false; - for (size_t i = 0; i < str.length(); i++) { - if (!isdigit(str[i]) && !(i == 0 && str[i] == '-')) { - return false; - } - } - return true; -} - -int stringToInt(const string& str) { - int result = 0; - int sign = 1; - size_t start = 0; - - if (str[0] == '-') { - sign = -1; - start = 1; - } - - for (size_t i = start; i < str.length(); i++) { - if (str[i] >= '0' && str[i] <= '9') { - result = result * 10 + (str[i] - '0'); - } - } - - return result * sign; -} - -void displayWelcome() { - cout << "ÖÐСѧÊýѧ¾í×Ó×Ô¶¯Éú³É³ÌÐò" << endl; - cout << "=================================" << endl; -} - -void handleLogin(SessionManager* session_manager) { - string username, password; - cout << "ÇëÊäÈëÓû§ÃûºÍÃÜÂ루Óÿոñ¸ô¿ª£©: "; - cin >> username >> password; - - if (session_manager->login(username, password)) { - UserType current_type = session_manager->getCurrentUserType(); - cout << "µÇ¼³É¹¦£¡µ±Ç°Ñ¡ÔñΪ" << current_type.getName() << "³öÌâ" << endl; - } else { - cout << "ÇëÊäÈëÕýÈ·µÄÓû§Ãû¡¢ÃÜÂë" << endl; - } -} - -void displayMainMenu() { - cout << "\nÇëÑ¡Ôñ²Ù×÷:" << endl; - cout << "1. Éú³ÉÌâÄ¿" << endl; - cout << "2. Çл»ÀàÐÍ" << endl; - cout << "3. Í˳ö³ÌÐò" << endl; - cout << "-1. Í˳öµ±Ç°Óû§" << endl; - cout << "ÇëÊäÈëÑ¡Ôñ: "; -} - -void displayCurrentStatus(SessionManager* session_manager, QuestionChecker* question_checker) { - cout << "\nµ±Ç°Óû§: " << session_manager->getCurrentUsername() << endl; - cout << "µ±Ç°ÀàÐÍ: " << session_manager->getCurrentUserType().getName() << endl; - cout << "ÒÑÉú³ÉÌâÄ¿: " << question_checker->getUserQuestionCount( - session_manager->getCurrentUsername()) << "µÀ" << endl; -} - -void handleGenerateQuestions(SessionManager* session_manager, IFileManager* file_manager) { - cout << "×¼±¸Éú³É" << session_manager->getCurrentUserType().getName() - << "ÊýѧÌâÄ¿£¬ÇëÊäÈëÉú³ÉÌâÄ¿ÊýÁ¿£¨10-30£©: "; - string input; - cin >> input; - - if (!isNumber(input)) { - cout << "ÇëÊäÈëÓÐЧµÄÊý×Ö" << endl; - return; - } - - int count = stringToInt(input); - if (count < 10 || count > 30) { - cout << "ÌâÄ¿ÊýÁ¿Ó¦ÔÚ10µ½30Ö®¼ä" << endl; - return; - } - - vector questions = session_manager->generateQuestions(count); - - if (file_manager->saveQuestions(questions, session_manager->getCurrentUsername(), - session_manager->getCurrentUserType())) { - cout << "³É¹¦Éú³É" << questions.size() << "µÀ²»Öظ´µÄ" - << session_manager->getCurrentUserType().getName() << "ÊýѧÌâÄ¿£¡" << endl; - - if (questions.size() < (size_t)count) { - cout << "×¢Ò⣺ÓÉÓÚÌâÄ¿ÖØ¸´£¬Êµ¼ÊÉú³É" << questions.size() - << "µÀÌâÄ¿£¨ÒªÇó" << count << "µÀ£©" << endl; - } - } -} - -void handleSwitchType(SessionManager* session_manager) { - cout << "ÇëÊäÈëÒªÇл»µÄÀàÐÍ£¨Ð¡Ñ§/³õÖÐ/¸ßÖУ©: "; - string target_type; - cin >> target_type; - session_manager->switchUserType(target_type); -} - -void handleUserChoice(SessionManager* session_manager, IFileManager* file_manager, - QuestionChecker* question_checker, const string& choice) { - if (choice == "1") { - handleGenerateQuestions(session_manager, file_manager); - } - else if (choice == "2") { - handleSwitchType(session_manager); - } - else if (choice == "-1") { - session_manager->logout(); - cout << "ÒÑÍ˳öµ±Ç°Óû§" << endl; - } - else if (choice == "3") { - cout << "¸ÐлʹÓã¬ÔÙ¼û£¡" << endl; - exit(0); - } - else { - cout << "ÎÞЧѡÔñ£¬ÇëÖØÐÂÊäÈë" << endl; - } -} - -void cleanupResources(SessionManager* session_manager, QuestionChecker* question_checker, - IFileManager* file_manager, IQuestionGenerator* question_generator, - IUserManager* user_manager) { - delete session_manager; - delete question_checker; - delete file_manager; - delete question_generator; - delete user_manager; -} +#include "Application.h" int main() { - // ´´½¨×é¼þ - IUserManager* user_manager = new UserManager(); - IQuestionGenerator* question_generator = new QuestionGenerator(); - IFileManager* file_manager = new FileManager(); - QuestionChecker* question_checker = new QuestionChecker(file_manager); - SessionManager* session_manager = new SessionManager(user_manager, question_generator, question_checker); - - displayWelcome(); - - // Ö÷Ñ­»· - while (true) { - if (!session_manager->isLoggedIn()) { - handleLogin(session_manager); - continue; - } - - displayCurrentStatus(session_manager, question_checker); - displayMainMenu(); - - string choice; - cin >> choice; - - handleUserChoice(session_manager, file_manager, question_checker, choice); - } - - cleanupResources(session_manager, question_checker, file_manager, question_generator, user_manager); - return 0; + Application app; + return app.Run(); } diff --git a/src/main.o b/src/main.o index d9459fc..539b543 100644 Binary files a/src/main.o and b/src/main.o differ diff --git a/src/test.dev b/src/test.dev index e0796d2..36df200 100644 --- a/src/test.dev +++ b/src/test.dev @@ -29,7 +29,7 @@ IncludeVersionInfo=0 SupportXPThemes=0 CompilerSet=0 CompilerSettings=0000000000000000000000000 -UnitCount=18 +UnitCount=20 [VersionInfo] Major=1 @@ -230,3 +230,23 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= +[Unit19] +FileName=Application.h +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit20] +FileName=Application.cpp +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/src/test.exe b/src/test.exe index d352199..21b3a0e 100644 Binary files a/src/test.exe and b/src/test.exe differ diff --git a/src/test.layout b/src/test.layout index e21361f..f042d5b 100644 --- a/src/test.layout +++ b/src/test.layout @@ -1,23 +1,23 @@ [Editors] -Order=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 -Focused=17 +Order=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 +Focused=18 [Editor_0] -CursorCol=5 -CursorRow=61 +CursorCol=3 +CursorRow=16 TopLine=1 LeftChar=1 [Editor_1] -CursorCol=7 -CursorRow=26 +CursorCol=8 +CursorRow=29 TopLine=1 LeftChar=1 [Editor_2] CursorCol=2 -CursorRow=53 +CursorRow=54 TopLine=1 LeftChar=1 [Editor_3] -CursorCol=7 +CursorCol=34 CursorRow=27 TopLine=1 LeftChar=1 @@ -27,67 +27,77 @@ CursorRow=8 TopLine=1 LeftChar=1 [Editor_5] -CursorCol=7 +CursorCol=27 CursorRow=23 TopLine=1 LeftChar=1 [Editor_6] -CursorCol=44 +CursorCol=45 CursorRow=5 TopLine=1 LeftChar=1 [Editor_7] -CursorCol=3 -CursorRow=26 +CursorCol=9 +CursorRow=28 TopLine=1 LeftChar=1 [Editor_8] -CursorCol=7 -CursorRow=20 +CursorCol=29 +CursorRow=11 TopLine=1 LeftChar=1 [Editor_9] -CursorCol=76 -CursorRow=33 -TopLine=3 +CursorCol=2 +CursorRow=46 +TopLine=4 LeftChar=1 [Editor_10] CursorCol=2 -CursorRow=190 -TopLine=158 +CursorRow=6 +TopLine=1 LeftChar=1 [Editor_11] -CursorCol=7 -CursorRow=15 +CursorCol=37 +CursorRow=10 TopLine=1 LeftChar=1 [Editor_12] -CursorCol=7 -CursorRow=15 +CursorCol=30 +CursorRow=10 TopLine=1 LeftChar=1 [Editor_13] -CursorCol=7 -CursorRow=18 +CursorCol=9 +CursorRow=20 TopLine=1 LeftChar=1 [Editor_16] -CursorCol=7 -CursorRow=30 +CursorCol=9 +CursorRow=33 TopLine=1 LeftChar=1 [Editor_17] -CursorCol=1 -CursorRow=12 -TopLine=1 +CursorCol=2 +CursorRow=76 +TopLine=44 LeftChar=1 [Editor_15] -CursorCol=1 -CursorRow=23 -TopLine=1 +CursorCol=2 +CursorRow=37 +TopLine=5 LeftChar=1 [Editor_14] -CursorCol=7 +CursorCol=38 CursorRow=23 TopLine=1 LeftChar=1 +[Editor_18] +CursorCol=34 +CursorRow=39 +TopLine=7 +LeftChar=1 +[Editor_19] +CursorCol=2 +CursorRow=177 +TopLine=145 +LeftChar=1 diff --git a/软件工程导论-个人项目需求-2025.docx b/软件工程导论-个人项目需求-2025.docx index 5782b70..bfdf95e 100644 Binary files a/软件工程导论-个人项目需求-2025.docx and b/软件工程导论-个人项目需求-2025.docx differ