Eis o código da Unit1.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TLabel *Label4;
TEdit *Edit1;
TEdit *Edit2;
TEdit *Edit3;
void __fastcall Label1Click(TObject *Sender);
void __fastcall Label2Click(TObject *Sender);
void __fastcall Label3Click(TObject *Sender);
void __fastcall Label4Click(TObject *Sender);
void __fastcall Label4MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall Label4MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Eis o código da Unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <math.h>
AnsiString a, b, c;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label1Click(TObject *Sender)
{
try
{
retornoA:
a = InputBox("Caixa de Entrada de Valores",
"Digite um valor para 'a'", "");
StrToInt(a);
if (a == 0)
{
MessageBox(0,"Zero não é um valor válido para 'a' !\nDigite outro valor... ",
"Erro no valor escolhido", 16);
goto retornoA;
}
else
Label1 -> Caption = " a = " + a;
Label1 -> Font -> Color = clRed;
Label1 -> Font -> Style = TFontStyles()<< fsBold;
Form1 -> ShowHint = false;
}
catch(...)
{
MessageBox(0, "Erro ... Valor não suportado pelo programa ...",
"Erro de digitação", 16);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label2Click(TObject *Sender)
{
try
{
b = InputBox("Caixa de Entrada de Valores",
"Digite um Valor para 'b'", "");
StrToInt(b);
Label2 -> Caption = " b = " + b;
Label2 -> Font -> Color = clRed;
Label2 -> Font -> Style = TFontStyles()<< fsBold;
Form1 -> ShowHint = false;
}
catch(...)
{
MessageBox(0, "Erro ... Valor não suportado pelo programa ...",
" Erro de digitação", 16);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label3Click(TObject *Sender)
{
try
{
c = InputBox("Caixa de Entrada de Valores",
"Digite um Valor para 'c'", "");
StrToInt(c);
Label3 -> Caption = " c = " + c;
Label3 -> Font -> Color = clRed;
Label3 -> Font -> Style = TFontStyles()<< fsBold;
Form1 -> ShowHint - false;
}
catch(...)
{
MessageBox(0, "Erro ... Valor não suportado pelo programa ...",
"Erro de digitação", 16);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label4Click(TObject *Sender)
{
try
{
Label4 -> Font -> Color = clBlue;
Label4 -> Font -> Style = TFontStyles()<< fsBold;
// float x1, x2, delta; // SETE DÍGITOS DE PRECISÃO
double x1, x2, delta; // QUINZE DÍGITOS DE PRECISÃO
delta = (b*b) - ((a * 4) * c);
if(delta < 0)
MessageBox(0,"delta negativo... não existem raízes reais...\n\n" +
"tente novamente com outros valores...", "Erro nos valores", 16);
else
{
Edit1 ->Text = "delta = " + FloatToStr(delta);
Edit1 -> Font -> Color = clBlue;
Edit1 -> Font -> Style = TFontStyles()<< fsBold;
Edit1 ->ShowHint = true;
x1 = ((b * (-1)) + (sqrt (delta))) / (a * 2);
Edit2 -> Text = "x1 = " + FloatToStr(x1);
Edit2 -> Font -> Color = clBlue;
Edit2 -> Font -> Style = TFontStyles()<< fsBold;
Edit2 -> ShowHint = true;
x2 = ((b * (-1)) - (sqrt (delta))) / (a * 2);
Edit3 -> Text = "x2 = " + FloatToStr(x2);
Edit3 -> Font -> Color = clBlue;
Edit3 -> Font -> Style = TFontStyles()<< fsBold;
Edit3 -> ShowHint = true;
}
}
catch(...)
{
MessageBox(0, "Por favor, digite os valores corretamente", "Erro de execução...", 16);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label4MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
Label4 -> Font -> Size = 6;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label4MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
Label4 -> Font -> Size = 10;
}
//---------------------------------------------------------------------------
voltar