-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrivate-data-member.cpp
65 lines (56 loc) · 2.13 KB
/
Private-data-member.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* @brief This program demonstrates the usage of a Circle class to compute the area of a circle.
*
* The Circle class has a private data member 'radius' and a public method 'compute_area' to calculate the area of the circle.
* The 'compute_area' method takes a radius as a parameter, calculates the area using the formula: area = π * r^2, and prints the radius and the computed area to the standard output.
*
* The main function creates an instance of the Circle class, calls the 'compute_area' method with a radius of 1.5, and handles any potential errors.
*
* @note The program does not validate the input radius. It assumes that the caller has already checked the validity of the input.
*
* @note The program prints the radius and the computed area to the standard output.
*/
// Including Header File
#include <iostream>
// Using Namespace
using namespace std;
/// @brief Class for Circle calculations
class Circle
{
private:
double radius;
public:
/**
* @brief This function computes the area of a circle given its radius.
*
* @param r The radius of the circle. It should be a positive value.
*
* @return The area of the circle. The result is calculated using the formula: area = π * r^2.
*
* @note This function does not validate the input radius. It assumes that the caller has already checked the validity of the input.
*
* @note The function prints the radius and the computed area to the standard output.
*/
double compute_area(double r)
{
radius = r;
double area = 3.14 * radius * radius;
cout << "Radius is: " << radius << endl;
cout << "Area is: " << area;
}
};
/**
* @brief The entry point of the program.
*
* @return An integer representing the exit status of the program. A return value of 0 indicates successful execution.
*
* @note This function demonstrates the usage of a Circle object by creating an instance, calling the compute_area method, and handling any potential errors.
*/
int main()
{
Circle obj;
// trying to access private data member
// obj.radius = 1.5;
obj.compute_area(1.5);
return 0;
}