ADVERTISEMENT

One of the works done by our Robotics and Machine Learning division,
SELF-LEVELING QUADCOPTER
Arduino based Quadcopter.
Self-leveling is acheived by the aligning the quadcopter using the readings from the gryo as well as the accelerometer.
A four channel RC transmitter is used to control the movement of the quadcopter when in flight. Kindly subscribe to our YouTube Channel and stay tuned.

Thursday 28 April 2016

CSE1002:BONUS: FIND A ROUTE

FIND A ROUTE
Rahul is fond of travelling and he visits cities and towns in the country whenever possible. All cities in the country are not connected to each other. Given the details of the cities that are connected to each city, source city from where he begins the travel and the destination city of the travel, design an algorithm and write a C++ code to list down the cities in the travel. Rahul must not visit a city more than once. When the destination city name is in the connected cities of the current city, chose it and complete the route. When there is more than one city from the current city, he sorts the city names and include the first minimum city name that is not yet visited. For example, if the connection between the cities are given as follows, source city as A and destination city as F the list of cities in the travel are A, B, D and F.

UML:


CODE:
void travel::get()
{
cin>>num_Of_Cities;
for(int i=0;i<num_Of_Cities;i++)
 {int c;
 string cur;
 cin>>cur>>c;
 for(int j=0;j<c;j++)
 {string temp;
 cin>>temp;
 city_Connection[cur].push_back(temp);
 }
 }
cin>>source>>destn;
}
void travel::find_Route()
{
route.push_back(source);
while(route.back()!=destn)
{
 bool f=true;
 vector<string> s=city_Connection[route.back()];
 sort(s.begin(),s.end());
 if(find(s.begin(),s.end(),destn)!=s.end())
 {route.push_back(destn);break;}
 for(int i=0;i<s.size();i++)
 if (find(route.begin(),route.end(),s[i])==route.end())
 {route.push_back(s[i]);f=false;break;}
}
}
void travel::print_Route()
{
for(int i=0;i<route.size();i++)
 cout<<route[i]<<endl;
}

1 comment: