473,508 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calculate coverage degree of node

10 New Member
i want to calulate coverage degree for a particular node having total number of nodes say n=10, in an xy coordinate having say size of x= y=500 and initial position of node is x = y= 0.5 and it should incremented by 1. Condition is that each node is capable of covering distance say d =5. i,ve tried but given below code is not working. pleaase somebody help me out.

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
Struct node {
float pos_x;
float pos_y;
};
Struct node s[50];
int main()
{
float d;
float x = 0.5;
float y=.05;
float degree = 0.0;
int i, n;
printf(“enter the number of nodes”);
scanf(“%d”, &n);
for(i=0; i<n; i++)
{
S[i].pos_x = random(500);
S[i].pos_y = random(500);
}
For(y=0.5 ; y<499.5; y++)
{
For(x=0.5 ;x<499.5; x++)
{
for(i=0; i<n; i++)
{
d = sqrt(pow((x-s[i].pos_x),2.0 )+ pow((y-s[i].pos_y),2.0));
if(d<5)
degree++;
}
degree = degree / 500.0;
printf(“ The average coverage is %f”,degree);
}
}
return(0);
}
Jan 19 '09 #1
4 3734
weaknessforcats
9,208 Recognized Expert Moderator Expert
Please put CODE tags around your sample code.

Next, post only code that compiles (unless you have a syntax question).

Next, this code y<499.5 can't work. The <, > , ==, etc operators don't work with floating point. Google floating point arithmetic and you will see what I mean.

Next, 499.5 is a double. y is a float. Mixing float and double will cause compiler warnings about truncation and possible loss of data. Use double for everything unless you can write down on paper the technical reason why you can't.

Next, put comments in your code. Often problems are solved when the comments and the code don't match.

Next, indent your braces so this code is readable.
Jan 19 '09 #2
donbock
2,426 Recognized Expert Top Contributor
@weaknessforcats
Actually, "<" and ">" are the only comparison operators that work properly with floating point. The problem is the way you're using them to control the number of iterations of a loop. That's a bad idea. The number of iterations could well be off-by-one from what you expect.
Jan 19 '09 #3
latalui
10 New Member
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
Struct node {
float pos_x;
float pos_y;
};
Struct node s[50];
int main()
{
float d;
float x = 0.5;
float y=.05;
float degree = 0.0;
int i, n;
printf(“enter the number of nodes”);
scanf(“%d”, &n);
for(i=0; i<n; i++)
{
S[i].pos_x = random(500);
S[i].pos_y = random(500);
}
for(y=0.5 ; y<499.5; y++) // for coordinate y axis varying from .5 to 500
{
for(x=0.5 ;x<499.5; x++) for coordinate y axis varying from .5 to 500

{
for(i=0; i<n; i++)
{
d = sqrt(pow((x-s[i].pos_x),2.0 )+ pow((y-s[i].pos_y),2.0));
if(d<5)
degree++;
}
degree = degree / 500.0;
printf(“ The average coverage is %f”,degree);
}
}
return(0);
}
Jan 21 '09 #4
latalui
10 New Member
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
Struct node {
float pos_x;
float pos_y;
};
Struct node s[50];
int main()
{
float d;
float x = 0.5;
float y=.05;
float degree = 0.0;
int i, n;
printf(“enter the number of nodes”);
scanf(“%d”, &n);
for(i=0; i<n; i++)
{
S[i].pos_x = random(500);
S[i].pos_y = random(500);
}
for(y=0.5 ; y<500; y++) // for coordinate y axis varying from .5 to 500
{
for(x=0.5 ;x<500; x++) /* for coordinate x axis varying from .5 to 500

{
for(i=0; i<n; i++)
{
d = sqrt(pow((x-s[i].pos_x),2.0 )+ pow((y-s[i].pos_y),2.0)); /* to calculate distance between nodes using sqr (x1 - x2) + sqr(y1-y2).*/
if(d<5) /*if distance between them is under sensing range d we increment the degree of coverage and then print coverge degree of that particular node*/
degree++;
}
degree = degree / 500.0;
printf(“ The average coverage is %f”,degree);
}
}
return(0);
}
Jan 21 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1579
by: Vijay Sankar | last post by:
Hi, I am using coverage.py to check the code coverage for some of my Python scripts. For a particular script which uses 'exit' calls, I am getting the following error when I invoke the script...
7
3044
by: patrickmee | last post by:
Hi all, The database that our php applications are running on is getting a major clean up. RI will be enforced, normalization and all that good stuff. Our QA department have a set of...
3
1740
by: Carles Company Soler | last post by:
Hello, I want to calculate the value of an attribute. For example <rect x="2+3" y="12"and be <rect x="5" y="12">. Is it possible using XSLT? Thanks!
2
1775
by: Orin | last post by:
Hi, I have a problem in using coverage.py module in my project: ../cov -c Traceback (most recent call last): File "./cov", line 10, in ? coverage.the_coverage.command_line(sys.argv) File...
1
1947
by: chittasuman | last post by:
QUESTION: There is a xml node like <icc> <cricket> <player>sachin</player> <score>15</score> </cricket> <cricket> <player>dravid</player>
5
4266
by: ev | last post by:
Hello, We are looking for any testing tool that is capable of checking code coverage for C,C ++ and Java code. Or at least for C and C++. We want to know how much (percentage) of our code written...
4
1560
by: sonia.sardana | last post by:
Hey frnds, i have faced the interview question-- Suppose time is 11:00, What is the degree at this particular time??? Suppose time is 3:00, What is the degree at this particular time??? I have...
0
782
by: python | last post by:
Looking for feedback from people using a coverage checking utility. I've found two - wondering if there's any feature that would recommend one of these utilities vs. another (or argue for the use...
2
2291
by: innes | last post by:
I can't find anything on this in the VS2008 help (searching for 'coverage' returns no results). Can anyone confirm that VS2008's code coverage functionality doesnt extend to working on C++/CLI...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.