Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

I am creating a class using python, I am stuck with inserting the functions as I have run across some errors. I will attach my program and the instructions.

  1. In your program define a class called GeoPoint that will have the following:
    1. A constructor __init__(self, lat=0, lon=0,description=’TBD’) that will initialize the class variables called: self.lat, self.lon, and self.description.
    2. A SetPoint(self, point) method that takes an individual points coordinates as a single sequence and sets them to self.lat, self.long. E.g: 

self.lat = point[0]

self.lon =point[1]

    1. A GetPoint(self) method that will return a tuple or list with self.lat, self.lon. 
    2. A CalcDistance(self, lat, lon) method that will figure out the distance between the object’s self.lat, self.lon and lat, lon parameters passed in.
    3. A CalcDistancePoint(self, point) method that takes in a point (both coordinates at once, a data sequence, or GeoPoint object) that will figure out the distance between the object’s self.lat, self.lon and the lat and lon from the point.
    4. A SetDescription(self, description) method that will set the objects self.description attribute (variable).
    5. A GetDescription(self) method that will return the objects self.description attribute.
    6. Add a property: Point = property(GetPoint,SetPoint). Make sure GetPoint and SetPoint are the names you used for the get and set methods you already wrote for points.
    7. Add another property: Description = property(GetDescription, SetDescription). Make sure GetDescription and SetDescription are the names you used for the get and set methods you already wrote.
  1. In the main part of your program do the following:
    1. Include the class.
    2. Instantiate three points.
      1. Use the constructor to set point1 coordinates and description. It should look something like the following but with your own coordinates and description:

point1 = GeoPoint(12.3456,-123.4567,'Loc1')

      1. Use a constructor without any arguments to instantiate the second point and use its properties to set its values. It should look something like the following but with your own coordinates and description:

point2 = GeoPoint()

point2.Point = 23.4567, -213.456

point2.Description = 'Loc2'

 

      1. For point3 use the SetPoint and SetDescription methods to set the points location and description. Make sure they have different coordinates and different descriptions. It should look something like the following but with your own coordinates and description:

 

point3 = GeoPoint()

point3.SetPoint((25.25,52.52))

point3.SetDescription(“Loc3”)

 

    1. Inside a “Do another (y/n)?” loop do the following:
      1. Create a fourth point by asking the user for their location. You can ask for coordinates in three inputs or ask them for their coordinates in one input with each element separated by a coma.
      2. Use the CalcDistance method to find the distance between point1 and a new latitude and longitude of your choosing. Then tell the user the coordinates for point1, the new latitude and longitude that was entered, and the distance between those coordinates. For example:

 

distanceToPoint1 = point1.CalcDistance(lat, lon)

 

      1. Use point2 and point3’s CalcDistancePoint method to find the distance from each point to the user’s location. Notice we are passing in the users point rather than the separate coordinates:

 

distanceToTwo = point2.CalcDistancePoint(userPoint)

distanceToThree = point3.CalcDistancePoint(userPoint)

 

      1. Tell the user which point they are closest to in this format:

 

You are closest to <description> which is located at <point’s lat and lon coordinates>

 

      1. Ask “Do another (y/n)?” and loop if they respond with ‘y’
```python
from math import cos, asin, sqrt, pi

class GeoPoint:
    # Parameterized and default constructor
    def __init__(self, lat=0, lon=0, description='TBD'):
        self.__lat = lat
        self.__lon = lon
        self.__description = description

    # Latitude and longitude setup programme
    def setPoint(self, coords):
        self.__lat = coords[0]
        self.__lon = coords[1]

    # Function helps to get the point
    def getPoint(self):
        return (self.__lat, self.__lon)

    # Distance calculation method between two points
    def Distance(self, toPoint):
        p = pi / 180
        a = 0.5 - cos((toPoint[0] - (self.Point)[0]) * p) / 2 + cos(self.Point[0] * p) * cos(toPoint[0] * p) * (1 - cos((toPoint[1] - (self.Point)[1]) * p)) / 2
        return 12742 * asin(sqrt(a))

    # Function defining to set the self description
    def setDescription(self, description):
        self.__description = description

    # Function that returns the self description
    def getDescription(self):
        return self.__description

    # Property of Point to access and set point values
    Point = property(getPoint, setPoint)
    # To set and access the point's description, use their description attribute
    Description = property(getDescription, setDescription)

# Giving a value to the function Object(), i.e. constructor to initialize the object
point1 = GeoPoint(12.3456, -123, 'Chicago')
# Initializing values of longitude and latitude
point2 = GeoPoint()
point2.Point = (12.34567, -213.45671)
point2.Description = "Loc2"

while True:
    lat, lon = map(float, input("Enter the location points of latitude and longitude: ").split(","))
    # Calculate the distance between the two places using a list of values (lat, lon)
    distanceone = point1.Distance((lat, lon))
    distancetwo = point2.Distance((lat, lon))

    if distanceone < distancetwo:
        print(f"You are closest to point1.GetDescription() which is located
expand button
Transcribed Image Text:```python from math import cos, asin, sqrt, pi class GeoPoint: # Parameterized and default constructor def __init__(self, lat=0, lon=0, description='TBD'): self.__lat = lat self.__lon = lon self.__description = description # Latitude and longitude setup programme def setPoint(self, coords): self.__lat = coords[0] self.__lon = coords[1] # Function helps to get the point def getPoint(self): return (self.__lat, self.__lon) # Distance calculation method between two points def Distance(self, toPoint): p = pi / 180 a = 0.5 - cos((toPoint[0] - (self.Point)[0]) * p) / 2 + cos(self.Point[0] * p) * cos(toPoint[0] * p) * (1 - cos((toPoint[1] - (self.Point)[1]) * p)) / 2 return 12742 * asin(sqrt(a)) # Function defining to set the self description def setDescription(self, description): self.__description = description # Function that returns the self description def getDescription(self): return self.__description # Property of Point to access and set point values Point = property(getPoint, setPoint) # To set and access the point's description, use their description attribute Description = property(getDescription, setDescription) # Giving a value to the function Object(), i.e. constructor to initialize the object point1 = GeoPoint(12.3456, -123, 'Chicago') # Initializing values of longitude and latitude point2 = GeoPoint() point2.Point = (12.34567, -213.45671) point2.Description = "Loc2" while True: lat, lon = map(float, input("Enter the location points of latitude and longitude: ").split(",")) # Calculate the distance between the two places using a list of values (lat, lon) distanceone = point1.Distance((lat, lon)) distancetwo = point2.Distance((lat, lon)) if distanceone < distancetwo: print(f"You are closest to point1.GetDescription() which is located
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education