Tuesday, November 5, 2013

Implementation of Frequency Reuse Factor in Mobile Computing using C

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>

#define SIDE 30
#define PI 3.14159
#define X 300
#define Y 220

void draw_hexagon(int,int);
void recur_draw(int,int,int);
void frequency(int,int);

char *name[]={"Blue","Green","Cyan","Red","Magenta","Brown","Lightgray"};
int count=1;

void main(){
int gd=DETECT,gm;
int k=0,f=0;
initgraph(&gd,&gm,"C:\\TC\\BGI");
printf("Enter the value of Reuse Factor (k) ");
scanf("%d",&k);
printf("Enter the frequency range: ");
scanf("%d",&f);
draw_hexagon(X,Y);
recur_draw(X,Y,k);
frequency(f,k);
getch();
closegraph();
}
void draw_hexagon(int x,int y){
int x1,y1,x2,y2,i;
int degree=0;
x1=x+SIDE*cos((degree*PI)/180);
y1=y+SIDE*sin((degree*PI)/180);
setcolor(WHITE);
setlinestyle(0,0,3);
for(i=1;i<=6;i++){
degree=degree+60;
x2=x+SIDE*cos((degree*PI)/180);
y2=y+SIDE*sin((degree*PI)/180);
line(x1,y1,x2,y2);
x1=x2;
y1=y2;
}
}
void recur_draw(int x,int y,int k){
int x1,y1,i;
int degree=30;
int COLOR=1;
count=count+1;
setfillstyle(SOLID_FILL,COLOR);
floodfill(x-1,y+1,WHITE);
if(COLOR==1 && count==2)
printf("1. %s\n",name[0]);
for(i=1;i<k;i++){
x1=x+1.732*SIDE*cos((degree*PI)/180);
y1=y+1.732*SIDE*sin((degree*PI)/180);
draw_hexagon(x1,y1);
if(COLOR==i && count==2)
printf("%d. %s\n",i+1,name[i]);
COLOR=COLOR+1;
setfillstyle(SOLID_FILL,COLOR);
floodfill(x1-1,y1+1,WHITE);
degree=degree+60;
}
}
void frequency(int f,int k){
int x1,y1,i;
int degree=3.2+(k-3)*1.75;
int D=1.732*sqrt(k)*SIDE;
int p=f/k;
for(i=1;i<p;i++){
x1=X+D*cos((degree*PI)/180);
y1=Y+D*sin((degree*PI)/180);
draw_hexagon(x1,y1);
recur_draw(x1,y1,k);
degree=degree+60;
}
}

10 comments:

  1. wah kya baat hai re ladke...

    ReplyDelete
  2. I am very much pleased with the contents you have mentioned. I wanted to thank you for this great article. I enjoyed every little bit part of it and I will be waiting for the new updates. cell phone detection

    ReplyDelete