Graph implementation in c++ using adjacency matrix Here is my code for implementing Graph using adjacency matrix. The code should be Object-oriented and there is a method isPath() checking if there is a connection between two nodes. Some advice?

#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;fstream&gt; 

using namespace std;

class Graph
{
protected:
    int value;
    int **graphm;

public:
    Graph(int value)
    {
        this-&gt;value = value;
        graphm = new int*[value];
        int k, j;
        for (k = 0; k &lt; value; k++)
        {
            graphm[k] = new int[value];
            for (j = 0; j &lt; value; j++)
            {
                graphm[k][j] = 0;
            }
        }
    }

    void newEdge(int head, int end)
    {
        if (head &gt; value || end &gt; value || head &lt; 0 || end &lt; 0)
        {
            cout &lt;&lt; "Invalid edge!\n";
        }
        else
        {
            graphm[head - 1][end - 1] = 1;
            graphm[end - 1][head - 1] = 1;
        }
    }

    void display()
    {
        int i, p;

        for (i = 0; i &lt; value; i++)
        {
            for (p = 0; p &lt; value; p++)
            {
                cout &lt;&lt; graphm[i][p] &lt;&lt; "   ";
            }
            cout &lt;&lt; endl;
        }
    }

    void isPath(int head, int end)
    {
        int k, o;
        ofstream fullstore("Test.txt");

        cout &lt;&lt; graphm[head - 1][end - 1];
        cout &lt;&lt; endl;
        if (!fullstore.is_open())
        {
            cout &lt;&lt; "File can't be open";
        }

        if (graphm[head - 1][end - 1] == 1)
        {
            cout &lt;&lt; "There is an edge between " &lt;&lt; head &lt;&lt; " and " &lt;&lt; end &lt;&lt; "\n";
            fullstore &lt;&lt; head &lt;&lt; ", " &lt;&lt; end;
            fullstore.close();
        }
        else
        {
            cout &lt;&lt; "Edge not found\n";
        }
    }
};

int main()
{
    int vertex, numberOfEdges, i, head, end;
    cout &lt;&lt; "Enter number of nodes: ";
    cin &gt;&gt; vertex;
    numberOfEdges = vertex * (vertex - 1);
    Graph g1(vertex);
    for (int i = 0; i &lt; numberOfEdges; i++)
    {
        cout &lt;&lt; "Enter edge ex.1 2 (-1 -1 to exit): \n";
        cin &gt;&gt; head &gt;&gt; end;
        if ((head == -1) &amp;&amp; (end == -1))
        {
            break;
        }
        g1.newEdge(head, end);
    }
    g1.display();
    cout &lt;&lt; endl;
    g1.isPath(1, 3);

    return 0;
}
Avoid using namespace std;.

Why are you using raw pointers?  Use smart pointers, or (better yet) standard containers like std::vector.  Since vector constructs its elements, much of your initialization code can be eliminated.

Make use of the member initializer list in your constructor.  There's no real difference with fundamental types like int, but with more complicated objects it can be a big help or outright necessity (to initialize a reference).

    Graph(int value): value(value) {


(That will initialize the member value with the parameter value.)  Then get rid of the this-&gt;value = value line.

Define variables as late as possible, with their first use if possible.  Make use of this in your for statements.

for (int k = 0; k &lt; value; ++k)


In newEdge, your parameter validation accepts 0 as a valid edge index, but you then subtract one from it for the subscripting, resulting in Undefined Behavior and a possible crash.

display and isPath should be const (void display() const.  isPath does not validate its parameters like newEdge does.