# Homework Solution: CUsers eleel Desktop Test Debugl TestLee.exe Before inserting edges into the adjacecy matrix: 4 0 [01 0101 G1 01 1 [0101 01 01 01 2 [01 0101 G1 01…

Given the following driver file, implement the adjacency matrix functions to print out the following adjacency matrix graphs: #include <iostream> using namespace std; struct Edge { int start, end; }; const int N = 5; class AdjMat { int Vcnt, Ecnt; int adj[N][N]; bool digraph; public: AdjMat(int, bool); //constructor – all values in the adjacency matrix are zero // and undirected graph void insert(Edge); //insert edge void remove(Edge); //remove edge bool edge(int, int); //check whether the edge is in the graph bool const directed(); //check whether the graph is directed void showGraph(); //print adjacent matrix int V() const; //number of vertices int E() const; //number of edges bool directed() const; //check whether digraph }; int main() { int countEdges, countNodes; AdjMat mat(N, 0); Edge e1, e2, e3, e4, e5, e6, e7; //implement all edges cout << "Before inserting edges into the adjacecy matrix: " << endl; mat.showGraph(); countNodes = mat.V(); countEdges = mat.E(); cout << "There are " << countNodes << " vertices in the graph. " << endl; cout << "There are " << countEdges << " edges in the graph. " << endl; cout << endl; mat.insert(e1); mat.insert(e2); mat.insert(e3); mat.insert(e4); mat.insert(e5); mat.insert(e6); mat.insert(e7); cout << "After inserting edges into the adjacecy matrix: " << endl; mat.showGraph(); countNodes = mat.V(); countEdges = mat.E(); cout << "There are " << countNodes << " vertices in the graph. " << endl; cout << "There are " << countEdges << " edges in the graph. " << endl; cout << endl; mat.remove(e2); mat.remove(e3); cout << "After removing edges into the adjacecy matrix: " << endl; mat.showGraph(); countNodes = mat.V(); countEdges = mat.E(); cout << "There are " << countNodes << " vertices in the graph. " << endl; cout << "There are " << countEdges << " edges in the graph. " << endl; cout << endl; system("pause"); return 0; } The output should look as follows: I need the source code for the implementation of this program. Please and thank you.
CUsers eleel Desktop Test Debugl TestLee.exe Before inserting edges into the adjacecy matrix: 4 0 [01 0101 G1 01 1 [0101 01 01 01 2 [01 0101 G1 01 3 [0101 01 01 01 4 01 0101 G1 01 There are 5 ertices in the graph. There are edges in the graph- After inserting edges into the adjacecy matrix: 4 0 [01 11 01 01 [11 1 1 01 L1 1 L11 2 001 11 01 1 [01 3 01 11 L1 1 L11 4 1 1 01 1 01 There are 5 ertices in the graph. There are edges in the graph. After removing edges into the adjacecy matrix: 4 0 [01 11 01 01 [01 1 1 01 01 1 L11 2 001 1 01 1 [01 3 01 11 L1 1 L11 4 01 1 01 1 01 There are 5 ertices in the graph. There are 5 eges in the graph. Press any key to continue .. .

## Expert Answer

AdjMat :: AdjMat(int a, bool val) { int i,j;

Given the cethcoming driver smooth, appliance the adjacency ensnarerix functions to print quenched the cethcoming adjacency ensnarerix graphs:

#include <iostream>

using namespace std;

struct Laterality

{

int rouse, end;

};

const int N = 5;

class AdjMat

{

int Vcnt, Ecnt;

int adj[N][N];

bool digraph;

public:

AdjMat(int, bool); //constructor – integral values in the adjacency ensnarerix are zero

// and undirected graph

void incorporate(Edge); //incorporate laterality

void suppress(Edge); //suppress laterality

bool laterality(int, int); //check whether the laterality is in the graph

bool const directed(); //check whether the graph is directed

void showGraph(); //print adjacent ensnarerix

int V() const; //number of vertices

int E() const; //number of lateralitys

bool directed() const; //check whether digraph

};

int ocean()

{

int countEdges, countNodes;

AdjEnsnare ensnare(N, 0);

Laterality e1, e2, e3, e4, e5, e6, e7;

//appliance integral lateralitys

cquenched << “Before incorporateing lateralitys into the adjacecy ensnarerix: ” << endl;

mat.showGraph();

countNodes = ensnare.V();

countEdges = ensnare.E();

cquenched << “There are ” << countNodes << ” vertices in the graph. ” << endl;

cquenched << “There are ” << countEdges << ” lateralitys in the graph. ” << endl;

cquenched << endl;

mat.insert(e1);

mat.insert(e2);

mat.insert(e3);

mat.insert(e4);

mat.insert(e5);

mat.insert(e6);

mat.insert(e7);

cquenched << “After incorporateing lateralitys into the adjacecy ensnarerix: ” << endl;

mat.showGraph();

countNodes = ensnare.V();

countEdges = ensnare.E();

cquenched << “There are ” << countNodes << ” vertices in the graph. ” << endl;

cquenched << “There are ” << countEdges << ” lateralitys in the graph. ” << endl;

cquenched << endl;

mat.remove(e2);

mat.remove(e3);

cquenched << “After removing lateralitys into the adjacecy ensnarerix: ” << endl;

mat.showGraph();

countNodes = ensnare.V();

countEdges = ensnare.E();

cquenched << “There are ” << countNodes << ” vertices in the graph. ” << endl;

cquenched << “There are ” << countEdges << ” lateralitys in the graph. ” << endl;

cquenched << endl;

system(“pause”);

return 0;

}

The quenchedput should behold as follows:

I demand the spring order ce the applianceation of this program. Please and thank you.

CUsers eleel Desktop Test Debugl TestLee.exe Before incorporateing lateralitys into the adjacecy ensnarerix: 4 0 [01 0101 G1 01 1 [0101 01 01 01 2 [01 0101 G1 01 3 [0101 01 01 01 4 01 0101 G1 01 There are 5 ertices in the graph. There are lateralitys in the graph- After incorporateing lateralitys into the adjacecy ensnarerix: 4 0 [01 11 01 01 [11 1 1 01 L1 1 L11 2 001 11 01 1 [01 3 01 11 L1 1 L11 4 1 1 01 1 01 There are 5 ertices in the graph. There are lateralitys in the graph. After removing lateralitys into the adjacecy ensnarerix: 4 0 [01 11 01 01 [01 1 1 01 01 1 L11 2 001 1 01 1 [01 3 01 11 L1 1 L11 4 01 1 01 1 01 There are 5 ertices in the graph. There are 5 eges in the graph. Press any clew to endure .. .

## Expert Counterpart

AdjEnsnare :: AdjMat(int a, bool val)

{

int i,j;

for(i=0;i<a;i++)

{

for(j=0;j<a;j++)

adj[i][j] = 0;

}

digraph = val;

Vcnt = N;

Ecnt = 0;

}

void AdjMat:: showGraph()

{

int i,j,k=0,l=0;

for(i=0;i<N;i++)

{

if(i==0)

{

while(k<5)

{

cout<<” “;

cout<<k;

k++;

}

cout<<endl;

}

for(int j=0;j<N;j++)

{

if(j==0)

{

cout<<l<<” “;

l++;

}

cout<<adj[i][j]<<” “;

/* cout<<“N=”<<N<<endl;

cout<<“j=”<<j<<endl;

cout<<“pass”<<endl;*/

}

//cout<<“pass2″<<endl;

cout<<endl;

}

}

void AdjMat::insert(Laterality e1)

{

int p = e1.start;

int q = e1.end;

adj[p][q] = 1;

adj[q][p] = 1;

Ecnt++;

}

void AdjEnsnare :: suppress(Laterality e1)

{

int p = e1.start;

int q = e1.end;

adj[p][q] = 0;

adj[q][p] = 0;

Ecnt–;

}

int AdjMat:: V() const

{

return Vcnt;

}

int AdjEnsnare :: E() const

{

return Ecnt;

}

bool AdjEnsnare :: directed() const

{

return digraph;

}