S
SallyBenjamin
Hello..
Can anyone help me with this coding. Basically, it needs to have add
node, remove node, add edges , remove edges and display the graph
But.I have only succedded to add node, add and remove edge and also
display graph...
Can anyone plz help me to change this and add the nodes..
Thank u
#include <iostream>
using namespace std;
const int max = 10;
const int min = 10;
class matrix
{
public:
void displayGraph(int [max][min]);
void addNode(int [max][min],int,int);
void addEdge(int [max][min],int,int);
void removeEdge(int [max][min],int,int);
void mainmenu();
};
void matrix::mainmenu()
{
cout << endl;
cout << "1) Add Node" << endl;
cout << "2) Remove Node" << endl;
cout << "3) Add Edge" << endl;
cout << "4) Remove Edge" << endl;
cout << "5) Display Graph" << endl;
cout << "6) " << endl;
cout << "9) Exit Program" << endl;
}
void matrix::addNode(int graph[max][min], int n1, int n2)
{
int aMatrixGraph[10][10]={0};
graph[n1][n2] = 1;
// int a,b = 0;
// int n1,n2=0;
// int no =0;
//char ** matrixGraph2;
//matrixGraph2 = new char* [ROWS];
/*for(int i=0;i<no;i++)
for(int j=0;j<no;j++)
{
cout << "Input matrix A : " << endl;
cin >> a;
cout << "Input matrix B : " << endl;
cin >> b;
cout << aMatrixGraph[j] << endl;
}
*/
}
void matrix::addEdge(int graph[max][min], int x, int y)
{
graph[x][y] = 1;
}
void matrix::removeEdge(int graph[max][min], int x, int y)
{
graph[x][y] = 0;
}
void matrix::displayGraph(int graph[max][min])
{
cout << " 0 1 2 3 4 5 6 7 8 9" << endl;
cout << " -------------------" << endl;
for (int i = 0; i < max; i++)
{
cout << i << "|";
for (int j = 0; j < min; j++)
{
cout << graph[j] << " ";
}
cout << endl;
}
}
void main()
{
matrix aMatrix;
int aMatrixGraph[10][10]={0};
int selection = 0;
int x,y;
int n1,n2;
int no;
do
{
aMatrix.mainmenu();
cout << "Choose : ";
cin >> selection;
switch(selection)
{
case 1:
cout << "Enter the node coordinate : " << endl;
cin >> no;
n1 = no;
n2 = n1;
aMatrix.addNode(aMatrixGraph, n1, n2);
system("cls");
break;
case 2 :
//removeNode();
break;
case 3 :
cout << "Please enter edge for graph : " << endl;
cout << "X : ";
cin >> x ;
cout << "Y : ";
cin >> y;
aMatrix.addEdge(aMatrixGraph, x,y);
system("cls");
break;
case 4 :
cout << "Please enter edge for graph : ";
cout << "X : ";
cin >> x;
cout << endl;
cout << "Y : " << endl;
cin >> y;
aMatrix.removeEdge(aMatrixGraph, x,y);
system("cls");
break;
case 5 :
system("cls");
aMatrix.displayGraph(aMatrixGraph);
break;
case 9 :
exit(1);
default:
cout << "Invalid input" << endl;
exit(1);
}
}while(selection != 9);
}
Can anyone help me with this coding. Basically, it needs to have add
node, remove node, add edges , remove edges and display the graph
But.I have only succedded to add node, add and remove edge and also
display graph...
Can anyone plz help me to change this and add the nodes..
Thank u
#include <iostream>
using namespace std;
const int max = 10;
const int min = 10;
class matrix
{
public:
void displayGraph(int [max][min]);
void addNode(int [max][min],int,int);
void addEdge(int [max][min],int,int);
void removeEdge(int [max][min],int,int);
void mainmenu();
};
void matrix::mainmenu()
{
cout << endl;
cout << "1) Add Node" << endl;
cout << "2) Remove Node" << endl;
cout << "3) Add Edge" << endl;
cout << "4) Remove Edge" << endl;
cout << "5) Display Graph" << endl;
cout << "6) " << endl;
cout << "9) Exit Program" << endl;
}
void matrix::addNode(int graph[max][min], int n1, int n2)
{
int aMatrixGraph[10][10]={0};
graph[n1][n2] = 1;
// int a,b = 0;
// int n1,n2=0;
// int no =0;
//char ** matrixGraph2;
//matrixGraph2 = new char* [ROWS];
/*for(int i=0;i<no;i++)
for(int j=0;j<no;j++)
{
cout << "Input matrix A : " << endl;
cin >> a;
cout << "Input matrix B : " << endl;
cin >> b;
cout << aMatrixGraph[j] << endl;
}
*/
}
void matrix::addEdge(int graph[max][min], int x, int y)
{
graph[x][y] = 1;
}
void matrix::removeEdge(int graph[max][min], int x, int y)
{
graph[x][y] = 0;
}
void matrix::displayGraph(int graph[max][min])
{
cout << " 0 1 2 3 4 5 6 7 8 9" << endl;
cout << " -------------------" << endl;
for (int i = 0; i < max; i++)
{
cout << i << "|";
for (int j = 0; j < min; j++)
{
cout << graph[j] << " ";
}
cout << endl;
}
}
void main()
{
matrix aMatrix;
int aMatrixGraph[10][10]={0};
int selection = 0;
int x,y;
int n1,n2;
int no;
do
{
aMatrix.mainmenu();
cout << "Choose : ";
cin >> selection;
switch(selection)
{
case 1:
cout << "Enter the node coordinate : " << endl;
cin >> no;
n1 = no;
n2 = n1;
aMatrix.addNode(aMatrixGraph, n1, n2);
system("cls");
break;
case 2 :
//removeNode();
break;
case 3 :
cout << "Please enter edge for graph : " << endl;
cout << "X : ";
cin >> x ;
cout << "Y : ";
cin >> y;
aMatrix.addEdge(aMatrixGraph, x,y);
system("cls");
break;
case 4 :
cout << "Please enter edge for graph : ";
cout << "X : ";
cin >> x;
cout << endl;
cout << "Y : " << endl;
cin >> y;
aMatrix.removeEdge(aMatrixGraph, x,y);
system("cls");
break;
case 5 :
system("cls");
aMatrix.displayGraph(aMatrixGraph);
break;
case 9 :
exit(1);
default:
cout << "Invalid input" << endl;
exit(1);
}
}while(selection != 9);
}