C/C++ Algorithms and programs
sobota, 21 lutego 2026
Moon phases - C++ Builder
środa, 18 lutego 2026
Valarray - C++ Builder
private: // User declarations
float tab[5];
#include <vcl.h>
#include <valarray>
#include <stdlib.h>
#include <time.h>
#pragma hdrstop
#include "p_aarray.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
srand(time(NULL));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
StringGrid1->ColCount=5;
StringGrid1->RowCount=1;
StringGrid1->FixedCols=0;
StringGrid1->FixedRows=0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i;
const float a=50.00;
for(i=0;i<5;i++)
{
tab[i]=(1+rand()%100)/a;
StringGrid1->Cells[i][0]=FloatToStrF(tab[i],ffGeneral,4,4);
}
std::valarray<float> bb {tab[0],tab[1], tab[2], tab[3], tab[4]};
Label1->Caption="sum() = "+FloatToStrF(bb.sum(),ffGeneral,4,4);
Label2->Caption="min() = "+FloatToStrF(bb.min(),ffGeneral,4,4);
Label3->Caption="max() = "+FloatToStrF(bb.max(),ffGeneral,4,4);
std::valarray<float> temp_Sqrt=sqrt(bb);
Label4->Caption="sqrt() = "+FloatToStrF(temp_Sqrt[0],ffGeneral,4,4)+" "+
FloatToStrF(temp_Sqrt[1],ffGeneral,4,4)+" "+
FloatToStrF(temp_Sqrt[2],ffGeneral,4,4)+" "+
FloatToStrF(temp_Sqrt[3],ffGeneral,4,4)+" "+
FloatToStrF(temp_Sqrt[4],ffGeneral,4,4)+" ";
}
sobota, 20 grudnia 2025
Fonts in Windows (C++ Builder)
private: // User declarations
UnicodeString text;
void __fastcall Begin();
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
UnicodeString d,t;
d=DateToStr(Date());
t=TimeToStr(Time());
text=d+" "+t;
Label1->Caption=text;
}
void __fastcall TForm1::Begin()
{
ListBox1->Items->Clear();
ComboBox1->Items->Clear();
ComboBox1->Items->Assign(Screen->Fonts);
ComboBox1->Text="";
ListBox1->Items->Assign(Screen->Fonts);
Label2->Caption="All fonts in Windows (testing ComboBox) ";
Label3->Caption="All fonts in Windows (testing ListBox) ";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Begin();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
Label2->Font->Name=ComboBox1->Text;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1Click(TObject *Sender)
{
Label3->Font->Name=ListBox1->Items->Strings[ListBox1->ItemIndex];
}
poniedziałek, 24 listopada 2025
Getting data from a file into a StringGrid - C++ Builder
czwartek, 16 października 2025
Discrete knapsack problem - C++ Builder
niedziela, 5 października 2025
CreateThread, SuspendThread, ResumeThread - C++ Builder



