Вы находитесь на странице: 1из 2

#include <iostream>

using namespace std;


#include <conio.h>
#include <math.h>
struct location
{
float x, y, z;
};

struct mesh
{
location lm;
mesh()
{
lm.x = (rand() % 5);
lm.y = (rand() % 5);
lm.z = (rand() % 5);
}

};
struct user
{
location lu;

user()
{
lu.x = (rand() % 5);
lu.y = (rand() % 5);
lu.z = (rand() % 5);

}
float distance(location lm)
{

float dis = sqrt(((lu.x - lm.x) * (lu.x - lm.x)) + ((lu.y - lm.y) * (lu.y -


lm.y)) + ((lu.z - lm.z)*(lu.z - lm.z)));

return dis;
}

};

void main()
{ int u = rand() % 100;
int m = rand() % 100;
cout << "Total Number of Meshes is: " << m<<endl;
cout << "Total Number of Users is: " << u << endl;

mesh * MESH = new mesh [m];

float * distance = new float [m];


for (int i = 0; i < m; i++)
{
distance[i] = 0;
}
char c = 'e';

while (c == 'e' )
{
user * USER = new user[u];

for (int i = 0; i < u; i++)


{
float min =100000000;

int Index = 0;
for (int j = 0; j < m; j++)
{
distance[j] = USER[i].distance(MESH[j].lm);
if (distance[j] < min)
{
min = distance[j];
Index = j ;
}

}
cout << "\nUser ( " << i + 1 << " ) is connected to Mesh ( " <<
Index + 1 << " )"<<endl;
}

cout << "Enter ( e ) to run again or any other key to exit "<<endl;
cout<<"Enter :";
cin >> c;

}
getch();

Вам также может понравиться