diff --git a/README.md b/README.md index 5e94d2a..6a38d23 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # Demo-Class A Simple C++ Class +Class: A class in C++ is the building block, that leads to Object-Oriented programming. It is a user-defined data type, which holds its own data members and member functions, which can be accessed and used by creating an instance of that class. A C++ class is like a blueprint for an object. diff --git a/main.cpp b/main.cpp index 1b999d6..e5f7f2c 100644 --- a/main.cpp +++ b/main.cpp @@ -1,10 +1,32 @@ -//complete me - -#include -using namespace std; - - -int main() -{ - -} +// C++ program to demonstrate +// accessing of data members + +#include +using namespace std; +class Geeks +{ + // Access specifier + public: + + // Data Members + string coder; + + // Member Functions() + void printname() + { + cout << "Geekname is: " << coder; + } +}; + +int main() { + + // Declare an object of class geeks + Geeks obj1; + + // accessing data member + obj1.geekname = "Abhi"; + + // accessing member function + obj1.printname(); + return 0; +}