/
IvanPolyakov
/
LabWork_5
Обзор
Документация
Войти
/
IvanPolyakov
/
LabWork_5
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Unit1.cpp
143 строки
4 KB
IvanPolyakov
create: Mendeleev.cpp, MendeleevPCH1.h, Unit1.cpp, Unit1.dfm, Unit1.h, Mendeleev.cbproj
06 май 2026, 08:08
Верифицирован
06 май 2026, 08:08
8c8233d
Код
Авторство
О чём код?
#include <vcl.h> #pragma hdrstop #include "Unit1.h" #include <math.h> #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //----------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //----------------------------------------------------- int CurrentZ = 1; String CurrentName = "Водород"; float Angle = 0; //----------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { // ===== Таблица Менделеева (упрощённая) ===== Grid->Cells[0][0] = "Водород"; Grid->Cells[17][0] = "Гелий"; Grid->Cells[0][1] = "Литий"; Grid->Cells[1][1] = "Бериллий"; Grid->Cells[12][1] = "Бор"; Grid->Cells[13][1] = "Углерод"; Grid->Cells[14][1] = "Азот"; Grid->Cells[15][1] = "Кислород"; Grid->Cells[16][1] = "Фтор"; Grid->Cells[17][1] = "Неон"; Grid->Cells[0][2] = "Натрий"; Grid->Cells[1][2] = "Магний"; Grid->Cells[12][2] = "Алюминий"; Grid->Cells[13][2] = "Кремний"; Grid->Cells[14][2] = "Фосфор"; Grid->Cells[15][2] = "Сера"; Grid->Cells[16][2] = "Хлор"; Grid->Cells[17][2] = "Аргон"; Timer1->Interval = 50; Timer1->Enabled = true; LabelInfo->Caption = "Выберите элемент"; } //----------------------------------------------------- void __fastcall TForm1::GridClick(TObject *Sender) { String el = Grid->Cells[Grid->Col][Grid->Row]; if (el == "Водород") ShowAtom(1, el); else if (el == "Гелий") ShowAtom(2, el); else if (el == "Литий") ShowAtom(3, el); else if (el == "Бериллий")ShowAtom(4, el); else if (el == "Бор") ShowAtom(5, el); else if (el == "Углерод") ShowAtom(6, el); else if (el == "Азот") ShowAtom(7, el); else if (el == "Кислород")ShowAtom(8, el); else if (el == "Фтор") ShowAtom(9, el); else if (el == "Неон") ShowAtom(10, el); else if (el == "Натрий") ShowAtom(11, el); else if (el == "Магний") ShowAtom(12, el); else if (el == "Алюминий")ShowAtom(13, el); else if (el == "Кремний") ShowAtom(14, el); else if (el == "Фосфор") ShowAtom(15, el); else if (el == "Сера") ShowAtom(16, el); else if (el == "Хлор") ShowAtom(17, el); else if (el == "Аргон") ShowAtom(18, el); } //----------------------------------------------------- // ⭐ ВОТ ГЛАВНОЕ ИСПРАВЛЕНИЕ (linker error fix) void TForm1::ShowAtom(int Z, String name) { CurrentZ = Z; CurrentName = name; LabelInfo->Caption = "Элемент: " + CurrentName + "\r\n" + "Порядковый номер: " + IntToStr(CurrentZ) + "\r\n" + "Электроны: " + IntToStr(CurrentZ); PaintBox1->Repaint(); } //----------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { Angle += 0.1f; PaintBox1->Repaint(); } //----------------------------------------------------- void __fastcall TForm1::PaintBox1Paint(TObject *Sender) { TCanvas *c = PaintBox1->Canvas; int cx = PaintBox1->Width / 2; int cy = PaintBox1->Height / 2; // фон c->Brush->Color = clWhite; c->FillRect(PaintBox1->ClientRect); // орбита c->Pen->Color = clSilver; c->Ellipse(cx - 80, cy - 80, cx + 80, cy + 80); // ядро c->Brush->Color = clRed; c->Ellipse(cx - 20, cy - 20, cx + 20, cy + 20); // электроны c->Brush->Color = clBlue; for (int i = 0; i < CurrentZ; i++) { double a = Angle + (2 * 3.1415926 / CurrentZ) * i; int x = cx + cos(a) * 80; int y = cy + sin(a) * 80; c->Ellipse(x - 5, y - 5, x + 5, y + 5); } } //-----------------------------------------------------