- Katılım
- 29 Mayıs 2019
- Mesajlar
- 8,558
- Tepkime puanı
- 2
Girilen elemanlara ait istenilen elemandan oluşan alt kümeleri ve sayısını kullancıya gösteren programdır. Girilen elemanların aynı olup olmadığıda kontrol edilmiştir.
Kod:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ListBox1->Items->Add(Edit1->Text);
Edit1->Text="";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
ListBox2->Items->Clear();
ListBox3->Items->Clear();
ListBox4->Items->Clear();
String of=InputBox("GİRİş","Bulmak İstediğiniz Alt Kümelere Ait Eleman Sayısını Giriniz","");
int altkume=StrToInt(of);
Application->MessageBox("Öncelikli Olarak Aynı Elemanların Eleminasyonu Kontrolü","UYARI",MB_ICONINFORMATION);
for(int i=0;i<ListBox1->Items->Count;i++)
{
for(int j=i+1;j<ListBox1->Items->Count;j++)
{
if(ListBox1->Items->Strings[i]==ListBox1->Items->Strings[j])
ListBox1->Items->Delete(j);
}
}
for(int i=0;i<ListBox1->Items->Count;i++)
{
for(int j=i+1;j<ListBox1->Items->Count;j++)
{
String olustur=ListBox1->Items->Strings[i]+","+ListBox1->Items->Strings[j];
ListBox3->Items->Add(olustur);
}
}
if(altkume==1)
{
for(int bir=0;bir<ListBox1->Items->Count;bir++)
ListBox2->Items->Add(ListBox1->Items->Strings[bir]);
}
else if(altkume==2)
{
for(int bir=0;bir<ListBox3->Items->Count;bir++)
ListBox2->Items->Add(ListBox3->Items->Strings[bir]);
}
else if(altkume>2)
{
for(int dolan=0;dolan<altkume-2;dolan++)
{
for(int i=0;i<ListBox3->Items->Count;i++)
{
String tut=ListBox3->Items->Strings[i];
String virgul=",";
while(tut.Length()>0)
{
int pos=tut.Pos(virgul);
String copy=tut;
String listesalla=tut.Delete(pos,tut.Length());
ListBox5->Items->Add(listesalla);
tut=copy.Delete(1,pos);
pos=tut.Pos(virgul);
if(pos<1)
{
ListBox5->Items->Add(tut);
break;
}
}//while sonu
for(int j=i+1;j<ListBox3->Items->Count;j++)
{
String tut=ListBox3->Items->Strings[j];
String virgul=",";
while(tut.Length()>0)
{
int pos=tut.Pos(virgul);
String copy=tut;
String listesalla=tut.Delete(pos,tut.Length());
int gontrol=0;
for(int g=0;g<ListBox6->Items->Count;g++)
{
if(listesalla==ListBox6->Items->Strings[g])
gontrol=1;
}
if(gontrol==0)
ListBox6->Items->Add(listesalla);
tut=copy.Delete(1,pos);
pos=tut.Pos(virgul);
if(pos<1)
{
int pontrol=0;
for(int g=0;g<ListBox6->Items->Count;g++)
{
if(tut==ListBox6->Items->Strings[g])
pontrol=1;
}
if(pontrol==0)
ListBox6->Items->Add(tut);
break;
}
}
} // icteki for sonu
for(int k=0;k<ListBox6->Items->Count;k++) // x foru
{
int kontrol=0;
for(int l=0;l<ListBox5->Items->Count;l++)
{
if(ListBox6->Items->Strings[k]==ListBox5->Items->Strings[l])
kontrol=1;
}
String uret="";
int saydir;
int konum;
for(int m=0;m<ListBox4->Items->Count;m++)
{
saydir=0;
for(int n=0;n<ListBox5->Items->Count;n++)
{
konum=ListBox4->Items->Strings[m].Pos(ListBox5->Items->Strings[n]);
if(konum>0)
saydir++;
}
konum=ListBox4->Items->Strings[m].Pos(ListBox6->Items->Strings[k]);
if(konum>0)
saydir++;
if(saydir==ListBox5->Items->Count+1)
kontrol=1;
}
if(kontrol==0)
{
for(int z=0;z<ListBox5->Items->Count;z++)
{
uret+=ListBox5->Items->Strings[z];
uret+=",";
}
uret+=ListBox6->Items->Strings[k];
ListBox4->Items->Add(uret);
}//if sonu
} // x foru sonu
ListBox5->Items->Clear();
ListBox6->Items->Clear();
} //son for
ListBox3->Items->Clear();
for(int donelim=0;donelim<ListBox4->Items->Count;donelim++)
{
ListBox3->Items->Add(ListBox4->Items->Strings[donelim]);
}
ListBox4->Items->Clear();
ListBox2->Items->Clear();
for(int bitir=0;bitir<ListBox3->Items->Count;bitir++)
{
ListBox2->Items->Add(ListBox3->Items->Strings[bitir]);
}
}
}//else if
Label2->Caption="Girilen Elemanlara Ait "+IntToStr(altkume)+" Elamanlı Alt Kümeler";
Label3->Caption=IntToStr(ListBox2->Items->Count)+".Adet";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
if((Key<'0'||Key>'9')&&(Key!=VK_BACK))
Key=0;
}
//---------------------------------------------------------------------------