Listing 2

using namespace System;
using namespace System::IO;

public ref class Point
{ 
   int x;
   int y;
/*1*/   int ID;

/*2*/   static int nextAvailableID;
/*3*/   static int GetNextAvailableID() { return nextAvailableID++; }
/*4*/   static bool traceID = false;
/*5*/   static String^ masterFileLocation;

/*6*/   static Point()
   {
/*6a*/      AppDomain^ appDom = AppDomain::CurrentDomain;
/*6b*/      masterFileLocation = String::Concat(appDom->BaseDirectory, 
              "\\PointID.txt");
/*6c*/      try {
/*6d*/         StreamReader^ inStream = File::OpenText(masterFileLocation);
/*6e*/         String^ s = inStream->ReadLine(); 
/*6f*/         nextAvailableID = Int32::Parse(s);
/*6g*/         inStream->Close();

/*6h*/         appDom->ProcessExit += gcnew 
                EventHandler(&Point::ProcessExitHandler);
      } 
/*6i*/      catch (FileNotFoundException^ ioFNFEx)
      {
         // take appropriate action
      }
/*6j*/      finally
      {
         appDom = nullptr;
      }
   }

/*7*/   static void ProcessExitHandler(Object^ sender, EventArgs^ e)
   {
/*7a*/      StreamWriter^ outStream = File::CreateText(masterFileLocation);
/*7b*/      outStream->WriteLine("{0}", nextAvailableID); 
/*7c*/      outStream->Close();
   } 
public:

// ...

/*8*/   static property bool TraceID
   {
      bool get() { return traceID; }
      void set(bool val) { traceID = val; }
   }

// define instance constructors

   Point() 
   {
/*9*/      ID = GetNextAvailableID();
      X = 0;
      Y = 0;
   }

   Point(int xor, int yor)
   {
/*10*/      ID = GetNextAvailableID();
      X = xor;
      Y = yor;
   }

   Point(Point% p)      // copy constructor
   {
/*11*/      ID = GetNextAvailableID();
      X = p.X;
      Y = p.Y;
   }

// ...

/*12*/   virtual int GetHashCode() override
   {
      // ...
   }

   virtual String^ ToString() override
   {
/*13*/      if (traceID)
      {
         return String::Format("[{0}]({1},{2})", ID, X, Y);
      }
      else
      {
         return String::Format("({0},{1})", X, Y);
      }
   }
};