// Fix this program that works // Use welcome function that display the message in diffreent color // Use Draw function to diplay table in gree/yellow // Remove, add, any code that you believe is not useful #include #include   using namespace std; char mat[3][3]; void table();            //function to print the table void welcome();          //function for welcome screen int main() {     int i, j, m, n, sum = 0;     char ch;     welcome();     system("pause");     for (m = 0; m < 3; m++)         for (n = 0; n < 3; n++)             mat[m][n] ='W';     table();     while (sum < 10)     {         //================== for player 1 ===================         cout << "Player 1 is X  Choose the position : ";         cout << "Row:";         cin >> i;         cout << "Coloumn:";         cin >> j;             //============== if position is wrong ============         for (; i > 3 || i < 1 || j>3 || j < 1 || ('x' == mat[i - 1][j - 1] || 'o' == mat[i - 1][j - 1]);)         {             cout << "Sorry!!!!wrong position, Choose the position again";             cout << "Row:";             cin >> i;             cout << "Coloumn:";             cin >> j;         }         mat[i - 1][j - 1] = 'x';         sum++;         //=============== to check if player 1 wins or not===================         if (mat[0][0] == 'x' && mat[0][0] == mat[0][1] && mat[0][0] == mat[0][2])         {             table();             cout << "Player 1 wins…….!!!";             cout << "You have played Great…..!!!";             //             break;         }         if (mat[1][0] == 'x' && mat[1][0] == mat[1][1] && mat[1][0] == mat[1][2])         {             table();             cout << "Player 1 wins…….!!!";             cout << "You have played Great…..!!!"<> i;         cout << "Coloumn:";         cin >> j;         //if position is wrong         for (; i > 3 || i < 1 || j>3 || j < 1 || ('x' == mat[i - 1][j - 1] || 'o' == mat[i - 1][j - 1]);)         {             cout << "Sorry!!!!wrong position, Choose the position again" << endl;             cout << "Row:"<> i;             cout << "Coloumn:" << endl;             cin >> j;         }         mat[i - 1][j - 1] = 'o';         sum++;         table();

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

// Fix this program that works
// Use welcome function that display the message in diffreent color
// Use Draw function to diplay table in gree/yellow
// Remove, add, any code that you believe is not useful


#include <iostream>
#include <windows.h>
 
using namespace std;
char mat[3][3];
void table();            //function to print the table
void welcome();          //function for welcome screen

int main()
{
    int i, j, m, n, sum = 0;
    char ch;

    welcome();
    system("pause");
    for (m = 0; m < 3; m++)
        for (n = 0; n < 3; n++)
            mat[m][n] ='W';

    table();

    while (sum < 10)
    {
        //================== for player 1 ===================
        cout << "Player 1 is X  Choose the position : ";
        cout << "Row:";
        cin >> i;
        cout << "Coloumn:";
        cin >> j;

            //============== if position is wrong ============
        for (; i > 3 || i < 1 || j>3 || j < 1 || ('x' == mat[i - 1][j - 1] || 'o' == mat[i - 1][j - 1]);)
        {
            cout << "Sorry!!!!wrong position, Choose the position again";
            cout << "Row:";
            cin >> i;
            cout << "Coloumn:";
            cin >> j;
        }
        mat[i - 1][j - 1] = 'x';
        sum++;

        //=============== to check if player 1 wins or not===================
        if (mat[0][0] == 'x' && mat[0][0] == mat[0][1] && mat[0][0] == mat[0][2])
        {
            table();
            cout << "Player 1 wins…….!!!";
            cout << "You have played Great…..!!!";
            //
            break;
        }

        if (mat[1][0] == 'x' && mat[1][0] == mat[1][1] && mat[1][0] == mat[1][2])
        {
            table();
            cout << "Player 1 wins…….!!!";
            cout << "You have played Great…..!!!"<<endl;
            break;
        }

        if (mat[2][0] == 'x' && mat[2][0] == mat[2][1] && mat[2][0] == mat[2][2])
        {
            table();
            cout << "Player 1 wins…….!!!";
            cout << "You have played Great…..!!!"<<endl;
            break;
        }

        if (mat[0][0] == 'x' && mat[0][0] == mat[1][0] && mat[0][0] == mat[2][0])
        {
            table();
            cout << "Player 1 wins…….!!!";
            cout << "You have played Great…..!!!";
           
            break;
        }

        if (mat[0][1] == 'x' && mat[0][1] == mat[1][1] && mat[0][1] == mat[2][1])
        {
            table();
            cout << "Player 1 wins…….!!!";
            cout << "You have played Great…..!!!";
           
            break;
        }

        if (mat[0][2] == 'x' && mat[0][2] == mat[1][2] && mat[0][2] == mat[2][2])
        {
            table();
            cout << "Player 1 wins…….!!!"<<endl;
            cout << "You have played Great…..!!!"<<endl;
           
            break;
        }

        if (mat[0][0] == 'x' && mat[0][0] == mat[1][1] && mat[0][0] == mat[2][2])
        {
            table();
            cout << "Player 1 wins…….!!!"<<endl;
            cout << "You have played Great…..!!!"<<endl;
           
            break;
        }

        if (mat[0][2] == 'x' && mat[0][2] == mat[1][1] && mat[0][0] == mat[2][0])
        {
            table();
            cout << "Player 1 wins…….!!!"<<endl;
            cout << "You have played Great…..!!!"<<endl;
           
            break;
        }

        if (sum == 9) //to check the chances
        {
            table();
            cout << "The game is over…….no one wins…HaHaHa…..!!!";
            break;
        }
        //for player 2
        cout << "Player 2 is’o’nChoose the position : " << endl;
        cout << "Row:";
        cin >> i;
        cout << "Coloumn:";
        cin >> j;

        //if position is wrong
        for (; i > 3 || i < 1 || j>3 || j < 1 || ('x' == mat[i - 1][j - 1] || 'o' == mat[i - 1][j - 1]);)
        {
            cout << "Sorry!!!!wrong position, Choose the position again" << endl;
            cout << "Row:"<<endl;
            cin >> i;
            cout << "Coloumn:" << endl;
            cin >> j;
        }
        mat[i - 1][j - 1] = 'o';
        sum++;
        table();

    

```cpp
cout << "Would you like to play more.... ? (y / n) : " << endl;
cin >> ch;
if (ch == 'y' || ch == 'Y')
    system("cls");
else
{
    cout << "Thanks for Playing.........:)" << endl;
    exit(0);
}

return 0;
}
//======================== draw table ====================
void table()
{
    system("cls");
    cout << "  1  2  3 " << endl;
    cout << "\t" << mat[0][0] << "|" << mat[0][1] << "|" << mat[0][2] << endl;
    cout << "\t_ _ _ " << endl;
    cout << "\t" << mat[1][0] << "|" << mat[1][1] << "|" << mat[1][2] << endl;
    cout << "\t_ _ _ " << endl;
    cout << "\t" << mat[2][0] << "|" << mat[2][1] << "|" << mat[2][2] << endl;
}
//========================
void welcome()
{
    /* Change the color here for welcome message*/

    cout << "Welcome To Tic - Tac - Toe Game" << endl;
    cout << "Press any key to continue.....!!";
}
```

The code is a part of a console-based Tic-Tac-Toe game written in C++. It includes functions to display the welcome message, draw the game table, and ask the user if they want to play again.

**Key Components:**

1. **Replay Functionality:**
   - Prompts the user with "Would you like to play more....? (y / n) :".
   - If the user inputs 'y' or 'Y', the game screen refreshes; otherwise, it displays a thank you message and exits.

2. **Draw Table Function:**
   - Clears the screen and prints the Tic-Tac-Toe board structure.
   - The board is displayed with a 3x3 grid, showing current gameplay positions.

3. **Welcome Function:**
   - Displays a welcome message for the Tic-Tac-Toe game.
   - Prompts the player to press any key to start the game.
```
Transcribed Image Text:```cpp cout << "Would you like to play more.... ? (y / n) : " << endl; cin >> ch; if (ch == 'y' || ch == 'Y') system("cls"); else { cout << "Thanks for Playing.........:)" << endl; exit(0); } return 0; } //======================== draw table ==================== void table() { system("cls"); cout << " 1 2 3 " << endl; cout << "\t" << mat[0][0] << "|" << mat[0][1] << "|" << mat[0][2] << endl; cout << "\t_ _ _ " << endl; cout << "\t" << mat[1][0] << "|" << mat[1][1] << "|" << mat[1][2] << endl; cout << "\t_ _ _ " << endl; cout << "\t" << mat[2][0] << "|" << mat[2][1] << "|" << mat[2][2] << endl; } //======================== void welcome() { /* Change the color here for welcome message*/ cout << "Welcome To Tic - Tac - Toe Game" << endl; cout << "Press any key to continue.....!!"; } ``` The code is a part of a console-based Tic-Tac-Toe game written in C++. It includes functions to display the welcome message, draw the game table, and ask the user if they want to play again. **Key Components:** 1. **Replay Functionality:** - Prompts the user with "Would you like to play more....? (y / n) :". - If the user inputs 'y' or 'Y', the game screen refreshes; otherwise, it displays a thank you message and exits. 2. **Draw Table Function:** - Clears the screen and prints the Tic-Tac-Toe board structure. - The board is displayed with a 3x3 grid, showing current gameplay positions. 3. **Welcome Function:** - Displays a welcome message for the Tic-Tac-Toe game. - Prompts the player to press any key to start the game. ```
```cpp
// to check player 2 wins or not
if (mat[0][0] == 'o' && mat[0][0] == mat[0][1] && mat[0][0] == mat[0][2])
{
    cout << "Player 2 wins……!!!" << endl;
    cout << "You have played Great…..!!!" << endl;
    break;
}

if (mat[1][0] == 'o' && mat[1][0] == mat[1][1] && mat[1][0] == mat[1][2])
{
    cout << "Player 2 wins……!!!" << endl;
    cout << "You have played Great…..!!!" << endl;
    break;
}

if (mat[2][0] == 'o' && mat[2][0] == mat[2][1] && mat[2][0] == mat[2][2])
{
    cout << "Player 2 wins……!!!" << endl;
    cout << "You have played Great…..!!!" << endl;
    break;
}

if (mat[0][0] == 'o' && mat[0][0] == mat[1][0] && mat[0][0] == mat[2][0])
{
    cout << "Player 2 wins……!!!" << endl;
    cout << "You have played Great…..!!!" << endl;
    break;
}

if (mat[0][1] == 'o' && mat[0][1] == mat[1][1] && mat[0][1] == mat[2][1])
{
    cout << "Player 2 wins……!!!" << endl;
    cout << "You have played Great…..!!!" << endl;
    break;
}

if (mat[0][2] == 'o' && mat[0][2] == mat[1][2] && mat[0][2] == mat[2][2])
{
    cout << "Player 2 wins……!!!" << endl;
    cout << "You have played Great…..!!!" << endl;
    break;
}

if (mat[0][0] == 'o' && mat[0][0] == mat[1][1] && mat[0][0] == mat[2][2])
{
    cout << "Player 2 wins
Transcribed Image Text:```cpp // to check player 2 wins or not if (mat[0][0] == 'o' && mat[0][0] == mat[0][1] && mat[0][0] == mat[0][2]) { cout << "Player 2 wins……!!!" << endl; cout << "You have played Great…..!!!" << endl; break; } if (mat[1][0] == 'o' && mat[1][0] == mat[1][1] && mat[1][0] == mat[1][2]) { cout << "Player 2 wins……!!!" << endl; cout << "You have played Great…..!!!" << endl; break; } if (mat[2][0] == 'o' && mat[2][0] == mat[2][1] && mat[2][0] == mat[2][2]) { cout << "Player 2 wins……!!!" << endl; cout << "You have played Great…..!!!" << endl; break; } if (mat[0][0] == 'o' && mat[0][0] == mat[1][0] && mat[0][0] == mat[2][0]) { cout << "Player 2 wins……!!!" << endl; cout << "You have played Great…..!!!" << endl; break; } if (mat[0][1] == 'o' && mat[0][1] == mat[1][1] && mat[0][1] == mat[2][1]) { cout << "Player 2 wins……!!!" << endl; cout << "You have played Great…..!!!" << endl; break; } if (mat[0][2] == 'o' && mat[0][2] == mat[1][2] && mat[0][2] == mat[2][2]) { cout << "Player 2 wins……!!!" << endl; cout << "You have played Great…..!!!" << endl; break; } if (mat[0][0] == 'o' && mat[0][0] == mat[1][1] && mat[0][0] == mat[2][2]) { cout << "Player 2 wins
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education