Lab3: Creating a Simple Class ############################# Let's use our Star Wars name generator code and build a simple class to manage the information needed to generate these names. Part 1: Create a basic Class **************************** Create a class called **Person** that will store the information needed to generate a Star Wars name for a person. Refer to :ref:`example-program` for the code to generate that name. Here is the header file you should use for this class: .. literalinclude:: code/Person.h :linenos: You will need to create two additional files for this project: * ``Person.cpp`` * ``main.cpp`` Build your program so the main function (in ``main.cpp``) creates one object of type ``Person``. Using that object load the required data using the methods defined in the class, then generate your Star Wars name to show that your class works properly. You can hand code your data for a sample person for this part. Once that is working, move on to step 2 Part 2: Load your data from a file ********************************** Modify your program so it reads the four input strings needed for a person from standard input (using ``cin``). Test your new program to make sure it still works as before, only now reading the four names from user input. Next, create a test file named ``name.data`` containing this data: .. code-block:: text Fred Flintstone Neanderthal Bedrock That is all on one line. Then, assuming your program executable is named ``lab3.exe``, open up a command prompt and navigate to the project directory. Make sure your program file and data file are both in that directory, then do this: .. code-block:: text $ lab3 < names.dat This is called **command redirection**, and it makes the operating system feed the contents of a file to your program, which still thinks a human is tying things in. The difference is that this human types really fast! YOu should see your Star Wars name for this person. Part 3: Read more names *********************** Now modify your program so it creates an array of Person objects. This is as simple as this: .. code-block:: c Person people[5]; Now, create a loop around the part of your code that reads in the data and loads it in the object for a person. This time, we will load one of the objects in the ``people`` array. Assuming your re using a ``for-loop`` with ``i`` as the counter variable, your code would look something like this: .. code-block:: c cin >> first; cin >> last; people[i].set_name(first, last) Next, add another method to the ``Person`` class called ``get_name`` that returns a string that looks like this: "first last". With this method in place generate a final display of names and associated start wars names that looks like this: .. code-block:: text Fred Flintstone: Flifr Nebed ... You should modify your ``name.dat`` file so it contains exactly five sets of data for your run. Use the same command used in Part 2 to see your output.