Using Python, create a program that has the following classes: Point - Just like in the lecture, with attributes x and y set to 0 by default. Circle - Contains two attributes, center and radius. center is of type Point defined above (initialize a Point instance for this), while radius is set to 0 by default. The program must have the function point_in_circle(c, p) where c is a Circle and p is a Point. The function returns True if the point is within the circle, and False otherwise. You may use the math module (and nothing else) if necessary. You may also create other functions that can help you code the main function much easier.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 10SA: Consider the definition of the class product Type as given in Exercise 8. Answer the following...
icon
Related questions
Question

Using Python, create a program that has the following classes:

  • Point - Just like in the lecture, with attributes x and y set to 0 by default.
  • Circle - Contains two attributes, center and radius. center is of type Point defined above (initialize a Point instance for this), while radius is set to 0 by default.

The program must have the function point_in_circle(c, p) where c is a Circle and p is a Point. The function returns True if the point is within the circle, and False otherwise.

You may use the math module (and nothing else) if necessary. You may also create other functions that can help you code the main function much easier.

Example usage

 
# Initialize a circle with center at (0, 0) and radius 1 (unit circle).
c = Circle()
c.center.x, c.center.y, c.radius = 0, 0, 1
 
# Initialize a point located at (1, 1)
p = Point()
p.x, p.y = 1, 1
 
# This returns False since (1, 1) is outside the circle
point_in_circle(c, p)
 
hint: apply "classes" concept
Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Reference Types in Function
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr