C++ Class Definition model an integer data type

Description

C++ Class Definition model an integer data type

#include <iostream>
using namespace std;
class Int//from   w w  w .  ja  v  a  2s .  c om
{
   private:
   int i;
   public:
   Int()
   { i = 0; }
   Int(int ii)
   { i = ii; }
   void add(Int i2, Int i3)
   { i = i2.i + i3.i; }
   void display()
   { cout << i; }
};
int main(){
   Int Int1(7);                 //create and initialize an Int
   Int Int2(11);                //create and initialize an Int
   Int Int3;                    //create an Int
   Int3.add(Int1, Int2);                 //add two Ints
   cout << "\nInt3 = "; Int3.display();  //display result
   cout << endl;
   return 0;
}



PreviousNext

Related