Happy Sunday everyone!

I am trying to teach myself C++ so I am doing a Battleship program. 

This version is fairly standard. The player enters the coordinates of a cell to try to hit a ship. The program stating if a ship is hit. If all cells occupied by a ship are hit, the program prints a message stating that that ship is sunk. After each attempt, the program prints the current state by showing the board with all successful attempts marked by `"*"` or `"x"`respectively.

What I am having trouble with is writing the level function in my Board class which sums up all the levels of the ships on the board.

So I have a board like this for the Battleships

```
   a b c d e f g h i j
  +-------------------+
 0|                   |
 1|                   |
 2|                   |
 3|                   |
 4|                   |
 5|                   |
 6|                   |
 7|                   |
 8|                   |
 9|                   |
  +-------------------+

```

This is my **board header** file for context : 

```
#ifndef BOARD_H
#define BOARD_H
#include "Ship.h"
#include <vector>
class Board
{
  public:
    Board(void);
    void addShip(char type, int x1, int y1, int x2, int y2);
    void print(void);
    void hit(char c, int i);
    int level(void);
  private:
    std::vector<Ship *> shipList;
    char score[10][10];
    Ship *shipAt(int x, int y);
};
#endif

```

I also have a ship class to store the coordinates of the ship

Here is my **ship header (it may not be necessary to read everything just look at the level function)**:

```
//
// Ship.h
//

#ifndef SHIP_H
#define SHIP_H
class Ship
{
  public:
    virtual ~Ship(void) {}
    virtual const char *name(void) const = 0;
    virtual int size(void) const = 0;
    int getX(int i) const;
    int getY(int i) const;
    void print(void) const;
    bool includes(int x, int y);
    int level(void) const;
    void decreaseLevel(void);
    static Ship *makeShip(char ch, int x1, int y1, int x2, int y2);
  protected:
    void setPos(int a1, int b1, int a2, int b2);
    int lev;
  private:
    bool checkConfig(int x1, int y1, int x2, int y2);
    int x1,y1,x2,y2;
};

class AircraftCarrier : public Ship
{
  public:
    AircraftCarrier(int x1, int y1, int x2, int y2);
    virtual const char *name(void) const;
    virtual int size(void) const;
};

class BattleShip: public Ship
{
  public:
    BattleShip(int x1, int y1, int x2, int y2);
    virtual const char *name(void) const;
    virtual int size(void) const;
};

class Cruiser: public Ship
{
  public:
    Cruiser(int x1, int y1, int x2, int y2);
    virtual const char *name(void) const;
    virtual int size(void) const;
};

class Destroyer: public Ship
{
  public:
    Destroyer(int x1, int y1, int x2, int y2);
    virtual const char *name(void) const;
    virtual int size(void) const;
};
#endif

```

Here is my **ship class (it may not be necessary to read everything so I just put the level function)** 

```
#include "Ship.h"
#include <iostream>
#include <stdexcept>
using namespace std;

//LOTS OF CODE I OMITTED FOR BREVITY

int Ship::level (void) const
{
    return lev;
}

    }

```

In my ship class the 

```
int level(void)

```

function returns the current value of the protected variable lev

Here is what I have so far for my Board.cpp (sorry for the long bits of code but it is necessary to provide context for this question):

```
#include "Board.h"
#include "Ship.h"
#include <iostream>
using namespace std;
#include <vector>
#include <string.h>
#include <stdexcept>

//member function definitions

Board::Board(void)
{
    //char score[10][10] = "                                                                                                    ";  
    char score[10][10] = {{' '}};
}

void Board::addShip(char type, int x1, int y1, int x2, int y2) 
{
    if(shipList.size()<=9)
        {
            shipList.push_back(Ship::makeShip(type ,x1 , y1,  x2,  y2)) ;
        }
}

void Board::print(void){

cout<< "   a b c d e f g h i j"<< endl;
cout <<"  +-------------------+"<< endl;
    for (int i = 0; i < 10; i++) {
        cout<<" "<< i <<"|" ;
        for (int j = 0; j < 10; j++) {
           cout << score[i][j];
        }
            if(i == 0){
                cout << "                  |";

            }
            else{
                cout << "                   |";
                }
        cout<< endl;

    }
    cout <<"  +-------------------+"<< endl;
}

void Board::hit(char c, int i){

    if (c<'a' || c>'j' || i > 9 || i<0){
        throw invalid_argument("invalid input");
    }

    Ship* ship = shipAt(i, c-'a');

    if (ship) {
        score[i][c-'a']= '*';
    }
    else{
        score[i][c-'a']= 'x';
    }

}

Ship* Board::shipAt(int x, int y){
    Ship* ship = shipAt(x, y);

    if (ship){
            return ship;   }
    else{
        return NULL;
         }

}
int Board::level(void)
{

}

```

In `int level(void)`
The function should return the sum of the levels of all ships on the board.

***Essentially I do not know how I would implement `int level(void)`in my board class I am trying to call each ship pointer's level and add to a sum by pointing the shipList pointer to level in each iteration of the loop. But I am struggling to execute that.***