Answered step by step
Verified Expert Solution
Question
1 Approved Answer
implent class Trip Planner with locate _ all, plan _ route, and find _ nearby in dssl 2 given these directions: locate - all Takes
implent class Trip Planner with locateall, planroute, and findnearby in dssl given these directions:
locateall Takes a pointofinterest category; returns the positions of all points
order you want, but the result should not include duplicates.
planroute Takes a starting position latitude and longitude and the name of
a pointofinterest; returns a shortest path from the starting position to
the named pointofinterest. You can assume the starting position is at a
road segment endpoint. Returns the empty list if the destination does not
exist or is unreachable.
findnearby Takes a starting position latitude and longitude a pointof
interest category, and a limit n; returns the up to n pointsofinterest
in the given category nearest the starting position. You can assume the
starting position is at a road segment endpoint. Resolve ties however you
want, and order pointsofinterest within the list in any order you want.
#lang dssl
# Final project: Trip Planner
import cons
### Basic Types ###
# Latitudes and longitudes are numbers:
let Lat? num?
let Lon? num?
# Pointofinterest categories and names are strings:
let Cat? str
let Name? str
# Raw positions are element vectors with a latitude and a longitude
let RawPos? TupCLat Lon?
# Raw road segments are element vectors with the latitude and
# longitude of their first endpoint, then the latitude and longitude
# of their second endpoint
let RawSeg? TupCLat Lon?, Lat?, Lon?
# Raw pointsofinterest are element vectors with a latitude, a
# longitude, a pointofinterest category, and a name
let RawPOI? TupCLat Lon?, Cat?, Name?
### Contract Helpers ###
# ListCT is a list of Ts linear time:
let ListC Cons.ListC
# List of unspecified element type constant time:
let List? Cons.list?
interface TRIPPLANNER:
# Returns the positions of all the pointsofinterest that belong to
# the given category.
def locateall
self,
dstcat: Cat? # pointofinterest category
ListCRawPos # positions of the POIs
# Returns the shortest route, if any, from the given source position
# to the pointofinterest with the given name.
def planroute
self,
srclat: Lat?, # starting latitude
srclon: Lon?, # starting longitude
dstname: Name? # name of goal
ListCRawPos # path to goal
# Finds no more than n pointsofinterest of the given category
# nearest to the source position.
def findnearby
self,
srclat: Lat?, # starting latitude
srclon: Lon?, # starting longitude
dstcat: Cat?, # pointofinterest category
n: nat? # maximum number of results
ListCRawPOI # list of nearby POIs
class TripPlanner TRIPPLANNER:
pass
# YOUR PART GOES HERE
def myfirstexample:
return TripPlanner
"bar", "The Empty Bottle"
"food", "Pierogi"
test My first locateall test':
assert myfirstexamplelocateallfood
cons None
test My first planroute test':
assert myfirstexampleplanroute "Pierogi"
cons cons None
test My first findnearby test':
assert myfirstexamplefindnearby "food",
cons "food", "Pierogi" None
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started