@@ -80,6 +80,12 @@ namespace ProjCLR {
80
80
81
81
private: System::Windows::Forms::Button^ btn_feminino;
82
82
private: System::Windows::Forms::ToolStripMenuItem^ novoDelegadoSortearToolStripMenuItem;
83
+
84
+
85
+
86
+
87
+
88
+ private: System::Windows::Forms::ToolStripMenuItem^ médiaDeIdadesToolStripMenuItem;
83
89
private: System::Windows::Forms::DataGridViewTextBoxColumn^ Nome;
84
90
private: System::Windows::Forms::DataGridViewTextBoxColumn^ Localidade;
85
91
private: System::Windows::Forms::DataGridViewTextBoxColumn^ AnoNasc;
@@ -130,6 +136,7 @@ namespace ProjCLR {
130
136
this ->novoDelegadoSortearToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem ());
131
137
this ->estat ísticasToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem ());
132
138
this ->identificarOMaisVelhoToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem ());
139
+ this ->m édiaDeIdadesToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem ());
133
140
this ->visualiza çãoToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem ());
134
141
this ->mostrarToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem ());
135
142
this ->mostrarOcultarSeletorDeLinhasToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem ());
@@ -267,7 +274,10 @@ namespace ProjCLR {
267
274
//
268
275
// estatísticasToolStripMenuItem
269
276
//
270
- this ->estat ísticasToolStripMenuItem->DropDownItems ->AddRange (gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1 ) { this ->identificarOMaisVelhoToolStripMenuItem });
277
+ this ->estat ísticasToolStripMenuItem->DropDownItems ->AddRange (gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2 ) {
278
+ this ->identificarOMaisVelhoToolStripMenuItem ,
279
+ this ->m édiaDeIdadesToolStripMenuItem
280
+ });
271
281
this ->estat ísticasToolStripMenuItem->Name = L" estatísticasToolStripMenuItem" ;
272
282
this ->estat ísticasToolStripMenuItem->Size = System::Drawing::Size (76 , 20 );
273
283
this ->estat ísticasToolStripMenuItem->Text = L" Estatísticas" ;
@@ -279,6 +289,13 @@ namespace ProjCLR {
279
289
this ->identificarOMaisVelhoToolStripMenuItem ->Text = L" Identificar o mais velho" ;
280
290
this ->identificarOMaisVelhoToolStripMenuItem ->Click += gcnew System::EventHandler (this , &Form1::IdentificarOMaisVelhoToolStripMenuItem_Click);
281
291
//
292
+ // médiaDeIdadesToolStripMenuItem
293
+ //
294
+ this ->m édiaDeIdadesToolStripMenuItem->Name = L" médiaDeIdadesToolStripMenuItem" ;
295
+ this ->m édiaDeIdadesToolStripMenuItem->Size = System::Drawing::Size (197 , 22 );
296
+ this ->m édiaDeIdadesToolStripMenuItem->Text = L" Média de idades" ;
297
+ this ->m édiaDeIdadesToolStripMenuItem->Click += gcnew System::EventHandler (this , &Form1::MédiaDeIdadesToolStripMenuItem_Click);
298
+ //
282
299
// visualizaçãoToolStripMenuItem
283
300
//
284
301
this ->visualiza çãoToolStripMenuItem->DropDownItems ->AddRange (gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3 ) {
@@ -398,6 +415,7 @@ namespace ProjCLR {
398
415
this ->Delegado ->FillWeight = 80 ;
399
416
this ->Delegado ->HeaderText = L" Delegado" ;
400
417
this ->Delegado ->Name = L" Delegado" ;
418
+ this ->Delegado ->Visible = false ;
401
419
//
402
420
// Form1
403
421
//
@@ -411,7 +429,7 @@ namespace ProjCLR {
411
429
this ->Controls ->Add (this ->menuStrip1 );
412
430
this ->MainMenuStrip = this ->menuStrip1 ;
413
431
this ->Name = L" Form1" ;
414
- this ->Text = L" Form1 " ;
432
+ this ->Text = L" Projecto Alpha " ;
415
433
this ->Load += gcnew System::EventHandler (this , &Form1::Form1_Load);
416
434
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this ->dataGridView1 ))->EndInit ();
417
435
this ->groupBox1 ->ResumeLayout (false );
@@ -471,29 +489,22 @@ namespace ProjCLR {
471
489
ano_mais_velho = ano_linha;
472
490
}
473
491
474
-
475
492
dataGridView1->ClearSelection ();
476
493
listBox1->Items ->Clear ();
477
494
478
-
479
495
// Recolher todos os elementos com o ano igual ao mais antigo
480
496
for (size_t i = 1 ; i < n_linhas; i++)
481
497
{
482
498
ano_linha = Convert::ToInt16 (dataGridView1->Rows [i]->Cells [" AnoNasc" ]->Value );
483
499
484
500
if (ano_mais_velho == ano_linha)
485
501
{
486
-
487
502
nome = dataGridView1->Rows [i]->Cells [" Nome" ]->Value ->ToString ();
488
-
489
503
resultado = nome + " , " + ano_mais_velho;
490
504
listBox1->Items ->Add (resultado);
491
-
492
505
dataGridView1->Rows [i]->Selected = true ;
493
506
}
494
-
495
507
}
496
-
497
508
}
498
509
499
510
@@ -607,9 +618,80 @@ namespace ProjCLR {
607
618
608
619
// Repor o estado original da linha de introdução de registos.
609
620
dataGridView1->AllowUserToAddRows = linha_intro;
621
+ dataGridView1->Columns [" Delegado" ]->Visible = true ;
622
+ }
623
+
624
+
625
+ // Gerar uma nota aleatória com ponderação (menos probabilidade de ocorrência nos extremos)
626
+ private: int gerar_nota_especial ()
627
+ {
628
+ int nota;
629
+ int extra;
630
+
631
+ Random^ r = gcnew Random (); // inicializar gerador de numeros aleatórios
632
+ nota = r->Next (8 , 16 ); // gerar número aleatório para nota mediana
633
+
634
+
635
+ extra = r->Next (0 , 6 );
636
+ switch (extra)
637
+ {
638
+ case 0 : // Nota muito baixa
639
+ extra = r->Next (0 , nota);
640
+ nota = nota - extra;
641
+ break ;
642
+ case 1 : // Nota muito alta
643
+ extra = r->Next (nota, 21 );
644
+ nota = nota + extra;
645
+ break ;
646
+ default :
647
+ break ;
610
648
}
649
+ return nota;
650
+ }
651
+
652
+ private: void calcular_media ()
653
+ {
654
+ int n, idade_linha, ano_linha;
655
+ int idade_max, idade_min;
656
+ float idade_media, idade_desv_padrao=0 ;
657
+ int idades[100 ];
658
+
659
+ bool linha_intro = dataGridView1->AllowUserToAddRows ;
660
+ dataGridView1->AllowUserToAddRows = false ;
661
+ n = dataGridView1->Rows ->Count ;
662
+
663
+ for (size_t i = 0 ; i < n; i++)
664
+ {
665
+ ano_linha = Convert::ToInt16 (dataGridView1->Rows [i]->Cells [" AnoNasc" ]->Value );
666
+ idade_linha = System::DateTime::Now.Year - ano_linha;
667
+ idades[i] = idade_linha;
668
+ }
669
+
670
+ // Calcular idade média, min e max
671
+ idade_max = idade_min = idades[0 ];
672
+ for (size_t i = 0 ; i < n; i++)
673
+ {
674
+ if (idade_max < idades[i]) idade_max = idades[i];
675
+ if (idade_min > idades[i]) idade_min = idades[i];
676
+
677
+ idade_media += idades[i];
678
+ }
679
+ idade_media = (float )idade_media / (float )n;
680
+
681
+
682
+ // Calcular desvio-padrão das idades
683
+
684
+
685
+
686
+ // Mostrar resultados
687
+ listBox1->Items ->Add (" Média: " + Convert::ToString (idade_media));
688
+ listBox1->Items ->Add (" Desv. Padrão: " + Convert::ToString (idade_desv_padrao));
689
+
690
+
691
+ dataGridView1->AllowUserToAddRows = linha_intro;
692
+ }
611
693
612
- private: System::Void Btn_init_grid_Click (System::Object^ sender, System::EventArgs^ e) { init_grid (); }
694
+ private: System::Void Btn_init_grid_Click (System::Object^ sender, System::EventArgs^ e) { init_grid (); }
613
695
private: System::Void Form1_Load (System::Object^ sender, System::EventArgs^ e) { on_form_load (); }
614
696
private: System::Void ToolStripMenuItem1_Click (System::Object^ sender, System::EventArgs^ e) { identificar_mais_velho (); }
615
697
private: System::Void IdentificarOMaisVelhoToolStripMenuItem_Click (System::Object^ sender, System::EventArgs^ e) {identificar_mais_velho ();
@@ -620,5 +702,6 @@ private: System::Void MostrarToolStripMenuItem_Click(System::Object^ sender, Sys
620
702
private: System::Void MostrarOcultarSeletorDeLinhasToolStripMenuItem_Click (System::Object^ sender, System::EventArgs^ e) { alternar_row_headers (); }
621
703
private: System::Void MostrarOcultarColunaDelegadoToolStripMenuItem_Click (System::Object^ sender, System::EventArgs^ e) {alternar_col_delegado ();}
622
704
private: System::Void NovoDelegadoSortearToolStripMenuItem_Click (System::Object^ sender, System::EventArgs^ e) { sortear_delegado ();}
705
+ private: System::Void MédiaDeIdadesToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {calcular_media ();}
623
706
};
624
707
}
0 commit comments