- Related Questions & Answers
- How to calculate the area and perimeter of a circle in JavaScript?
- Python Program to find the area of a circle
- Program to find the Area and Perimeter of a Semicircle in C++
- Program to calculate area and perimeter of Trapezium
- Java program to find the area of a circle
- C program to find the area of circle and cylinder using structures.
- C Program for Area And Perimeter Of Rectangle
- Program to calculate area and perimeter of equilateral triangle
- C Program for Program to find the area of a circle?
- C++ Program to Compute the Area of a Triangle Using Determinants
- Program to calculate area and perimeter of equilateral triangle in C++
- Find maximum volume of a cuboid from the given perimeter and area in C++
- Program to calculate the area of an Circle inscribed in a Square
- Python Program for Find the perimeter of a cylinder
- Find the perimeter of a cylinder in Python Program

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

When it is required to find the area and perimeter of a circle using classes, object oriented method is used. Here, a class is defined, and attributes are defined. Functions are defined within the class that perform certain operations. An instance of the class is created, and the functions are used to find the area and perimeter of the circle.

Below is a demonstration for the same −

import math class circle_compute(): def __init__(self,my_radius): self.radius=my_radius def area_calculate(self): return math.pi*(self.radius**2) def perimeter_calculate(self): return 2*math.pi*self.radius my_result = int(input("Enter the radius of circle...")) my_instance = circle_compute(my_result) print("The radius entered is :") print(my_result) print("The computed area of circle is ") print(round(my_instance.area_calculate(),2)) print("The computed perimeter of circle is :") print(round(my_instance.perimeter_calculate(),2))

Enter the radius of circle...7 The radius entered is : 7 The computed area of circle is 153.94 The computed perimeter of circle is : 43.98

- A class named ‘circle_compute’ class is defined, that has functions like ‘area_calculate’, ‘perimeter_calculate’.
- These are used to calculate the area and perimeter of a circle respectively.
- An instance of this class is created.
- The value for radius is entered and operations are performed on it.
- Relevant messages and output is displayed on the console.

Advertisements