C++Challenge for all Programmers of the Programming World

Hello Programmers,

I have a TicTacToe source code that I want everyone to finish. It is challenging for beginners but it will be fun to complete. Let's see how many answers, questions, and comments we get. We can see the power of digital communication in action. We can comment/vote on the use who completes the source code as stated. Above all this is about seeing how intelligent today's programmers are.

Implement displayBoard to display Tic Tac Toe board.
Prompt User for a box on the board to select, i.e. a number between 1 and 9 with 1 being the upper left corner.

use cin.get(box) to get the box number and isdigit to verify it is a number;
1 | 2 | 3
4 | 5 | 6
7 | 8 | 9
If the box is available put the appropriate X or O in there and switch players, i.e. X becomes O and vice versa. If the box is NOT available warn the user and get another box until they select a valid open box.

After all spots have been select Display "Game Over!";

Write a main function to use the TicTacToe class and test all of the above functionality.
.

#include<iostream>

using namespace std;


class TicTacToe {
public:
    void displayBoard();
    void getMove();
    void playGame();
private:
    char board[9];
    char player; // Switch after each move.
};

int main ()
{
    TicTacToe ttt;

    // you need to do the following in a loop 9 times
    ttt.playGame();
}

void TicTacToe::playGame()
{
    getMove();
    // Your implementation here...
}

void TicTacToe::displayBoard()
{
    // Your implementation here...
}

void TicTacToe::getMove()
{
    cout << "Enter Box: ";
    char c;
    cin.get(c);
    if (c > '9' || c < '0')
        // Error message here.

    int number = c - '0';

    cout << "your number is " << number;
    // Your implementation here...
}



Last edited on
closed account (z05DSL3A)
Above all this is about seeing how intelligent today's programmers are.
and maybe get someone to do your homework for you? (!)
Haha I knew someone was going to say that. It's summer I don't have any homework. This was out of curiosity and boredom.
+1 Grey Wolf

The only input I have is that your grid is upside down:

1 | 2 | 3
4 | 5 | 6
7 | 8 | 9


Take a look at your keypad and you'll see why that's goofy.
Oh, your right the 1 2 3 should be at the bottom while 7 8 9 at the top
Thanks
closed account (z05DSL3A)
http://people.howstuffworks.com/sarcasm.htm
It could be a phone application. (¿why they invert the digits?)

[code] "Please use code tags" [/code]
Topic archived. No new replies allowed.