domingo, 10 de janeiro de 2021

FMX - verificando inteiros e decimais


Os números inteiros positivos
foram os primeiros números trabalhados
pela humanidade e tinham como finalidade
contar objetos, animais, frutas, enfim,
elementos do contexto histórico no qual
eles se encontravam.
Sobre os números decimais, como surgiu,
ou quem foi o primeiro a utilizá-los
basta fazer uma boa pesquisa para conhecer.
Criei uma simples função em C, 
que verifica se um número é inteiro ou decimal,
com respostas ao usuário.
O estudante de C ou C++, só precisa concentrar
suas atenções nesta função e na sua chamada,
ignorando os muitos códigos da interface 
gráfica criada no C++ builder.




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

#include <fmx.h>
#pragma hdrstop

#include "Unit1.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__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 = 240;
Text1 -> Position -> X = 200;
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 = 240;
Text2 -> Position -> X = 245;
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 = 255;
Text3 -> Position -> X = 200;
Text3 -> Text = "sa_sp10@hotmail.com";
}
//---------------------------------------------------------------------------
float Verifica_Inteiro ( float y ) {
    int inteiro = 0;
    inteiro = y;
    if ( y == ( float ) inteiro ) {
         return 1;
    } else {
         return 0;
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
Rectangle1 -> Width = 600;
Rectangle1 -> Height = 340;
Rectangle1 -> Position -> X = 0;
Rectangle1 -> Position -> Y = 0;
//Rectangle1 -> Fill -> Color = ( RGB ( 255, 0, 205 ) );
Rectangle1 -> Size -> PlatformDefault = False;
Rectangle1 -> Stroke -> Color = claYellow;
//Rectangle1 -> Stroke -> Kind = TBrushKind::Solid;
//Rectangle1 -> Stroke -> Color = ( RGB ( 255, 255, 0 ) );
Rectangle1 -> Stroke -> Thickness = 10;
Rectangle1 -> XRadius = 15;
Rectangle1 -> YRadius = 15;

Edit1 -> SetFocus ( );
Edit1 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
Edit1 -> TextSettings -> FontColor = claRed;
Edit1 -> Font -> Size = 10;
Edit1 -> Width = 70;
Edit1 -> Height = 20;
Edit1 -> Position -> X = 200;
Edit1 -> Position -> Y = 150;

Button1 -> Visible = true;
Button1 -> Width = 30;
Button1 -> Height = 20;
Button1 -> Position -> X = 280;
Button1 -> Position -> Y = 150;
Button1 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
Button1 -> TextSettings -> Font -> Family = "Arial";
Button1 -> TextSettings -> Font -> Size = 16;
Button1 -> TextSettings -> FontColor = claBlue;
Button1 -> Text = "Ok";

Label1 -> Position -> X = 80;
Label1 -> Position -> Y = 15;
Label1 -> Size -> Width = 500;
Label1 -> Size -> Height = 19;
//Label4 -> AutoSize = True;
Label1 -> TextSettings -> Font -> Size = 18;
Label1 -> TextSettings -> FontColor = claRed;
Label1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
Label1 -> Text = "C++ BUILDER - VERIFICANDO INTEIROS E DECIMAIS";

Label2 -> Position -> X = 200;
Label2 -> Position -> Y = 50;
Label2 -> Size -> Width = 400;
Label2 -> Size -> Height = 100;
Label2 -> TextSettings -> Font -> Size = 16;
Label2 -> TextSettings -> FontColor = claBlack;
Label2 -> TextSettings -> Font -> Family = "Consolas";
Label2 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

Label3 -> Position -> X = 200;
Label3 -> Position -> Y = 170;
Label3 -> Size -> Width = 300;
Label3 -> Size -> Height = 20;
Label3 -> TextSettings -> Font -> Size = 12;
Label3 -> TextSettings -> FontColor = claBlack;
Label3 -> TextSettings -> Font -> Family = "Consolas";
Label3 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
Label3 -> Text = "Dígite um  número";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Imprime_Int_Dec ( TObject *Sender ) {
double n = 0.00;
n = StrToFloat ( Edit1 -> Text );
if ( Verifica_Inteiro ( n ) == 1 ) {
Label2 -> Text = "O Numero ";
Label2 -> Text = Label2 -> Text + FloatToStrF ( n, ffFixed, 8, 0 );
Label2 -> Text = Label2 -> Text + " é inteiro.";
} else {
Label2 -> Text = "O Numero ";
Label2 -> Text = Label2 -> Text + FloatToStrF ( n, ffFixed, 8, 1 );
Label2 -> Text = Label2 -> Text + " não é inteiro.";

Label2 -> Text = Label2 -> Text + "\nO Numero ";
Label2 -> Text = Label2 -> Text + FloatToStrF ( n, ffFixed, 8, 1 );
Label2 -> Text = Label2 -> Text + " é decimal.";
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click ( TObject *Sender ) {
   Imprime_Int_Dec  ( Sender );
       Informe ( Sender );
   Beep ( 500, 500 );

   Edit1 -> Text = "";
   Edit1 -> SetFocus ( );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate ( TObject *Sender ) {
   Label_Manual ( Sender );
}
//---------------------------------------------------------------------------



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

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

void __fastcall Imprime_Int_Dec ( TObject *Sender );
void __fastcall Label_Manual ( TObject *Sender );
void __fastcall Button1Click ( TObject *Sender );
void __fastcall FormCreate ( TObject *Sender );
void __fastcall Informe ( TObject *Sender );
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

Nenhum comentário:

Postar um comentário

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