//---------------------------------------------------------------------------
// Проект 17. RC-фильтр: частота среза
// fc = 1/(2πRC), постоянная времени τ = RC.
//---------------------------------------------------------------------------
#include <vcl.h>
#include <math.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
}
//---------------------------------------------------------------------------

double rcCutoff(double R, double C) { return (R<=0||C<=0)?0:1.0/(2*M_PI*R*C); }
//---------------------------------------------------------------------------
void __fastcall TForm1::ButtonCalcClick(TObject *Sender)
{
    double R, Cnf;
    try { R=StrToFloat(EditR->Text); Cnf=StrToFloat(EditC->Text); }
    catch (...) { MemoOut->Text="Проверьте числа"; return; }
    double C = Cnf * 1e-9;                       // нФ → Ф
    double fc = rcCutoff(R, C);
    if (fc<=0) { MemoOut->Text="R и C должны быть больше нуля"; return; }
    MemoOut->Lines->Clear();
    MemoOut->Lines->Add("Частота среза: " + FormatFloat("0.###", fc) + " Гц");
    MemoOut->Lines->Add("τ = RC:        " + FormatFloat("0.######", R*C) + " с");
    MemoOut->Lines->Add("Заряд 5τ:      " + FormatFloat("0.######", 5*R*C) + " с");
}
//---------------------------------------------------------------------------
