Skillrack IL 9

Solutions for Skillrack CSE1002 Inlab 9

Total time : 20 mins

Challenges : 1

Question

Design a class point with datamembers name of the point(string), value in x-axis and value in y-axis. Provide functions to get the details of a point, print the details of a point and a function to compute distance between the point and a given point. Design a class mobileSpace, with a list of points representing the latitude and longitude of the mobile towers and a point to represent a mobile phone, provide member functions to get details and determine the tower that shall be connected to the phone. Use STL for implementation.

Input Format

Number of points, ‘n’

Name of tower-1

X-axis of tower-1

Y-axis of tower-1

Name of tower-n

X-axis of tower-n

Y-axis of tower-n

Name of mobile

X-axis of mobile phone

Y-axis of mobile phone

Output Format

Name of the tower to which the phone has to be connected

Solution

#include < iostream >

#include < vector >

#include < math.h >

#include< list >

using namespace std;

class point

{

char name[30];

float x;

float y;

public:

void get();

void print();

float dist(point p);

};

class mobile

{

int num_Tower_Pts;

list< point > tower_Pts;

point mobile_Pt;

public:

void get();

point find_Min();

};

void point :: get()
{
	cin>>name>>x>>y;
}
void point :: print()
{
	cout<<name; 
} 
float point :: dist(point p) 
{ 
	return(sqrt(pow(x-p.x,2)+pow(y-p.y,2))); 
} 
void mobile :: get() 
{ 
	cin>>num_Tower_Pts;
	for(int i=0;i < num_Tower_Pts;i++)
	{
		point p;
		p.get();
		tower_Pts.push_back(p);
	}
	mobile_Pt.get();
}
point mobile :: find_Min()
{
	point p;
	float min=999;
	for(list < point > :: iterator i=tower_Pts.begin();i!=tower_Pts.end();i++)
	if(min > mobile_Pt.dist(*i))
	{
		p=*i;
		min=mobile_Pt.dist(*i);
	}
	return(p);
}

int main()

{

mobile m;

m.get();

(m.find_Min()).print();

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s