-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrols.cpp
37 lines (34 loc) · 1.39 KB
/
controls.cpp
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
#include "main.h"
#include <wx/msgdlg.h>
// Ñëó÷àéíûå ÷èñëà â òàáëèöó
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)); // Âûäàäèì â êîìïîíåíò çíà÷åíèå ñóììû
}