Загрузка данных
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Drawing;
using namespace System::IO;
namespace Examinator
{
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
index = 0;
score = 0;
LoadQuestions();
ShowQuestion();
}
protected:
~Form1()
{
if (components)
delete components;
}
private:
array<String^>^ lines;
int index;
int score;
Label^ label1;
PictureBox^ pictureBox1;
RadioButton^ radio1;
RadioButton^ radio2;
RadioButton^ radio3;
TextBox^ textBox1;
Button^ button1;
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->label1 = gcnew Label();
this->pictureBox1 = gcnew PictureBox();
this->radio1 = gcnew RadioButton();
this->radio2 = gcnew RadioButton();
this->radio3 = gcnew RadioButton();
this->textBox1 = gcnew TextBox();
this->button1 = gcnew Button();
this->SuspendLayout();
this->label1->Location = Point(20,20);
this->label1->Size = Drawing::Size(500,30);
this->pictureBox1->Location = Point(20,60);
this->pictureBox1->Size = Drawing::Size(250,150);
this->pictureBox1->SizeMode =
PictureBoxSizeMode::StretchImage;
this->radio1->Location = Point(20,230);
this->radio2->Location = Point(20,260);
this->radio3->Location = Point(20,290);
this->textBox1->Location = Point(20,230);
this->textBox1->Size = Drawing::Size(200,20);
this->button1->Text = L"OK";
this->button1->Location = Point(20,350);
this->button1->Click +=
gcnew EventHandler(this,
&Form1::button1_Click);
this->Controls->Add(label1);
this->Controls->Add(pictureBox1);
this->Controls->Add(radio1);
this->Controls->Add(radio2);
this->Controls->Add(radio3);
this->Controls->Add(textBox1);
this->Controls->Add(button1);
this->Text = L"Экзаменатор";
this->ResumeLayout(false);
}
#pragma endregion
private:
void LoadQuestions()
{
lines =
File::ReadAllLines("questions.txt");
}
void ShowQuestion()
{
if (index >= lines->Length)
{
Finish();
return;
}
label1->Text = lines[index];
String^ img = lines[index + 1];
if (img != "-")
pictureBox1->Image =
Image::FromFile(img);
else
pictureBox1->Image = nullptr;
int type =
Convert::ToInt32(lines[index + 2]);
radio1->Visible = false;
radio2->Visible = false;
radio3->Visible = false;
textBox1->Visible = false;
if (type == 1)
{
radio1->Visible = true;
radio2->Visible = true;
radio3->Visible = true;
radio1->Text = lines[index+3];
radio2->Text = lines[index+4];
radio3->Text = lines[index+5];
}
else
{
textBox1->Visible = true;
textBox1->Text = "";
}
}
void button1_Click(
Object^ sender,
EventArgs^ e)
{
bool ok = false;
int type =
Convert::ToInt32(lines[index+2]);
String^ correct =
lines[index+6];
if (type == 1)
{
int ans = 0;
if (radio1->Checked) ans=1;
if (radio2->Checked) ans=2;
if (radio3->Checked) ans=3;
if (ans ==
Convert::ToInt32(correct))
ok = true;
}
if (type == 2)
{
if (textBox1->Text ==
correct)
ok = true;
}
if (type == 3)
{
String^ a =
textBox1->Text->ToUpper();
array<String^>^ k =
correct->Split(';');
if (a->Contains(k[0]) &&
a->Contains(k[1]) &&
a->Contains(k[2]))
ok = true;
}
if (ok) score++;
index += 8;
ShowQuestion();
}
void Finish()
{
int mark = 2;
if (score >= 3) mark = 5;
else if (score == 2) mark = 4;
else if (score == 1) mark = 3;
String^ fio =
Microsoft::VisualBasic
::Interaction::InputBox(
"Введите ФИО");
StreamWriter^ sw =
gcnew StreamWriter(
"Журнал.txt", true);
sw->WriteLine(
fio + " Оценка: " + mark);
sw->Close();
MessageBox::Show(
"Оценка: " + mark);
Close();
}
};
}