Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- /*1) Generuj n random cisiel do listboxu
- - moznost ulozit do suboru generuj.txt (cez dialog)
- 2) Nacita zo suboru generuj.txt (cez dialog) cisla do stlpcov v tabulke (stringgrid)
- 3) Zo stlpca v tabulke prekopirujes tieto cisla do komponentu memo tak aby boli v riadku 13 8 20 ...
- 4) Vypis poctu parnych, neparnych, nulovych cisiel (ShowMessage) Vypis je robeny z MEMA
- 5) Nacitanie tychto cisiel zo sltpca zabulky do pola
- vypis cisiel z pola do druheho stlpca v tabulke
- vypis zoradenych cisiel do tretieho stlpca v tabulke
- */
- void __fastcall TForm1::Button1Click(TObject *Sender) // 1)
- {
- ListBox1->Items->Clear();
- int n = StrToInt(InputBox("", "", ""));
- for (int i = 0; i < n; i++) {
- ListBox1->Items->Add(random(100));
- }
- if ( SaveDialog1->Execute() ) {
- ListBox1->Items->LoadFromFile(SaveDialog1->FileName);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender) // 2)
- {
- for (int i = 1; i < StringGrid1->RowCount; i++) {
- StringGrid1->Cells[0][i] = "";
- StringGrid1->Cells[1][i] = "";
- }
- ListBox2->Items->Clear();
- StringGrid1->RowCount = 2;
- if ( OpenDialog1->Execute() ) {
- ListBox2->Items->LoadFromFile(OpenDialog1->FileName);
- }
- StringGrid1->RowCount = ListBox2->Items->Count + 1;
- for (int i = 0; i < ListBox2->Items->Count; i++) {
- StringGrid1->Cells[0][i+1] = i+1;
- StringGrid1->Cells[1][i+1] = ListBox2->Items->Strings[i];
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button3Click(TObject *Sender) // 3)
- {
- Memo1->Lines->Clear();
- AnsiString str = "";
- for (int i = 1; i < StringGrid1->RowCount; i++) {
- str += StringGrid1->Cells[1][i];
- if ( i-1 != StringGrid1->RowCount ) {
- str += " ";
- }
- }
- Memo1->Lines->Add(str);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- StringGrid1->Cells[0][0] = "#";
- StringGrid1->Cells[1][0] = "Hodnota";
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button4Click(TObject *Sender) // 4)
- {
- int a = 0,
- b = 0,
- c = 0;
- AnsiString str = Memo1->Lines->Strings[0],
- cislo = "";
- for (int i = 1; i <= str.Length(); i++) {
- if ( str[i] != ' ' ) {
- cislo += str[i];
- } else {
- if ( StrToInt(cislo) % 2 == 0 ) {
- a++;
- } else {
- b++;
- }
- if ( StrToInt(cislo) == 0 ) {
- c++;
- }
- cislo = "";
- }
- }
- ShowMessage(
- "Počet párnych: "+IntToStr(a)+"\n"+
- "Počet nepárnych: "+IntToStr(b)+"\n"+
- "Počet nulových: "+IntToStr(c)
- );
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button5Click(TObject *Sender) //5)
- {
- int pole[256];
- for (int i = 1; i < StringGrid1->RowCount; i++) {
- pole[i-1] = StrToInt(StringGrid1->Cells[1][i]);
- }
- for ( int i = 1; i < StringGrid1->RowCount; i++ ) {
- StringGrid->Cells[2][i] = pole[i-1];
- }
- i = 0;
- while ( i != StringGrid1->RowCount ) {
- if ( pole[i] < pole[i+1] ) {
- int p = pole[i];
- pole[i] = pole[i+1];
- pole[i+1] = p;
- i = 0;
- } else {
- i++;
- }
- }
- for ( int i = 1; i < StringGrid1->RowCount; i++ ) {
- StringGrid->Cells[3][i] = pole[i-1];
- }
- }
- //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment