Скачиваний:
3
Добавлен:
30.05.2020
Размер:
4.66 Кб
Скачать
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "massiv.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
  int n = 5,i,j;   double *ax,*ay,*bx,*by;
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
int ind = RadioGroup1->ItemIndex, counter=0;
for(i=0;i<n;i++)  {
      ax[i]=StrToFloat(StringGrid1->Cells[0][i]);
      ay[i]=StrToFloat(StringGrid1->Cells[1][i]);
      bx[i]=StrToFloat(StringGrid2->Cells[0][i]);
      by[i]=StrToFloat(StringGrid2->Cells[1][i]);
      StringGrid3->Cells[0][i]="";StringGrid3->Cells[1][i]="";}
switch(ind) {
case 0: for(j=0;j<n;j++)
for (i=0;i<n;i++){
         if (ax[i]==by[j]) counter++;
         }
       if (counter==0)ShowMessage("Вірних пар не знайдено");
       else {
         StringGrid3->RowCount=counter;
         counter=0;
         for(j=0;j<n;j++)
         for (i=0;i<n;i++){
         if (ax[i]==by[j]) {StringGrid3->Cells[0][counter]=FloatToStr(ax[i]);
                            StringGrid3->Cells[1][counter]=FloatToStr(ay[i]);
                            counter++;
         }  }   }
         counter=0;
          break;
case 1:for(j=0;j<n;j++)
for (i=0;i<n;i++){
         if (ax[i]==by[j] && ay[i]==bx[j]) counter++;
         }
       if (counter==0)ShowMessage("Вірних пар не знайдено");
       else {
         StringGrid3->RowCount=counter;
         counter=0;
         for(j=0;j<n;j++)
         for (i=0;i<n;i++){
         if (ax[i]==by[j] && ay[i]==bx[j]) {StringGrid3->Cells[0][counter]=FloatToStr(ax[i]);
                            StringGrid3->Cells[1][counter]=FloatToStr(ay[i]);
                            counter++;
         }  }   }
         counter=0; break;
case 2:
for (i=0;i<n;i++){
         if (ax[i]<ay[i]) counter++;
         }
       if (counter==0)ShowMessage("Вірних пар не знайдено");
       else {
         StringGrid3->RowCount=counter;
         counter=0;
         for (i=0;i<n;i++){
         if (ax[i]<ay[i]) {StringGrid3->Cells[0][counter]=FloatToStr(ax[i]);
                            StringGrid3->Cells[1][counter]=FloatToStr(ay[i]);
                            counter++;
         }  }   }
         counter=0; break;
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
Edit1->Text=IntToStr(n);
  StringGrid1->RowCount=n;
  StringGrid2->RowCount=n;
  ax = new double[n]; ay = new double[n];bx = new double[n];by = new double[n];
  randomize;
  for (i=0;i<n;i++) {
      StringGrid1->Cells[0][i]=FloatToStr(random(8)-3+i*(1./4));
      StringGrid1->Cells[1][i]=FloatToStr(random(8)-3+i*(1./4));
      StringGrid2->Cells[0][i]=FloatToStr(random(8)-3+i*(1./4));
      StringGrid2->Cells[1][i]=FloatToStr(random(8)-3+i*(1./4));
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
n=StrToInt(Edit1->Text);
if (Edit1->Text.Length()==0) n=1;
FormCreate(this);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
if (IsCharAlpha(Key) || Key=='-' || Key==',' || Key=='.') Key=0;
if (Edit1->Text.Length()==1 && Key==VK_BACK) Edit1->Text="1";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton2Click(TObject *Sender)
{
delete[]ax; delete[]ay;delete[]bx;delete[]by;
Close();
}
//---------------------------------------------------------------------------



void __fastcall TForm1::SpeedButton3Click(TObject *Sender)
{
ShowMessage("Всі поля були очищені або приведені в стан мінімального значення");

for(i=0;i<n;i++) {StringGrid3->Cells[0][i]="";StringGrid3->Cells[1][i]="";}
Edit1->Text="1";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
long SC_DRAGMOVE = 0xF012;
if(Button == mbLeft)
{
ReleaseCapture();
SendMessage(Handle, WM_SYSCOMMAND, SC_DRAGMOVE, 0);
}        
        
}
//---------------------------------------------------------------------------
Соседние файлы в папке Курсач_Косенко
  • #
    30.05.20204.66 Кб3massiv.cpp
  • #
    30.05.20205.57 Кб4massiv.dfm
  • #
    30.05.20201.7 Кб3massiv.h
  • #
    30.05.2020110.16 Кб3massiv.obj
  • #
    30.05.20204.66 Кб4massiv.~cpp
  • #
    30.05.20205.5 Кб3massiv.~dfm