Hi..everybody! I am new in this forum. Can any one please help me to run the following C++ code? I will be greatfull if any one help me.
Thanks
//#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define forward 1
#define backward -l
#define successful 1
#define failed 0
//using namespace std;
struct Router {
int adj[25];
int pak[25];
} r[25];
struct Packet {
int current_router;
int path_length;
int total_length;
int path[10];
int packet_status;
int delivery_status;
int source;
int destination;
} p[20];
int init()
{
int i,j;
//connectivity
for (i=1;i<20;i++)
{
for (j=1;j<=11;j++)
{
r[i].adj[j]=0;
}
}
r[1].adj[5]=1;
r[1].adj[2]=1;
r[1].adj[3]=1;
r[2].adj[8]=1;
r[3].adj[4]=1;
r[4].adj[6]=1;
r[5].adj[11]=1;
r[6].adj[8]=1;
r[8].adj[7]=1;
r[9].adj[7]=1;
r[10].adj[9]=1;
r[11].adj[10]=1;
//and so on
for (i=1;i<=15;i++)
{
p[i].current_router = 1;
p[i].packet_status = forward;
p[i].path_length = 0;
p[i].path[1] = 0;
p[i].source = 1;
p[i].destination = 7;
}
}
int random (int highest)
{
int random_integer;
int lowest=0; //highest=100;
int range= (highest-lowest)+1;
random_integer = lowest+int(range*rand() / (RAND_MAX+1.0));
return random_integer;
}
int rollet_wheel(int cr)
{
int i,j,k,m,rnd,max,max_count,count,num =11;
int wheel[100000];
int list[100];
for (i =1,m=0; i<=11; i++); //maximun router
{
if (r[cr].adj[i]>0)
{
k= r[cr].adj[i];
for (j=1;j<=k; j++)
wheel[m++]=i;
}
}
rnd = random(m-1);
return wheel[rnd];
}
int Edge (int i)
{
int j, counter=0;
for (j=1;j<=15;j++)
if(r[i].adj[j]==1)
counter++;
return counter;
}
int routerAt(int i,int pos)
{
return p[i].path[pos];
}
void deposite_pheromone(int i, int j, int length_ratio)
{
int Q=10;
r[i].adj[j] = r[i].adj[j] + (int) (Q / length_ratio);
r[i].pak[j]++; //just to keep track the number of packet passed
}
int next_router_selection(int i)
{
int cr,next_router,tmp,length_ratio;
cr = p[i].current_router;
if (p[i].packet_status == forward) //forard packet
{
next_router = rollet_wheel(cr);
p[i].path_length = p[i].path_length+1;
tmp = p[i].path_length;
p[i].Path[tmp]=cr;
}
else if (p[i].packet_status == backward && p[i].delivery_status ==successful) //Backard packet
{
length_ratio = p[i].total_length - p[i].path_length + 1;
deposite_pheromone (cr, routerAt (i,p[i].path_length),length_ratio);
p[i].path_length--;
next_router = routerAt (i,p[i].path_length - 1);
}
else if (p[i].packet_status == backward && p[i].delivery_status ==failed)
{
}
else
{ //no more arch to go Edge(cr) == 1
}
return next_router;
}
void print(int i)
{
printf("\n%d %d",p[i].current_router,p[i].packet_status);
}
int checkpath(int i)
{
int k,len,cr;
for (k=1;k<=p[i].path_length;k++)
if(p[i].path[k] == p[i].current_router)
return 1;
return 0;
}
void move (int i, int next;
{
p[i].current_router = next;
}
void end_of_the_journey(int i)
{
p[i].current_router = 1;
p[i].packet_status = forward;
p[i].path_length = 0;
p[i].path[1] = 0;
p[i].source = 1 ;
p[i].destination = 7;
}
void adaptive_aodv(int i)
{
int source = p[i].source;
int destination = p[i].destination;
int path_length = p[i].path_length;
int previous_router = routerAt(i,p[i].path_length);
int current_router = p[i].current_router;
int packet_status = p[i].packet_status;
int delivery_status = p[i].delivery_status;
int next;
}
int main()
{
int a,b,c:
double p1,p2,p3;
freopen("Packet4.out","w",stdout};
int ()
srand ((unsigned)time(0));
for int i=0;i<=500;i++;
{
simulate(); //if
When I compiled the code, I got 28 errors.
You need to work through the list of errors and correct each one.
For example, you need to pay attention to capitialization.
Line 117: p[i].Path[tmp]=cr;
Member path is delcared as 'path' (no capitialization) in struct Packet.
You still have quite a few errors, including still referring to path as Path. Only one of them is of any difficult to spot:
#define backward -l
I think you want a -1 there, not a -l. Prefer not to use defines.
constint backward = -1; would work fine.
When you're fixing your errors, fix the first error reported, then try to compile again before fixing any more errors. Often times errors immediately after the first reported are a direct result of failing to parse the code where the first reported error occurred.
Getting your code to compile is a major part of programming, keep working on it.
Do not post code on here and say: "I get errors. Please help." Do, if you're having trouble resolving a specific compilation error, post the first few lines of the compiler output beginning with the reported error. Do use code tags when you post. See the <> button to the right of the edit box when you're composing a reply.