-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
89 lines (77 loc) · 3.33 KB
/
main.cpp
File metadata and controls
89 lines (77 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*********************************************************************
* Name: main.cpp
* Purpose: Implements simple wxWidgets application with GUI
* created using wxFormBuilder.
* Author:
* Created:
* Copyright:
* License: wxWidgets license (www.wxwidgets.org)
*
* Notes: Note that all GUI creation code is implemented in
* gui.cpp source file which is generated by wxFormBuilder.
*********************************************************************/
#include "main.h"
// initialize the application
IMPLEMENT_APP(MainApp);
////////////////////////////////////////////////////////////////////////////////
// application class implementation
////////////////////////////////////////////////////////////////////////////////
bool MainApp::OnInit()
{
SetTopWindow(new MainFrame(NULL));
GetTopWindow()->Show();
// true = enter the main loop
return true;
}
////////////////////////////////////////////////////////////////////////////////
// main application frame implementation
////////////////////////////////////////////////////////////////////////////////
MainFrame::MainFrame(wxWindow* parent)
: MainFrameBase(parent)
{
}
MainFrame::~MainFrame()
{
}
void MainFrame::OnCloseFrame(wxCloseEvent& event)
{
Destroy();
}
void MainFrame::OnExitClick(wxCommandEvent& event)
{
Destroy();
}
// Случайные числа в таблицу
void MainFrame::onRand(wxCommandEvent& event)
{
std::srand(time(0)); // Инициализация датчика случайных чисел
int rc = m_grid1->GetNumberRows(); // Определяем количество строк в таблице
int cc = m_grid1->GetNumberCols(); // Определяем количество столбцов в таблице
// Перебираем все строки таблицы
for(int i = 0; i < rc; i++) {
// Перебираем все столбцы таблицы
for(int j = 0; j < cc; j++) {
int r = std::rand() % 41 - 20; // Генерируем случайное число
m_grid1->SetCellValue(i, j, wxString::Format("%d", r)); // Занесем в ячейку таблицы нужное значение
}
}
// Программно нажмем на кнопку расчета суммы
onSum(event);
}
// Сумма чисел в таблице
void MainFrame::onSum(wxCommandEvent& event)
{
int rc = m_grid1->GetNumberRows(); // Определяем количество строк в таблице
int cc = m_grid1->GetNumberCols(); // Определяем количество столбцов в таблице
int sum = 0;
wxString ss;
// Перебираем все строки таблицы
for(int i = 0; i < rc; i++) {
// Перебираем все столбцы таблицы
for(int j = 0; j < cc; j++) {
ss = m_grid1->GetCellValue(i, j); // Считываем текстовое значение ячейки таблицы
sum += strtol(ss, NULL, 0); // Накапливаем в переменной значение суммы, преобразовав в число значение ячейки
}
}
m_staticText_Sum->SetLabel(L"Сумма = " + wxString::Format("%d", sum)); // Выдадим в компонент значение суммы
}