Created
September 3, 2018 06:21
-
-
Save dibakarsutradhar/e527741e64abeba29a99c86fe9d4d550 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // c++ oop public access modifier | |
| #include <iostream> | |
| using namespace std; | |
| // defining a class | |
| class Circle { | |
| public: // we defined that this class data members will be public | |
| double radius; | |
| double compute_area(){ | |
| return 3.14*radius*radius; | |
| } | |
| }; // always put semicolons after defining a class | |
| //main function | |
| int main(){ | |
| Circle ball; | |
| ball.radius = 3.5; // accessed public data number outside Circle class | |
| cout << "Radius is: " << ball.radius << endl; | |
| cout << "Area is: " << ball.compute_area(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment