title: c++ inner class with methods not working
body: <p>I have a homework assignment due, but I don't understand what is wrong with my code. The name variable is messed up. I look through my textbook and I can't see anything wrong with my code. Please help. </p>
  
  <p>The name has to be stored in an array length of 80 and that was the only way I knew how to do that. </p>
  
  <p>I come from a lot of java experience, so I don't know if there is a syntax thing I am missing or what. </p>
  
  <p>Thanks for your time. </p>
  
  <pre><code>//import statements
  #include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  //class declaration section
  class Student
  {
      //declare private instance variables
      private:
          int ssn;
          char* name[80];
          const int ARRAYLENGTH =80;
  
      //deckale public methods and constructor
      public:
          Student();
          void setName(string);
          int getSSN();
          string getName();
          void setSSN(int);
  
  
  };
  
  //class implementation section
  Student::Student()
  {
      //set ssn equal to 99999999 by default
      ssn = 999999999;
      //set name equal to unassigned by default
      string someString ="unassigned";
      for(int i = 0; i &lt; ARRAYLENGTH; i++)
      {
          if (i &lt; someString.length())
              name[i] = &amp;someString[i];
          else
              name[i]= "";
      }
  }
  
  void Student::setName(string newName)
  {
      //assigns the newName to the char array
      for(int i = 0; i &lt; ARRAYLENGTH; i++)
      {
          if (i &lt; newName.length())
              name[i] = &amp;newName[i];
          else
              name[i]= "";
      }
  
      return;
  }
  
  int Student::getSSN()
  {
      return ssn;
  }
  
  string Student::getName()
  {
      //make a string from the char array to return a string
      string name1 = "";
      for(int i = 0; i &lt; 80; i++)
      {
          name1 += *(name+i);
      }
      return name1;
  }
  
  void Student::setSSN(int num)
  {
      //check to make sure ssn isnt below or equal to 0
      if (num &gt; 0)
          ssn = num;
  
      return;
  }
  
  
  //main function
  int main() {
  
      Student student1, student2;
  
      //changing name and ssn of student2
      student2.setName("John Doe");
      student2.setSSN(123456789);
  
      //printing out information
      cout&lt;&lt; "Name for student1 is "&lt;&lt; student1.getName() &lt;&lt;" and snn is "&lt;&lt; student1.getSSN() &lt;&lt;endl; //name should be unassigned and ssn should be 999999999
      cout&lt;&lt; "Name for student1 is "&lt;&lt; student2.getName() &lt;&lt;" and snn is "&lt;&lt; student2.getSSN() &lt;&lt;endl; //name should be John Doe and ssn should be 123456789
  
      return 0;
  
  }
  </code></pre>