Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a network that models something with at least 5 objects/nodes. Have two t

ID: 3815377 • Letter: C

Question

Create a network that models something with at least 5 objects/nodes. Have two types of connections for each object with at least one connection from each object. Have at least one cycle/loop in the graph of the objects. Call your code file network.c. Print out each object one at a time showing the things one level deep connected to it. (Have at least a function to create the network and at least one function that prints out the information at a node; call the print function once for each object.) I need to do a cellphone model network with a c language.

Allow an input to network.exe of “debug” at the run command to print out debugging statements – add debugging information in your code.

If in the debug mode (that is, debug was given as an input parameter),

print out more information that would be useful to the programmer such as all the values including memory addresses in a structure/node.

As variables change values, print out the values with the variable name.

Explanation / Answer

network.c:

#include<stdio.h>
#include<stdlib.h>
#include <time.h>

#define MAX_EDGES 10

typedef unsigned char vertex;

int main(){

int verts = 5;

srand ( time(NULL) );
int edges = rand() % MAX_EDGES;
  
if( verts == 0)
verts++;
vertex ***graph;

if ((graph = (vertex ***) malloc(sizeof(vertex **) * verts)) == NULL){
printf("Could not allocate memory for graph ");
exit(1);
}

int vCnt = 0;
int eCnt = 0;

for (vCnt = 0; vCnt < verts; vCnt++){
if ((graph[vCnt] = (vertex **) malloc(sizeof(vertex *) * edges)) == NULL){
printf("Could not allocate memory for edges ");
exit(1);
}
for (eCnt = 0; eCnt < edges; eCnt++){
if ((graph[vCnt][eCnt] = (vertex *) malloc(sizeof(vertex))) == NULL){
printf("Could not allocate memory for vertex ");
exit(1);
}
}
}

vCnt = 0;eCnt = 0;
for (vCnt = 0; vCnt < verts; vCnt++){
printf("%d: ",vCnt);
for (eCnt=0; eCnt < edges; eCnt++){
if (rand()%2 == 1){
int linkedVertex = rand() % verts;
graph[vCnt][eCnt] = graph[linkedVertex];
printf("%d, ", linkedVertex);
}
else{
graph[vCnt][eCnt] = NULL;
}
}
printf(" ");
}
return 1;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote