segunda-feira, 25 de maio de 2020

C++ Builder - Relógio digital

Já que criamos um relógio digital
em eletrônica com proteus,
outro em Linguagem C,
com saída no console do windows, 
outro com a biblioteca graphics.h,
outro usando linguagem java,
e outro usando o JavaFx, o que poderia impedir
de criarmos um usando o C++ Builder?
Aqui está funcionando no vídeo 
um relógio digital criado no C++ Builder,
e em nada ficou em falta.




//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer ( TObject *Sender ) {
if ( horas < 10 )
Label1 -> Caption = "0";
if ( horas == 24 ) {
Label1 -> Left = 90;
horas = 0;
Label1 -> Caption = "0";
}
Label1 -> Caption = Label1 -> Caption + StrToInt ( horas );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer2Timer ( TObject *Sender ) {
if ( inicia_minutos == true ) {
minutos++;
}
if ( minutos < 10 ) {
Label2 -> Caption = "0";
}
if ( minutos == 60 ) {
minutos = 0;
horas++;
Label2 -> Caption = "0";
}
if ( ( minutos >= 10 && minutos < 60 ) )
Label2 -> Caption = StrToInt ( minutos );

if ( ( minutos >= 20 && minutos < 60 ) ){
Label2 -> Caption = StrToInt ( minutos );
Label2 -> Caption = Label2 -> Caption + " ";
}

Label2 -> Caption = Label2 -> Caption + StrToInt ( minutos );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer3Timer ( TObject *Sender ) {
if ( inicia_segundos == true ) {
segundos++;
}
if ( segundos < 10 ) {
Label3 -> Caption = "0";
}
if ( segundos == 60 ) {
segundos = 0;
        minutos++;
Label3 -> Caption = "0";
}
if ( ( segundos >= 10 && segundos < 60 ) )
Label3 -> Caption = StrToInt ( segundos );

if ( ( segundos >= 20 && segundos < 60 ) ){
Label3 -> Caption = StrToInt ( segundos );
Label3 -> Caption = Label3 -> Caption + " ";
}

Label3 -> Caption = Label3 -> Caption + StrToInt ( segundos );
}
//---------------------------------------------------------------------------



quarta-feira, 6 de maio de 2020

Juros compostos - pesquisando o tempo necessário

Para pesquisar o tempo em uma aplicação de juros compostos,
precisamos entrar com três parâmetros:

1º) Valor do capital
2º) Taxa de juros
3º) Montante

Com estas informações e uma fórmula bem aplicada,
já somos capazes de descobrir o tempo em que
um certo Capital, aplicado com tal Taxa de Juros,
alcance o determinado Montante.
Mas não foi fácil criar esta fórmula.
Quando aprendemos a resolver isto no papel,
usávamos logaritmo para complementar a fórmula,
e agora quando fui passar a fórmula para
linguagem de programação, fui por um caminho
complicado e duvidoso, mas pesquisando sobre
a biblioteca math.h do C, encontrei a função  log ();
e com esta solução o código ficou resumido e funcional.

Assista o programa funcionando no vídeo abaixo:



Veja abaixo a principal função do programa:

//---------------------------------------------------------------------------
void __fastcall TForm5::SpeedButton2Click ( TObject *Sender ) {
              double Capital = 0.00, Juros, Tx_juros = 0.00, Tempo = 0.00, Montante, Aux = 0.00;

              Capital  = StrToFloat ( Edit1 -> Text );
              Tx_juros = StrToFloat ( Edit2 -> Text );
              Montante = StrToFloat ( Edit3 -> Text );

              Montante = Montante / Capital;
              Tx_juros = Tx_juros / 100;
              Aux = ( 1 + Tx_juros );

              Montante = log10 ( Montante );
              Aux = log10 ( Aux );

              Montante =  Montante / Aux;
              Montante = Montante * 12;

              Label1 -> Caption = FloatToStrF ( Montante , ffFixed, 8, 2 );
              Label1 -> Caption = Label1 -> Caption + " Meses";

              //Informe ( Sender );
 }
//---------------------------------------------------------------------------

Juros compostos - pesquisando a taxa de juros

Para pesquisar a taxa de juros em uma aplicação
de juros compostos, precisamos entrar com três parâmetros:
1º) Valor do capital
2º) Valor do juros
3º) Tempo - que em nosso caso estamos entrando
com o tempo em meses, que pode ser facilmente
convertido para bimestre, trimestre, semestre ou ano.
Assista o programa funcionando no vídeo abaixo:



Abaixo a principal função do programa:

//---------------------------------------------------------------------------
void __fastcall TForm4::SpeedButton2Click ( TObject *Sender ) {
              double Capital = 0.00, Val_juros = 0.00, Tx_juros = 0.00, Tempo = 0.00, Montante;

              Capital = StrToFloat ( Edit1 -> Text );
              Val_juros = StrToFloat ( Edit2 -> Text );
              Tempo = StrToFloat ( Edit3 -> Text );

              Tempo = Tempo / 12;

              Montante = Capital + Val_juros;
              Montante = Montante / Capital;
              Montante = pow ( Montante, 1.0 / Tempo );
              Montante = Montante - 1;
              Montante = Montante * 100;
              Label1 -> Caption = FloatToStrF ( Montante , ffFixed, 8, 2 );
              Label1 -> Caption = Label1 -> Caption + " %";

              Informe ( Sender );
}
//---------------------------------------------------------------------------

Juros compostos - pesquisando o valor do juros

Para calcular o valor do juros em uma aplicação
de juros compostos, precisamos entrar com três parâmetros:


1º) Valor do capital
2º) Taxa de juros
3º) Tempo - que em nosso caso estamos entrando
com o tempo em meses, que pode ser facilmente
convertido para bimestre, trimestre, semestre ou ano.


Assista o programa funcionando no vídeo abaixo:





Veja abaixo a principal função do programa:

//---------------------------------------------------------------------------
void __fastcall TForm4::SpeedButton2Click ( TObject *Sender ) {
             double Capital = 0.00, Juros, Tx_juros = 0.00,
             Val_juros = 0.00, Tempo = 0.00, Montante;

              Capital = StrToFloat ( Edit1 -> Text );
              Tx_juros = StrToFloat ( Edit2 -> Text );
              Tempo = StrToFloat ( Edit3 -> Text );

              Tx_juros = Tx_juros / 100;
              Tx_juros = Tx_juros + ( 1 );
              Tempo = Tempo / 12;

              Montante = pow ( Tx_juros, Tempo );
              Montante = Montante * Capital;
              Val_juros = Montante - Capital;
              Label1 -> Caption = FloatToStrF ( Val_juros, ffFixed, 8, 2 );

              //Informe ( Sender );
}
//---------------------------------------------------------------------------

Juros compostos - pesquisando o valor do montante

Juros compostos são muito utilizados
em transações comerciais e financeiras
em todas as partes do mundo.
Compra de casas ou apartamentos a longo prazo,
investimentos em conta bancárias,
aquisição de empréstimos consignados,
e outros negócios onde estes cálculos são necessários.
Revendo nossos conhecimentos em matemática financeira,
criamos quatro programas baseado em juros compostos,
que são os seguintes: Pesquisando o valor do montante,
que é este agora apresentado,
Pesquisando o valor do juros,
Pesquisando a taxa de juros, e,
Pesquisando tempo necessário.
Acompanhem seu funcionamento no vídeo abaixo:





Veja abaixo a principal função do código:

//---------------------------------------------------------------------------
void __fastcall TForm2::SpeedButton2Click ( TObject *Sender ) {

             double Capital = 0.00, Juros, Tx_juros = 0.00, Tempo = 0.00, Montante;

              Capital = StrToFloat ( Edit1 -> Text );
              Tx_juros = StrToFloat ( Edit2 -> Text );
              Tempo = StrToFloat ( Edit3 -> Text );

              Tx_juros = Tx_juros / 100;
              Tx_juros = Tx_juros + ( 1 );
              Tempo = Tempo / 12;

              Montante = pow ( Tx_juros, Tempo );
              Montante = Montante * Capital;

             Label1 -> Caption = FloatToStrF ( Montante , ffFixed, 8, 2 );

             //Informe ( Sender );
}
//---------------------------------------------------------------------------



sábado, 25 de abril de 2020

C++ Builder - Calculando o volume de uma esfera

É impressionante a utilidade de corpos esféricos nos dias atuais.
Podemos citar algumas, mas seria impossível destacar
todos os locais onde ela se encontra.
Na maioria dos melhores esportes, na indústria,
nas máquinas, nos veículos motorizados, etc...
Por ser tão utilizadas, foi necessário a criação
de fórmulas matemáticas para cálculos precisos
de seu volume, área, circunferência e diâmetro.
Sabendo-se o valor do raio que é a distância entre
o centro da esfera e sua extremidade e o valor constante
do número irracional π (pi), dado por aproximadamente 3,14,
já somos capazes de criar um programa capaz de calcular
o seu volume com boa precisão e com certa facilidade.
E como estou usando o C++ Builder, aproveitei uma variável
nativa contida na Vcl, própria para cálculos matemáticos,
empregados em programação, e os resultados são
apresentados abaixo num vídeo com o programa funcionando.





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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1 ( TComponent* Owner )
    : TForm ( Owner )
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
    Edit1 -> Font -> Name = "alarm clock";
    Edit1 -> SetFocus ( );
    Edit1 -> Font -> Color = clBlack;
    Edit1 -> Color = clOlive;
    Edit1 -> Font-> Style = TFontStyles ( ) << fsBold;
    Edit1 -> Font -> Size = 12;
    Edit1 -> Width = 105;
    Edit1 -> Height = 21;
    Edit1 -> Left = 170;
    Edit1 -> Top = 68;
    Edit1 -> Alignment = taRightJustify; //Orientação à direita do TEdit

    Image1 -> Width = 600;
    Image1 -> Height = 300;
    Image1 -> Left = 0;
    Image1 -> Top = 0;

    Image2 -> Width = 130;
    Image2 -> Height = 35;
    Image2 -> Left = 280;
    Image2 -> Top = 62;

    Image3 -> Width = 130;
    Image3 -> Height = 35;
    Image3 -> Left = 280;
    Image3 -> Top = 62;

    Image4 -> Width = 600;
    Image4 -> Height = 300;
    Image4 -> Left = 0;
    Image4 -> Top = 0;

    Image5 -> Width = 130;
    Image5 -> Height = 40;
    Image5 -> Left = 280;
    Image5 -> Top = 50;

    Image6 -> Width = 130;
    Image6 -> Height = 40;
    Image6 -> Left = 280;
    Image6 -> Top = 50;

    Label1 -> Visible = true;
    Label1 -> Font -> Size = 12;
    Label1 -> Font -> Name = "Venacti";
    Label1 -> Font-> Style = TFontStyles ( ) << fsItalic << fsBold;
    Label1 -> Font -> Color = clBlack;
    Label1 -> Width = 130;
    Label1 -> Height = 20;
    Label1 -> Left = 270;
    Label1 -> Top = 110;

    Label2 -> Visible = true;
    Label2 -> Font -> Size = 12;
    Label2 -> Font -> Name = "Venacti";
    Label2 -> Font-> Style = TFontStyles ( ) << fsItalic << fsBold;
    Label2 -> Font -> Color = clBlack;
    Label2 -> Width = 130;
    Label2 -> Height = 20;
    Label2 -> Left = 270;
    Label2 -> Top = 157;

    Label3 -> Visible = true;
    Label3 -> Font -> Size = 12;
    Label3 -> Font -> Name = "Venacti";
    Label3 -> Font-> Style = TFontStyles ( ) << fsItalic << fsBold;
    Label3 -> Font -> Color = clBlack;
    Label3 -> Width = 330;
    Label3 -> Height = 20;
    Label3 -> Left = 270;
    Label3 -> Top = 204;

    Label4 -> Visible = true;
    Label4 -> Font -> Size = 12;
    Label4 -> Font -> Name = "Venacti";
    Label4 -> Font-> Style = TFontStyles ( ) << fsItalic << fsBold;
    Label4 -> Font -> Color = clBlack;
    Label4 -> Width = 330;
    Label4 -> Height = 20;
    Label4 -> Left = 270;
    Label4 -> Top = 249;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender) {
       Label_Manual ( Sender );
       Image4 -> Visible = false;
       Image6 -> Visible = false;
       Image5 -> Visible = false;

       Edit1 -> Height = 21;

       Label1 -> Visible = false;
       Label2 -> Visible = false;
       Label3 -> Visible = false;
       Label4 -> Visible = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image2MouseEnter ( TObject *Sender ) {
        Image3 -> Visible = true;
        Image2 -> Visible = false;
        Image5 -> Visible = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image3MouseLeave ( TObject *Sender ) {
        Image3 -> Visible = false;
        Image2 -> Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image3Click ( TObject *Sender ) {
       double Raio, Dim, Circumferencia, Area, Volume;

       Raio = Edit1 -> Text.ToDouble ( );
       Dim = Raio * 2;
       Circumferencia = Raio * 2 * M_PI;
       Area = Raio * Raio * M_PI;
       Volume = Raio * Raio * Raio * 4.00 * M_PI / 3;

       Label1 -> Visible = true;
       Label2 -> Visible = true;
       Label3 -> Visible = true;
       Label4 -> Visible = true;

       Label1 -> Caption = FloatToStrF ( Dim, ffFixed, 8, 2 );
       Label2 -> Caption = FloatToStrF ( Circumferencia, ffFixed, 8, 2 );
       Label3 -> Caption = FloatToStrF ( Area, ffFixed, 8, 2 );
       Label4 -> Caption = FloatToStrF ( Volume, ffFixed, 8, 2 );

       Image1 -> Visible = false;
       Image2 -> Visible = false;
       Image3 -> Visible = true;
       Image4 -> Visible = true;
       Image6 -> Visible = true;
       Image5 -> Visible = true;
       Edit1 -> Top = 63;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image5MouseEnter ( TObject *Sender ) {
    Image5 -> Visible = false;
    Image6 -> Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image6MouseLeave ( TObject *Sender ) {
    Image6 -> Visible = false;
    Image5 -> Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image6Click ( TObject *Sender ) {
         Image1 -> Visible = true;
         Image2 -> Visible = true;
         Image3 -> Visible = false;
         Image4 -> Visible = false;
         Image5 -> Visible = false;
         Image6 -> Visible = false;

         Edit1 -> Top = 68;
         Edit1 -> Clear ( );

         Label1 -> Caption = " ";
         Label2 -> Caption = " ";
         Label3 -> Caption = " ";
         Label4 -> Caption = " ";
}
//---------------------------------------------------------------------------


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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Graphics.hpp>
#include <Vcl.Imaging.pngimage.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE-managed Components
    TImage *Image1;
    TEdit *Edit1;
    TImage *Image2;
    TImage *Image3;
    TImage *Image4;
    TImage *Image5;
    TImage *Image6;
    TLabel *Label1;
    TLabel *Label2;
    TLabel *Label3;
    TLabel *Label4;
    void __fastcall Label_Manual ( TObject *Sender );
    void __fastcall FormShow ( TObject *Sender );
    void __fastcall Image2MouseEnter ( TObject *Sender );
    void __fastcall Image3MouseLeave ( TObject *Sender );
    void __fastcall Image3Click ( TObject *Sender );
    void __fastcall Image5MouseEnter ( TObject *Sender );
    void __fastcall Image6MouseLeave ( TObject *Sender );
    void __fastcall Image6Click ( TObject *Sender );
private:    // User declarations
public:        // User declarations
    __fastcall TForm1 ( TComponent* Owner );
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

sexta-feira, 24 de abril de 2020

C++ Builder - Cálculo de variação percentual

Quando queremos descobrir a diferença entre dois valores,
usamos um pequeno cálculo matemático numa fórmula aplicada.
se dois valores são comparados utilizando a fórmula abaixo:
Val2 - Val1 / Val1 x 100, podemos dizer que a relação
entre os dois é a variação percentual entre eles.
Se o resultado destas comparações forem positivos,
na matemática dizemos que houve um aumento percentual,
e se for negativo uma diminuição negativa foi constatada,
e para deixar isto mais claro criamos este programa
no C++ Builder para cálculos destas variações,
acompanhem no vídeo, e se tiver interesse clique
no link e confira como isto foi feito.





//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1 ( TComponent* Owner )
    : TForm ( Owner ) {
}
int x = 0;
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
    Edit1 -> Font -> Name = "alarm clock";
    Edit1 -> SetFocus ( );
    Edit1 -> Font -> Color = clBlack;
    Edit1 -> Color = clOlive;
    Edit1 -> Font-> Style = TFontStyles ( ) << fsBold;
    Edit1 -> Font -> Size = 12;
    Edit1 -> Width = 105;
    Edit1 -> Height = 21;
    Edit1 -> Left = 272;
    Edit1 -> Top = 70;
    Edit1 -> Alignment = taRightJustify; //Orientação à direita do TEdit

    Edit2 -> Font -> Name = "alarm clock";
    Edit2 -> Font -> Color = clBlack;
    Edit2 -> Color = clOlive;
    Edit2 -> Font-> Style = TFontStyles ( ) << fsBold;
    Edit2 -> Font -> Size = 12;
    Edit2 -> Width = 105;
    Edit2 -> Height = 21;
    Edit2 -> Left = 272;
    Edit2 -> Top = 98;
    Edit2 -> Alignment = taRightJustify; //Orientação à direita do TEdit

    Image1 -> Visible = true;
    Image1 -> Width = 600;
    Image1 -> Height = 300;
    Image1 -> Left = 0;
    Image1 -> Top = 0;

    Image2 -> Visible = true;
    Image2 -> Width = 130;
    Image2 -> Height = 35;
    Image2 -> Left = 430;
    Image2 -> Top = 80;

    Image3 -> Width = 600;
    Image3 -> Height = 300;
    Image3 -> Left = 0;
    Image3 -> Top = 0;

    Image4 -> Width = 160;
    Image4 -> Height = 36;
    Image4 -> Left = 430;
    Image4 -> Top = 80;

    Label1 -> Visible = true;
    Label1 -> Font -> Size = 12;
    Label1 -> Font -> Name = "Venacti";
    Label1 -> Font-> Style = TFontStyles ( ) << fsItalic << fsBold;
    Label1 -> Font -> Color = clBlack;
    Label1 -> Width = 130;
    Label1 -> Height = 20;
    Label1 -> Left = 380;
    Label1 -> Top = 150;

    Label2 -> Visible = true;
    Label2 -> Font -> Size = 12;
    Label2 -> Font -> Name = "Venacti";
    Label2 -> Font-> Style = TFontStyles ( ) << fsItalic << fsBold;
    Label2 -> Font -> Color = clBlack;
    Label2 -> Width = 130;
    Label2 -> Height = 20;
    Label2 -> Left = 380;
    Label2 -> Top = 185;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image2Click ( TObject *Sender ) {
       double Valor_Antigo = 0.00, Valor_Novo = 0.00, Valor_Resp;
       double Dif_Percent;

       Valor_Antigo = StrToFloat ( Edit1 -> Text );
       Valor_Novo = StrToFloat ( Edit2 -> Text );
       Valor_Resp = ( Valor_Novo - Valor_Antigo );

       Dif_Percent = ( Valor_Resp / Valor_Antigo );
       Dif_Percent = ( Dif_Percent * 100 );

       Label1 -> Caption = FloatToStrF ( Valor_Resp, ffFixed, 8, 3 );
       Label2 -> Caption = FloatToStrF ( Dif_Percent, ffFixed, 8, 2 );
       Label2 -> Caption = Label2 -> Caption + " %";

        Label_Manual ( Sender );
        Image3 -> Visible = true;
        Image4 -> Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image4Click ( TObject *Sender ) {
        Label_Manual ( Sender );
        Image3 -> Visible = false;
        Image4 -> Visible = false;
        Label1 -> Caption = " ";
        Label2 -> Caption = " ";
        Edit1 -> Clear ( );
        Edit2 -> Clear ( );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender ) {
    Label_Manual ( Sender );
    Image1 -> Visible = true;
    Image2 -> Visible = true;
    Image3 -> Visible = false;
    Image4 -> Visible = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint ( TObject *Sender ) {
 Label_Manual ( Sender );
}
//---------------------------------------------------------------------------
 


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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.Buttons.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Imaging.GIFImg.hpp>
#include <Vcl.Graphics.hpp>
#include <Vcl.Imaging.pngimage.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE-managed Components
    TImage *Image1;
    TImage *Image2;
    TImage *Image3;
    TImage *Image4;
    TLabel *Label1;
    TLabel *Label2;
    TEdit *Edit1;
    TEdit *Edit2;
    void __fastcall Label_Manual ( TObject *Sender );
    void __fastcall Image2Click(TObject *Sender);
    void __fastcall Image4Click(TObject *Sender);
    void __fastcall FormShow(TObject *Sender);
    void __fastcall FormPaint(TObject *Sender);

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