21xrx.com
2024-03-29 23:15:10 Friday
登录
文章检索 我的文章 写文章
C++类示例程序
2021-07-08 15:30:53 深夜i     --     --
C + +

C++类程序示例:在我们的程序中,我们创建了一个名为programming的类,其中包含一个变量和两个函数。 在main函数中,我们创建了这个类的一个对象并调用了这些函数。

C++编程代码

#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;
}

 

  
  

评论区

{{item['qq_nickname']}}
()
回复
回复
    相似文章