rendered paste body------------------unit.h-----------------------------
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
const char *CDuom = "Duomenys.txt";
const char *CRez = "Rezultatai.txt";
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TButton *Button2;
TButton *Button3;
TEdit *Edit1;
TEdit *Edit2;
TEdit *Edit3;
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TMemo *Memo1;
TMemo *Memo2;
TMemo *Memo3;
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button3Click(TObject *Sender);
private: // User declarations
int *Rx, *Ry, *Mx, *My;
int Ax , Ay, R;
int RKiekis, MKiekis;
int n;
bool Duomenys();
void Parodyti();
double Atstumas(int [], int [], int [], int[]);
void TaskuKiekis();
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
------------------------------------unit.cpp----------------------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <fstream>
#include <iomanip>
#include <conio.h>
#include <math.h>
#include <stdio.h>
#include "Unit1.h"
using namespace std;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
/*Ax = 0; Ay = 0; R = 0;*/
Button1->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{ int s = 0;
Duomenys();
Parodyti();
Memo3->Lines->Add("RKiekis = " + IntToStr(RKiekis));
Memo3->Lines->Add("MKiekis = " + IntToStr(MKiekis));
s = pow(pow(Rx[1] - Ax, 2.0) + pow(Ry[1] - Ay,2.0), 0.5);
Memo3->Lines->Add(IntToStr(s));
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
bool TForm1::Duomenys()
{
n = 0;
int sk;
int i = 0;
ifstream fd(CDuom);
if(fd)
{
while (fd)
{
fd >> sk;
n++;
}
n /= 4;
Rx = new int [n];
Ry = new int [n];
Mx = new int [n];
My = new int [n];
fd.close();
fd.open(CDuom);
while (fd)
{
fd >> *(Rx+i) >> *(Ry+i) >> *(Mx+i) >> *(My+i);
i++;
}
fd.close();
return true;
}
else
return false;
}
void TForm1::Parodyti()
{
Memo1->Lines->Clear();
Memo2->Lines->Clear();
Memo1->Lines->Add("Raudonø taðkø koordintës (x; y)");
Memo2->Lines->Add("Mëlinø taðkø koordintës (x; y)");
for (int i = 0; i < n; i++)
{
Memo1->Lines->Add (IntToStr(*(Rx+i)) + " " + IntToStr(*(Ry+i)));
Memo2->Lines->Add (IntToStr(*(Mx+i)) + " " + IntToStr(*(My+i)));
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Ax = StrToInt(Edit1->Text);
Ay = StrToInt(Edit2->Text);
R = StrToInt(Edit3->Text);
Button1->Enabled = true;
}
//---------------------------------------------------------------------------
double TForm1::Atstumas(int *x1, int x2, int *y1, int y2)
{
return pow(pow(x1 - x2, 2.0) + pow(y1 - y2,2.0), 0.5);
}
//---------------------------------------------------------------------------
void TForm1:: TaskuKiekis()
{
for (int i = 0; i < n; i++)
{
if (Atstumas(*(Rx+i),Ax,*(Ry+i),Ay) < R){
RKiekis++;
if (Atstumas(*(Mx+i),Ax,*(My+i),Ay) < R)
MKiekis++;
}
}
//---------------------------------------------------------------------------