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

How do I compile these codes???? What do I type in puTTy?? g++ .....???? Thank y

ID: 3867407 • Letter: H

Question

How do I compile these codes???? What do I type in puTTy?? g++ .....???? Thank you!!!!

#ifndef BOARD_H_
#define BOARD_H_

enum status{
   XWON,
   OWON,
   DRAW,
   IN_PROGRESS
};

class Board{
private:
   char arr[3][3];
public:
   Board();
   bool makeMove(int x, int y, char ch);
   status gameState();
   void display();
};

#endif

#include "Board.h"
#include <iostream>

using namespace std;

Board::Board(){
   for(int i = 0; i < 3; ++i){
       for(int j = 0; j < 3; ++j){
           arr[i][j] = ' ';
       }
   }
}

bool Board::makeMove(int x, int y, char ch){
   if(x >= 0 && x <= 2 && y >= 0 && y <= 2 && arr[x][y] == ' '){
       arr[x][y] = ch;
       return true;
   }
   else{
       return false;
   }
}

void Board::display(){
   for(int i = 0; i < 3; ++i){
       for(int j = 0; j < 3; ++j){
           cout << arr[i][j] << " | ";
       }
       cout << endl << "-------------" << endl;
   }
   cout << endl;
}

status Board::gameState(){
   int count = 0;
   for(int i = 0; i < 3; ++i){
       for(int j = 0; j < 3; ++j){
           if(arr[i][j] == ' ')
               ++count;
       }
   }
   if(count == 0)
       return DRAW;
   for(int i = 0; i < 3; ++i){
       if(arr[i][0] == arr[i][1] && arr[i][1] == arr[i][2]){
           if(arr[i][0] == 'X'){
               return XWON;
           }
           else if(arr[i][0] == 'O'){
               return OWON;
           }
       }
       if(arr[0][i] == arr[1][i] && arr[1][i] == arr[2][i]){
           if(arr[0][i] == 'X'){
               return XWON;
           }
           else if(arr[0][i] == 'O'){
               return OWON;
           }
       }
   }
   if((arr[0][0] == arr[1][1] && arr[1][1] == arr[2][2]) || (arr[0][2] == arr[1][1] && arr[1][1] == arr[2][0])){
       if(arr[1][1] == 'X'){
           return XWON;
       }
       else if(arr[1][1] == 'O'){
           return OWON;
       }
   }
   return IN_PROGRESS;
}

#include "Board.h"

#ifndef TICTACTOE_H_
#define TICTACTOE_H_

class TicTacToe{
private:
   Board b;
   char ch;
public:
   TicTacToe(char ch);
   void play();
};

#endif

#include "TicTacToe.h"
#include <iostream>

using namespace std;

TicTacToe::TicTacToe(char ch){
   this->ch = ch;
}

void TicTacToe::play(){
   status s;
   int x, y;
   while((s = b.gameState()) == IN_PROGRESS){
       b.display();
       cout << "Player " << ch << ", Enter position x, y? ";
       cin >> x >> y;
       while(!b.makeMove(x, y, ch)){
           cout << "Invalid move. Try again: ";
           cin >> x >> y;
       }
       ch = ch == 'X' ? 'O' : 'X';
   }
   if(s == XWON){
       cout << "'x' has Won!!" << endl;
   }
   else if(s == OWON){
       cout << "'o' has Won!!" << endl;
   }
   else if(s == DRAW){
       cout << "The game is a draw" << endl;
   }
   else{
       cout << "Game exited with an invalid state" << endl;
   }
}

#include <iostream>
#include "TicTacToe.h"

using namespace std;

int main(){
   char ch;
   cout << "Enter the player who should go first: ";
   cin >> ch;
   TicTacToe t(ch);
   t.play();
   return 0;
}

Board.h

Explanation / Answer

To compile the code, use the following command:
g++ main.cpp TicTacToe.cpp Board.cpp
and then run the application with
./a.out

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