You are on page 1of 1

20 10 2014 C++ class example program | Programming Simplified

Home

C++ class example program


C++ class program example: In our code we create a class named programming with one variable and two functions. In main we create an
object of class and call the functions using it.

C++ programming code


#include<iostream>

using namespace std;

class programming
{
private:
int variable;

public:

void input_value()
{
cout << "In function input_value, Enter an integer\n";
cin >> variable;
}

void output_value()
{
cout << "Variable entered is ";
cout << variable << "\n";
}
};

main()
{
programming object;

object.input_value();
object.output_value();

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

return 0;
}

http://www.programmingsimplified.com/cpp/source-code/cpp-class-example-program 1/1

You might also like