Em um map cada elemento é um par,
e seu uso é indicado para uso e recuperação de dados
dentro de uma coleção.
Podemos alterar seu valor diretamente,
mas os valores de suas chaves são constantes,
e não são permitidos que se altere.
Um map é um conteiner de tamanho variável,
e nele é possível recuperar valores de elementos,
baseados nas chaves relacionadas.
Um map ordena seus elementos de forma ascendente,
e exclui elementos ou chaves repetidas.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <map>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
std::map < String, int > mp = {
{ " Ana Celia ", 1 },
{ " Eder Costa ", 5 },
{ " Humberto Gomes ", 8 },
{ " Dijalma Lacerda ", 4 },
{ " Caroline Silva ", 3 },
{ " Igor Goncalves ", 9 },
{ " Bruna Carla ", 2 },
{ " Fabio Quadros ", 6 },
{ " Geany Barros ", 7 },
{ " Jaqueline Vega ",10 }};
//---------------------------------------------------------------------------
void __fastcall TForm1::Informe ( TObject *Sender ) {
//SetBkColor ( Canvas -> Handle, RGB ( 255, 182, 193 ) );
Canvas -> Font-> Style = TFontStyles ( ) << fsItalic;
Canvas -> Font -> Size = 11;
Canvas -> Font -> Name = "Arial";
Canvas -> Font -> Color = clBlack;
Canvas -> TextOut ( 200, 250, "Por: " );
Canvas -> Font -> Color = clRed;
Canvas -> TextOut ( 240, 250, "Samuel Lima" );
Canvas -> Font -> Color = clBlue;
Canvas -> TextOut ( 200, 265, "sa_sp10@hotmail.com" );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
Label1 -> Visible = true;
Label1 -> Font -> Size = 13;
Label1 -> Font -> Name = "Arial";
Label1 -> Font-> Style = TFontStyles ( ) << fsBold << fsItalic;
//Label1 -> Font -> Color = clBlack;
Label1 -> Font -> Color = static_cast < TColor > ( RGB ( 0, 0, 0 ) );
Label1 -> Color = static_cast < TColor > ( RGB ( 0, 255, 255 ) );
Label1 -> Transparent = False;
Label1 -> Width = 100;
Label1 -> Height = 70;
Label1 -> Left = 200;
Label1 -> Top = 35;
Label2 -> Visible = true;
Label2 -> Font -> Size = 13;
Label2 -> Font -> Name = "Arial";
Label2 -> Font-> Style = TFontStyles ( ) << fsBold << fsItalic;
//Label1 -> Font -> Color = clBlack;
Label2 -> Font -> Color = static_cast < TColor > ( RGB ( 0, 0, 0 ) );
Label2 -> Color = static_cast < TColor > ( RGB ( 0, 255, 55 ) );
Label2 -> Transparent = False;
Label2 -> Width = 100;
Label2 -> Height = 70;
Label2 -> Left = 350;
Label2 -> Top = 35;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint ( TObject *Sender ) {
//Alterando a cor do form
Canvas -> Brush -> Color = static_cast < TColor > ( RGB ( 255, 255, 205 ) );
Canvas -> Font -> Size = 14;
Canvas -> Font-> Style = TFontStyles ( ) << fsBold << fsItalic;
Canvas -> Font -> Name = "Arial";
Canvas -> Pen -> Width = 10;
//Colorindo o roundrect com rgb
Canvas -> Pen -> Color = static_cast < TColor > ( RGB ( 231, 220, 202 ) );
Canvas -> RoundRect ( 05, 05, 595, 295, 25, 25 );
//Colorindo a cor de frente do canvas com RGB
SetTextColor ( Canvas -> Handle, RGB ( 255, 0, 0 ) );
//SetBkColor ( Canvas -> Handle, RGB ( 0, 255, 103 ) );
Canvas -> TextOut ( 70, 10, "CONTAINER MAP - DECLARANDO E INICIALIZANDO" );
Informe ( Sender );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender ) {
Label_Manual ( Sender );
String str_1;
String str_2;
for ( auto p : mp ) {
if ( p.second % 1 == 0 ) {
str_1 += "\n";
str_2 += "\n";
}
str_1 += p.first;
str_2 += " ";
str_2 += p.second;
}
Label1 -> Caption = str_1;
Label2 -> Caption = str_2;
}
//---------------------------------------------------------------------------
Nenhum comentário:
Postar um comentário
Observação: somente um membro deste blog pode postar um comentário.