About A B CD E A 0 1 1 1 0 B1 1 1 01 C1 1 0 0 0 D 1 00 0 2 E O 1 0 2 1 Recall th
ID: 3751840 • Letter: A
Question
About A B CD E A 0 1 1 1 0 B1 1 1 01 C1 1 0 0 0 D 1 00 0 2 E O 1 0 2 1 Recall that we can use adjacency matrices to represent the relationships between nodes in a graph each row shows the "from" location, and each column shows the "to location. Using this matrix, we can figure out where you can get in one step between any two nodes. 0 means there's no path in one edge, 1 means one edge, 2 means 2 edges, etc. If we want to look at paths with more than one edge, we have to multiply the matrix to get that information.Explanation / Answer
code:
#include<iostream>
using namespace std;
int rowCount,colCount;
int choice;
int **M;
void changeDimesion()
{
cout<<"CHANGE MATRIX DIMENSIONS"<<endl;
cout<<"Matrix value must be square : ";
cin>>rowCount;
colCount=rowCount;
M=new int *[rowCount];
for(int i=0; i<rowCount; i++)
{
M[i]= new int[colCount];
}
}
void deleteMemory()
{
for(int i=0; i<rowCount; i++)
{
delete []M[i];
}
delete[]M;
}
void setmatrixvalue()
{
for(int i=0; i<rowCount; i++)
{
for(int j=0; j<colCount; j++)
{
cout<<" Enter the value for cell ["<<(i+1)<<", "<<(j+1)<<"] : ";
cin>>M[i][j];
}
cout<<endl;
}
cout<<"Set."<<endl;
}
void viewmatrix()
{
for(int i=0; i<rowCount; i++)
{
for(int j=0; j<colCount; j++)
{
cout<<M[i][j]<<" ";
}
cout<<endl;
}
}
void matrixmultiplication()
{
int power;
cout<<"Enter power : ";
cin>>power;
int **T=new int *[rowCount];
for(int i=0; i<rowCount; i++)
{
T[i]= new int[colCount];
}
for(int v=0; v<power; v++)
{
for(int i=0;i<rowCount;i++)
{
for(int j=0;j<colCount;j++)
{
T[i][j]=0;
for(int k=0;k<colCount;k++)
{
T[i][j]+=M[i][k]*M[k][j];
}
}
}
for(int i=0; i<rowCount; i++)
{
for(int j=0; j<colCount; j++)
{
M[i][j]=T[i][j];
}
}
}
}
int main()
{
while(true)
{
cout<<"MATRIX PROGRAM"<<endl;
cout<<"1. Change Matrix dimentions"<<endl;
cout<<"2. Set matrix value "<<endl;
cout<<"3. View Matrix"<<endl;
cout<<"4. multiply matrix"<<endl;
cout<<" - ";
cin>>choice;
switch(choice)
{
case 1:
changeDimesion();
break;
case 2:
setmatrixvalue();
break;
case 3:
viewmatrix();
break;
case 4:
break;
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.