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

Other questions on the subject: Engineering

image
Engineering, 04.07.2019 18:10, 19deleonl
Coiled springs ought to be very strong and stiff. si3n4 is a strong, stiff material. would you select this material for a spring? explain.
Answers: 2
image
Engineering, 04.07.2019 18:10, salazjlove
Which of the following refers to refers to how well the control system responds to sudden changes in the system. a)-transient regulation b)- distributed regulation c)-constant regulation d)-steady-state regulation
Answers: 1
image
Engineering, 04.07.2019 18:20, ashleyjaslin
Derive the correction factor formula for conical nozzle i=-(1+ cosa) and calculate the nozzle angle correction factor for a nozzle whose divergence hal-fangle is 13 (hint: assume that all the mass flow originates at the apex of the cone.
Answers: 3
image
Engineering, 04.07.2019 18:20, hayleymckee
Steam enters a converging nozzle at 3.0 mpa and 500°c with a at 1.8 mpa. for a nozzle exit area of 32 cm2, determine the exit velocity, mass flow rate, and exit mach number if the nozzle: negligible velocity, and it exits (a) is isentropic (b) has an efficiency of 94 percent
Answers: 2
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 in other subjects:

Konu
Mathematics, 11.01.2022 01:00
Konu
Mathematics, 11.01.2022 01:00