|
|
#ifndef DATA_STRUCTURES_H
|
|
|
#define DATA_STRUCTURES_H
|
|
|
|
|
|
#include <string>
|
|
|
#include <vector>
|
|
|
|
|
|
// 用户信息结构体
|
|
|
struct UserInfo {
|
|
|
std::string email;
|
|
|
std::string password;
|
|
|
bool isLoggedIn = false;
|
|
|
};
|
|
|
|
|
|
// 题目信息结构体
|
|
|
struct QuestionInfo {
|
|
|
int id;
|
|
|
std::string content;
|
|
|
std::vector<std::string> options;
|
|
|
int correctAnswer; // 0-3 对应ABCD
|
|
|
};
|
|
|
|
|
|
// 测试结果结构体
|
|
|
struct TestResult {
|
|
|
int totalQuestions; ///< 总问题数
|
|
|
int correctAnswers; ///< 正确问题数
|
|
|
double score; ///< 得分
|
|
|
std::string difficulty;
|
|
|
};
|
|
|
|
|
|
// 前后端通信接口
|
|
|
class BackendInterface {
|
|
|
public:
|
|
|
/**
|
|
|
* @brief 请求发送验证码
|
|
|
* @param email 邮箱地址
|
|
|
* @return 发送成功true
|
|
|
*/
|
|
|
virtual bool sendSecondCode(const std::string& email) = 0;
|
|
|
|
|
|
/**
|
|
|
* @brief 用户注册
|
|
|
* @param user_name 用户名
|
|
|
* @param password 密码
|
|
|
* @param code 验证码
|
|
|
* @return 注册成功true
|
|
|
*/
|
|
|
virtual bool userRegitster(const std::string& user_name, const std::string& password, const std::string& code) = 0;
|
|
|
|
|
|
/**
|
|
|
* @brief 用户登陆
|
|
|
* @param user_name 用户名
|
|
|
* @param password 密码
|
|
|
* @return 登陆成功true
|
|
|
*/
|
|
|
virtual bool userLogin(const std::string& user_name, const std::string& password) = 0;
|
|
|
virtual void userLogout() = 0;
|
|
|
virtual bool changePassword(const std::string& oldPassword, const std::string& newPassword) = 0;
|
|
|
virtual void userExit() = 0;
|
|
|
|
|
|
/**
|
|
|
* @brief 题目生成
|
|
|
* @param difficulty 题目难度(小学、初中、高中)
|
|
|
* @param count 题目数量
|
|
|
* @return 返回生成的题目信息(采用QuestionInfor存储题目)
|
|
|
*/
|
|
|
virtual std::vector<QuestionInfo> generateQuestions(const std::string& difficulty, int count) = 0;
|
|
|
|
|
|
/**
|
|
|
* @brief 提交答案
|
|
|
* @param userAnswers 0-3分别表示选项A-D
|
|
|
* @return 返回测试结果(采用TestResult存储测试结果)
|
|
|
*/
|
|
|
virtual TestResult submitAnswers(const std::vector<int>& userAnswers) = 0;
|
|
|
|
|
|
virtual ~BackendInterface() = default;
|
|
|
};
|
|
|
|
|
|
class BackendImpl : public BackendInterface {
|
|
|
public:
|
|
|
bool sendSecondCode(const std::string& email){ return true; };
|
|
|
bool userRegitster(const std::string& user_name, const std::string& password, const std::string& code){ return true; };
|
|
|
bool userLogin(const std::string& user_name, const std::string& password){ return true; };
|
|
|
bool changePassword(const std::string& old_password, const std::string& new_password){ return true; };
|
|
|
void userLogout(){return;};
|
|
|
void userExit(){return;};
|
|
|
std::vector<QuestionInfo> generateQuestions(const std::string& difficulty, int count) {
|
|
|
std::vector<QuestionInfo> questions = {
|
|
|
{1, "1 + 1 = ?", {"1", "2", "3", "4"}, 1},
|
|
|
{2, "3 * 4 = ?", {"10", "12", "14", "16"}, 1},
|
|
|
{3, "10 / 2 = ?", {"3", "4", "5", "6"}, 2},
|
|
|
{4, "7 - 3 = ?", {"2", "3", "4", "5"}, 2},
|
|
|
{5, "2 * 2 = ?", {"2", "3", "4", "5"}, 2},
|
|
|
{6, "9 / 3 = ?", {"2", "3", "4", "5"}, 1},
|
|
|
{7, "5 * 6 = ?", {"25", "30", "35", "40"}, 1},
|
|
|
{8, "8 + 7 = ?", {"14", "15", "16", "17"}, 1},
|
|
|
{9, "20 / 4 = ?", {"3", "4", "5", "6"}, 2},
|
|
|
{10, "6 * 7 = ?", {"40", "42", "44", "46"}, 1}
|
|
|
};
|
|
|
return questions;
|
|
|
}
|
|
|
|
|
|
TestResult submitAnswers(const std::vector<int>& userAnswers){
|
|
|
TestResult test_result = {
|
|
|
10,
|
|
|
8,
|
|
|
80.0,
|
|
|
"小学"
|
|
|
};
|
|
|
|
|
|
return test_result;
|
|
|
}
|
|
|
|
|
|
~BackendImpl() = default ;
|
|
|
};
|
|
|
|
|
|
|
|
|
#endif |