title: How to get size c++ dynamic array
body: <p>I'm studying C++ and I need to create structure <code>Airplane</code> and work with it. </p>
  
  <p>My structure <strong>Airplane.h</strong></p>
  
  <pre><code>#include "stdafx.h"
  using namespace std;
  
  struct Airplane {
      string destination;
      int number;
      string type;
  };
  </code></pre>
  
  <p>and it's my code </p>
  
  <pre><code>#include "stdafx.h"
  #include "Airplane.h"
  
  string SetDestination(int n);
  string SetType(int n);
  void PrintAirplaneList(Airplane * &amp;airplaneList, int n, string title);
  void SortByDestination (Airplane *&amp;airplaneList, int n);
  void FindAirplanesAndPrint(Airplane *&amp;airplaneList, int n, string type);
  
  int _tmain(int argc, _TCHAR* argv[])
  {
  using namespace std;
  
  srand((unsigned)time(NULL));
  
  int n;
  cout &lt;&lt; "Input n = ";
  cin &gt;&gt; n;
  
  Airplane * airplaneList = new Airplane[n];
  
  for (int i = 0; i &lt; n; ++i)
  {
      airplaneList[i].destination = SetDestination(rand()%5);
      airplaneList[i].number = rand()%9001 + 1000;
      airplaneList[i].type = SetType(rand()%3);
  }
  
  PrintAirplaneList(airplaneList, n, "List:");
  SortByDestination (airplaneList, n);
  PrintAirplaneList(airplaneList, n, "Sorted list (by destination):");
  
  string type;
  cout &lt;&lt; "Input type: ";
  getline(cin, type);
  FindAirplanesAndPrint(airplaneList, n, type);
  
  delete [] airplaneList;
  
  system("PAUSE");
  return 0;
  }
  
  string SetDestination (int n)
  {
      string destination;
      switch(n){
      case 0: destination = "Tokio"; break;
      case 1: destination = "Amsterdam"; break;
      case 2: destination = "Moscow"; break;
      case 3: destination = "Philadelphia"; break;
      case 4: destination = "San Diego"; break;
      default: destination = "Unknown city"; break;
      }
      return destination;
  }
  
  string SetType (int n)
  {
      string type;
      switch(n){
      case 0: type = "passenger"; break;
      case 1: type = "cargo"; break;
      case 2: type = "post"; break;
      default: type = "unknown type"; break;
      }
      return type;
  }
  
  void PrintAirplaneList(Airplane *&amp;airplaneList, int n, string title)
  {
      cout &lt;&lt; "\n";
      cout &lt;&lt; title &lt;&lt; "\n\n";
      for (int i = 0; i &lt; n; ++i)
      {
          cout &lt;&lt; "Destination: " &lt;&lt; airplaneList[i].destination &lt;&lt; "\n";
          cout &lt;&lt; "Number: " &lt;&lt; airplaneList[i].number &lt;&lt; "\n";
          cout &lt;&lt; "Type: " &lt;&lt; airplaneList[i].type &lt;&lt; "\n\n";
      }
  }
  
  void SortByDestination (Airplane *&amp;airplaneList, int n)
  {
      for (int i = 0; i &lt; n - 1; ++i)
      {
          for (int j = 0; j &lt; n -1; ++j)
          {
              if(airplaneList[j + 1].destination &gt; airplaneList[j].destination) continue;
              Airplane tempAirplane = airplaneList[j];
              airplaneList[j] = airplaneList[j + 1];
              airplaneList[j + 1] = tempAirplane;
          }
      }
  }
  
  void FindAirplanesAndPrint(Airplane *&amp;airplaneList, int n, string type) {
      cout &lt;&lt; "Type - " &lt;&lt; type &lt;&lt; "\n";
      int count = 0;
      for (int i = 0; i &lt; n; ++i)
      {
          if (airplaneList[i].type == type)
          {
              cout &lt;&lt; "Destination: " &lt;&lt; airplaneList[i].destination &lt;&lt; "\n";
              cout &lt;&lt; "Number: " &lt;&lt; airplaneList[i].number &lt;&lt; "\n";
              ++count;
          }
      }
      if (count == 0)
      {
          cout &lt;&lt; "Not found\n";
      }
  }
  </code></pre>
  
  <p>I have two questions.<br>
  1. I can't input type in   </p>
  
  <pre><code>string type;
  cout &lt;&lt; "Input type: ";
  getline(cin, type);
  FindAirplanesAndPrint(airplaneList, n, type);
  </code></pre>
  
  <p>and my function <code>FindAirplanesAndPrint</code> starts to work without any value for type.  How to make my programm to get value?<br>
  2. How to get size of dynamic array in functions? Because it seems the passing size of array <code>n</code> in every function is the wrong way.</p>