Skip to content

Instantly share code, notes, and snippets.

@dibakarsutradhar
Created September 3, 2018 06:21
Show Gist options
  • Select an option

  • Save dibakarsutradhar/e527741e64abeba29a99c86fe9d4d550 to your computer and use it in GitHub Desktop.

Select an option

Save dibakarsutradhar/e527741e64abeba29a99c86fe9d4d550 to your computer and use it in GitHub Desktop.
// 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