A simple class:This example contains a class and two objects of that class.The program demonstrates the syntax and general features of classes in c++.

#include<iostream>
using namespace std;
class myclass
{
    private:
       int a;
    public:
        void set_a()
         {
            cout<<"Enter the value:" <<endl;
            cin>>a;
        }
        void get_a()
        {
            cout<<"Your value is:" <<a <<endl;
        }
};
int main()
{
    myclass a1,a2;
    a1.set_a();
    a1.get_a();
    a2.set_a();
    a2.get_a();
return 0;

}

Comments

Popular posts from this blog

Simple class example of c++ for beginners

C++ basic input output