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:10
Acompressor receives the shaft work to decrease the pressure of the fluid. a)- true b)- false
Answers: 3
question
Engineering, 04.07.2019 18:10
Slip occurs via two partial dislocations because of (a) the shorter path of the partial dislocation lines; (b) the lower energy state through partial dislocations; (c) the charge balance.
Answers: 1
question
Engineering, 04.07.2019 18:10
An air compression refrigeration system is to have an air pressure of 100 psia in the brine tank and an allowable air temperature increase of 60°f for standard vapor compression cycle temperatures of 77 f entering the expansion cylinder and 14 f entering the compression cylinder, calculate the coefficient of performance a. 2.5 b 3.3 c. 4.0 d. 5.0
Answers: 3
question
Engineering, 04.07.2019 19:10
A)-in the process of engineering design, explain the contribution of material selection. b)- explain the procedure of synthesis as is employed in engineering design. c)- is there any relationship between ergonomics and engineering design? explain. d)- safety consideration in engineering design includes human, product and the enviroment . explain how safety will be incorporated into the design?
Answers: 3
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, 15.03.2020 00:07