0 / 0 / 0
Регистрация: 13.04.2015
Сообщений: 2
1

Составить блок-схему по готовой программе c++

16.05.2017, 14:43. Показов 594. Ответов 2
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
ПОМОГИТЕ ПОЖАЛУЙСТА!

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
// TIcTacToeeee.cpp: определяет точку входа для приложения.
//
 
#include "stdafx.h"
#include "TIcTacToeeee.h"
#include  <windowsx.h>
 
#define MAX_LOADSTRING 100
 
// Глобальные переменные:
HINSTANCE hInst;                                // текущий экземпляр
WCHAR szTitle[MAX_LOADSTRING];                  // Текст строки заголовка
WCHAR szWindowClass[MAX_LOADSTRING];            // имя класса главного окна
 
                                                // Отправить объявления функций, включенных в этот модуль кода:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
 
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
    _In_opt_ HINSTANCE hPrevInstance,
    _In_ LPWSTR    lpCmdLine,
    _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);
 
    // TODO: разместите код здесь.
 
    // Инициализация глобальных строк
    LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadStringW(hInstance, IDC_TICTACTOEEEE, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);
 
    // Выполнить инициализацию приложения:
    if (!InitInstance(hInstance, nCmdShow))
    {
        return FALSE;
    }
 
    HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TICTACTOEEEE));
 
    MSG msg;
 
    // Цикл основного сообщения:
    while (GetMessage(&msg, nullptr, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
 
    return (int)msg.wParam;
}
 
 
 
//
//  ФУНКЦИЯ: MyRegisterClass()
//
//  НАЗНАЧЕНИЕ: регистрирует класс окна.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEXW wcex;
 
    wcex.cbSize = sizeof(WNDCLASSEX);
 
    wcex.style = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc = WndProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TICTACTOEEEE));
    wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
    //wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
    wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_TICTACTOEEEE);
    wcex.lpszClassName = szWindowClass;
    wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
 
    return RegisterClassExW(&wcex);
}
 
//
//   ФУНКЦИЯ: InitInstance(HINSTANCE, int)
//
//   НАЗНАЧЕНИЕ: сохраняет обработку экземпляра и создает главное окно.
//
//   КОММЕНТАРИИ:
//
//        В данной функции дескриптор экземпляра сохраняется в глобальной переменной, а также
//        создается и выводится на экран главное окно программы.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
    hInst = hInstance; // Сохранить дескриптор экземпляра в глобальной переменной
 
    HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
 
    if (!hWnd)
    {
        return FALSE;
    }
 
    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);
 
    return TRUE;
}
 
//
//  ФУНКЦИЯ: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  НАЗНАЧЕНИЕ:  обрабатывает сообщения в главном окне.
//
//  WM_COMMAND — обработать меню приложения
//  WM_PAINT — отрисовать главное окно
//  WM_DESTROY — отправить сообщение о выходе и вернуться
//
//
 
//Игровые константы и переменные
const int CELL_SIZE = 100;
HBRUSH hbr1, hbr2;
HICON hIcon1, hIcon2;
int playerTurn = 1;
int gameBoard[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, };
int winner = 0;
int wins[3];
 
class CTicTacTOe
{
private:
    const int CELL_SIZE = 100;
    HBRUSH hbr1, hbr2;
    HICON hIcon1, hIcon2;
    int playerTurn = 1;
    int gameBoard[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, };
    int winner = 0;
    int wins[3];
 
public:
};
 
CTicTacTOe ticTacToe;
 
BOOL GetGameBoardRect(HWND hwnd, RECT * pRect)
{
    RECT rc;
    if (GetClientRect(hwnd, &rc))
    {
        int width = rc.right - rc.left;
        int height = rc.bottom - rc.top;
 
        pRect->left = (width - CELL_SIZE * 3) / 2;
        pRect->top = (height - CELL_SIZE * 3) / 2;
 
        pRect->right = pRect->left + CELL_SIZE * 3;
        pRect->bottom = pRect->top + CELL_SIZE * 3;
        return TRUE;
    }
    SetRectEmpty(pRect);
    return FALSE;
}
 
void DrawLine(HDC hdc, int x1, int y1, int x2, int y2)
{
    MoveToEx(hdc, x1, y1, NULL);
    LineTo(hdc, x2, y2);
}
int GetCellNumberFromPoint(HWND hwnd, int x, int y)
{
    POINT pt = { x,y };
    RECT rc;
 
    if (GetGameBoardRect(hwnd, &rc))
    {
        if (PtInRect(&rc, pt))
        {
            //Пользователь щелкнул внутри игрового поля
            //Normalize ( 0 to 3*CELL_SIZE)
            x = pt.x - rc.left;
            y = pt.y - rc.top;
 
            int column = x / CELL_SIZE;
            int row = y / CELL_SIZE;
 
            //Конвертировать в индекс (0 to 8)
            return column + row * 3;
        }
    }
    return -1; // Вне игрового поля или сбой
}
 
BOOL GetCellRect(HWND hWnd, int index, RECT * pRect)
{
    RECT rcBoard;
 
    SetRectEmpty(pRect);
    if (index < 0 || index > 8)
        return FALSE;
 
    if (GetGameBoardRect(hWnd, &rcBoard))
    {
        //Convert index from 0 to 8 info x,y pair
        int y = index / 3; //Номер строки
        int x = index % 3; // Номер столбца
 
        pRect->left = rcBoard.left + x * CELL_SIZE + 1;
        pRect->top = rcBoard.top + y * CELL_SIZE + 1;
        pRect->right = pRect->left + CELL_SIZE - 1;
        pRect->bottom = pRect->top + CELL_SIZE - 1;
 
        return TRUE;
 
    }
 
    return FALSE;
 
}
/*
Returns:
0 - No winner
1 - Player wins
2 - Player wins
3 - It' a draw
*/
 
/*
0,1,2
3,4,5
6,7,8
*/
 
int GetWinner(int wins[3])
{
    int cells[] = { 0,1,2, 3,4,5, 6,7,8,  0,3,6, 1,4,7,  2,5,8, 0,4,8, 2,4,6 };
 
    //chech for winner
    for (int i = 0; i < ARRAYSIZE(cells); i += 3)
    {
        if ((0 != gameBoard[cells[i]]) && gameBoard[cells[i]] == gameBoard[cells[i + 1]] && gameBoard[cells[i]] == gameBoard[cells[i + 2]])
        {
            //We have a winner
            wins[0] = cells[i];
            wins[1] = cells[i + 1];
            wins[2] = cells[i + 2];
 
            return gameBoard[cells[i]];
        }
    }
 
    //Далее, посмотрим, остались ли какие-то ячейки пустыми
    for (int i = 0; i < ARRAYSIZE(gameBoard); ++i)
        if (gameBoard[i])
            return 0; //Продолжай играть...
 
    return 3; //it's a draw
}
 
void ShowTurn(HWND hwnd, HDC hdc)
{
    static const WCHAR szTurn1[] = L"Turn: Игрок 1";
    static const WCHAR szTurn2[] = L"Turn: Игрок 2";
 
    const WCHAR * pszTurnText = NULL;
    
    switch (winner)
    {
    case 0: //Продолжай играть
        pszTurnText = (playerTurn == 1) ? szTurn1 : szTurn2;
        break;
    case 1: //Player 1 wins
        pszTurnText = L"Игрок 1 победил!";
        break;
    case 2: //Player 2 wins
        pszTurnText = L"Игрок 2 победил!";
        break;
    case 3: //It' a draw
        pszTurnText = L"Это ничья!";
        break;
 
    }
 
    RECT rc;
    
    if (NULL != pszTurnText && GetClientRect(hwnd, &rc))
    {
        rc.top = rc.bottom - 48;
        FillRect(hdc, &rc, (HBRUSH)(GetStockObject(GRAY_BRUSH)));
        SetTextColor(hdc, RGB(255, 255, 255));
        SetBkMode(hdc, TRANSPARENT);
        DrawText(hdc, pszTurnText, lstrlen(pszTurnText), &rc, DT_CENTER);
    }
}
 
void DrawIconCentered(HDC hdc,RECT * pRect,HICON hIcon)
{
    const int ICON_WIDTH = GetSystemMetrics(SM_CXICON);
    const int ICON_HEIGHT = GetSystemMetrics(SM_CXICON);
 
    if (NULL != pRect)
    {
        int left = pRect->left + ((pRect->right - pRect->left) - ICON_WIDTH) / 2;
        int top = pRect->top + ((pRect->bottom - pRect->top) - ICON_HEIGHT) / 2;
        DrawIcon(hdc, left, top, hIcon);
    }
}
 
void ShowWinner(HWND hWnd, HDC hdc)
{
    RECT rcWin;
 
    for (int i = 0; i < 3; ++i)
    {
        if (GetCellRect(hWnd, wins[i], &rcWin))
        {
            FillRect(hdc, &rcWin, (winner == 1) ? hbr1 : hbr2);
            DrawIconCentered(hdc, &rcWin, (winner == 1) ? hIcon1 : hIcon2);
        }
    }
}
 
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_CREATE:
         {
            hbr1 = CreateSolidBrush(RGB(255, 0, 0));
            hbr2 = CreateSolidBrush(RGB(0, 0, 255));
 
            //Иконки загрузки проигрывателя
            hIcon1 = LoadIcon(hInst, MAKEINTRESOURCE(IDI_PLAYER1));
            hIcon2 = LoadIcon(hInst, MAKEINTRESOURCE(IDI_PLAYER2));
         }
         break;
    case WM_COMMAND:
         {
            int wmId = LOWORD(wParam);
            // Разобрать выбор в меню:
            switch (wmId)
            {
            case ID_FILE_NEWGAME:
                 {
                    int ret = MessageBox(hWnd, L"Вы уверены ,что хотите начать новую игру?", L"Новая игра", MB_YESNO | MB_ICONQUESTION);
                    if (IDYES == ret)
                    {
                      //Сброс и запуск новой игры
                      playerTurn = 1;
                      winner = 0;
                      ZeroMemory(gameBoard, sizeof(gameBoard));
                      //Принудительное сообщение с краской
                      InvalidateRect(hWnd, NULL, TRUE); //Post WM_PAINT to  our windowsProc. It gets queued in our msg queue
                      UpdateWindow(hWnd); // force  immediate handling of WM_PAINT
                  }
            }
            break;
        case IDM_ABOUT:
            DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
            break;
        case IDM_EXIT:
            DestroyWindow(hWnd);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
    }
    break;
    case WM_LBUTTONDOWN:
         {
 
            int xPos = GET_X_LPARAM(lParam);
            int yPos = GET_Y_LPARAM(lParam);
 
            //Only handle clicks if  it is a player turn (i.e. 1 or 2)
            if (0 == playerTurn)
                break;
            int index = GetCellNumberFromPoint(hWnd, xPos, yPos);
 
            HDC hdc = GetDC(hWnd);
            if (NULL != hdc)
            {
            //WCHAR temp[100];
 
            //wsprintf(temp, L"Index= %d", index);
            //TextOut(hdc, xPos, yPos, temp, lstrlen(temp));
 
            //Get cell dimension from its index
            if (index != -1)
            {
                RECT rcCell;
                if ((0 == gameBoard[index]) && GetCellRect(hWnd, index, &rcCell))
                {
                    gameBoard[index] = playerTurn;
 
                    //FillRect(hdc, &rcCell, (playerTurn == 1) ? hbr1 : hbr2);
                    DrawIconCentered(hdc, &rcCell, (playerTurn == 1) ? hIcon1 : hIcon2);
 
                    //Chech for a winner!
                    winner = GetWinner(wins);
                    if (winner == 1 || winner == 2)
                    {
                        ShowWinner(hWnd, hdc);
 
                        //We have a winner 
                        MessageBox(hWnd,
                            (winner == 1) ? L"Игрок 1 является победителем" : L"Игрок 2 является победителем!",
                            L"Ты победил!",
                            MB_OK | MB_ICONINFORMATION);
                        playerTurn = 0;
                    }
                    else if (3 == winner)
                    {
                        //It's a draw!
                        MessageBox(hWnd,
                            L"На этот раз никто не выйграл!",
                            L"Это ничья!",
                            MB_OK | MB_ICONEXCLAMATION);
                        playerTurn = 0;
                    }
                    else if (0 == winner)
                    {
                        playerTurn = (playerTurn == 1) ? 2 : 1;
                    }
 
                    //DisPlay turn
                    ShowTurn(hWnd, hdc);
                }
 
            }
            ReleaseDC(hWnd, hdc);
         }
       }
       break;
 
    case WM_GETMINMAXINFO:
       {
           MINMAXINFO * pMinMax = (MINMAXINFO*)lParam;
           if (pMinMax != NULL)
           {
               pMinMax->ptMinTrackSize.x = CELL_SIZE * 5;
               pMinMax->ptMinTrackSize.y = CELL_SIZE * 5;
           }
    }
    break;
    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hWnd, &ps);
 
        RECT rc;
 
        if (GetGameBoardRect(hWnd, &rc))
        {
            RECT rcClient;
 
            //Dilsplay player text and turn
            if (GetClientRect(hWnd, &rcClient))
            {
                const WCHAR szPlayer1[] = L"Игрок 1";
                const WCHAR szPlayer2[] = L"Игрок 2";
 
                SetBkMode(hdc, TRANSPARENT);
                //Draw Player 1 and Plaer 2 text
                SetTextColor(hdc, RGB(255, 255, 0));
                TextOut(hdc, 16, 16, szPlayer1, ARRAYSIZE(szPlayer1));
                DrawIcon(hdc, 24, 40, hIcon1);
 
                SetTextColor(hdc, RGB(0, 0, 255));
                TextOut(hdc, rcClient.right - 72, 16, szPlayer2, ARRAYSIZE(szPlayer2));
                DrawIcon(hdc, rcClient.right - 64, 40, hIcon2);
 
                //DisPlay turn
                ShowTurn(hWnd, hdc);
            }
 
            //Draw game board
            FillRect(hdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));
            //Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
 
            for (int i = 0; i < 4; ++i)
            {
                //Draw lines for cells
                //Vertical lines
                DrawLine(hdc, rc.left + CELL_SIZE * i, rc.top, rc.left + CELL_SIZE * i, rc.bottom);
                //Draw Horizontal lines
                DrawLine(hdc, rc.left, rc.top + CELL_SIZE * i, rc.right, rc.top + CELL_SIZE * i);
            }
 
            //Draw all occupied cells
            RECT rcCell;
 
            for (int i = 0; i < ARRAYSIZE(gameBoard); ++i)
            {
                if ((0 != gameBoard[i]) && GetCellRect(hWnd, i, &rcCell))
                {
                    //FillRect(hdc, &rcCell, (gameBoard[i] == 2) ? hbr2 : hbr1);
                    DrawIconCentered(hdc, &rcCell, (gameBoard[i] == 1) ? hIcon1 : hIcon2);
                }
            }
 
            if (winner == 1 || winner == 2)
            {
 
                //Show winner
                ShowWinner(hWnd, hdc);
            }
        }
 
        EndPaint(hWnd, &ps);
    }
    break;
    case WM_DESTROY:
        DeleteObject(hbr1);
        DeleteObject(hbr2);
        //Dispose of icons images
        DestroyIcon(hIcon1);
        DestroyIcon(hIcon2);
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
        }
        return 0;
    }
 
    // Обработчик сообщений для окна "О программе".
    INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
        UNREFERENCED_PARAMETER(lParam);
        switch (message)
        {
        case WM_INITDIALOG:
            return (INT_PTR)TRUE;
 
        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
            {
                EndDialog(hDlg, LOWORD(wParam));
                return (INT_PTR)TRUE;
            }
            break;
        }
        return (INT_PTR)FALSE;
    }
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
16.05.2017, 14:43
Ответы с готовыми решениями:

Составить блок-схему по программе
Не получается создать блок схему алгоритма по тексту программы. 1 курс только помогите кто может)

составить блок-схему к программе
Добрые люди) Помогите пожалуйста срочно составить в ближайшее время блок-схему к этой программе,...

Составить блок-схему к программе
составить блок-схему программы(самое основное)#include&lt;stdio.h&gt; #include&lt;stdlib.h&gt;...

Составить блок-схему по программе
Кто сможет накидать блок схему по программе? #include &lt;iostream&gt; using namespace std; void...

2
Рэмбо комнатный
103 / 103 / 99
Регистрация: 05.03.2017
Сообщений: 511
16.05.2017, 17:21 2
ну я чот ору))))))
0
0 / 0 / 0
Регистрация: 13.04.2015
Сообщений: 2
16.05.2017, 17:22  [ТС] 3
почему?
0
16.05.2017, 17:22
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
16.05.2017, 17:22
Помогаю со студенческими работами здесь

Составить блок-схему к программе с матрицами
помогите составить блок схему: #include&lt;stdio.h&gt; #include&lt;math.h&gt; #include&lt;stdlib.h&gt; void...

Помогите составить блок-схему к программе
помогите сделать блок-схему к этому коду #include&lt;stdio.h&gt; #include&lt;math.h&gt; #include&lt;stdlib.h&gt;...

Составить схему алгоритма(блок-схему) по заданию
Дана матрица S. Нужно составить схему алгоритма, который элементы в каждом столбце этой матрицы...

Создать блок-схему по программе
Задача:составить программу в которой случайным образом определен массив и два указателя, один из...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
3
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru