Code for calculating circle Area and Circumference

Asked By 20 points N/A Posted on -
qa-featured

Need help with a program calculate the area and circumference of the circle by declaring a class

thanks in advance

SHARE
Best Answer by James20
Best Answer
Best Answer
Answered By 0 points N/A #95971

Code for calculating circle Area and Circumference

qa-featured

//  This program calculate the area and circumference of the circle by declaring a class

//  Including header files in the program.
#include <iostream>

using namespace std;
// defining a macro for the value of PI
#define PI 3.14

//  Beginning of the class Circle
class Circle {
   
   
    //  declaring public members of the class
    public:
       
       double radius;    //    only data member of the class
      
       //       declaration of public member functions of the class
      
       Circle();            //  default constructor
      
       Circle(double);       //  Parameterized constructor
      
       double CalculateArea();       // calculates area of the circle and then returns
      
       double CalculateCircum();//       calculates circumference of the circle
      
       void Display();       //       displays the area and circumference of the screen
      
};

//       end of class


//  definition of default constructor of class
Circle::Circle()      
{
    radius = 0.0;   // assignning default value to the data member radius
}


//    definition of parameterized constructor of the class
Circle::Circle(double rad)
{
    radius = rad;
}

//    definition of the function for area calculation of the circle
double Circle::CalculateArea()
{
    return (PI * radius * radius);  //  calculating area and then returning it the caller function
}


//    definition of the function for calculating circumference of the circle
double Circle::CalculateCircum()
{
    return ( 2 * PI * radius ); //  calculating and returning the circumferencr to the caller function
}

//    definition of display() function
void Circle::Display()
{

   
    cout<<"nRadius of Circle:tt"<<radius;
    cout<<endl<<endl;
   
    cout<<"Area of Circle:ttt"<<CalculateArea();
    cout<<endl<<endl;
   
    cout<<"Circumference of Circlett"<<CalculateCircum();
    cout<<endl<<endl;   

}

//    beginning of the main() function
main()
{
    Circle C1, C2(3.5);     // declaring two objects of class student
   

    //    for each object created, displaying the information on the screen
    C1.Display();   
    C2.Display();   
 

    system("pause");    // system function to halt the output screen
}

 

Answered By 0 points N/A #95972

Code for calculating circle Area and Circumference

qa-featured
Check out this :
#include<iostream>
#include<cmath>
usingnamespacestd;
 
intmain ()
{
 
    floatradius;
    floatcircumference;
    floatarea;
 
    cout <<"Please enter the radius of a circle: ";
    cin >>radius;
    cout <<"n";
 
    circumference =2*3.1416*radius;
    area =3.1416*radius *radius;
 
    cout <<"************************************"<<"n"
         <<"*Area and Circumference of A Circle*"<<"n"
         <<"************************************"<<"n"
         <<"tRadius= "<<radius <<"n"
         <<"tArea= "<<area <<"n"
         <<"tCircumference= "<<circumference <<"n";
 
    cin.get();
 
 
    return0;
 
}//end main

 

 

 

Login/Register to Answer

Related Questions