e oferece aos usuários uma precisa e rápida
pesquisa em valores armazenados numa matriz
de inteiros, é indicado aos iniciantes em C/C++,
Que estão utilizando esta poderosa IDE
da Embarcadero, que é sem dúvidas a melhor
opção para criação de janelas em C++.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
AnsiString str_1;
AnsiString str_2;
int n;
int a = 0, b = 0;
int A [ 10 ] [ 10 ], i;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
//Limpa o Edit na entrada
{ Edit1 -> Clear ( );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Informe ( TObject *Sender ) {
Canvas -> Font -> Size = 14;
Canvas -> Font -> Color = clBlack;
Canvas -> TextOut ( 200, 240, "Por: " );
Canvas -> Font -> Color = clRed;
Canvas -> TextOut ( 240, 240, "Samuel Lima" );
Canvas -> Font -> Color = clBlack;
Canvas -> Font -> Name = "Garamond";
Canvas -> Font -> Size = 14;
Canvas -> Font -> Color = clSkyBlue;
Canvas -> TextOut ( 196, 266, "sa_sp10@hotmail.com" );
SetBkMode ( Canvas -> Handle, TRANSPARENT );
Canvas -> Font -> Color = clBlue;
Canvas -> TextOut ( 190, 260, "sa_sp10@hotmail.com" );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnCreate(TObject *Sender)
{
for( i = 0; i < 100; i++ ) {
A [ b ] [ a ] = i;
a++;
}
for ( a = 0; a < 10; a++ ) {
for ( b = 0; b < 10; b++ ) {
AppendStr ( str_1, "\t" );
if ( A [ a ] [ b ] % 10 == 0 ) {
AppendStr ( str_1, "\n" );
}
if ( A [ a ] [ b ] >= 0 && A [ a ] [ b ] < 10 ) {
AppendStr ( str_1, "0" );
}
AppendStr ( str_1, A [ a ] [ b ] );
}
}
Label1 -> Caption = str_1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnPaint(TObject *Sender)
{
Canvas -> Pen -> Color = clBlue;
Canvas -> Brush -> Color = static_cast < TColor > ( RGB ( 0,255,255 ) );
Canvas -> Pen -> Width = 10;
Canvas -> Rectangle ( 05, 05, 595, 295 );
Canvas -> Font -> Size = 14;
Canvas -> Font -> Name = "arial";
Canvas -> Font -> Color = clRed;
Canvas -> TextOut ( 148, 15, "PESQUISA EM MATRIZ DE INTEIROS" );
Canvas -> Font -> Size = 8;
Canvas -> Font -> Name = "arial";
Canvas -> Font -> Color = clBlack;
Canvas -> TextOut ( 40, 245, "Pesquisa" );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
n = StrToInt ( Edit1 -> Text );
if ( n > 99 ) {
Beep ( 1000, 500 );
}
Label1 -> Caption = " ";
str_1 = " ";
str_2 = " ";
for ( a = 0; a < 10; a++ ) {
for ( b = 0; b < 10; b++ ) {
AppendStr ( str_1, "\t" );
AppendStr ( str_2, "\t" );
if ( A [ a ] [ b ] % 10 == 0 ) {
AppendStr ( str_1, "\n" );
AppendStr ( str_2, "\n" );
}
if ( A [ a ] [ b ] >= 0 && A [ a ] [ b ] < 10 ) {
AppendStr ( str_1, "0" );
if ( n > 0 && n < 10 && A [ a ] [ b ] == n )
AppendStr ( str_2, "0" );
}
AppendStr ( str_1, A [ a ] [ b ] );
if ( n > 0 )
if ( A [ a ] [ b ] == n ) {
AppendStr ( str_2, n );
}
}
}
Label1 -> Caption = str_1;
Label2 -> Caption = str_2;
//Limpa o Edit para uma nova pesquisa
Edit1 -> Clear ( );
//Posiciona o cusrsor do Edit para uma nova pesquisa
Edit1 -> SetFocus ( );
Informe ( Sender );
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TLabel *Label1;
TLabel *Label2;
TEdit *Edit1;
TButton *Button1;
void __fastcall OnPaint(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall OnCreate(TObject *Sender);
void __fastcall Informe ( TObject *Sender );
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
object Form1: TForm1
Left = 398
Top = 133
Caption = 'PESQUISA EM MATRIZ DE INTEIROS'
ClientHeight = 300
ClientWidth = 600
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poDesigned
OnCreate = OnCreate
OnPaint = OnPaint
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 36
Top = 28
Width = 5
Height = 19
Caption = ' '
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -16
Font.Name = 'Tahoma'
Font.Style = []
ParentFont = False
end
object Label2: TLabel
Left = 36
Top = 28
Width = 5
Height = 19
Caption = ' '
Font.Charset = DEFAULT_CHARSET
Font.Color = clRed
Font.Height = -16
Font.Name = 'Tahoma'
Font.Style = []
ParentFont = False
end
object Edit1: TEdit
Left = 36
Top = 261
Width = 53
Height = 26
AutoSelect = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -15
Font.Name = 'Tahoma'
Font.Style = []
NumbersOnly = True
ParentFont = False
TabOrder = 0
Text = ' '
end
object Button1: TButton
Left = 95
Top = 261
Width = 34
Height = 25
Caption = 'Ok'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -15
Font.Name = 'Tahoma'
Font.Style = []
ParentFont = False
TabOrder = 1
OnClick = Button1Click
end
end