Guru Mamatxalilov Subxonjon 2-Amaliy mashg’uloti. Mavzu: Hisoblash murakkabligi. Ishdan maqsad


Download 267.26 Kb.
bet3/3
Sana08.01.2022
Hajmi267.26 Kb.
#246061
1   2   3
Bog'liq
2-amaliyot (2)

2.1. rasm. Dasturni tanlash

Keyin joylashtirilgan komponentalarning properties dagi xususiyatlarini sozlab chiqamiz: sSkinManager ga qobiq fayl turgan papkani va qobiq nomini kо‘rsatamiz; sButtonlarning Caption iga kerakli nomlanishlarni yozamiz;





2.2. rasm. Rasmni tо‘g‘ri joylashtirish.

Endi rasmni bо‘laklarga bо‘lingan holda chiquvchi 30x30 о‘lchamli

kataklarni hosil qilish uchun

TPole *A[30][30];

TPole *B[30][30];

maydon kodlarini kiritamiz.

Int tipidagi k va V о‘zgaruvchilarini hosil qilamiz.

Rasmni ochish uchun sButton1ga quyidagicha kodlarni yozamiz (Bu kod bmp formatli rasmni OpenPictureDialog1 komponentasi orqali ochadi va biz hosil qilgan kataklarga bо‘laklagan holda joylashtiradi. Bundan tashqari rasm ochilgan payt bu rasm Image1 ga yaxlit holda chiqariladi):

if(OpenPictureDialog1->Execute()==true)

{ for(j=0;j

{for(i=0;i

{delete A[i][j];

delete B[i][j];

A[i][j]=NULL;

B[i][j]=NULL;

Delete PBitmap[j*Maydon_olchami_1+i];

PBitmap[j*Maydon_olchami_1+i]=NULL;} }Oyin_ishla();

MBitmap1 = new Graphics::TBitmap(); MBitmap1->Height=340;

MBitmap1->Width=340;

try{MBitmap1->LoadFromFile(OpenPictureDialog1->FileName); Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName); for(j=0;j

{if((i==Maydon_olchami-1)&&(j==Maydon_olchami-1)){ A[i][j]->status=2;

A[i][j]->SetA(i);

A[i][j]->SetB(j);

A[i][j]->X=IntToStr(j*Maydon_olchami+i+1); AS=i;

BS=j;


A[i][j]->Paint();

B[i][j]->status=2;

B[i][j]->SetA(i);

B[i][j]->SetB(j);

B[i][j]->X=IntToStr(j*Maydon_olchami+i+1); AS=i;

BS=j;}else{A[i][j]->status=1; Alisher1(MBitmap1,A[i][j]->Bitmap1,i,j); A[i][j]->X=IntToStr(j*Maydon_olchami+i+1); A[i][j]->SetA(i);

A[i][j]->SetB(j);

A[i][j]->Paint();

B[i][j]->status=1; Alisher1(MBitmap1,B[i][j]->Bitmap1,i,j);

B[i][j]->X=IntToStr(j*Maydon_olchami+i+1); B[i][j]->SetA(i);

B[i][j]->SetB(j);}} } } catch (...){MessageBeep(0); } delete MBitmap1; }

Rasmni almashtirishda esa quyidagi kodlar yoziladi (Bu kodda rasm almashtirish xuddi ikki о‘lchovli massivlarda bajariladigan amallarkabi bajariladi):

RoyxatToplami(); randomize();

for(int j=0;j

for(int i=0;i

{A[i][j]->status=2; AS=i;

BS=j;

A[i][j]->X=IntToStr(Maydon_olchami*Maydon_olchami); A[i][j]->Paint(); }else{A[i][j]->status=1; Alisher2=random(MyList->Count); AStruct=(PAList)MyList->Items[Alisher2];

A[i][j]->Bitmap1=B[AStruct->x][AStruct->y]->Bitmap1; A[i][j]->X=IntToStr(AStruct->I);

MyList->Delete(Alisher2); A[i][j]->Paint();}} } }

MeningRoyxatim(); int bp=0; bp=(Alisher());

if((bp%2)!=0) {TPole *C=new TPole(this); Graphics::TBitmap *CBitmap = new Graphics::TBitmap(); C->Bitmap1=CBitmap;

C->Bitmap1= A[Maydon_olchami-2][Maydon_olchami-1]->Bitmap1; C->X=A[Maydon_olchami-2][Maydon_olchami-1]->X; A[Maydon_olchami-2][Maydon_olchami-1]-



>Bitmap1=A[Maydon_olchami-3][Maydon_olchami-1]->Bitmap1; A[Maydon_olchami-2][Maydon_olchami-1]-

>Bitmap1=A[Maydon_olchami-3][Maydon_olchami-1]->Bitmap1; A[Maydon_olchami-2][Maydon_olchami-1]->X=A[Maydon_olchami-

3][Maydon_olchami-1]->X;

A[Maydon_olchami-3][Maydon_olchami-1]->Bitmap1=C->Bitmap1; A[Maydon_olchami-3][Maydon_olchami-1]->Bitmap1=C->Bitmap1; A[Maydon_olchami-3][Maydon_olchami-1]->X=C->X;

delete CBitmap; delete C; bp=(Alisher());

A[Maydon_olchami-3][Maydon_olchami-1]->Paint(); A[Maydon_olchami-2][Maydon_olchami-1]->Paint(); }

Bu dastur kodi uchun Main.h kutubxonasida ba’zi klass va strukturalar yaratiladi:

#ifndef MainH #define MainH

#include #include #include #include #include #include

#include #include #include #include "sButton.hpp" #include "sPanel.hpp" #include "sSkinProvider.hpp" #include "sSkinManager.hpp"

#define CM_XXX WM_APP+2 #define CM_XX1 WM_APP+3 typedef struct AList { int I;

int x;


int y; }TAList; typedef TAList* PAList;

class TForm1 : public TForm{ published: TsPanel *sPanel1;

TImage *Image1;

TOpenPictureDialog *OpenPictureDialog1; TsButton *sButton2;

TsButton *sButton1; TsSkinManager *sSkinManager1;

void fastcall FormClose(TObject *Sender, TCloseAction &Action); void fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);

void fastcall sButton1Click(TObject *Sender); void fastcall sButton2Click(TObject *Sender);

private: int AS,BS; int i,j;

Graphics::TBitmap *MBitmap1; Graphics::TBitmap *PBitmap[900]; void fastcall Oyin_ishla();

void fastcall Alisher1(Graphics::TBitmap

*Asosiy,Graphics::TBitmap *Qoshimcha,int k,int j);

void fastcall WndProc(Messages::TMessage &Message); void fastcall RoyxatToplami();

void fastcall MeningRoyxatim(); public:// foydalanuvchi e’lonlari

int Maydon_olchami,Maydon_olchami_1,Alisher2; TList *MyList;

PAList AStruct; PAList A1Struct;

fastcall TForm1(TComponent* Owner); int Alisher(void); };

extern PACKAGE TForm1 *Form1; #endif

Dastur natijasi.





2.3. rasm. Rasmni tо‘gri joylashtirilganligi

Xulosa

Men bu amaliy ish bajarish davomida Masalalarni yechishning hisoblash murakkabligini о‘rgandimva Ushbu jarayonni о‘yinlar yaratishda qо‘llashni o’ragandim Hisoblash murakkabligi – bir qancha algoritmlarni bajaruvchi ish hajmiga bog‘liq funksiylarni belgilydigan informatika va algoritm nazariyasidagi tushuncha hisoblanadi
Download 267.26 Kb.

Do'stlaringiz bilan baham:
1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling