Question: CIS 1 2 5 0 Python Competency 9 Create a better class Turn in Requirements: 5 pts . Name your project LastnameFirstInitialP 9 , such

CIS 1250 Python
Competency 9 Create a better class
Turn in Requirements:
5 pts. Name your project LastnameFirstInitialP9, such as CurtisIP9.
Documentation & Requirements:
1.5 pts. Write the file name, your name, email address and purpose of the program at the top of your source code in a comment.
Example:
# GutierrezTP9
# Programmer: Thomas Gutierrez
# Email: tgutierrez53@cnm.edu
# Purpose: demonstrates how to define a class further
2.10 pts. Add comments as appropriate. Be sure that your program output is neatly presented to the user. Add documentation comments to your functions.
Program:
Worth 80 pts.
You are going to modify the GeoPoint created in Program 6 so that it has a default constructor and some properties.
1. In your GeoPoint class make the following changes (note your variable, parameter and method names may be different. Adjust as needed.):
a. Add a constructor __init__(self, lat=0, lon=0,description =TBD) that will initialize the class variables self.lat, self.lon and the self.description. Notice that the constructor will also default lat and lon to zero and description to TBD if they are not provided.
b. Change the SetPoint method so that instead of individual coordinates SetPoint(self, lat, lon) it takes a single sequence/tuple/list. SetPoint(self,point).
self.lat = point[0]
self.lon =point[1]
c. 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.
d. 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.
e. Change the distance method so that it takes a GeoPoint instead of coordinates: CalcDistance(self, point) instead of CalcDistance(self, lat, lon).
lat1= math.radians(self.lat)
lon1= math.radians(self.lon)
lat2= math.radians(point.lat)
lon2= math.radians(point.lon)
2. In the main part of your program do the following:
a. Include the class.
b. Instantiate two points
c. Instead of using SetPoint and SetDescription methods to set each of the points locations and descriptions, do the following:
i. 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')
ii. 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'
d. Inside the Do another (y/n)? loop do the following:
i. Ask the user for their location: latitude, longitude, and description of location.
ii. Create a third point to represent the users location. You can use either the constructor or properties. With a constructor it will look something like the following:
pointUser = GeoPoint(lat,lon, 'User Location')
iii. Use point1 and point2s Distance method to find the distance from each point to the users location. Notice we are passing in the users point rather than the separate coordinates:
distanceToOne = point1.calcDistance(pointUser)
distanceToTwo = point2.calcDistance(pointUser)
iv. Tell the user which point they are closest to in this format:
You are closest to which is located at
v. Ask Do another (y/n)? and loop if they respond with y
Extra Credit (Worth 10 Points):
Turn your GeoPoint class into a library and import that into your main program. Perform the same steps required of your program just as GeoPoint as an imported class module instead.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!