domingo, 19 de abril de 2020

C++ Builder - calculando o volume do cilindro

Um corpo redondo, sólido e de geometria tridimensional,
é denominado cilindro.
O cilindro possui um volume que determina a sua capacidade,
e a sua base é de formato circular.
Para encontrar a área da base temos que calcular
a área de uma circunferência, já que a base de um cilindro
é circular como já foi citado acima. e sua fórmula

para cálculo da área da base é:

Ab = π . r²

    Ab: é a área da base;
    π: é o número pi (3,14);
    r: é o raio da base;

E para calcular seu volume,
basta multiplicar sua área base pela altura,
e sua fórmula é apresentada abaixo:

V = Ab . h = π . r² . h

Pronto, isto é tudo o que precisávamos saber
para criar um programa capaz de calcular
o volume de um cilindro, acompanhem no vídeo abaixo:





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

#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 -> Visible = true;
    Edit1 -> Font -> Name = "alarm clock";
    Edit1 -> SetFocus ( );
    Edit1 -> Clear ( );
    Edit1 -> Font -> Color = clBlack;
    Edit1 -> Color = clOlive;
    Edit1 -> Font-> Style = TFontStyles ( ) << fsBold;
    Edit1 -> Font -> Size = 12;
    Edit1 -> Width = 90;
    Edit1 -> Height = 20;
    Edit1 -> Left = 270;
    Edit1 -> Top = 48;

    Edit2 -> Visible = true;
    Edit2 -> Font -> Name = "alarm clock";
    Edit2 -> Clear ( );
    Edit2 -> Font -> Color = clBlack;
    Edit2 -> Color = clOlive;
    Edit2 -> Font-> Style = TFontStyles ( ) << fsBold;
    Edit2 -> Font -> Size = 12;
    Edit2 -> Width = 90;
    Edit2 -> Height = 20;
    Edit2 -> Left = 270;
    Edit2 -> Top = 78;

    BitBtn1 -> Font -> Name = "Venacti";
    BitBtn1 -> Visible = true;
    BitBtn1 -> Font -> Size = 12;
    BitBtn1    -> Font-> Style = TFontStyles ( ) << fsItalic << fsBold;
    BitBtn1 -> Font -> Color = clBlack;
    BitBtn1     -> Width = 210;
    BitBtn1     -> Height = 22;
    BitBtn1 -> Top = 110;
    BitBtn1 -> Left = 152;
    BitBtn1 -> Caption = ( "Calcular volume do cilindro" );

    BitBtn2 -> Font -> Name = "Venacti";
    BitBtn2 -> Font -> Size = 12;
    BitBtn2 -> Font -> Color = clBlack;
    BitBtn2    -> Font-> Style = TFontStyles ( ) << fsItalic ;
    BitBtn2 -> Top = 230;
    BitBtn2 -> Left = 152;
    BitBtn2 -> Height = 21;
    BitBtn2 -> Width = 110;
    BitBtn2 -> Caption = ( "Novo cálculo" );

    BitBtn3 -> Font -> Name = "Venacti";
    BitBtn3 -> Font -> Size = 12;
    BitBtn3 -> Font -> Color = clBlack;
    BitBtn3    -> Font-> Style = TFontStyles ( ) << fsItalic ;
    BitBtn3 -> Top = 230;
    BitBtn3 -> Left = 430;
    BitBtn3 -> Height = 21;
    BitBtn3 -> Width = 140;
    BitBtn3 -> Caption = ( "Sair do programa" );

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

    Label2 -> Visible = true;
    Label2 -> Font -> Size = 12;
    Label2 -> Font -> Name = "Arial";
    Label2 -> Font-> Style = TFontStyles ( ) << fsItalic ;
    Label2 -> Font -> Color = clRed;
    Label2 -> Width = 130;
    Label2 -> Height = 20;
    Label2 -> Left = 270;
    Label2 -> Top = 140;

    Label3 -> Visible = true;
    Label3 -> Font -> Size = 11;
    Label3 -> Font -> Name = "Arial";
    Label3 -> Font-> Style = TFontStyles ( ) << fsItalic ;
    Label3 -> Font -> Color = clRed;
    Label3 -> Width = 330;
    Label3 -> Height = 20;
    Label3 -> Left = 270;
    Label3 -> Top = 170;

    Label4 -> Visible = true;
    Label4 -> Font -> Size = 11;
    Label4 -> Font -> Name = "Arial";
    Label4 -> Font-> Style = TFontStyles ( ) << fsItalic ;
    Label4 -> Font -> Color = clRed;
    Label4 -> Width = 330;
    Label4 -> Height = 20;
    Label4 -> Left = 270;
    Label4 -> Top = 200;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender ) {
       Label_Manual ( Sender );

       Image1 -> Visible = true;
       Image2 -> Visible = false;

       BitBtn2 -> Visible = false;
       BitBtn3 -> Visible = false;

       Label1 -> Visible = false;
       Label2 -> Visible = false;
       Label3 -> Visible = false;
       Label4 -> Visible = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click ( TObject *Sender ) {
       double Radius = 0.00, Height = 0.00;
       double BaseArea, LateralArea, TotalArea, Volume;

       Radius = StrToFloat ( Edit1 -> Text );
       Height = StrToFloat ( Edit2 -> Text );

       BaseArea = Radius * Radius * M_PI;
       LateralArea = Radius * Height * 2 * M_PI;
       TotalArea = BaseArea + LateralArea;
       Volume = BaseArea * Height;

       Label1 -> Caption = FloatToStrF ( BaseArea, ffFixed, 8, 6 );
       Label2 -> Caption = FloatToStrF ( LateralArea, ffFixed, 8, 6 );
       Label3 -> Caption = FloatToStrF ( TotalArea, ffFixed, 8, 6 );
       Label4 -> Caption = FloatToStrF ( Volume, ffFixed, 8, 6 );

       Constraints -> MinHeight = 345;
       Constraints -> MinWidth = 600;
       Constraints -> MaxHeight = 345;
       Constraints -> MaxWidth = 600;

       Image1 -> Visible = false;
       Image2 -> Visible = true;

       BitBtn1 -> Visible = false;
       BitBtn2 -> Visible = true;
       BitBtn3 -> Visible = true;

       Label1 -> Visible = true;
       Label2 -> Visible = true;
       Label3 -> Visible = true;
       Label4 -> Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click ( TObject *Sender ) {
         Label_Manual ( Sender );

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

         Edit1 -> Clear ( );
         Edit2 -> Clear ( );

         Image1 -> Visible = true;
         Image2 -> Visible = false;

         BitBtn2 -> Visible = false;
         BitBtn3 -> Visible = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn3Click ( TObject *Sender ) {
Close ( );
}
//---------------------------------------------------------------------------



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

#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>
#include <Vcl.Buttons.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE-managed Components
    TImage *Image1;
    TImage *Image2;
    TBitBtn *BitBtn1;
    TBitBtn *BitBtn2;
    TBitBtn *BitBtn3;
    TEdit *Edit1;
    TEdit *Edit2;
    TLabel *Label1;
    TLabel *Label2;
    TLabel *Label3;
    TLabel *Label4;

    void __fastcall Label_Manual ( TObject *Sender );
    void __fastcall FormShow ( TObject *Sender );
    void __fastcall BitBtn1Click ( TObject *Sender );
    void __fastcall BitBtn3Click(TObject *Sender);
    void __fastcall BitBtn2Click(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.