Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++: The WordGame codes are below ----------------------------------------------

ID: 3780292 • Letter: C

Question

C++:

The WordGame codes are below

------------------------------------------------------------------------

#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include "resource.h"
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>

using namespace std;

//Declare global variables
char word[4]={'d','b','a','w'};
char letter;
int check[4]={0,0,0,0};
HWND t1,t2,t3,t4;

HINSTANCE hInst;

BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
    case WM_INITDIALOG:
    {
    }
    return TRUE;

    case WM_CLOSE:
    {
        EndDialog(hwndDlg, 0);
    }
    return TRUE;

    case WM_COMMAND:
    {
        switch(LOWORD(wParam))
        {
            //insert the cases for the buttons
        case 1:
            //check if the letter a is in the Word
            //get the handes for each textbox
            t1=GetDlgItem(hwndDlg,100);
            t2=GetDlgItem(hwndDlg,101);
            t3=GetDlgItem(hwndDlg,102);
            t4=GetDlgItem(hwndDlg,103);
            // check if the letter is in the word
            for (int i=0;i<4;i++){
                if (word[i]=='a')
                check[i]=1;
            }
            //write the letter in the correct position
            for(int i=0;i<4;i++){
                    switch(i)
                    {
                    case 0:
                    if(check[i]==1){
                    SetWindowText(t1,"a");
                    check[i]=0;
                    }
                    break;
                    case 1:
                    if(check[i]==1){
                    SetWindowText(t2,"a");
                    check[i]=0;

                    }
                    break;
                    case 2:
                    if(check[i]==1){
                    SetWindowText(t3,"a");
                    check[i]=0;
                    }
                    break;
                    case 3:
                    if(check[i]==1){
                    SetWindowText(t3,"a");
                    check[i]=0;
                    }
                    break;
                    }
            }
         break;

         case 2:
            //check if the letter a is in the Word
            //get the handes for each textbox
            t1=GetDlgItem(hwndDlg,100);
            t2=GetDlgItem(hwndDlg,101);
            t3=GetDlgItem(hwndDlg,102);
            t4=GetDlgItem(hwndDlg,103);
            // check if the letter is in the word
            for (int i=0;i<4;i++){
                if (word[i]=='b')
                check[i]=1;
            }
            //write the letter in the correct position
            for(int i=0;i<4;i++){
                    switch(i)
                    {
                    case 0:
                    if(check[i]==1){
                    SetWindowText(t1,"b");
                    check[i]=0;
                    }
                    break;
                    case 1:
                    if(check[i]==1){
                    SetWindowText(t2,"b");
                    check[i]=0;
                    }
                    break;
                    case 2:
                    if(check[i]==1){
                    SetWindowText(t3,"b");
                    check[i]=0;
                    }
                    break;
                    case 3:
                    if(check[i]==1){
                    SetWindowText(t3,"b");
                    check[i]=0;
                    }
                    break;
                    }
            }
         break;

        }
    }
    return TRUE;
    }
    return FALSE;
}


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    hInst=hInstance;
    InitCommonControls();
    return DialogBox(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
}

___________________________
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"


//
// Dialog resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
DLG_MAIN DIALOG 0, 0, 286, 296
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "Ms Shell Dlg"
{
    EDITTEXT        100, 35, 38, 30, 26, ES_AUTOHSCROLL, WS_EX_LEFT
    EDITTEXT        101, 81, 38, 30, 26, ES_AUTOHSCROLL, WS_EX_LEFT
    EDITTEXT        102, 124, 38, 30, 26, ES_AUTOHSCROLL, WS_EX_LEFT
    EDITTEXT        103, 169, 37, 30, 26, ES_AUTOHSCROLL, WS_EX_LEFT
    PUSHBUTTON      "A", 1, 34, 94, 21, 18, 0, WS_EX_LEFT
    PUSHBUTTON      "B", 2, 61, 94, 18, 18, 0, WS_EX_LEFT
    PUSHBUTTON      "C", 0, 84, 94, 19, 17, 0, WS_EX_LEFT
    PUSHBUTTON      "D", 0, 107, 94, 18, 17, 0, WS_EX_LEFT
    PUSHBUTTON      "E", 0, 129, 94, 18, 17, 0, WS_EX_LEFT
    PUSHBUTTON      "F", 0, 153, 94, 19, 18, 0, WS_EX_LEFT
    PUSHBUTTON      "G", 0, 176, 94, 18, 17, 0, WS_EX_LEFT
}

//
// Manifest resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
1                  RT_MANIFEST    ".\manifest.xml"

_____________________________________________

Download the WordGame project The program lei the user to guess a 4 letter word each time that the use click a letter button the program will cheek if the letter is in the word and show the letter in a text box. The word is stored in a char variable (constraint the size to a 4 letter word) Code all the missing buttons Show a counter of the number of mistakes Use a message box to show the user that he gassed the word correctly Let the user to reset the game.

Explanation / Answer

Solution:

#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include "resource.h"
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
using namespace std;
//Declare global variables
char word[4]={'d','b','a','w'};
char letter;
int check[4]={0,0,0,0};
HWND t1,t2,t3,t4;
HINSTANCE hInst;
BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
{
}
return TRUE;
case WM_CLOSE: // If the user clicks the X to close the dialog box

{
EndDialog(hwndDlg, 0);
}
return TRUE;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
//insert the cases for the buttons
case 1:
//check if the letter a is in the Word
//get the handes for each textbox
t1=GetDlgItem(hwndDlg,100);
t2=GetDlgItem(hwndDlg,101);
t3=GetDlgItem(hwndDlg,102);
t4=GetDlgItem(hwndDlg,103);
// check if the letter is in the word
for (int i=0;i<4;i++){
if (word[i]=='a')
check[i]=1;
}
//write the letter in the correct position
for(int i=0;i<4;i++){
switch(i)
{
case 0:
if(check[i]==1){
SetWindowText(t1,"a");
check[i]=0;
}
break;
case 1:
if(check[i]==1){
SetWindowText(t2,"a");
check[i]=0;
}
break;
case 2:
if(check[i]==1){
SetWindowText(t3,"a");
check[i]=0;
}
break;
case 3:
if(check[i]==1){
SetWindowText(t3,"a");
check[i]=0;
}
break;
}
}
break;
case 2:
//check if the letter b is in the Word
//get the handes for each textbox
t1=GetDlgItem(hwndDlg,100);
t2=GetDlgItem(hwndDlg,101);
t3=GetDlgItem(hwndDlg,102);
t4=GetDlgItem(hwndDlg,103);
// check if the letter is in the word
for (int i=0;i<4;i++){
if (word[i]=='b')
check[i]=1;
}
//write the letter in the correct position
for(int i=0;i<4;i++){
switch(i)
{
case 0:
if(check[i]==1){
SetWindowText(t1,"b");
check[i]=0;
}
break;
case 1:
if(check[i]==1){
SetWindowText(t2,"b");
check[i]=0;
}
break;
case 2:
if(check[i]==1){
SetWindowText(t3,"b");
check[i]=0;
}
break;
case 3:
if(check[i]==1){
SetWindowText(t3,"b");
check[i]=0;
}
break;
}
}
break;
case 3:
//check if the letter d is in the Word
//get the handes for each textbox
t1=GetDlgItem(hwndDlg,100);
t2=GetDlgItem(hwndDlg,101);
t3=GetDlgItem(hwndDlg,102);
t4=GetDlgItem(hwndDlg,103);
// check if the letter is in the word
for (int i=0;i<4;i++){
if (word[i]=='d')
check[i]=1;
}
//write the letter in the correct position
for(int i=0;i<4;i++){
switch(i)
{
case 0:
if(check[i]==1){
SetWindowText(t1,"d");
check[i]=0;
}
break;
case 1:
if(check[i]==1){
SetWindowText(t2,"d");
check[i]=0;
}
break;
case 2:
if(check[i]==1){
SetWindowText(t3,"d");
check[i]=0;
}
break;
case 3:
if(check[i]==1){
SetWindowText(t3,"d");
check[i]=0;
}
break;
}
}
break;
case 4:
//check if the letter w is in the Word
//get the handes for each textbox
t1=GetDlgItem(hwndDlg,100);
t2=GetDlgItem(hwndDlg,101);
t3=GetDlgItem(hwndDlg,102);
t4=GetDlgItem(hwndDlg,103);
// check if the letter is in the word
for (int i=0;i<4;i++){
if (word[i]=='w')
check[i]=1;
}
//write the letter in the correct position
for(int i=0;i<4;i++){
switch(i)
{
case 0:
if(check[i]==1){
SetWindowText(t1,"w");
check[i]=0;
}
break;
case 1:
if(check[i]==1){
SetWindowText(t2,"w");
check[i]=0;
}
break;
case 2:
if(check[i]==1){
SetWindowText(t3,"w");
check[i]=0;
}
break;
case 3:
if(check[i]==1){
SetWindowText(t3,"w");
check[i]=0;
}
break;
}
}
break;
}
}
return TRUE;
}
return FALSE;
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
hInst=hInstance;
InitCommonControls();
return DialogBox(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
}
___________________________
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"

//
// Dialog resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
DLG_MAIN DIALOG 0, 0, 286, 296
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "Ms Shell Dlg"
BEGIN
{
EDITTEXT 100, 35, 38, 30, 26, ES_AUTOHSCROLL, WS_EX_LEFT
EDITTEXT 101, 81, 38, 30, 26, ES_AUTOHSCROLL, WS_EX_LEFT
EDITTEXT 102, 124, 38, 30, 26, ES_AUTOHSCROLL, WS_EX_LEFT
EDITTEXT 103, 169, 37, 30, 26, ES_AUTOHSCROLL, WS_EX_LEFT
PUSHBUTTON "A", 1, 34, 94, 21, 18, 0, WS_EX_LEFT
PUSHBUTTON "B", 2, 61, 94, 18, 18, 0, WS_EX_LEFT
PUSHBUTTON "C", 0, 84, 94, 19, 17, 0, WS_EX_LEFT
PUSHBUTTON "D", 0, 107, 94, 18, 17, 0, WS_EX_LEFT
PUSHBUTTON "E", 0, 129, 94, 18, 17, 0, WS_EX_LEFT
PUSHBUTTON "F", 0, 153, 94, 19, 18, 0, WS_EX_LEFT
PUSHBUTTON "G", 0, 176, 94, 18, 17, 0, WS_EX_LEFT
return 0;
getch();
}

Output:

control

Property

Setting

Form1

Name

frmSearch

Size

834, 532

Text

HTG Word Search

WindowState

Maximized

Panel

Name

pnlGrid

Dock

Left

Size

518, 380

Label

Name

lblITBF

Dock

Top

Location

518, 0

Text

""

Panel

Name

pnlItems

Location

518, 26

Size

308, 363

Panel

Name

Panel1

Dock

Bottom

Label

Name

lblTimeLeft

AutoSize

True

BorderStyle

FixedSingle

Location

10, 12 ( Inside Panel 1 )

Label

Name

lblScore

Location

93, 12 ( Inside Panel 1 )

Size

706, 103

Button

Name

btnStart

Location

12, 75 ( Inside Panel 1 )

Text

Start

Timer

Name

tmrCountDown

Interval

100

control

Property

Setting

Form1

Name

frmSearch

Size

834, 532

Text

HTG Word Search

WindowState

Maximized

Panel

Name

pnlGrid

Dock

Left

Size

518, 380

Label

Name

lblITBF

Dock

Top

Location

518, 0

Text

""

Panel

Name

pnlItems

Location

518, 26

Size

308, 363

Panel

Name

Panel1

Dock

Bottom

Label

Name

lblTimeLeft

AutoSize

True

BorderStyle

FixedSingle

Location

10, 12 ( Inside Panel 1 )

Label

Name

lblScore

Location

93, 12 ( Inside Panel 1 )

Size

706, 103

Button

Name

btnStart

Location

12, 75 ( Inside Panel 1 )

Text

Start

Timer

Name

tmrCountDown

Interval

100

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote