19 Apr 2017

Inlab 9 - CSE1002

 You don't need to tick the "Request desktop site" option in your browser anymore while using a mobile device, but if you don't then the code formatting of the code given as text for copying will be disturbed.

 

Code:

[verified] 
{reportedly working.}

 

  If you know how to copy paste on skillrack then you can copy the code from below:


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

 

Input:

n (number of towers)
for n towers : name,x,y
mobile's name,x,y  

Output:


name of tower closest to mobile

Processing:

distance between two points =( (x1-x2)^2 + (y1-y2)^2) ^0.5


Psuedocode: 

start
input n
for i=i till n
input nth towers's name,x,y
end for
input mobile's name,x,y
let min=tends to infinity 
for i=1 till n
      if(min>ithtowers distance to mobile)
            min=th tower's distance to mobile
            closest=ith tower
      end if     
end for
output closest's name
stop
   

1 comment: