473,748 Members | 4,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help me with this coding please. Adjacency Matrix

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(in t [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::mainmen u()
{
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[i][j] << endl;
}
*/
}

void matrix::addEdge (int graph[max][min], int x, int y)
{
graph[x][y] = 1;
}

void matrix::removeE dge(int graph[max][min], int x, int y)
{
graph[x][y] = 0;
}

void matrix::display Graph(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[i][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.mainmen u();

cout << "Choose : ";
cin >> selection;

switch(selectio n)
{
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.removeE dge(aMatrixGrap h, x,y);
system("cls");
break;

case 5 :
system("cls");
aMatrix.display Graph(aMatrixGr aph);
break;

case 9 :
exit(1);
default:
cout << "Invalid input" << endl;
exit(1);
}
}while(selectio n != 9);
}
Jul 22 '05 #1
1 4535
SallyBenjamin wrote:

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...


Not sure if I would accept your solutions but then I don't know
your exact assignment.

Anyway. It seems that to add a node you somehow (hint) need to
dynamically resize the whole matrix.

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
10822
by: imani_technology_spam | last post by:
We need to present hierarchical data on a web page, the same way the tree view shows files in Windows Explorer. Here's the catch: that tree view needs to be bound to a SQL Server database. How can this be done?
7
3479
by: Dan Trowbridge | last post by:
He everyone, I am just getting started with .NET and I am having a porting problem. I get and error in code that lookssomething like this (really stripped down but you get the idea)... class dt { std::deque< class dt > dtdq; };
10
1842
by: Nevets Steprock | last post by:
I'm writing a web program where one of the sections is supposed to output a correlation matrix. The typical correlation matrix looks like this: ..23 ..34 .54 ..76 .44 .28 ..02 .77 .80 .99 I've written code to calculate the correlation data and it is populated in a vector like this:
8
6568
by: Dip | last post by:
Hello Experts, Here is the code to flatten a PC hierarchy into a level based table. It works fine. SELECT t1.TASK_ID AS TASK_LV1, t2.TASK_ID AS TASK_LV2, t3.TASK_ID AS TASK_LV3, t4.TASK_ID AS TASK_LV4, t5.TASK_ID AS TASK_LV5 FROM dbo.Project t1 LEFT OUTER JOIN
3
1517
by: cool17 | last post by:
/* IsScalarMatrix --------------- Check if a Matrix is a Scalar matrix where: diagonal elements all contain the same scalar aij. Return (!false == true,!true == false) */ bool CDblMatrix::IsScalarMatrix() { int nRows = 0, nCols = 0;
5
1902
by: mohammaditraders | last post by:
Write a program which overloads a binary Minus (-) operator, The program will contain a class Matrix, This class will contain a private data member Array which store int values. The class will further contain a Default constructor, get() function which takes values for array from the user and also contain a Display function witch display the array on the screen, In main function create three objects Mat1, Mat2, Mat3 of this class,...
1
3113
by: madhuparna | last post by:
Plzz give the code for implementing adjacency matrix in C
3
7843
by: victorporton | last post by:
D.K. is traveling from City A to City B. He can stop at some designated spots only. I am trying to use Dijkstra’s algorithm to determine the “spot-to-spot” path that will get D.K. from City A to the City B in the minimum amount of time. The input in my program is an integer n and the 2D coordinates of n spots. Some assumptions have been made about the physical layout of the problem: 1) All the spots are considered to be in a square of...
11
2853
by: lenygold via DBMonster.com | last post by:
I am tryieng to convert our time consuming recursive queries too very efficient queries based on nested set model. The only problem is to convert an adjacency list model into a nested set model, with push down stack algorithm to DB2 query. The client does not want to use Stored Procedure. Please any Recurcive or CWE ideas. Thank's in advance. -- Tree holds the adjacency model
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4597
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.