Program To Calculate Area And Circumference Of A Circle Using Objects And Classes in C++

LEVEL: Beginner

Whats in this post?

  1. Code
  2. Output
  3. Background and Explanation of the code

Code


To copy code: Click View Source “View Source” on the right of this code snippet.


Background and Explanation of the code


The above program is used to calculate the area and circumference of a circle for a given radius r.The class circle contains a private data member r and three public member functions : input ( ) , area ( ) and circumference ( ) which are declared inside the class and defined outside.In the main ( ) , the statement circle c1; informs the compiler that c1(object) is a variable of type circle which is user defined data type.The public member functions are called from  main ( ) through the object c1 to generate the required output.

OUTPUT

Enter radius of circle =  4

Area of circle = 50.26

Circumference of circle =  25.13