sábado, 30 de janeiro de 2021

FMX - excluindo multiplos entre 0 e 10000


A alguns meses passados construímos um programa,
que marcava as ocorrências dos múltiplos de um número,
em uma cor diferente dos não múltiplos dentro de uma
matriz de inteiros de dez mil elementos,
agora fizemos diferente, estamos pesquisando
os múltiplos de um determinado número e apagando
todas as suas ocorrências dentro da matriz,
acompanhem no vídeo por favor:





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

#include <fmx.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
int n;
int A [ 100 ] [ 100 ];
int t, x;
    TText *Text1;
TText *Text4;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Informe ( TObject *Sender ) {
TText *Text1;
Text1  = new TText ( this );
Text1 -> Parent = Form1;
Text1 -> AutoSize = True;
Text1 -> TextSettings -> Font -> Family = "Consolas";
Text1 -> TextSettings -> Font -> Size = 14;
Text1 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Text1-> Color = clYellow;
Text1-> TextSettings -> FontColor = claRed;
Text1 -> Width = 200;
Text1 -> Height = 50;
Text1 -> Position -> Y = 330;
Text1 -> Position -> X = 250;
Text1 -> Text = "Por: ";

TText *Text2;
Text2  = new TText ( this );
Text2 -> Parent = Form1;
Text2 -> AutoSize = True;
Text2 -> TextSettings -> Font -> Family = "Consolas";
Text2 -> TextSettings -> Font -> Size = 14;
Text2 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Text2-> Color = clYellow;
Text2-> TextSettings -> FontColor = claBlue;
Text2 -> Width = 200;
Text2 -> Height = 50;
Text2 -> Position -> Y = 330;
Text2 -> Position -> X = 295;
Text2 -> Text = "Samuel Lima";

TText *Text3;
Text3  = new TText ( this );
Text3 -> Parent = Form1;
Text3 -> AutoSize = True;
Text3 -> TextSettings -> Font -> Family = "Consolas";
Text3 -> TextSettings -> Font -> Size = 14;
Text3 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Text3-> Color = clYellow;
Text3 -> TextSettings -> FontColor = claBlack;
Text3 -> Width = 200;
Text3 -> Height = 50;
Text3 -> Position -> Y = 342;
Text3 -> Position -> X = 250;
Text3 -> Text = "sa_sp10@hotmail.com";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
Rectangle1 -> Width = 640;
Rectangle1 -> Height = 370;
Rectangle1 -> Position -> X = 0;
Rectangle1 -> Position -> Y = 0;
//Rectangle1 -> Fill -> Color = claWhite;
Rectangle1 -> Size -> PlatformDefault = False;
Rectangle1 -> Stroke -> Color = claBlue;
Rectangle1 -> Stroke -> Thickness = 10;
Rectangle1 -> XRadius = 15;
Rectangle1 -> YRadius = 15;

Label1 -> Position -> X = 130;
Label1 -> Position -> Y = 10;
Label1 -> Size -> Width = 580;
Label1 -> Size -> Height = 19;
Label1 -> TextSettings -> Font -> Size = 18;
Label1 -> TextSettings -> FontColor = claRed;
Label1 -> TextSettings -> Font -> Family = "Consolas";
Label1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
Label1 -> Text = "FMX - PESQUISANDO MÚLTIPLOS E APAGANDO";


   Text1 -> TextSettings -> Font -> Family = "Alarm clock";
   Text1 -> TextSettings -> Font -> Size = 14;
   Text1 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold;
   Text1-> TextSettings -> FontColor = claBlack;
   Text1 -> Position -> X = 20;
   Text1 -> Position -> Y = -40;
   Text1 -> AutoSize = True;
   //Text1 -> Size -> Height = 9000;
   Text1 -> Size -> Width = 540;

Text4  = new TText ( this );
Text4 -> Parent = Form1;
Text4 -> TextSettings -> Font -> Size = 14;
Text4 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold;
Text4-> TextSettings -> FontColor = claBlue;
Text4 -> Position -> X = 0;
Text4 -> Position -> Y = 310;
Text4 -> Size -> Width = 700;
Text4 -> Size -> Height = 20;

   Edit1 -> SetFocus ( );
   Edit1 -> Font -> Size = 13;
   //Edit1 -> TextSettings -> Font -> Family = "Alarm clock";
   Edit1 -> Size -> PlatformDefault = False;
   Edit1 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold;
   Edit1 -> TextSettings -> FontColor = claRed;
   Edit1 -> Width = 90;
   Edit1 -> Height = 20;
   Edit1 -> Position -> X = 60;
   Edit1 -> Position -> Y = 330;

Button1 -> Visible = true;
Button1 -> Width = 30;
Button1 -> Height = 20;
Button1 -> Position -> X = 160;
Button1 -> Position -> Y = 330;
Button1 -> TextSettings -> Font -> Family = "Arial";
Button1 -> TextSettings -> Font -> Size = 16;
Button1 -> TextSettings -> FontColor = claBlue;
Button1 -> Text = "Ok";

ScrollBox1 -> Width = 600;
ScrollBox1 -> Height = 270;
ScrollBox1 -> Position -> X = 20;
ScrollBox1 -> Position -> Y = 40;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Imprime_matriz ( TObject* Sender ) {
   AnsiString str_1 = " ";
   int a, b, i;
  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 ] );
}
}
Text1 -> Text = str_1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click ( TObject *Sender ) {
int a, b;
String str_4;
Text1 -> Text = "";
n = StrToInt ( Edit1 -> Text );
AnsiString str_1 = " ";

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 ] % n == 0 ) {
   t++;
   str_4 = t - 1;
   }
   else {
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 ];
   }
   //==================================================================
}
}
Text1 -> Text = str_1;

Text4 -> Text = " ";
Text4 -> Text = Text4 -> Text + "Apagado ";
Text4 -> Text = Text4 -> Text + str_4;
Text4 -> Text = Text4 -> Text + " múltiplos de ";
Text4 -> Text = Text4 -> Text + n;
Edit1 -> Text = "";
Edit1 -> SetFocus ( );
t = 0;
Informe ( Sender );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender){
Label_Manual ( Sender );
Imprime_matriz ( Sender );
}
//---------------------------------------------------------------------------




Nenhum comentário:

Postar um comentário

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