Question

you to develop object oriented programs of a graph that can achieve the following functions l. A graph can be empty with no vertex or edge. 2. A graph can be either a directed graph or an undirected graph. 3. A graph can be added in vertices and edges 4. A vertex of a graph can contain values in theory, the values can be of any type 5. A graph can be displayed by listing all the possible paths, each linking vertices 6. A graph can be queried by given a starting vertex, listing the path this vertex leads. 7. A graph can be queried by given an edge, if this edge exists in the graph 8. A graph can be queried if a value is contained by any of its vertex.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stduio.h>

#include<stdlib.h>

void main()

{

int option;

do

{

printf("\n A Program to repersent a Graph by using an");

printf("Adjacency Matrix method \n");

printf("\n 1.Directed Graph");

printf("\n 2.Un-Directed Graph ");

printf("\n 3.Exit");

printf("\n\n Select a proper option:");

scanf("%d",&option);

switch(option)

{

case 1:dir_graph():

break;

case 2:undir_graph();

break;

case 3:exit(0);

}

}

while(1);

}

int dir_graph()

{

int adj_mat[50][50];

int n;

int in_deg,out_deg, i, j;

printf("\n How Many vertices ?:");

scanf("%d",&n);

printf("\n vertex \t In Degree \t Out_Degree \t Total_Degree ");

for(i=1; i<n; i++)

{

in_deg = out_deg = 0;

for(j = 1; j<=n; j++)

{

if(adj_mat[j][i]==1)

in_deg++;

}

for(j=1; j<=n; j++)

if(adj_mat[i][j]==1)

out_deg++;

printf("\n\n %5\t\t\t%d\t\t%d\t\t%d\n\n", i, in_deg, out_deg, in_deg +out_deg);

}

return;

}

int undir_graph()

{

int adj_mat[50][50];

int deg,i,j,n;

printf("\n How many vertices");

scanf("%d",&n);

read_graph(adj_mat,n);

printf("n vertex \t Degre");

for (i=1; i<=n; i++)

{

deg=0;

for(j=1; j<=n; j++)

if(adj_mat[i][j]==1)

deg++;

printf("\n\n%5d \t\t %d\n\n", i, deg);

}

return;

}

int read_graph(int adj_mat[50][50], int n)

{

int i, j;

char reply;

for (i=1;i<n;i++)

{

for(j=1;j<=n;j++)

{

if(i==j)

{

adj_mat[i][j]=0;

continue;

}

printf("\n Vertices %d & %d are Adjacent" i,j);

scanf("%c",&reply);

if(reply=='y'|| reply == 'Y')

adj_mat[i][j]=1;

else

adj_mat[i][j]=0;

}

}

retrurn;

}

Add a comment
Know the answer?
Add Answer to:
This project requires you to develop object oriented programs of a graph that can achieve the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT