piątek, 30 grudnia 2022

PointF Visual C++

 








date.h 

#pragma once



int tab1[40];

int tab2[40];

int tab3[40];


void m_Isort(int* tab, int s)

{

int i, j, k;

for (i = 1; i < s; i++)

{

j = i;

k = tab[j];

while ((j > 0) && (tab[j - 1] > k))

{

tab[j] = tab[j - 1];

j--;

}

tab[j] = k;

}

}

Form1.h


#pragma once

#include <stdlib.h>

#include <time.h>

#include "date.h"

#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
int i;
srand(time(NULL));
dataGridView1->ColumnCount = 40;
dataGridView1->RowCount = 2;
for (i = 0; i < 40; i++)
dataGridView1->Columns[i]->Width = 30;
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
Close();
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
int max_X = panel1->Width;
int max_Y = panel1->Height;
int min_X, min_Y,i,j,k,l;
min_X = min_Y = 1;
Graphics^ gr = panel1->CreateGraphics();
Pen^ my_Pen = gcnew Pen(System::Drawing::Color::Blue);
array<System::Drawing::PointF>^ xy = gcnew array<System::Drawing::PointF>(40);
my_Pen->Width = 3;
for (i = 0; i < 40; i++)
{
k = rand() % max_X + min_X;
l = rand() % max_Y + min_Y;
tab1[i] = k;
tab2[i] = l;
}
m_Isort(tab1, 40);
m_Isort(tab2, 40);
for (i = 0; i < 40; i++)
tab3[i] = max_Y - tab2[i];
for (i = 0; i < 40; i++)
{
dataGridView1->Rows[0]->Cells[i]->Value = tab1[i].ToString();
dataGridView1->Rows[1]->Cells[i]->Value = tab2[i].ToString();
xy[i].X = tab1[i];
xy[i].Y = tab3[i];

}
gr->DrawCurve(my_Pen, xy);
}
};
}

sobota, 3 grudnia 2022

Mondial 2022 group C - TStringGrid - C++ Builder

 




struct mundial_2022
{
 AnsiString Name;
 int win_Goal;
 int los_Goal;
 int pkt;
}soccer_GroupC[4];;

 int __fastcall Result(int x, int y);
 void __fastcall write_Match(AnsiString team1,AnsiString team2,int goal1,int goal2,int rows);
 void __fastcall date_Team1();


__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
  soccer_GroupC[0].Name="Argentina";
  soccer_GroupC[1].Name="Poland";
  soccer_GroupC[2].Name="Mexico";
  soccer_GroupC[3].Name="Saudi Arabia";
  for(int i=0;i<4;i++)
  {
   soccer_GroupC[i].win_Goal=0;
   soccer_GroupC[i].los_Goal=0;
   soccer_GroupC[i].pkt=0;
  }
}

int __fastcall TForm1::Result(int x, int y)
{
 int pkt;
 if(x>y)
  pkt=3;
 else if(x<y)
  pkt=0;
 else
  pkt=1;
 return pkt;
}
void __fastcall TForm1::write_Match(AnsiString team1,AnsiString team2,int goal1,int goal2,int rows)
{
  StringGrid1->Cells[0][rows]=team1;
  StringGrid1->Cells[1][rows]=team2;
  StringGrid1->Cells[2][rows]=IntToStr(goal1);
  StringGrid1->Cells[3][rows]=IntToStr(goal2);
}
void __fastcall TForm1::date_Team1()
{

  int goals_Arg[6]={1,2,2,0,2,0};
  int w,l;
  w=l=0;
  soccer_GroupC[0].pkt+=Result(goals_Arg[0],goals_Arg[1]);
  soccer_GroupC[0].pkt+=Result(goals_Arg[2],goals_Arg[3]);
  soccer_GroupC[0].pkt+=Result(goals_Arg[4],goals_Arg[5]);
  w=goals_Arg[0]+goals_Arg[2]+goals_Arg[4];
  l=goals_Arg[1]+goals_Arg[3]+goals_Arg[5];
  soccer_GroupC[0].win_Goal=w;
  soccer_GroupC[0].los_Goal=l;

  int goals_Pol[6]={0,0,2,0,0,2};
  w=l=0;
  soccer_GroupC[1].pkt+=Result(goals_Pol[0],goals_Pol[1]);
  soccer_GroupC[1].pkt+=Result(goals_Pol[2],goals_Pol[3]);
  soccer_GroupC[1].pkt+=Result(goals_Pol[4],goals_Pol[5]);
  w=goals_Pol[0]+goals_Pol[2]+goals_Pol[4];
  l=goals_Pol[1]+goals_Pol[3]+goals_Pol[5];
  soccer_GroupC[1].win_Goal=w;
  soccer_GroupC[1].los_Goal=l;

  int goals_Mex[6]={0,0,0,2,2,1};
  w=l=0;
  soccer_GroupC[2].pkt+=Result(goals_Mex[0],goals_Mex[1]);
  soccer_GroupC[2].pkt+=Result(goals_Mex[2],goals_Mex[3]);
  soccer_GroupC[2].pkt+=Result(goals_Mex[4],goals_Mex[5]);
  w=goals_Mex[0]+goals_Mex[2]+goals_Mex[4];
  l=goals_Mex[1]+goals_Mex[3]+goals_Mex[5];
  soccer_GroupC[2].win_Goal=w;
  soccer_GroupC[2].los_Goal=l;

  int goals_Sau[6]={2,1,0,2,1,2};
  w=l=0;
  soccer_GroupC[3].pkt+=Result(goals_Sau[0],goals_Sau[1]);
  soccer_GroupC[3].pkt+=Result(goals_Sau[2],goals_Sau[3]);
  soccer_GroupC[3].pkt+=Result(goals_Sau[4],goals_Sau[5]);
  w=goals_Sau[0]+goals_Sau[2]+goals_Sau[4];
  l=goals_Sau[1]+goals_Sau[3]+goals_Sau[5];
  soccer_GroupC[3].win_Goal=w;
  soccer_GroupC[3].los_Goal=l;


}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{

 write_Match(soccer_GroupC[0].Name,soccer_GroupC[3].Name,1,2,0);
 write_Match(soccer_GroupC[1].Name,soccer_GroupC[2].Name,0,0,1);
 write_Match(soccer_GroupC[3].Name,soccer_GroupC[1].Name,0,2,2);
 write_Match(soccer_GroupC[2].Name,soccer_GroupC[0].Name,0,2,3);
 write_Match(soccer_GroupC[1].Name,soccer_GroupC[0].Name,0,2,4);
 write_Match(soccer_GroupC[2].Name,soccer_GroupC[3].Name,2,1,5);
 date_Team1();
 for(int i=0;i<4;i++)
 {
  StringGrid2->Cells[0][i]=soccer_GroupC[i].Name;
  StringGrid2->Cells[1][i]=IntToStr(soccer_GroupC[i].pkt);
  StringGrid2->Cells[2][i]=IntToStr(soccer_GroupC[i].win_Goal);
  StringGrid2->Cells[3][i]=IntToStr(soccer_GroupC[i].los_Goal);
 }
}
//---------------------------------------------------------------------------