Search Results

Search found 2 results on 1 pages for 'laian alsabbagh'.

Page 1/1 | 1 

  • I’m new to C++ and unsure about how to improve this code [migrated]

    - by Laian Alsabbagh
    The purpose of the following code is to get a random number of 100 nodes and to distribute these nodes randomly in range 500*500 …(X,Y).. this was the first step #include<iostream> #include <fstream> #include<cmath> using namespace std; int main() { const int x = 0, y = 1; int nodes[100][2]; ofstream myfile; myfile.open ("example.txt"); myfile << "Writing this to a file.\n"; for (int i=0; i<100 ;i++) { nodes[i][x] = rand() % 501; nodes[i][y] = rand() % 501; myfile <<nodes[i][x]<<" "<<nodes[i][y]; } myfile.close(); } now the next step is to improve this code to distribute these nodes in order ( "Imust divide both xy_coordinates as : x= 0-100-200-300-400-500 & y=0-100-200-300-400-500) next is to distribute the nodes (regardless number of nodes) in order range Starting from (0,100 )….(100,100)..(100,200)…….untile i reach the last point (500,500),, ") I’m really confused of how to do it correctly I start to think to define 2 dimensional array , and then to define 2 for loops enter code here Int no_nodes=100; Int XY_coordinate [500][500]; For (int i=0;i<no_nodes; i++) { For (int j=0;j<no_nodes; j++)

    Read the article

  • I’m new to c++. can anyone help me in the following function [migrated]

    - by Laian Alsabbagh
    In this code I’m using a function Distance{to calculate the distance between two nodes } I declare the function like this : int Distance( int x1 , int y1 ,int x2 , y2){ int distance_x = x1-x2; int distance_y = y1- y2; int distance =sqrt( (distance_x * distance_x) + (distance_y * distance_y)); return distance ; } and in the main memory I have 2 for loops what iam asking for ,can I pass the values like this?? Distance (i, j , i+1 ,j+1) for(int i=0;i< No_Max;i++) { for(int j=0;j<No_Max;j++) { if( Distance (i, j , i+1 ,j+1)<=Radio_Range)//the function node_degree[i]=node_degree[i]+1; cout<<node_degree[i]<<endl; } }

    Read the article

1