title: C++ how can I get user input to search text file and populate the array; returning only the info reuqested?
body: <p>I am new to programming so please, so I know I am just making a mess. My assignment is as follows....</p>
  
  <p>Write a program that takes the name of instructors from a text file.  It then places the names into an array of objects.  Allow the user to search for an instructor (using the last name) using the Linear Search algorithm. If found, the program should return the name of the instructor. </p>
  
  <p>Name the file as: facultySearch.cpp  (EXACTLY like this. Copy and paste it if you need to) </p>
  
  <p>Follow this format:</p>
  
  <p>The class name is: Faculty
  It should have private members: firstName (string), lastName (string), and facultyID (short)
  It should have public members: setters, getters, and a constructor (to setup default information) </p>
  
  <p>The function ‘linearSearch’ does not have to be part of the class. </p>
  
  <p>Create an external text file with the instructor information.</p>
  
  <p>In main:
  Create an array of Faculty object: instructorArray[]
  The array should hold up to 50 objects.
  Output the data as: lastName, firstName, facultyID (Make it a nice format)</p>
  
  <p>Here is the code I have so far:</p>
  
  <pre><code>//classtxt60.cpp
  //Put all header and description stuff here.
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  class Faculty
  {
  private: //attributes go here (variables)
      string firstName;
      string lastName;
      //short facultyID;
  
  public: //methods go here (functions)
      Faculty(); //constructor
      void setfirstName(string first); //mutator
      void setlastName(string last);
      //void setfacultyID(short fID);
      string getfirstName(); //accessor
      string getlastName();
      //string getID();
  };
  
  //Define the public functions here
  Faculty::Faculty()
  {
      //The constructor will give defaults to
      //the private members of my class
      firstName = "No First Name";
      lastName = "No Last Name";
  }
  
  void Faculty::setfirstName(string first)
  {
      firstName = first;
  }
  void Faculty::setlastName(string last)
  {
      lastName = last;
  }
  
  
  string Faculty::getfirstName()
  {
      return firstName;
  }
  string Faculty::getlastName()
  {
      return lastName;
  }
  
  
  const short SIZE = 50; //maximum class size
  
  int main()
  {
      //Create an object of type Faculty
      //All 25 objects are set to the default "No Name"
      Faculty instructorArray[SIZE];
  
      ifstream inputfile("source.txt"); //creates object to read from textfile &amp; opens/links it to textfile
  
      //Read from your file now.
      //Use a while loop when you do not know how many items are in the text file.
      string first; //holds name in file
      string last;
      short classSize = 0; //used as counter
      while (!inputfile.eof())
      {
          //reads the name from the textfile
          getline(inputfile, first);
          getline(inputfile, last);
          //if adding age or gender you would need to add a separate line for each
  
          //places the name into the array
          instructorArray[classSize].setfirstName(first);
          instructorArray[classSize].setlastName(last);
          //if adding age or gender you would need to add a separate line for each
  
          classSize++; //moves to the next item
      }
  
      cout &lt;&lt; first &lt;&lt; " " &lt;&lt; last &lt;&lt; endl;
  
      inputfile.close();
  
  
      return 0;
  }
  </code></pre>