C++ class example program


SUBMITTED BY: RavishBhatt

DATE: June 29, 2016, 8:53 a.m.

FORMAT: C++

SIZE: 577 Bytes

HITS: 580

  1. #include<iostream>
  2. using namespace std;
  3. class programming
  4. {
  5. private:
  6. int variable;
  7. public:
  8. void input_value()
  9. {
  10. cout << "In function input_value, Enter an integer\n";
  11. cin >> variable;
  12. }
  13. void output_value()
  14. {
  15. cout << "Variable entered is ";
  16. cout << variable << "\n";
  17. }
  18. };
  19. main()
  20. {
  21. programming object;
  22. object.input_value();
  23. object.output_value();
  24. //object.variable; Will produce an error because variable is private
  25. return 0;
  26. }

comments powered by Disqus