
- •Індивідуальне завдання
- •Аналітичний розділ
- •Побудова інформаційно-математичної моделі задачі
- •Об’єктна модель
- •4. Визначення структури даних
- •5. Розробка інтерфейсу програми з користувачем
- •6. Складання коду програми:
- •7. Реалізація проекту у візуальному середовищі
- •8. Аналіз програми
- •9. Тестування програми
- •10. Інструкція з експлуатації програми
- •10.1 Вимоги до технічного забезпечення
- •10.2 Інсталяція програмного забезпечення
- •10.3 Експлуатація програмного продукту
- •11. Аналіз отриманих результатів
6. Складання коду програми:
Робота з чергою:
Запрограмуємо кнопку «Створити чергу»:
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
x.create_cherga();
button3->Enabled=false;
timer3->Start();
}
Запрограмуємо кнопку «Додати елемент»:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
if (x.kilk_el>=9)
{
MessageBox::Show("Черга переповнена");
return;
}
if (textBox1->Text!=""){
if (textBox1->Text->Length>2)
{
MessageBox::Show("Можна вводити значення з діапазону 0..99");
textBox1->Clear();
return;
}
x.kilk_el++;
x.getel(pictureBox1,textBox1,x.i);
if (x.kilk_el>1)
x.v-=x.mas[x.i]->Width + 2;
else
x.v=760;
timer1->Start();
button1->Enabled=false;
button2->Enabled=false;
textBox1->Enabled=false;
textBox1->Clear();
}
else
MessageBox::Show("Введіть значення!!!");
}
Запрограмуємо кнопку «Видалити елемент»:
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
textBox1->Clear();
if (x.kilk_el>0)
{
x.mas[9]=x.mas[0];
x.kilk_el--;
if (x.i>1)
x.j=x.mas[x.i-2]->Left;
for (int ii=0; ii<x.i; ii++)
x.mas[ii] = x.mas[ii+1];
x.i--;
x.d=x.mas[9]->Left;
x.k=0;
timer2->Start();
button1->Enabled=false;
button2->Enabled=false;
textBox1->Enabled=false;
}
else
MessageBox::Show("Черга порожня");
}
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
if (x.mas[x.i]->Top<=135)
x.mas[x.i]->Top+=4;
if(x.mas[x.i]->Left<x.v && x.mas[x.i]->Top>133)
x.mas[x.i]->Left+=8;
if (x.mas[x.i]->Top>133 && x.mas[x.i]->Left>x.v-7)
{
button1->Enabled=true;
button2->Enabled=true;
textBox1->Enabled=true;
timer1->Stop();
x.i++;
}
}
Програмний код компоненти timer1, яка відповідає за додавання елементів до черги:
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
if (x.mas[x.i]->Top<=135)
x.mas[x.i]->Top+=4;
if(x.mas[x.i]->Left<x.v && x.mas[x.i]->Top>133)
x.mas[x.i]->Left+=8;
if (x.mas[x.i]->Top>133 && x.mas[x.i]->Left>x.v-7)
{
button1->Enabled=true;
button2->Enabled=true;
textBox1->Enabled=true;
timer1->Stop();
x.i++;
}
}
Програмний код компоненти timer2, яка відповідає за видалення та зсув елементів черги:
private: System::Void timer2_Tick(System::Object^ sender, System::EventArgs^ e)
{
if (x.mas[9]->Left<=837)
x.mas[9]->Left+=4;
if (x.mas[9]->Top<=340 && x.mas[9]->Left>834)
x.mas[9]->Top+=4;
if (x.mas[9]->Top>337 && x.mas[9]->Left>=834 && x.kilk_el>=1)
{
if (x.mas[x.k]->Left<=x.d)
x.mas[x.k]->Left+=8;
if (x.mas[x.k]->Left>x.d-7 && x.k<x.i)
{
x.d-=80;
x.k++;
}
};
if (x.i==0)
x.i=10;
if (x.mas[9]->Top>343 && x.mas[9]->Left>=834 && x.mas[x.i-1]->Left>=x.j-3){
if (x.kilk_el==0)
x.i=0;
Sleep(100);
delete x.mas[9];
x.v+=80;
timer2->Stop();
button1->Enabled=true;
button2->Enabled=true;
textBox1->Enabled=true;
};
}
Робота зі списком:
1) Запрограмуємо кнопку «Створити список»:
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e)
{
y.create_spusok();
label4->Parent=pictureBox1;
label4->Top=50+20*y.i+4;
timer1->Start();
button3->Enabled=false;
timer3->Start();
y.index_list(comboBox4);
}
2) Запрограмуємо кнопку «Створити елемент»:
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e)
{
comboBox2->SelectedIndex=-1;
y.index_list(comboBox3);
if (y.kilk_el>4)
{
MessageBox::Show("Список переповнений");
return;
}
y.addel(pictureBox1,50+40*y.i,80,y.i);
y.mas[y.i]->Text="*"+System::Convert::ToString(y.z);
y.addel(pictureBox1,50+40*y.i,240,y.j);
y.mas[y.j]->Text=System::Convert::ToString(y.z);
y.addel(pictureBox1,50+40*y.i,320,y.n);
y.mas[y.n]->Width=140;
y.mas[y.n]->Text="NUL";
y.i++;
y.j++;
y.n++;
button1->Enabled=true;
button2->Enabled=false;
button4->Enabled=false;
comboBox1->Enabled=true;
comboBox2->Enabled=false;
}
3) Запрограмуємо кнопку «Додати елемент»:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
comboBox2->SelectedIndex=-1;
if (comboBox1->Text=="")
{
MessageBox::Show("Виберіть місце вставки нового елемента!");
return;
}
y.kilk_el++;
if(comboBox1->SelectedIndex==0)
{
y.dod_pochatok(label4);
label4->Top+=40*(y.i-y.s-1);
}
else
if(comboBox1->SelectedIndex==1)
y.dod_kinets();
else
{
if(!y.check)
{
MessageBox::Show("Ця дія тимчасово недоступна");
comboBox1->SelectedIndex=-1;
return;
}
else
if(comboBox3->Text == "")
{
MessageBox::Show("Виберіть індекс після якого потрібно вставити елемент");
return;
}
y.dod_pislya_indeksa_1(comboBox3);
}
timer2->Start();
button1->Enabled=false;
button2->Enabled=false;
button4->Enabled=false;
comboBox1->Enabled=false;
comboBox2->Enabled=false;
}
4) Запрограмуємо кнопку «Видалити елемент»:
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e)
{
y.p=0;
if (comboBox2->Text=="")
{
MessageBox::Show("Виберіть елемент для видалення!");
return;
}
if (y.kilk_el>=1)
{
if (comboBox2->SelectedIndex==0)
{
if (y.kilk_el>1)
{
y.vud_pochatok(label4);
y.kilk_el--;
}
else
{
y.kilk_el--;
delete y.mas[0];
delete y.mas[5];
delete y.mas[10];
}
}
if (comboBox2->SelectedIndex==1)
{
if (y.kilk_el>1)
{
y.vud_kinets();
}
else
{
delete y.mas[y.i-1];
delete y.mas[y.j-1];
delete y.mas[y.n-1];
}
y.kilk_el--;
}
if (comboBox2->SelectedIndex == 2)
{
if(!y.check)
{
MessageBox::Show("Ця дія тимчасово недоступна");
comboBox2->SelectedIndex=-1;
return;
}
else
if(comboBox4->Text == "")
{
MessageBox::Show("Виберіть індекс після якого потрібно видалити елемент ");
return;
}
y.vud_pislya_indeksa(comboBox4);
timer2->Start();
y.kilk_el--;
}
if (y.kilk_el<1)
{
label4->Visible=false;
button3->Enabled=true;
button1->Enabled=false;
button2->Enabled=false;
button4->Enabled=false;
comboBox1->Enabled=false;
comboBox2->Enabled=false;
return;
}
else
if(comboBox2->SelectedIndex != 2)
{
button2->Enabled=false;
comboBox2->Enabled=false;
button4->Enabled=false;
timer2->Start();
}
}
else
MessageBox::Show("Список порожній");
}
5) Програмний код компоненти timer1, яка відповідає за анімаційне створення форми, та створення першого елементу списку:
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e)
{
if (spisok::Height<539)
spisok::Height+=16;
else
{
timer1->Stop();
y.kilk_el++;
y.addel(pictureBox1,50+20*y.i,80,y.i);
y.mas[y.i]->Text="*1";
y.addel(pictureBox1,50+20*y.i,240,y.j);
y.mas[y.j]->Text="1";
y.addel(pictureBox1,50+20*y.i,320,y.n);
y.mas[y.n]->Width=140;
y.mas[y.n]->Text="NUL";
y.i++;
y.j++;
y.n++;
label4->Visible=true;
button4->Enabled=true;
button2->Enabled=true;
comboBox2->Enabled=true;
}
}
6) Програмний код компоненти timer2, яка відповідає за зміну поля адреси елементу списку:
private: System::Void timer2_Tick(System::Object^ sender, System::EventArgs^ e) {
if (y.mas[y.d]->Left<480 && y.mas[y.d]->BackColor==System::Drawing::Color::Red)
y.mas[y.d]->Left+=4;
if(y.mas[y.d]->Left>=477 && y.mas[y.d]->BackColor==System::Drawing::Color::Red)
{
Sleep(1000);
if (comboBox2->SelectedIndex==1)
y.mas[y.d]->Text="NUL";
else
y.mas[y.d]->Text=y.mas[y.s]->Text;
y.mas[y.d]->BackColor=System::Drawing::Color::Yellow;
}
if (y.mas[y.d]->Left>320 && y.mas[y.d]->BackColor==System::Drawing::Color::Yellow)
y.mas[y.d]->Left-=4;
if (y.mas[y.d]->Left<=323 && y.mas[y.d]->BackColor==System::Drawing::Color::Yellow)
{
timer2->Stop();
if (comboBox2->SelectedIndex==0 || comboBox2->SelectedIndex==1 || comboBox2->SelectedIndex==2)
{
y.i--;
y.j--;
y.n--;
if (label4->Top > y.mas[y.v]->Top && label4->Top < y.mas[y.v]->Top + 33)
y.p=1;
y.zsuv();
if (y.v != y.n)
{
timer4->Start();
label4->Visible=false;
}
else
{
button2->Enabled=true;
comboBox2->Enabled=true;
button4->Enabled=true;
label4->Visible=true;
}
}
if (comboBox2->SelectedIndex==1 || comboBox2->SelectedIndex==2)
{
delete y.mas[16];
delete y.mas[17];
delete y.mas[18];
}
if (comboBox1->SelectedIndex==0 || comboBox1->SelectedIndex==1)
{
comboBox1->SelectedIndex=-1;
button4->Enabled=true;
button2->Enabled=true;
comboBox2->Enabled=true;
comboBox2->SelectedIndex=-1;
}
else
comboBox2->SelectedIndex=-1;
y.kilk=y.kilk_el;
y.set_index();
if (comboBox1->SelectedIndex==2)
{
y.dod_pislya_indeksa_2();
timer2->Start();
comboBox1->SelectedIndex=-1;
y.mas[y.d]->Left+=4;
}
if (y.mas[y.d]->Left<323 && y.u==1)
{
button4->Enabled=true;
button2->Enabled=true;
comboBox2->Enabled=true;
y.u=0;
}
y.index_list(comboBox4);
}
}
7) Програмний код компоненти timer3, яка відповідає за зміну режиму (приховати/показати) comboBox-ів, які використовуються для таких операцій над списком: «Видалити елемент після індексу», «Додати елемент після індексу»:
private: System::Void timer3_Tick(System::Object^ sender, System::EventArgs^ e) {
if (comboBox1->SelectedIndex==2)
comboBox3->Visible=true;
else
comboBox3->Visible=false;
if (comboBox2->SelectedIndex==2)
comboBox4->Visible=true;
else
comboBox4->Visible=false;
}
8) Програмний код компоненти timer4, яка використовується для зсуву елементів списку(графічного) в тому випадку якщо був видалений не останній елемент(у порядку відображення на екрані):
private: System::Void timer4_Tick(System::Object^ sender, System::EventArgs^ e)
{ if (y.mas[y.v]->Top>y.c)
y.up(label4);
else
{ timer4->Stop();
if (y.p==1)
label4->Top-=40;
comboBox2->SelectedIndex=-1;
button2->Enabled=true;
comboBox2->Enabled=true;
button4->Enabled=true;
label4->Visible=true;
}
}