473,799 Members | 2,940 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 3751
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
1591
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 with the -x option for coverage. Error in sys.exitfunc: Traceback (most recent call last):
7
3054
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 regression plans but I don't know how complete they are. Neither do they :( My idea would be to have them run through their plans on an application
3
1751
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
1786
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 "/usr/lib/python2.4/site-packages/coverage.py", line 363, in command_line self.collect() File "/usr/lib/python2.4/site-packages/coverage.py", line 467, in
1
1965
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
4283
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 on C/C++ is covered in terms of function calls and line calls. We tried Rational PureCoverage. It's excellent but has some limitations in our case. Any idea would be greatly appreciated.
4
1576
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 clue abt this question,plz reply.
0
796
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 of both utilities). Coverage.py http://nedbatchelder.com/code/modules/coverage.html and Pycover
2
2309
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 assemblies, apart from the least useful type (/clr:safe)? I think I saw that last detail somewhere on the internet. Thanks.
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10251
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10027
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
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 we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.