Book.Mql4.Com/ru/operators/if
10 code-live.ru/post/cpp-variables-and-datatypes/
Kvodo.ru/urok-5-tsiklyi.html
Ru.wikipedia.org
Citforum.ru/programming/application/cb3.shtml
H-l-l.ru/publ/44
15 radio-hobby.org/modules/instruction/page.php?id=491
Приложения
Листинг программы
//---------------------------------------------------------------------------
#include <vcl.h>
//---------------------------------------------------------------------------
#pragma hdrstop
//---------------------------------------------------------------------------
#include "Tester_MF.h"
#include "Functions.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
//---------------------------------------------------------------------------
TMF *MF;
//---------------------------------------------------------------------------
int QueCountInExam = 20;
int QueCountInFile = 0;
bool ShuffleAnswers = true;
bool IsFileOpened = false;
bool IsTestStarted = false;
//---------------------------------------------------------------------------
int CurrQueNumber = 0;
int CurrCorr = 0;
int CorrCount = 0;
//---------------------------------------------------------------------------
TStringList *SourceData = new TStringList;
TStringList *QAIndex = new TStringList;
TStringList *CorrIndex = new TStringList;
//---------------------------------------------------------------------------
TStringList *ExamQueList = new TStringList;
//---------------------------------------------------------------------------
__fastcall TMF::TMF(TComponent* Owner)
: TForm(Owner)
{}
//---------------------------------------------------------------------------
void __fastcall TMF::NCloseAppClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TMF::NOpenFileClick(TObject *Sender)
{
if (OpenFileDlg->Execute()) {
SourceData->LoadFromFile(OpenFileDlg->FileName);
CreateIndex();
MF->Caption = "Программа тестирования - " +
ExtractFileName(ChangeFileExt(OpenFileDlg->FileName, ""));
IsFileOpened = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TMF::NQue10Click(TObject *Sender)
{
QueCountInExam = 10;
NQue10->Checked = true;
}
//---------------------------------------------------------------------------
void __fastcall TMF::NQue20Click(TObject *Sender)
{
QueCountInExam = 20;
NQue20->Checked = true;
}
//---------------------------------------------------------------------------
void __fastcall TMF::NQue30Click(TObject *Sender)
{
QueCountInExam = 30;
NQue30->Checked = true;
}
//---------------------------------------------------------------------------
void __fastcall TMF::NQue40Click(TObject *Sender)
{
QueCountInExam = 40;
NQue40->Checked = true;
}
//---------------------------------------------------------------------------
void __fastcall TMF::NQue50Click(TObject *Sender)
{
QueCountInExam = 50;
NQue10->Checked = true;
}
//---------------------------------------------------------------------------
void __fastcall TMF::NShuffleAnswersClick(TObject *Sender)
{
ShuffleAnswers = !ShuffleAnswers;
NShuffleAnswers->Checked = ShuffleAnswers;
}
//---------------------------------------------------------------------------
void __fastcall TMF::NStartTestClick(TObject *Sender)
{
StartTest();
}
//---------------------------------------------------------------------------
void __fastcall TMF::NStopTestClick(TObject *Sender)
{
StopTest();
}
//---------------------------------------------------------------------------
void TMF::StartTest()
{
if (!IsFileOpened) {
ShowMessage("Внимание! Файл не открыт!");
return;
}
IsTestStarted = true;
NSettings->Enabled = !IsTestStarted;
NStartTest->Enabled = !IsTestStarted;
NStopTest->Enabled = IsTestStarted;
QuestionBox->Enabled = IsTestStarted;
AnswersBox->Enabled = IsTestStarted;
ButtonNext->Enabled = IsTestStarted;
CurrQueNumber = 1;
CurrCorr = 0;
CorrCount = 0;
LabelQueNumber->Caption = "Вопрос: " + IntToStr(CurrQueNumber) +
" из " + IntToStr(QueCountInExam);
CreateExamQueList();
LoadQAC(GetQueIDFEL(CurrQueNumber));
}
//---------------------------------------------------------------------------
void TMF::StopTest()
{
IsTestStarted = false;
NSettings->Enabled = !IsTestStarted;
NStartTest->Enabled = !IsTestStarted;
NStopTest->Enabled = IsTestStarted;
QuestionBox->Enabled = IsTestStarted;
AnswersBox->Enabled = IsTestStarted;
ButtonNext->Enabled = IsTestStarted;
}
//---------------------------------------------------------------------------
void TMF::CreateIndex()
{
int i, iBuf = 0, RM = 0, QueID = -1, QueCount = 0, AnsCount = 0;
QAIndex->Clear();
CorrIndex->Clear();
for (i = 0; i < SourceData->Count; i++) {
if (AnsiUpperCase(ReadHeader(SourceData->Strings[i], ':')) == "QUE") {
QAIndex->Add("-1");
CorrIndex->Add("-1");
QueCount++;
}
}
QueCountInFile = QueCount;
for (i = 0; i < SourceData->Count; i++) {
switch (RM) {
case 0 : {
if (AnsiUpperCase(ReadHeader(SourceData->Strings[i], ':')) == "QUE") {
iBuf = i;
QueID++;
AnsCount = 0;
RM = 1;
continue;
}
}
case 1 : {
if (AnsiUpperCase(ReadHeader(SourceData->Strings[i], ':')) == "ANS") {
AnsCount++;
continue;
}
if (AnsiUpperCase(ReadHeader(SourceData->Strings[i], ':')) == "CORR") {
QAIndex->Strings[QueID] = IntToStr(iBuf) + "-" + IntToStr(AnsCount);
CorrIndex->Strings[QueID] = ReadValue(SourceData->Strings[i], ':');
RM = 0;
continue;
}
}
} // switch
} // for
}
//---------------------------------------------------------------------------
bool TMF::IsInExamQueList(int Num)
{
int i;
for (i = 0; i < ExamQueList->Count; i++) {
if (StrToInt(ExamQueList->Strings[i]) == Num) {
return true;
}
}
return false;
}
//---------------------------------------------------------------------------
void TMF::CreateExamQueList()
{
int i, rn;
Randomize();
ExamQueList->Clear();
for (i = 0; i < QueCountInExam; i++) {
ExamQueList->Add("-1");
}
for (i = 0; i < QueCountInExam; i++) {
while (StrToInt(ExamQueList->Strings[i]) == -1) {
rn = Random(QueCountInFile + 1);
if (!IsInExamQueList(rn)) {
ExamQueList->Strings[i] = IntToStr(rn);
}
}
}
}
//---------------------------------------------------------------------------
String TMF::GetQueFromIndex(int QueID)
{
int LineID = 0; QueID--;
LineID = StrToInt(ReadHeader(QAIndex->Strings[QueID], '-'));
return ReadValue(SourceData->Strings[LineID], ':');
}
//---------------------------------------------------------------------------
String TMF::GetAnsFromIndex(int QueID, int AnsID)
{
int LineID = 0; QueID--;
LineID = StrToInt(ReadHeader(QAIndex->Strings[QueID], '-'));
return ReadValue(SourceData->Strings[LineID + AnsID], ':');
}
//---------------------------------------------------------------------------
int TMF::GetAnsCountFromIndex(int QueID)
{
QueID--;
eturn StrToInt(ReadValue(QAIndex->Strings[QueID], '-'));
}
//---------------------------------------------------------------------------
int TMF::GetCorrFromIndex(int QueID)
{
return StrToInt(CorrIndex->Strings[QueID-1]);
}
//---------------------------------------------------------------------------
void TMF::LoadQAC(int QueID)
{
int i;
LabelQueNumber->Caption = "Вопрос: " + IntToStr(CurrQueNumber) +
" из " + IntToStr(QueCountInExam);
QuestionBox->Clear();
AnswersBox->Items->Clear();
QuestionBox->Lines->Add(GetQueFromIndex(QueID));
for (i = 1; i <= GetAnsCountFromIndex(QueID); i++) {
AnswersBox->Items->Add(GetAnsFromIndex(QueID, i));
}
CurrCorr = GetCorrFromIndex(QueID) - 1;
if (NShuffleAnswers->Checked) {
PShuffleAnswers();
}
}
//---------------------------------------------------------------------------
void TMF::PShuffleAnswers()
{
int i, rn;
String Buf = "", CorrBuf = "";
Randomize();
CorrBuf = AnswersBox->Items->Strings[CurrCorr];
for (i = 0; i < AnswersBox->Items->Count; i++) {
Buf = AnswersBox->Items->Strings[i];
rn = Random(AnswersBox->Items->Count);
AnswersBox->Items->Strings[i] = AnswersBox->Items->Strings[rn];
AnswersBox->Items->Strings[rn] = Buf;
}
for (i = 0; i < AnswersBox->Items->Count; i++) {
if (AnswersBox->Items->Strings[i] == CorrBuf) {
CurrCorr = i;
break;}
}
}
//---------------------------------------------------------------------------
int TMF::GetQueIDFEL(int QueID)
{
return StrToInt(ExamQueList->Strings[QueID-1]);
}
//---------------------------------------------------------------------------
void TMF::Next()
{
if (AnswersBox->ItemIndex == CurrCorr) {
CorrCount++;
}
CurrQueNumber++;
LoadQAC(GetQueIDFEL(CurrQueNumber));
}
//---------------------------------------------------------------------------
void __fastcall TMF::ButtonNextClick(TObject *Sender)
{
if (AnswersBox->ItemIndex >= 0) {
if (CurrQueNumber < QueCountInExam) {
Next();
}
else
{
ShowResult();
}
}
else
{
ShowMessage("Выберите один из вариантов ответа!");
}
}
//---------------------------------------------------------------------------
void TMF::ShowResult()
{
float CellA, CellB, CellC;
CellA = CorrCount;
CellB = QueCountInExam;
CellC = (CellA/CellB) * 100;
LabelQueNumber->Caption = "Результат";
QuestionBox->Clear();
AnswersBox->Items->Clear();
QuestionBox->Lines->Add("Правильных ответов: " + IntToStr(CorrCount) +
" из " + IntToStr(QueCountInExam) + " ("+
FloatToStr(CellC) + "%)");
StopTest();
}
//---------------------------------------------------------------------------
Интерфейс программы