2.2 数据结构设计
“专业技术理论考试系统”采用试卷管理类实现了试题题型、单题数据、大题数据、用户输入信息等内容的统一管理,系统结构清晰,层次分明。
(1) 试题类型结构
struct TQuestionType
{
int type_id; //题型ID
AnsiString type_name; //题型名称
};
(2) 试题类型管理类
class TQuestionTypeManager
{
public:
TList * QuestionTypes; //试题类型列表
int GetTypesNum()
{
return QuestionTypes->Count;
};
//加入新题型
void AddQuestionType(AnsiString type_name,int type_id)
{
TQuestionType * curType = new TQuestionType();
curType->type_id = type_id;
curType->type_name = type_name;
QuestionTypes->Add(curType);
};
TQuestionTypeManager() { QuestionTypes = new TList();};
//析构时释放题型对象实例
~TQuestionTypeManager()
{
for(int i=QuestionTypes->Count-1;i>=0;i--)
delete (TQuestionType *)QuestionTypes->Items[i];
delete QuestionTypes;
};
};
(3) 试题对象类
试题对象类用来描述试卷上的每一道试题对象,包括试题的题干、答案、选项等内容。
//试题对象描述类
class TQuestion
{
public:
AnsiString Body; //题干内容
TStringList* SelectItems; //试题选项
TStringList* UserAnswerItems; //用户填空题输入内容
AnsiString Answers; //试题原答案
AnsiString UserAnswers; //用户选择、判断题输入内容
TQuestion()
{
SelectItems = new TStringList();
UserAnswerItems = new TStringList();
UserAnswerCheck = new TStringList();
};
~TQuestion()
{
delete SelectItems;
delete UserAnswerCheck;
delete UserAnswerItems;
};
};
(4) 试题集合类
试题集合类用来管理一个大题内的所有试题,同时存储本类大题的题型和每题分值信息。
class TQuestionUnits //试题集合类
{
public:
TQuestionType* questionType; //题型
float questionScore; //每题分值
TList* Questions;
TQuestionUnits()
{
Questions = new TList();
};
~TQuestionUnits()
{
for(int i=Questions->Count-1;i>=0;i--)
delete (TQuestion *)Questions->Items[i];
delete Questions;
};
};
(5) HTML试卷管理类
HTML试卷管理类用来实现对一次考试的全部信息进行管理,包括设定的考试时间、用户姓名和单位、HTML试卷题头以及试卷包含的大题等内容。
//HTML试卷管理类
class THTMLPaper
{
public:
TList* QuestionUnits; //试题集合列表(试卷大题列表)
int ExamTimes; //考试时长
long long ExamStartTime; //考试开始时间
long long ExamEndTime; //考试结束时间
float UserScores; //用户成绩
float PaperTotalScore; //卷面总分
AnsiString UserName; //用户名
AnsiString UserCompany; //用户单位
bool AllowMakePaper; //允许生成试卷标志
AnsiString PaperTitle; //试卷标题题头
float SimilitudeValue; //答案相似度
//当相似度大于该值时得分
//清空试卷数据
void Clear()
{
UserScores - 0;
PaperTotalScore = 0;
for(int i=QuestionUnits->Count-1;i>=0;i--)
delete (TQuestionUnits *)QuestionUnits->Items[i];
QuestionUnits->Clear();
};
THTMLPaper()
{
QuestionUnits = new TList();
};
~THTMLPaper()
{
for(int i=QuestionUnits->Count-1;i>=0;i--)
delete (TQuestionUnits *)QuestionUnits->Items[i];
delete QuestionUnits;
};
};
2.3 系统流程设计
|