title: Data representation for multiple vectors
body: <p>I have two items directory and movies. I need to represent a single directory with particular set of movies (only 4 per dir). Lets say we have 2 directories and 8 movies. 1 directory will contain 4 movies and another will contain 4. Programatically its like 0th directory contains: 0 to 3 movie ID's and 1st directory contains: 4 to 7 movie ID's. I've written the following code, but could not able to achieve what I need as shown in the expected output vs. original output with the help of vectors.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  const int noofmovies = 4;
  
  class Myclass{
  private:
      int directory;
      vector&lt;int&gt; directories;
      vector&lt;int&gt; movies;
  public:
      void read();
      void display() const;
  };
  void Myclass::read(){
      cout &lt;&lt; "Enter number of directories: " &lt;&lt; endl;
      cin &gt;&gt; directory;
      for(int i=0;i&lt;directory;i++){
          directories.push_back(i);
      }
      for(int j=0;j&lt;(directory*noofmovies);j++){
          movies.push_back(j);
      }
  }
  void Myclass::display() const{
      for(int i=0;i&lt;directories.size();i++){
          cout &lt;&lt; "directory[" &lt;&lt; i &lt;&lt; "]" &lt;&lt; " contains " &lt;&lt; endl;
      }
      for(int j=0;j&lt;movies.size();j++){
          cout &lt;&lt; "movies[" &lt;&lt; j &lt;&lt;"]" &lt;&lt;endl;
      }
  }
  int main(){
      Myclass my;
      my.read();
      my.display();
  }
  </code></pre>
  
  <p>original output:</p>
  
  <pre><code>Enter number of directories:
  2
  directory[0] contains
  directory[1] contains
  movies[0]
  movies[1]
  movies[2]
  movies[3]
  movies[4]
  movies[5]
  movies[6]
  movies[7]
  </code></pre>
  
  <p>expected output:</p>
  
  <pre><code>Enter number of directories:
  2
  directory[0] contains
  movies[0]
  movies[1]
  movies[2]
  movies[3]
  directory[1] contains
  movies[4]
  movies[5]
  movies[6]
  movies[7]
  </code></pre>
  
  <p>Well I tried modifying the loops as below but the result is not what I wanted:</p>
  
  <pre><code>    void Myclass::read(){
      cout &lt;&lt; "Enter number of directories: " &lt;&lt; endl;
      cin &gt;&gt; directory;
  
      for(int i=0;i&lt;directory;i++){
          directories.push_back(i);
          for(int j=0;j&lt;noofmovies;j++){
              movies.push_back(j);
          }
      }
  }
  void Myclass::display() const{
  
      for(int i=0;i&lt;directories.size();i++){
          cout &lt;&lt; "directory[" &lt;&lt; i &lt;&lt; "]" &lt;&lt; " contains " &lt;&lt; endl;
          for(int j=0;j&lt;movies.size();j++){
              cout &lt;&lt; "movies[" &lt;&lt; j &lt;&lt;"]" &lt;&lt;endl;
          }
      }
  
  }
  </code></pre>