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, 03.07.2019 14:10
Amass of m 1.5 kg of steam is contained in a closed rigid container. initially the pressure and temperature of the steam are: p 1.5 mpa and t 240°c (superheated state), respectively. then the temperature drops to t2= 100°c as the result of heat transfer to the surroundings. determine: a) quality of the steam at the end of the process, b) heat transfer with the surroundings. for: p1.5 mpa and t 240°c: enthalpy of superheated vapour is 2900 kj/kg, specific volume of superheated vapour is 0. 1483 m/kg, while for t 100°c: enthalpy of saturated liquid water is 419kj/kg, specific volume of saturated liquid water is 0.001043m/kg, enthalpy of saturated vapour is 2676 kj/kg, specific volume of saturated vapour is 1.672 m/kg and pressure is 0.1 mpa.
Answers: 3
question
Engineering, 04.07.2019 12:10
On a average work day more than work place firs are reorted
Answers: 1
question
Engineering, 04.07.2019 18:10
The higher the astm grain-size number, the coarser the grain is. a)-true b)-false
Answers: 3
question
Engineering, 04.07.2019 18:10
Carbon dioxide gas expands isotherm a turbine from 1 mpa, 500 k at 200 kpa. assuming the ideal gas model and neglecting the kinetic and potential energies, determine the change in entropy, heat transfer and work for each kilogram of co2.
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
Questions on the website: 13722359