divide my code on files main.cpp, board.cpp, board.h, ship.cpp, ship.h and in answer provide me a whole code
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <iostream>
#include <limits>
#include <vector>
#include <ostream>

using namespace std;


class Ship {
public:
  virtual ~Ship() {}
  virtual char getSymbol() const = 0;
  virtual int getLength() const = 0;
};

class AircraftCarrier : public Ship {
public:
  char getSymbol() const override { return 'A'; }
  int getLength() const override { return 5; }
};

class Battleship : public Ship {
public:
  char getSymbol() const override { return 'B'; }
  int getLength() const override { return 4; }
};

class Cruiser : public Ship {
public:
  char getSymbol() const override { return 'C'; }
  int getLength() const override { return 3; }
};

class Destroyer : public Ship {
public:
  char getSymbol() const override { return 'D'; }
  int getLength() const override { return 2; }
};

class Submarine : public Ship {
public:
  char getSymbol() const override { return 'S'; }
  int getLength() const override { return 1; }
};

class Board {
public:
  static const int SIZE = 10;

  Board() {
    // Initialize the grid and hits matrices
    grid.resize(SIZE, vector<Ship *>(SIZE, nullptr));
    hits.resize(SIZE, vector<bool>(SIZE, false));
  }

  friend ostream& operator<<(ostream& os, const Board& board) {
    os << "  \033[1;31m0 1 2 3 4 5 6 7 8 9\033[0m" << endl;
    for (int y = 0; y < SIZE; ++y) {
      os << "\033[1;31m" << y << " \033[0m";
      for (int x = 0; x < SIZE; ++x) {
        if (board.hits[y][x]) {
          if (board.grid[y][x] != nullptr) {
            os << "\033[1;31m" << board.grid[y][x]->getSymbol() << "\033[0m";
          } else {
            os << "\033[1;34mX\033[0m";
          }
        } else {
          if (board.grid[y][x] != nullptr) {
            os << "\033[1;37m.\033[0m";
          } else {
            os << "~";
          }
        }
        os << " ";
      }
      os << endl;
    }
    return os;
  }

  void clear() {
    // Cleanup the grid and hits matrices
    for (int y = 0; y < SIZE; ++y) {
      for (int x = 0; x < SIZE; ++x) {
        grid[y][x] = nullptr;
        hits[y][x] = false;
      }
    }
  }

  bool placeShip(int x, int y, Ship *ship, char direction) {
    int length = ship->getLength();
    if (canPlaceShip(x, y, length, direction)) {
      for (int i = 0; i < length; ++i) {
        int newX = x;
        int newY = y;
        if (direction == 'H') {
          newX += i;
        } else if (direction == 'V') {
          newY += i;
        }
        grid[newY][newX] = ship;
      }
      return true;
    }
    return false;
  }

  void print(bool showShips) const {
    cout << "  \033[1;31m0 1 2 3 4 5 6 7 8 9\033[0m" << endl;
    for (int y = 0; y < SIZE; ++y) {
      cout << "\033[1;31m" << y << " \033[0m";
      for (int x = 0; x < SIZE; ++x) {
        if (hits[y][x]) {
          if (grid[y][x] != nullptr) {
            cout << "\033[1;31m" << grid[y][x]->getSymbol() << " ";
          } else {
            cout << "\033[1;31mX ";
          }
        } else if (showShips && grid[y][x] != nullptr) {
          cout << "\033[1;31m" << grid[y][x]->getSymbol() << " ";
        } else {
          cout << "\033[1;32m~ ";
        }
      }
      cout << endl;
    }
  }

void saveToFile(string filename, bool showShips) const {
  ofstream file(filename);
  if (file.is_open()) {
    file << "  0 1 2 3 4 5 6 7 8 9" << endl;
    for (int y = 0; y < SIZE; ++y) {
      file << y << " ";
      for (int x = 0; x < SIZE; ++x) {
        if (hits[y][x]) {
          if (grid[y][x] != nullptr) {
            file << grid[y][x]->getSymbol() << " ";
          } else {
            file << "X ";
          }
        } else if (showShips && grid[y][x] != nullptr) {
          file << grid[y][x]->getSymbol() << " ";
        } else {
          file << "~ ";
        }
      }
      file << endl;
    }
    file.close();
    cout << "Board saved to " << filename << endl;
  } else {
    cout << "Unable to open file " << filename << endl;
  }
}

  bool receiveAttack(int x, int y) {
    if (x < 0 || x >= SIZE || y < 0 || y >= SIZE) {
      return false;
    }

    if (hits[y][x]) {
      return false;
    }

    hits[y][x] = true;
    if (grid[y][x] != nullptr) {
      return true;
    }

    return false;
  }

  bool isGameOver() const {
    for (int y = 0; y < SIZE; ++y) {
      for (int x = 0; x < SIZE; ++x) {
        if (grid[y][x] != nullptr && !hits[y][x]) {
          return false;
        }
      }
    }
    return true;
  }

private:
  vector<vector<Ship *>> grid;
  vector<vector<bool>> hits;

  bool canPlaceShip(int x, int y, int length, char direction) const {
    if (x < 0 || x + length > SIZE || y < 0 || y + length > SIZE) {
      return false;
    }

    if (direction == 'H') {
      if (x + length > SIZE) {
        return false;
      }
      for (int i = 0; i < length; ++i) {
        if (grid[y][x + i] != nullptr) {
          return false;
        }
        if (x + i > 0 && grid[y][x + i - 1] != nullptr) {
          return false;
        }
        if (x + i < SIZE - 1 && grid[y][x + i + 1] != nullptr) {
          return false;
        }
        if (y > 0 && grid[y - 1][x + i] != nullptr) {
          return false;
        }
        if (y < SIZE - 1 && grid[y + 1][x + i] != nullptr) {
          return false;
        }
      }
    } else if (direction == 'V') {
      if (y + length > SIZE) {
        return false;
      }
      for (int i = 0; i < length; ++i) {
        if (grid[y + i][x] != nullptr) {
          return false;
        }
        if (y + i > 0 && grid[y + i - 1][x] != nullptr) {
          return false;
        }
        if (y + i < SIZE - 1 && grid[y + i + 1][x] != nullptr) {
          return false;
        }
        if (x > 0 && grid[y + i][x - 1] != nullptr) {
          return false;
        }
        if (x < SIZE - 1 && grid[y + i][x + 1] != nullptr) {
          return false;
        }
      }
    }

    return true;
  }
};

void placeShips(Board &board, const vector<Ship *> &ships, bool isPlayer) {
  for (Ship *ship : ships) {
    bool placed = false;
    while (!placed) {
      int x, y;
      char direction;


      auto isValidCoordinate = [](int x, int y) {
        return x >= 0 && x < Board::SIZE && y >= 0 && y < Board::SIZE;
      };

      // Використання лямбда-функції для валідації координат гравця
      if (isPlayer) {
        cout << "Enter the starting coordinates (x y) for the ship "
             << ship->getSymbol() << " (" << ship->getLength() << "): ";
        cin >> x >> y;

        cout << "Enter the direction (H for horizontal, V for vertical): ";
        cin >> direction;
      } else {
        x = rand() % Board::SIZE;
        y = rand() % Board::SIZE;
        direction = (rand() % 2 == 0) ? 'H' : 'V';
      }

      placed = board.placeShip(x, y, ship, direction);
      if (!placed && isPlayer) {
        cout << "Invalid ship placement. Please try again." << endl;
      }
    }

    if (isPlayer) {
      board.print(true);
    }
  }
}

int main() {
  srand(time(0));
  
  Board playerBoard;
  Board computerBoard;
  playerBoard.saveToFile("player_board.txt", true);
  computerBoard.saveToFile("computer_board.txt", false);
  
  AircraftCarrier playerAircraftCarrier, computerAircraftCarrier;
  Battleship playerBattleship, computerBattleship;
  Cruiser playerCruiser, computerCruiser;
  Destroyer playerDestroyer, computerDestroyer;
  Submarine playerSubmarine, computerSubmarine;

  vector<Ship *> playerShips = {&playerAircraftCarrier, &playerBattleship,
                                &playerCruiser, &playerDestroyer,
                                &playerSubmarine};

  vector<Ship *> computerShips = {&computerAircraftCarrier, &computerBattleship,
                                  &computerCruiser, &computerDestroyer,
                                  &computerSubmarine};

  placeShips(playerBoard, playerShips, true);
  placeShips(computerBoard, computerShips, false);

  while (true) {
    cout << "Player Board:" << endl;
    playerBoard.print(true);
    cout << endl;

    cout << "Computer Board:" << endl;
    computerBoard.print(false);
    cout << endl;

    int x, y;
    char direction;
    cout << "Enter the coordinates to attack (x y): ";
    cin >> x >> y;

    // Validate the input
    while (cin.fail() || x < 0 || x >= Board::SIZE || y < 0 ||
           y >= Board::SIZE) {
      cin.clear();
      cin.ignore(numeric_limits<streamsize>::max(), '\n');
      cout << "Invalid coordinates. Please try again." << endl;
      cout << "Enter the coordinates to attack (x y): ";
      cin >> x >> y;
    }

    bool playerHit = computerBoard.receiveAttack(x, y);
    if (playerHit) {
      cout << "Player hit the computer's ship!" << endl;
      if (computerBoard.isGameOver()) {
        cout << "Player wins!" << endl;
        break;
      }
    } else {
      cout << "Player missed!" << endl;
    }

    // Check if the game is over before the computer attacks
    if (playerBoard.isGameOver()) {
      cout << "Computer wins!" << endl;
      break;
    }

    // Computer's turn
    x = rand() % Board::SIZE;
    y = rand() % Board::SIZE;
    bool computerHit = playerBoard.receiveAttack(x, y);
    if (computerHit) {
      cout << "Computer hit your ship!" << endl;
      if (playerBoard.isGameOver()) {
        cout << "Computer wins!" << endl;
        break;
      }
    } else {
      cout << "Computer missed!" << endl;
    }

    cout << endl;
  }
  playerBoard.saveToFile("player_board.txt", true);
computerBoard.saveToFile("computer_board.txt", false)
  return 0;
}