diff --git a/20200311.cpp b/20200311.cpp new file mode 100644 index 0000000..ab7312e --- /dev/null +++ b/20200311.cpp @@ -0,0 +1,79 @@ +#include "iostream" + +using namespace std; + +class Circle { +public: + Circle(int r); + Circle(); + + const double PI = 3.1415926; + + double getLength(); + + double getArea(); + + double getRadius(); +private: + + double radius = 0; +}; + +double Circle::getLength() { + return radius * 2 * PI; +} + +double Circle::getArea() { + return radius * radius * PI; +} + +double Circle::getRadius() { + return radius; +} + +Circle::Circle(int r) : radius(r) {} +Circle::Circle() : radius(0) {} + +int main() { + Circle circle(17); + cout << "Area | Length | Radius" << endl; + cout << circle.getArea() << endl << circle.getLength() << endl << circle.getRadius(); +} + +// -------------------------------------------------------------- + +class Circle2 { +public: + const double PI = 3.1415926; + void printArea(); + void printLength(); + void printRadius(); + + Circle2(double radius) : radius(radius) { + area = radius * radius * PI; + length = radius * 2 * PI; + } + + Circle2(const Circle2 &c2) { + radius = c2.radius; + length = c2.length; + area = c2.area; + } + +private: + double radius = 0; + double length = 0; + double area = 0; +}; + +void Circle2::printArea() { + cout << "Area: " << area << endl; +} + +void Circle2::printLength() { + cout << "Length: " << length << endl; +} + +void Circle2::printRadius() { + cout << "Radius: " << radius << endl; +} diff --git a/CPP-Learning.md b/CPP-Learning.md new file mode 100644 index 0000000..445bae0 --- /dev/null +++ b/CPP-Learning.md @@ -0,0 +1,3 @@ +# CPP-Learning + +