CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "circle.h"
#include <iostream>
using namespace std;
float radius; //declaring variables and types
const float PI = 3.141593f;
void circle::setRadius(float r) //describing member functions and return types
{ //since it is a regular member function it is important
radius = r; //to specify its return type in the declaration and the definition
}
float circle::getRadius() //getRadius returns variable radius with return type float
{
return radius;
}
circle::circle()
{
radius = 0; //initializing radius to 0
}
circle::circle(float r) //circle function takes one parameter, variable 'r' of the float type
{
radius = r;
}
float circle::getArea(float r) //getArea function takes one parameter, variable 'r' of the float type
{
radius = r; //assigning the value 'r' to variable radius
return PI*radius*radius; //returns PI*radius*radius to getArea
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run