Термінова допомога студентам
Дипломи, курсові, реферати, контрольні...

Код програмної реалізації

РефератДопомога в написанніДізнатися вартістьмоєї роботи

Cout << «Количество шагов: «<< k << endl; Hanoi_towers (k, start_peg, destination_peg, buffer_peg); Int BCX_Line (HWND, int, int, int, int, int=0,HDC=0); If (os.dwPlatformId == VER_PLATFORM_WIN32s) return 0; If (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS). While (strcmp (szClassName, «ttyGrab») ≠ 0). Os. dwOSVersionInfoSize = sizeof (OSVERSIONINFO); HConWnd = GetNextWindow (hConWnd… Читати ще >

Код програмної реалізації (реферат, курсова, диплом, контрольна)

#include // Win32API Header File.

#include.

#include.

#include.

#include.

using namespace std;

#define Red RGB (255,0,0).

#define Lime RGB (206,255,0).

#define Blue RGB (0,0,255).

#define My RGB (50,100,40).

static HWND hConWnd;

int BCX_Line (HWND, int, int, int, int, int=0,HDC=0);

HWND GetConsoleWndHandle (void);

void hanoi_towers (int quantity, int from, int to, int buf_peg) //quantity-число колец, from-начальное положение колец (1−3), to-конечное положение колец (1−3).

{ //buf_peg — промежуточный колышек (1−3).

if (quantity ≠ 0).

{.

hanoi_towers (quantity-1, from, buf_peg, to);

cout << from < «<< to << endl;

hanoi_towers (quantity-1, buf_peg, to, from);

}.

}.

double krok (double n){.

double k=pow (2,n)-1;

cout << «Количество шагов: «<< k << endl;

}.

int Nachalo (int stolb, int k){.

BCX_Line (hConWnd, 290, 30, 290,120, Blue);

BCX_Line (hConWnd, 370, 30, 370,120, Blue);

BCX_Line (hConWnd, 450, 30, 450,120, Blue);

BCX_Line (hConWnd, 220, 120,510,120, Blue);

//Strelka.

BCX_Line (hConWnd, 520, 75, 600,75, Blue);

BCX_Line (hConWnd, 580, 55, 600,75, Blue);

BCX_Line (hConWnd, 580, 95, 600,75, Blue);

int l=114;

int m, n;

if (stolb==1).

{.

m=245; n=335;

while (k≠0){.

BCX_Line (hConWnd, m, l, n, l, Lime);

m=m+10;

n=n-10;

l=l-7;

k=k-1;

}.

}.

if (stolb==2).

{.

m=325;n=415;

while (k≠0){.

BCX_Line (hConWnd, m, l, n, l, Lime);

m=m+10;

n=n-10;

l=l-7;

k=k-1;

}.

}.

if (stolb==3).

{.

m=405;n=495;

while (k≠0){.

BCX_Line (hConWnd, m, l, n, l, Lime);

m=m+10;

n=n-10;

l=l-7;

k=k-1;

}.

}.

}.

int Konec (int stolb, int k){.

BCX_Line (hConWnd, 290, 160, 290,250, Blue);

BCX_Line (hConWnd, 370, 160, 370,250, Blue);

BCX_Line (hConWnd, 450, 160, 450,250, Blue);

BCX_Line (hConWnd, 220, 250, 510,250, Blue);

int h=244;

int m, n;

if (stolb==1).

{.

m=245;n=335;

while (k≠0){.

BCX_Line (hConWnd, m, h, n, h, Lime);

m=m+10;

n=n-10;

h=h-7;

k=k-1;

}.

}.

if (stolb==2).

{.

m=325;n=415;

while (k≠0){.

BCX_Line (hConWnd, m, h, n, h, Lime);

m=m+10;

n=n-10;

h=h-7;

k=k-1;

}.

}.

if (stolb==3).

{.

m=405;n=495;

while (k≠0){.

BCX_Line (hConWnd, m, h, n, h, Lime);

m=m+10;

n=n-10;

h=h-7;

k=k-1;

}.

}.

}.

int main ().

{.

int m, l, k, h, r;

double n;

setlocale (LC_ALL," rus");

int start_peg, destination_peg, buffer_peg, plate_quantity;

cout << «Номер первого столбика (1−3):» << endl;

cin >> start_peg;

if (start_peg>3){.

printf («Ви неправильно вказали номер стовпця! «);

}.

cout << «Номер конечного столбика (1−3):» << endl;

cin >> destination_peg;

cout << «Номер промежуточного столбика (1−3):» << endl;

cin >> buffer_peg;

cout << «Количество дисков (1−5):» << endl;

cin >> k;

hanoi_towers (k, start_peg, destination_peg, buffer_peg);

krok (k);

hConWnd = GetConsoleWndHandle ();

if (hConWnd).

{.

Nachalo (start_peg, k);

Konec (destination_peg, k);

getchar (); // wait.

}.

return 0;

}.

int BCX_Line (HWND Wnd, int x1, int y1, int x2, int y2, int Pen, HDC DrawHDC).

{.

int a, b=0;

HPEN hOPen;

// penstyle, width, color.

HPEN hNPen = CreatePen (PS_SOLID, 2, Pen);

if (!DrawHDC) DrawHDC = GetDC (Wnd), b = 1;

hOPen = (HPEN)SelectObject (DrawHDC, hNPen);

// starting point of line.

MoveToEx (DrawHDC, x1, y1, NULL);

// ending point of line.

a = LineTo (DrawHDC, x2, y2);

DeleteObject (SelectObject (DrawHDC, hOPen));

if (b) ReleaseDC (Wnd, DrawHDC);

return a;

}.

HWND GetConsoleWndHandle (void).

{.

HWND hConWnd;

OSVERSIONINFO os;

char szTempTitle[64], szClassName[128], szOriginalTitle[1024];

os.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);

GetVersionEx (&os);

// may not work on WIN9x.

if (os.dwPlatformId == VER_PLATFORM_WIN32s) return 0;

GetConsoleTitle (szOriginalTitle, sizeof (szOriginalTitle));

sprintf (szTempTitle," %u — %u", GetTickCount (), GetCurrentProcessId ());

SetConsoleTitle (szTempTitle);

Sleep (40);

// handle for NT.

hConWnd = FindWindow (NULL, szTempTitle);

SetConsoleTitle (szOriginalTitle);

// may not work on WIN9x.

if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS).

{.

hConWnd = GetWindow (hConWnd, GW_CHILD);

if (hConWnd == NULL) return 0;

GetClassName (hConWnd, szClassName, sizeof (szClassName));

while (strcmp (szClassName, «ttyGrab») ≠ 0).

{.

hConWnd = GetNextWindow (hConWnd, GW_HWNDNEXT);

if (hConWnd == NULL) return 0;

GetClassName (hConWnd, szClassName, sizeof (szClassName));

}.

}.

return hConWnd;

}.

Показати весь текст
Заповнити форму поточною роботою