You are here

C++ class example program

C++ class program example: In our program, we create a class named programming with one variable and two functions. In the main function, we create an object of this class and call these functions.

C++ programming code


using namespace std;

class programming
      int variable;
      void input_value()
         cout << "In function input_value, Enter an integer\n";
         cin >> variable;
      void output_value()
         cout << "Variable entered is ";
         cout << variable << "\n";

   programming object;
   //object.variable;  Will produce an error because variable is private
   return 0;