Skip to content

Commit 3358116

Browse files
#TDP - 13 Add dataGrid
Data grid for equability data grid for data method (count <10)
1 parent 23fb7bf commit 3358116

File tree

3 files changed

+357
-176
lines changed

3 files changed

+357
-176
lines changed

MethodsGenerationNumber/GenerationForm.cpp

Lines changed: 145 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "GenerationForm.h"
2-
#include <vector>
3-
#include <iostream>
2+
43
using namespace System;
54
using namespace System::Windows::Forms;
65

@@ -13,6 +12,75 @@ void main(array<String^>^ args)
1312
Application::Run(% form);
1413

1514
}
15+
System::Void MethodsGenerationNumber::GenerationForm::clearChart(int series)
16+
{
17+
this->chart1->Series[series]->Points->Clear();
18+
}
19+
20+
System::Void MethodsGenerationNumber::GenerationForm::clearDataGrid_data()
21+
{
22+
while (this->dg_data->Rows->Count != 0)
23+
this->dg_data->Rows->RemoveAt(0);
24+
}
25+
26+
void MethodsGenerationNumber::GenerationForm::fillDiagram(int series, int* countPointsInDiapason)
27+
{
28+
for (int i = 0; i < 10; i++)
29+
{
30+
if (countPointsInDiapason[i] != 0)
31+
fillChart(series, countPointsInDiapason[i]);
32+
}
33+
}
34+
35+
System::Void MethodsGenerationNumber::GenerationForm::fillChart(int series, int count)
36+
{
37+
this->chart1->Series[series]->Points->AddY(count);
38+
39+
}
40+
System::Void MethodsGenerationNumber::GenerationForm::fillChart(int series, int* countPointsInDiapason)
41+
{
42+
this->chart1->Series[series]->Points->AddXY("0.0-0.1", countPointsInDiapason[0]);
43+
this->chart1->Series[series]->Points->AddXY("0.1-0.2", countPointsInDiapason[1]);
44+
this->chart1->Series[series]->Points->AddXY("0.2-0.3", countPointsInDiapason[2]);
45+
this->chart1->Series[series]->Points->AddXY("0.3-0.4", countPointsInDiapason[3]);
46+
this->chart1->Series[series]->Points->AddXY("0.4-0.5", countPointsInDiapason[4]);
47+
this->chart1->Series[series]->Points->AddXY("0.5-0.6", countPointsInDiapason[5]);
48+
this->chart1->Series[series]->Points->AddXY("0.6-0.7", countPointsInDiapason[6]);
49+
this->chart1->Series[series]->Points->AddXY("0.7-0.8", countPointsInDiapason[7]);
50+
this->chart1->Series[series]->Points->AddXY("0.8-0.9", countPointsInDiapason[8]);
51+
this->chart1->Series[series]->Points->AddXY("0.9-1.0", countPointsInDiapason[9]);
52+
}
53+
54+
double expectedValue(std::vector<double> vector_random)
55+
{
56+
double sum = 0;
57+
for (int i = 0; i < vector_random.size(); i++)
58+
sum += vector_random[i];
59+
return sum / (double)vector_random.size();
60+
}
61+
62+
double dispersion(std::vector<double> vector_random, double expectedValue)
63+
{
64+
double sum = 0;
65+
for (int i = 0; i < vector_random.size(); i++)
66+
sum += (vector_random[i] - expectedValue) * (vector_random[i] - expectedValue);
67+
68+
return sum / vector_random.size();
69+
}
70+
71+
double standardDeviation(double dispersion)
72+
{
73+
return std::sqrt(dispersion);
74+
}
75+
76+
System::Void MethodsGenerationNumber::GenerationForm::fillDataGridEquability(int const& method, double expectedValue, double dispersion, double standardDeviation)
77+
{
78+
this->dg_equability->Rows[method]->Cells[0]->Value = int(expectedValue * 1000 + 0.5) / 1000.0;
79+
this->dg_equability->Rows[method]->Cells[1]->Value = int(dispersion * 1000 + 0.5) / 1000.0;
80+
this->dg_equability->Rows[method]->Cells[2]->Value = int(standardDeviation * 1000 + 0.5) / 1000.0;
81+
}
82+
83+
1684

1785
double cutNumber(int posNumbers,__int64 numbers,int const& start,int const& end)
1886
{
@@ -33,41 +101,67 @@ double cutNumber(int posNumbers,__int64 numbers,int const& start,int const& end)
33101
return R3;
34102
}
35103

36-
std::vector<double> methodOfMeanSquares(int countPoints,__int64 R0)
104+
std::vector<double> MethodsGenerationNumber::GenerationForm::methodOfMeanSquares(int countPoints,__int64 R0)
37105
{
38106
std::vector<double> randNumb;
39107

40108
for (int i = 0; i < countPoints; i++)
41109
{
42110
__int64 R1 = R0 * R0;
43-
44-
double R3 = cutNumber(8, R1,2,6);
111+
112+
double R3 = 0;// cutNumber(8, R1, 2, 6);
113+
if (R1 > 1000000)
114+
R3 = cutNumber(8, R1, 2, 6);
115+
else
116+
if (R1 > 100000)
117+
R3 = cutNumber(7, R1, 1, 6);
118+
else
119+
if (R1 > 10000)
120+
R3 = cutNumber(6, R1, 0, 5);
121+
else
122+
R3 = R1;
123+
if(i<10)
124+
fillDataGrid(R0, R1, R3);
45125
R0 = R3;
46126
randNumb.push_back(R3/10000.0);
47127
}
48128
return randNumb;
49129
}
50130

51-
std::vector<double> methodOfMult(int const& countPoints, __int64 R0,__int64& R1)
131+
std::vector<double> MethodsGenerationNumber::GenerationForm::methodOfMult(int const& countPoints, __int64 R0,__int64& R1)
52132
{
53133
std::vector<double> randNumb;
54134
for (int i = 0; i < countPoints; i++)
55135
{
56136
__int64 R3 = R0 * R1;
57-
double temp = cutNumber(8, R3,2,6);
137+
double temp = 0;
138+
if (R3 > 1000000)
139+
temp = cutNumber(8, R3, 2, 6);
140+
else
141+
if (R3 > 100000)
142+
temp = cutNumber(7, R3, 1, 6);
143+
else
144+
if (R3 > 10000)
145+
temp = cutNumber(6, R3, 0, 5);
146+
else
147+
temp = R3;
148+
if(i<10)
149+
fillDataGrid(R1, R3, temp);
58150
randNumb.push_back(temp / 10000.0);
59151
R1 = cutNumber(8, R3, 4, 8);
60152
}
61153
return randNumb;
62154
}
63155

64-
std::vector<double> methodLinearCongruen(int const& countPoints, __int64 multiplier, __int64& divisor)
156+
std::vector<double> MethodsGenerationNumber::GenerationForm::methodLinearCongruent(int const& countPoints, __int64 multiplier, __int64 divisor)
65157
{
66158
std::vector<double> randNumb;
67159
__int64 temp = multiplier;
68160
for (int i = 0; i < countPoints; i++)
69161
{
70162
__int64 R3 = multiplier * temp;
163+
if(i<10)
164+
fillDataGrid(temp, R3, R3%divisor);
71165
randNumb.push_back((R3%divisor) / 10000.0);
72166
temp = R3 % divisor;
73167
}
@@ -104,74 +198,43 @@ int* countPointBySegment(std::vector<double> vector_randomPoints)
104198
return countPointByDiapason;
105199
}
106200

107-
System::Void MethodsGenerationNumber::GenerationForm::clearChart(int series)
108-
{
109-
this->chart1->Series[series]->Points->Clear();
110-
}
111-
112-
void MethodsGenerationNumber::GenerationForm::fillDiagram(int series, int* countPointsInDiapason)
113-
{
114-
for (int i = 0; i < 10; i++)
115-
{
116-
if (countPointsInDiapason[i] != 0)
117-
fillChart(series, countPointsInDiapason[i]);
118-
}
119-
}
120-
121-
System::Void MethodsGenerationNumber::GenerationForm::fillChart(int series, int count)
122-
{
123-
this->chart1->Series[series]->Points->AddY(count);
124-
125-
}
126-
System::Void MethodsGenerationNumber::GenerationForm::fillChart(int series, int* countPointsInDiapason)
127-
{
128-
this->chart1->Series[series]->Points->AddXY("0.0-0.1", countPointsInDiapason[0]);
129-
this->chart1->Series[series]->Points->AddXY("0.1-0.2", countPointsInDiapason[1]);
130-
this->chart1->Series[series]->Points->AddXY("0.2-0.3", countPointsInDiapason[2]);
131-
this->chart1->Series[series]->Points->AddXY("0.3-0.4", countPointsInDiapason[3]);
132-
this->chart1->Series[series]->Points->AddXY("0.4-0.5", countPointsInDiapason[4]);
133-
this->chart1->Series[series]->Points->AddXY("0.5-0.6", countPointsInDiapason[5]);
134-
this->chart1->Series[series]->Points->AddXY("0.6-0.7", countPointsInDiapason[6]);
135-
this->chart1->Series[series]->Points->AddXY("0.7-0.8", countPointsInDiapason[7]);
136-
this->chart1->Series[series]->Points->AddXY("0.8-0.9", countPointsInDiapason[8]);
137-
this->chart1->Series[series]->Points->AddXY("0.9-1.0", countPointsInDiapason[9]);
138-
}
139-
140-
double expectedValue(std::vector<double> vector_random)
141-
{
142-
double sum = 0;
143-
for (int i = 0; i < vector_random.size(); i++)
144-
{
145-
sum += vector_random[i];
146-
}
147-
return sum / vector_random.size();
148-
}
149-
150-
double dispersion(std::vector<double> vector_random, double expectedValue)
151-
{
152-
double sum = 0;
153-
for (int i = 0; i < vector_random.size(); i++)
154-
sum += (vector_random[i] - expectedValue) * (vector_random[i] - expectedValue);
155201

156-
return sum / vector_random.size();
157-
}
158202

159-
double standardDeviation(double dispersion)
203+
System::Void MethodsGenerationNumber::GenerationForm::fillDataGrid(__int64 curNumb, __int64 squareCurNumb, __int64 receivedNumb)
160204
{
161-
return std::sqrt(dispersion);
205+
this->dg_data->Rows->Add();
206+
this->dg_data->Rows[this->dg_data->Rows->Count-1]->Cells[0]->Value = curNumb.ToString();
207+
this->dg_data->Rows[this->dg_data->Rows->Count-1]->Cells[1]->Value = squareCurNumb.ToString();
208+
if(receivedNumb <100)
209+
this->dg_data->Rows[this->dg_data->Rows->Count-1]->Cells[2]->Value = "0,00" + receivedNumb.ToString();
210+
else
211+
if(receivedNumb <1000)
212+
this->dg_data->Rows[this->dg_data->Rows->Count - 1]->Cells[2]->Value = "0,0" + receivedNumb.ToString();
213+
else
214+
this->dg_data->Rows[this->dg_data->Rows->Count - 1]->Cells[2]->Value = receivedNumb.ToString();
162215
}
163216

164217
System::Void MethodsGenerationNumber::GenerationForm::Btn_squre_Click(System::Object^ sender, System::EventArgs^ e)
165218
{
166219
clearChart(0);
220+
clearDataGrid_data();
167221
int countStep = Convert::ToInt32(numeric_countPoint->Text);
168222
if (countStep != 0)
169223
{
170224
__int64 R0 = Convert::ToInt64(tb_numb->Text->ToString());
171225
std::vector<double> randomNumbers = methodOfMeanSquares(countStep, R0);
172226
int* countPointByDiapason = countPointBySegment(randomNumbers);
173227
/*fillDiagram(0, countPointByDiapason);*/
174-
fillChart(0, countPointByDiapason);
228+
229+
double expectedVal = expectedValue(randomNumbers);
230+
double dispers = dispersion(randomNumbers, expectedVal);
231+
double standartDev = standardDeviation(dispers);
232+
fillDataGridEquability(0, expectedVal, dispers, standartDev);
233+
234+
fillChart(0, countPointByDiapason);
235+
double start = int((expectedVal - standartDev) * 10000 + 0.5) / 10000.0;
236+
double end = int((expectedVal + standartDev) * 10000 + 0.5) / 10000.0;
237+
lbl_intervalTest1->Text = "Èíòåðâàë ÷àñòîòíîãî òåñòà 1: (" + start + " ; " + end + ")" + (int((end-start) * 1000 + 0.5) / 1000.0) * 100 + "%";
175238
}
176239
else
177240
{
@@ -182,6 +245,7 @@ System::Void MethodsGenerationNumber::GenerationForm::Btn_squre_Click(System::Ob
182245
System::Void MethodsGenerationNumber::GenerationForm::Btn_mult_Click(System::Object^ sender, System::EventArgs^ e)
183246
{
184247
clearChart(1);
248+
clearDataGrid_data();
185249
int countPoints = Convert::ToInt32(numeric_countPoint->Text);
186250
if (countPoints != 0)
187251
{
@@ -190,7 +254,16 @@ System::Void MethodsGenerationNumber::GenerationForm::Btn_mult_Click(System::Obj
190254
std::vector<double> randomNumbers = methodOfMult(countPoints, R0,R1);
191255
int* countPointByDiapason = countPointBySegment(randomNumbers);
192256
/*fillDiagram(1, countPointByDiapason);*/
257+
258+
double expectedVal = expectedValue(randomNumbers);
259+
double dispers = dispersion(randomNumbers, expectedVal);
260+
double standartDev = standardDeviation(dispers);
261+
fillDataGridEquability(1, expectedVal, dispers, standartDev);
262+
193263
fillChart(1, countPointByDiapason);
264+
double start = int((expectedVal - standartDev) * 10000 + 0.5) / 10000.0;
265+
double end = int((expectedVal + standartDev) * 10000 + 0.5) / 10000.0;
266+
lbl_intervalTest2->Text = "Èíòåðâàë ÷àñòîòíîãî òåñòà 2: (" + start + " ; " + end + ")" + (int((end - start) * 1000 + 0.5) / 1000.0) * 100 + "%";
194267
}
195268
else
196269
{
@@ -201,15 +274,25 @@ System::Void MethodsGenerationNumber::GenerationForm::Btn_mult_Click(System::Obj
201274
System::Void MethodsGenerationNumber::GenerationForm::Btn_linearCongruentMethod_Click(System::Object^ sender, System::EventArgs^ e)
202275
{
203276
clearChart(2);
277+
clearDataGrid_data();
204278
int countPoints = Convert::ToInt32(numeric_countPoint->Text);
205279
if (countPoints != 0)
206280
{
207281
__int64 R0 = Convert::ToInt64(tb_numb->Text->ToString());
208282
__int64 R1 = Convert::ToInt64(tb_numb2->Text->ToString());
209-
std::vector<double> randomNumbers = methodLinearCongruen(countPoints, R0, R1);
283+
std::vector<double> randomNumbers = methodLinearCongruent(countPoints, R0, R1);
210284
int* countPointByDiapason = countPointBySegment(randomNumbers);
211285
/*fillDiagram(2, countPointByDiapason);*/
286+
287+
double expectedVal = expectedValue(randomNumbers);
288+
double dispers = dispersion(randomNumbers, expectedVal);
289+
double standartDev = standardDeviation(dispers);
290+
fillDataGridEquability(2, expectedVal, dispers, standartDev);
291+
212292
fillChart(2, countPointByDiapason);
293+
double start = int((expectedVal - standartDev) * 10000 + 0.5) / 10000.0;
294+
double end = int((expectedVal + standartDev) * 10000 + 0.5) / 10000.0;
295+
lbl_intervalTest3->Text = "Èíòåðâàë ÷àñòîòíîãî òåñòà 3: (" + start + " ; " + end + ")" + (int((end - start) * 1000 + 0.5) / 1000.0) * 100 + "%";
213296
}
214297
else
215298
{

0 commit comments

Comments
 (0)