sábado, 25 de julho de 2020

FMX - marcando as ocorrências de múltiplos

Se criamos um programa semelhante a este no Qt,
e mostramos seu funcionamento para todos os que
se interessam por programação em desktop,
o que poderia nos impedir de criar também uma versão
no C++ builder da Embarcadero?
nós somos fanáticos por C++ e isto faz a diferença. 
Este programa marca todas as ocorrências 
dos múltiplos de um número dentro de uma matriz
de inteiros de dez mil elementos.



//---------------------------------------------------------------------------

#include <fmx.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
#pragma resource ("*.Windows.fmx", _PLAT_MSWINDOWS)

TForm1 *Form1;
//AnsiString str_1;
//AnsiString str_2;
AnsiString str_3 = "C++ BUILDER - MARCANDO AS OCORRÊNCIAS DE MÚLTIPLOS";
int n;
int a = 0, b = 0;
int A [ 100 ] [ 100 ], i;
bool x = false;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1 ( TComponent* Owner )
: TForm ( Owner )
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Imprime_matriz ( TObject* Sender ) {
    AnsiString str_1;
//AnsiString str_2;
  for( i = 0; i < 10000; i++ ) {
A [ b ] [ a ] =  i;
a++;
}
for ( a = 0; a < 100; a++ ) {
for ( b = 0; b < 100; 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, "000" );
}
if ( A [ a ] [ b ] >= 10 && A [ a ] [ b ] < 100 ) {
AppendStr ( str_1, "00" );
}
if ( A [ a ] [ b ] >= 100 && A [ a ] [ b ] < 1000 ) {
AppendStr ( str_1, "0" );
}
   AppendStr ( str_1, A [ a ] [ b ] );

}
}
Label1 -> Text = str_1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
   Rectangle1 -> Width = 750;
   Rectangle1 -> Height = 400;
   Rectangle1 -> Position -> X = 0;
   Rectangle1 -> Position -> Y = 0;

   Edit1 -> SetFocus ( );
   Edit1 -> Font -> Size = 10;
   Edit1 -> Width = 70;
   Edit1 -> Height = 20;
   Edit1 -> Position -> X = 80;
   Edit1 -> Position -> Y = 353;

   Button1 -> Visible = true;
   Button1 -> Width = 30;
   Button1 -> Height = 20;
   Button1 -> Position -> X = 165;
   Button1 -> Position -> Y = 353;
   Button1 -> TextSettings -> Font -> Family = "Arial";
   //Button1 -> TextSettings -> Font -> Size = 16;
   Button1 -> TextSettings -> FontColor = claBlue;

   Label1 -> Position -> X = 40;
   Label1 -> Position -> Y = -30;
   Label1 -> Size -> Width = 650;
   Label1 -> Size -> Height = 16720;
   Label1 -> TextSettings -> Font -> Size = 16;
   Label1 -> TextSettings -> FontColor = claBlack;
   Label1 -> Font -> Style = TFontStyles ( ) << fsBold;

   Label2 -> Position -> X = 40;
   Label2 -> Position -> Y = -30;
   Label2 -> Size -> Width = 650;
   Label2 -> Size -> Height = 16720;
   Label2 -> TextSettings -> Font -> Size = 16;
   Label2 -> TextSettings -> FontColor = claRed;
   Label2 -> Font -> Style = TFontStyles ( ) << fsBold;

   Text1 -> Position -> X = 20;
   Text1 -> Position -> Y = 20;
   Text1 -> Size -> Width = 700;
   Text1 -> Size -> Height = 20;
   Text1 -> TextSettings -> Font -> Size = 20;
   Text1 -> TextSettings -> FontColor = claRed;
   //Text1 -> AutoSize = True;
   Text1 -> Size -> PlatformDefault = False;
   Text1 -> Font -> Style = TFontStyles ( ) << fsBold;
   Text1 -> Text = str_3;

   Text2 -> Position -> X = -210;
   Text2 -> Position -> Y = 330;
   Text2 -> Size -> Width = 700;
   Text2 -> Size -> Height = 20;
   Text2 -> TextSettings -> Font -> Size = 12;
   Text2 -> TextSettings -> FontColor = claBlack;
   //Text2 -> AutoSize = True;
   Text2 -> Size -> PlatformDefault = False;
   //Text2 -> Font -> Style = TFontStyles ( ) << fsBold;
   Text2 -> Text = "Digite um número: ";

   Text3 -> Position -> X = 30;
   Text3 -> Position -> Y = 320;
   Text3 -> Size -> Width = 700;
   Text3 -> Size -> Height = 20;
   Text3 -> TextSettings -> Font -> Size = 18;
   Text3 -> TextSettings -> FontColor = claBlack;
   //Text3 -> AutoSize = True;
   Text3 -> Size -> PlatformDefault = False;
   Text3 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

   Text4 -> Position -> X = 280;
   Text4 -> Position -> Y = 346;
   Text4 -> Size -> Width = 70;
   Text4 -> Size -> Height = 20;
   Text4 -> TextSettings -> Font -> Size = 18;
   Text4 -> TextSettings -> FontColor = claBlack;
   //Text4 -> AutoSize = True;
   Text4 -> Size -> PlatformDefault = False;
   Text4 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
   Text4 -> Text = "Por : ";

   Text5 -> Position -> X = 40;
   Text5 -> Position -> Y = 346;
   Text5 -> Size -> Width = 700;
   Text5 -> Size -> Height = 20;
   Text5 -> TextSettings -> Font -> Size = 18;
   Text5 -> TextSettings -> FontColor = claRed;
   //Text5 -> AutoSize = True;
   Text5 -> Size -> PlatformDefault = False;
   Text5 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
   Text5 -> Text = "Samuel lima";

   Text6 -> Position -> X = 36;
   Text6 -> Position -> Y = 365;
   Text6 -> Size -> Width = 700;
   Text6 -> Size -> Height = 20;
   Text6 -> TextSettings -> Font -> Size = 18;
   Text6 -> TextSettings -> FontColor = claBlue;
   //Text6 -> AutoSize = True;
   Text6 -> Size -> PlatformDefault = False;
   Text6 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
   Text6 -> Text = "sa_sp10@hotmail.com";

   Form1 -> Left = 426;
   Form1 -> Top = 85;
   Form1 -> Caption = "C++ BUILDER - MÚLTIPLOS EM MATRIZ DE INTEIROS";
   Form1 -> ClientHeight = 400;
   Form1 -> ClientWidth = 750;

   ScrollBox1 -> Width = 720;
   ScrollBox1 -> Height = 250;
   ScrollBox1 -> Position -> X = 20;
   ScrollBox1 -> Position -> Y = 68;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender ) {
Label_Manual ( Sender );
Imprime_matriz ( Sender );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click ( TObject *Sender ) {
   int totMult;
   AnsiString str_1;
   AnsiString str_2;
   String str_4;
    Beep ( 500, 500 );
n = StrToInt ( Edit1 -> Text );
str_2 = " ";
/*
for ( a = 0; a < 100; a++ ) {
for ( b = 0; b < 100; b++ ) {
AppendStr ( str_2, "\t" );
if ( A [ a ] [ b ] % 10 == 0 ) {
AppendStr ( str_2, "\n" );
}
if ( A [ a ] [ b ] >= 0 && A [ a ] [ b ] < 10 && ( A [ a ] [ b ] % n == 0 ) ) {
AppendStr ( str_2, "000" );
}
if ( A [ a ] [ b ] >= 10 && A [ a ] [ b ] < 100 && ( A [ a ] [ b ] % n == 0 ) ) {
AppendStr ( str_2, "00" );
}
if ( A [ a ] [ b ] >= 100 && A [ a ] [ b ] < 1000 && ( A [ a ] [ b ] % n == 0 ) ) {
AppendStr ( str_2, "0" );
}
if ( A [ a ] [ b ] % n == 0 ) {
++totMult;
AppendStr ( str_2, A [ a ] [ b ] );
str_4 = totMult - 2;
   }
}
}

//Label2 -> Text = str_2;

Text3 -> Text = " ";
Text3 -> Text = Text3 -> Text + "Encontrado ";
Text3 -> Text = Text3 -> Text + str_4;
Text3 -> Text = Text3 -> Text + " múltiplos de ";
Text3 -> Text = Text3 -> Text + n;
//Text3 -> Text = Text3 -> Text + " na matriz";
*/
Label1 -> Text = " ";
for ( a = 0; a < 100; a++ ) {
for ( b = 0; b < 100; 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 ] % n == 0 ) {
if ( A [ a ] [ b ] >= 0 && A [ a ] [ b ] < 10 ) {
AppendStr ( str_1, "000" );
}
if ( A [ a ] [ b ] >= 10 && A [ a ] [ b ] < 100 ) {
AppendStr ( str_1, "00" );
}
if ( A [ a ] [ b ] >= 100 && A [ a ] [ b ] < 1000 ) {
AppendStr ( str_1, "0" );
}
str_1 += A [ a ] [ b ];
   }
   else {
   if ( A [ a ] [ b ] % 10 == 0 ) {
AppendStr ( str_2, "\n" );
}
if ( A [ a ] [ b ] >= 0 && A [ a ] [ b ] < 10 ) {
AppendStr ( str_2, "000" );
}
if ( A [ a ] [ b ] >= 10 && A [ a ] [ b ] < 100 ) {
AppendStr ( str_2, "00" );
}
if ( A [ a ] [ b ] >= 100 && A [ a ] [ b ] < 1000 ) {
AppendStr ( str_2, "0" );
}
str_2 += A [ a ] [ b ];
   }
   //==================================================================
}
}

Label1 -> Text = str_2;
//Label2 -> Text = str_1;

Edit1 -> Text = "";
Edit1 -> SetFocus ( );
}

//---------------------------------------------------------------------------


//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.Edit.hpp>
#include <FMX.Layouts.hpp>
#include <FMX.StdCtrls.hpp>
#include <FMX.Types.hpp>
#include <FMX.Objects.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TRectangle *Rectangle1;
TEdit *Edit1;
TButton *Button1;
TScrollBox *ScrollBox1;

TLabel *Label1;
TLabel *Label2;

TText *Text1;
TText *Text2;
TText *Text3;
TText *Text4;
TText *Text5;
TText *Text6;

void __fastcall FormShow ( TObject *Sender );
void __fastcall Label_Manual ( TObject *Sender );
void __fastcall Button1Click (TObject *Sender );
void __fastcall Imprime_matriz ( TObject* Sender );

private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif



object Form1: TForm1
  Left = 426
  Top = 85
  Caption = 'Form1'
  ClientHeight = 350
  ClientWidth = 789
  Fill.Kind = Gradient
  Fill.Gradient.Points = <
    item
      Color = xFF00FF1A
      Offset = 0.000000000000000000
    end
    item
      Color = claWhite
      Offset = 1.000000000000000000
    end>
  Fill.Gradient.StartPosition.X = 0.500000000000000000
  Fill.Gradient.StartPosition.Y = 1.000000000000000000
  Fill.Gradient.StopPosition.X = 0.499999970197677600
  Fill.Gradient.StopPosition.Y = 0.000000000000000000
  Position = Designed
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop]
  OnShow = FormShow
  Left = 426
  Top = 85
  DesignerMasterStyle = 0
  object Text1: TText
    Position.X = 536.000000000000000000
    Position.Y = 8.000000000000000000
    TextSettings.Font.Family = 'Consolas'
    TextSettings.Font.Size = 14.000000000000000000
    TextSettings.Font.StyleExt = {00070000000100000004000000}
    TextSettings.FontColor = claCrimson
  end
  object Text2: TText
    Position.X = 536.000000000000000000
    Position.Y = 64.000000000000000000
    TextSettings.Font.Family = 'Consolas'
    TextSettings.Font.Size = 14.000000000000000000
    TextSettings.Font.StyleExt = {00070000000100000004000000}
    TextSettings.FontColor = claCrimson
  end
  object Rectangle1: TRectangle
    Position.X = 704.000000000000000000
    Position.Y = 64.000000000000000000
    Size.Width = 81.000000000000000000
    Size.Height = 73.000000000000000000
    Size.PlatformDefault = False
    Stroke.Color = claBlue
    Stroke.Thickness = 10.000000000000000000
    object ScrollBox1: TScrollBox
      Position.X = 16.000000000000000000
      Position.Y = -193.000000000000000000
      Size.Width = 49.000000000000000000
      Size.Height = 50.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 0
      Viewport.Width = 49.000000000000000000
      Viewport.Height = 34.000000000000000000
      object Label1: TLabel
        StyledSettings = [FontColor]
        Position.X = 496.000000000000000000
        Position.Y = 17.000000000000000000
        TextSettings.Font.Family = 'alarm clock'
        TextSettings.Font.Size = 14.000000000000000000
        TextSettings.Font.StyleExt = {00070000000000000004000000}
        TabOrder = 0
      end
      object Label2: TLabel
        StyledSettings = []
        Position.X = 496.000000000000000000
        Position.Y = 17.000000000000000000
        TextSettings.Font.Family = 'alarm clock'
        TextSettings.Font.Size = 14.000000000000000000
        TextSettings.Font.StyleExt = {00070000000000000004000000}
        TextSettings.FontColor = claRed
        TabOrder = 1
      end
    end
    object Edit1: TEdit
      Touch.InteractiveGestures = [LongTap, DoubleTap]
      TabOrder = 1
      Position.X = 13.000000000000000000
      Position.Y = 11.000000000000000000
      Size.Width = 52.000000000000000000
      Size.Height = 22.000000000000000000
      Size.PlatformDefault = False
    end
  end
  object Text3: TText
    Position.X = 536.000000000000000000
    Position.Y = 120.000000000000000000
    TextSettings.Font.Family = 'Bahnschrift'
    TextSettings.Font.Size = 14.000000000000000000
    TextSettings.Font.StyleExt = {00070000000000000003000000}
    TextSettings.FontColor = claFirebrick
  end
  object Text4: TText
    Position.X = 536.000000000000000000
    Position.Y = 176.000000000000000000
    TextSettings.Font.Family = 'Bahnschrift'
    TextSettings.Font.Size = 14.000000000000000000
    TextSettings.Font.StyleExt = {00070000000000000003000000}
    TextSettings.FontColor = claFirebrick
  end
  object Text5: TText
    Position.X = 536.000000000000000000
    Position.Y = 232.000000000000000000
    TextSettings.Font.Family = 'Bahnschrift'
    TextSettings.Font.Size = 14.000000000000000000
    TextSettings.Font.StyleExt = {00070000000000000003000000}
    TextSettings.FontColor = claFirebrick
  end
  object Text6: TText
    Position.X = 536.000000000000000000
    Position.Y = 288.000000000000000000
    TextSettings.Font.Family = 'Bahnschrift'
    TextSettings.Font.Size = 14.000000000000000000
    TextSettings.Font.StyleExt = {00070000000000000003000000}
    TextSettings.FontColor = claFirebrick
  end
  object Button1: TButton
    Position.X = 712.000000000000000000
    Position.Y = 147.000000000000000000
    Size.Width = 65.000000000000000000
    Size.Height = 30.000000000000000000
    Size.PlatformDefault = False
    TabOrder = 6
    Text = 'Ok'
    OnClick = Button1Click
  end
end

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.