subject
Engineering, 14.03.2020 01:28 sharonbullock9558

Say we have an abstract data type for cities. A city has a name, a latitude coordinate, and a longitude coordinate. Our ADT has one constructor: make_city(name, lat, lon) : Creates a city object with the given name, latitude, and longitude. We also have the following selectors in order to get the information for each city: • get_name(city) : Returns the city's name • get_lat(city): Returns the city's latitude • get_lon(city): Returns the city's longitude Here is how we would use the constructor and selectors to create cities and extract their information: >>> berkeley = make_city('Berkeley', 122, 37) >>> get_name(berkeley) 'Berkeley' >>> get_lat(berkeley) 122 >>> new-york = make_city('New York City', 74, 40) >>> get_lon(new-york) 40 All of the selector and constructor functions can be found in the lab file, if you are curious to see how they are implemented. However, the point of data abstraction is that we do not need to know how an abstract data type is implemented, but rather just how we can interact with and use the data type. 04: Distance We will now implement the function distance, which computes the distance between two city objects. Recall that the distance between two coordinate pairs (x1, yl) and (x2, y2) can be found by calculating the sort of (x1 - x2)**2 + (y1 - y2)**2. We have already imported sqrt for your convenience. Use the latitude and longitude of a city as its coordinates; you'll need to use the selectors to access this info! from math import sqrt def distance(city, city2): >>> city1 = make_city('cityl', 0, 1) >>> city2 = make_city('city2', 0, 2) >>> distance(city, city2) 1.0 >>> city3 = make_city('city3', 6.5, 12) >>> city4 = make_city('city4', 2.5, 15) >>> distance(city3, city4) 5.0 HI "*** YOUR CODE HERE ***"

ansver
Answers: 2

Another question on Engineering

question
Engineering, 04.07.2019 18:20
Inspection for bearing condition will include: (clo4) a)-color b)-smell c)-size d)-none of the above
Answers: 1
question
Engineering, 04.07.2019 18:20
Describe one experiment in which the glass transition temperature and melting temperature of a totally amorphous thermoplastic material can be determined. show the relevant experimental results in a diagram which should be properly annotated with the two temperatures clearly marked. what is likely to happen to the curve in the diagram if the amorphous polymer is replaced by a thermosetting type?
Answers: 2
question
Engineering, 04.07.2019 18:20
An open feedwater heater operates at steady state with liquid entering at inlet 1 with t? = 40°c and pl = 1 .2 mpa. water vapor att2-200°c and p2 = 1.2 mpa enters at inlet 2. saturated liquid water exits with a pressure of pa 1.2 mpa. neglect heat transfer with the surroundings and all kinetic and potential energy effects, determine the mass flow rate of steam at inlet 2 if the mass flow rate of liquid water at inlet 1 is given as 2 kg/s.
Answers: 3
question
Engineering, 04.07.2019 19:10
Abarometer contains mercury with a density of 13600 kg/m3. atmospheric conditions are 95.8 kpa and 20 °c at 20 °c, the vapor pressure of the mercury is 0.000173 kpa. the column of mercury will rise to a height of most nearly. select one: a)- 0.38 m b)- 0.82 m c)- 0.48 m d)- 0.72 m
Answers: 1
You know the right answer?
Say we have an abstract data type for cities. A city has a name, a latitude coordinate, and a longit...
Questions
question
Mathematics, 24.04.2020 03:06
question
Advanced Placement (AP), 24.04.2020 03:06
Questions on the website: 13722361