{"id":34,"date":"2024-08-01T18:35:48","date_gmt":"2024-08-01T18:35:48","guid":{"rendered":"https:\/\/bhiggs.x10hosting.com\/PracticalC%2B%2BProgramming\/?page_id=34"},"modified":"2025-01-20T20:48:11","modified_gmt":"2025-01-20T20:48:11","slug":"assignment-5","status":"publish","type":"page","link":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/assignments\/assignment-5\/","title":{"rendered":"Assignment 5"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Linked_Lists_With_Polymorphism\"><\/span>Linked Lists With Polymorphism<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_More_About_Linked_Lists\"><\/span><em>Why More About Linked Lists?<\/em><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">So you thought you&#8217;d seen all you ever wanted to know about linked lists after the last assignment? Read on&#8230;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">While the previous design worked (at least if you implemented it right&#8230;), it had its drawbacks. Let&#8217;s list some of them:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The list classes were very generic. In particular, there was no type checking to provide compile-time checking to prevent mistakes. For example, imagine you had a list item that represented a\u00a0<strong>Person<\/strong>\u00a0and put it into a list, and then you navigated the list assuming that the list items represented\u00a0<strong>Fruit<\/strong>\u00a0or a\u00a0<strong>Wine<\/strong>\u00a0&#8212; something other than a\u00a0<strong>Person<\/strong>. You have to\u00a0<em>typecast<\/em>\u00a0the data from the list item from a\u00a0<strong>void *<\/strong>\u00a0to some other kind of pointer (having to typecast all the time can become a real pain, and it&#8217;s very error-prone). Because there is no type-checking at compile time, your program will likely compile and link without problems. There is also no run-time type-checking, so you will likely get very strange results when you run your program. Even if you don&#8217;t see anything obvious (like an access violation, core dump, or GPF), there&#8217;s usually something evil going on under the surface. In fact, if you don&#8217;t see something wrong, that&#8217;s probably the time to start worrying, because you don&#8217;t even know where to start looking. What&#8217;s more it&#8217;s usually a real bear to debug and fix these kinds of problems, even if you do see the symptoms.<\/li>\n\n\n\n<li>There was no support for homogeneous lists &#8212; lists which can only contain items that represent a single type. What if you wanted to ensure that all the items in a list represented\u00a0<strong>Person<\/strong>s? Or that they all represented\u00a0<strong>Wine<\/strong>s? There is no type-checking of that, at all &#8212; again, neither at compile-time nor at run-time.<\/li>\n\n\n\n<li>Even the support for heterogeneous lists wasn&#8217;t that great. While you often need to have a list of things that are of identical type, it&#8217;s rare that you have a use for a list that can contain absolutely anything. More likely, you will have a list of related, or similar, items. For example, in a payroll application, you might have a list of\u00a0<strong>Manager<\/strong>s,\u00a0<strong>Secretary<\/strong>s,\u00a0<strong>Programmer<\/strong>s,\u00a0<strong>Janitor<\/strong>s &#8212; yes, even\u00a0<strong>VicePresident<\/strong>s and the\u00a0<strong>ChairmanOfTheBoard<\/strong>\u00a0(yes, even they get paid!). They are of different types, but they are all\u00a0<em>related<\/em>\u00a0to each other &#8212; they are all\u00a0<strong>Employee<\/strong>s. If you wish to ensure that only\u00a0<strong>Employee<\/strong>s (of whatever job description) may be contained in a list, the previous design doesn&#8217;t help you much.<\/li>\n\n\n\n<li>That pesky\u00a0<strong>ListItem<\/strong>\u00a0class being separate from the data it represents is a real pain in the, er&#8230; Well, it&#8217;s very clumsy and inconvenient. Couldn&#8217;t we integrate it into the class that we wish to place in the list?<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">These shortcomings mostly boil down to lack of safety and convenience. It&#8217;s hard enough work to come up a well-designed, solid and well-tested application.&nbsp; Why can&#8217;t the compiler help a little more, and then maybe you&#8217;d get home on time at least once a week? Well, it can, but you have to do some of the work &#8212; more design. An investment in the proper up-front design can pay great dividends in making it easier to implement that design, and that can translate into less work (time, money&#8230;) to implement and test that design.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s take a look at what we might do to improve things&#8230;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Design_Alternatives\"><\/span><em>Design Alternatives<\/em><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Here are a couple of ideas on how we might be able to improve matters:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Have a\u00a0<strong>ListItem<\/strong>\u00a0actually contain, rather than point to, the data it represents.<\/li>\n\n\n\n<li>Change every\u00a0<strong>void *<\/strong>\u00a0to a specific pointer type. This would allow you to have a homogeneous list, and would add the necessary type-checking.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Well, they&#8217;re fine and dandy as ideas go, but both of them move us away from the idea that you would like to write the code for a list&nbsp;<em>once<\/em>, and then use it for whatever you wish to place in that list.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, let&#8217;s say that you decided to have a&nbsp;<strong>ListItem<\/strong>&nbsp;<em>contain<\/em>&nbsp;a&nbsp;<strong>Person<\/strong>. Then you could place the&nbsp;<strong>ListItem<\/strong>&nbsp;in a&nbsp;<strong>List<\/strong>&nbsp;and (with the appropriate member functions) manipulate the&nbsp;<strong>List<\/strong>&nbsp;with the full knowledge that it can only contain&nbsp;<strong>Person<\/strong>s. With the proper code, you would also get type-checking, so you could detect at compile-time when you (or someone who uses your code) make a stupid mistake.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But what if you also wanted to make a&nbsp;<strong>List<\/strong>&nbsp;of&nbsp;<strong>Wine<\/strong>s? and a&nbsp;<strong>List<\/strong>&nbsp;of&nbsp;<strong>Fruit<\/strong>s? and a&nbsp;<strong>List<\/strong>&nbsp;of&nbsp;<strong>Employee<\/strong>s? Then you would have to create a&nbsp;<strong>PersonListItem<\/strong>, and a&nbsp;<strong>WineListItem<\/strong>, and a&nbsp;<strong>FruitListItem<\/strong>, and.&#8211; you get the picture&#8230; Not only that, to make it all consistent, you would have create a new&nbsp;<strong>List<\/strong>&nbsp;class and a new&nbsp;<strong>ListIterator<\/strong>&nbsp;class for each type of&nbsp;<strong>ListItem<\/strong>&nbsp;derivative you invent.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Sure, you could simply cut and paste the code to create new classes each time, with the appropriate changes in types, but what if someone found a bug in the original implementation? Could you reliably find all the places you&#8217;d cut and pasted the code to, and fix that bug everywhere it exists? Multiply that bug by a thousand or more, and the number of places to find each instance of each bug, and you might get a feeling for the problem you&#8217;re creating for yourself. (It&#8217;s called the most primitive form of code reuse &#8212; cut, paste and hope the original doesn&#8217;t break, and that you don&#8217;t introduce new bugs in the copied version as you make changes.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Well, this problem is really solved in C++ by&nbsp;<em>template classes<\/em>. Unfortunately, there are two problems with template classes:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>We haven&#8217;t got to that topic in the course. Be warned that it&#8217;s a complex and advanced topic. On the other hand, the ISO C++ standard includes STL (the Standard Template Library), a very important\u00a0<em>generic programming<\/em>\u00a0library, which uses templates all over the place. Much of the C++ standard class library has been redefined and re-implemented using STL and templates, and so it&#8217;s a road we will all have to take eventually.<\/li>\n\n\n\n<li>Templates have historically been one of the most troublesome areas of C++. The ISO C++ standards committee wrestled with them for a long time, and came up with merely a compromise solution to some of the problems. Different C++ compilers have implemented templates in different ways, and with different features. So compatibility and portability across platforms used to be a big issue when it comes to C++ templates. This problem has mostly gone away, now that the ISO C++ standards committee has finally published the C++ standard. <\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Phew! That said, what are we going to do in the absence of templates?<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Containment\"><\/span><em>Containment<\/em><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Well, first, take a look at a technique that I used in the previous assignment, in the list of&nbsp;<strong>Person<\/strong>s. I&#8217;ll reproduce it here, so you don&#8217;t have to flip pages or browse to it and back:<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-995f960e wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  Person.h\n\/\/  Assignment 4: Linked Lists\n\/\/\n\/\/  Created by Bryan Higgs on 10\/31\/24.\n\/\/\n\n#ifndef Person_h\n#define Person_h\n\n#include &lt;string&gt;\nusing namespace std;\n\n#include &quot;List.h&quot;\n\nclass Person\n{\npublic:\n  Person(const string &amp;name);\n  Person(const Person &amp;person);\n  ~Person();\n\n  const string &amp;Name() const\n  {\n      return m_name;\n  }\n\n  void Add(List &amp;list, Person *prevPerson);\n  void Remove();\n\n  void Print() const;\n\n  \/\/ Assignment operator\n  Person &amp;operator=(const Person &amp;person);\n\n  \/\/ Conversion function to ListItem &amp;\n  operator ListItem &amp;()\n  {\n      return m_item;\n  }\n\nprivate:\n  ListItem  m_item;\n  string    m_name;\n};\n\n#endif \/* Person_h *\/\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Person.h<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Assignment 4: Linked Lists<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 10\/31\/24.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#ifndef<\/span><span style=\"color: #0000FF\"> Person_h<\/span><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#define<\/span><span style=\"color: #0000FF\"> Person_h<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&lt;string&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">using<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">namespace<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&quot;List.h&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Person<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">Person<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">string<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">name<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">Person<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">person<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">~Person<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">string<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #795E26\">Name<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> m_name;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">Add<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #267F99\">List<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #001080\">prevPerson<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">Remove<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Assignment operator<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #AF00DB\">operator=<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">person<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Conversion function to ListItem &amp;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">operator<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #AF00DB\">ListItem<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #AF00DB\">&amp;<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> m_item;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">private:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  ListItem  m_item;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  string    m_name;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#endif<\/span><span style=\"color: #008000\"> \/* Person_h *\/<\/span><\/span><\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Note that here, instead of having the&nbsp;<strong>ListItem<\/strong>&nbsp;class contain an instance of class&nbsp;<strong>Person<\/strong>, class&nbsp;<strong>Person<\/strong>&nbsp;contains an instance of class&nbsp;<strong>ListItem<\/strong>. Kind of inside out thinking, don&#8217;t you think?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This was a reasonable solution, except for one thorny problem: How, given an instance of class&nbsp;<strong>Person<\/strong>, do I treat that class like a&nbsp;<strong>ListItem<\/strong>, so it can be placed in the&nbsp;<strong>List<\/strong>? My solution was to introduce into the&nbsp;<strong>Person<\/strong>&nbsp;class a&nbsp;<em><strong>conversion function<\/strong><\/em>:<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"padding-top:0px;padding-bottom:0px\"><code><strong>operator ListItem &amp;() { return m_item; }<\/strong><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">which allows an instance of class\u00a0<strong>Person<\/strong>\u00a0to be &#8216;converted&#8217; to an instance of class\u00a0<strong>ListItem<\/strong>. In this case, all this means is that the conversion function returns a reference to\u00a0<strong>m_item<\/strong>, the\u00a0<strong>ListItem<\/strong> instance contained within the\u00a0<strong>Person<\/strong>\u00a0class. With this, I can write code like:<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"padding-top:0px;padding-bottom:0px\"><code><strong>list.Append(person&#91;i]);<\/strong><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">and have the conversion function do its silent work, making it look like I&#8217;m adding a&nbsp;<strong>Person<\/strong>&nbsp;to the list. In addition, I added some additional member functions to class&nbsp;<strong>Person<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"padding-top:0px;padding-bottom:0px\"><code><strong>void Add(List &amp;list, Person *prevPerson);\nvoid Remove();<\/strong><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">which allow us to add and remove instances of class&nbsp;<strong>Person<\/strong>&nbsp;from a&nbsp;<strong>List<\/strong>, while providing type-safety (meaning that I know that I&#8217;m adding instances of&nbsp;<strong>Person<\/strong>&nbsp;to the list). Note that these new member functions are implemented using the existing&nbsp;<strong>ListItem<\/strong>&nbsp;member functions. They merely hide the details from users of the&nbsp;<strong>Person<\/strong>&nbsp;class, and also provide the stronger typing..<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, this code does not prevent a malicious or underachieving programmer from using the bare&nbsp;<strong>ListItem<\/strong>&nbsp;class. And we still have the problem of&nbsp;<strong>List<\/strong>&nbsp;and&nbsp;<strong>ListIterator<\/strong>&nbsp;knowing nothing about the&nbsp;<strong>Person<\/strong>&nbsp;class.<\/p>\n<\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">We could, of course, apply the same techniques to the&nbsp;<strong>List<\/strong>&nbsp;and&nbsp;<strong>ListIterator<\/strong>&nbsp;classes to produce&nbsp;<strong>PersonList<\/strong>&nbsp;and&nbsp;<strong>PersonIterator<\/strong>&nbsp;classes.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But we won&#8217;t, because there&#8217;s a better way &#8212; using&nbsp;<em>inheritance<\/em>&nbsp;and&nbsp;<em>polymorphism<\/em>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_Assignment_Step_1\"><\/span><em>The Assignment (Step 1)<\/em><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Preparing_for_Polymorphism\"><\/span><em>Preparing for Polymorphism<\/em><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><em><strong>Here&#8217;s where you get to do some of the work:<\/strong><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, make a copy of your original linked list classes, and create a new project to put the copies in. You can always go back to the old project if you want to have a taste of something that still works &#8212; we&#8217;re going to be making some changes that will initially stop things from working, and you may get frustrated for a while &#8212; bear with me!<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Making_the_List_Classes_pseudo-Abstract\"><\/span><em>Making the List Classes (pseudo-)Abstract<\/em><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Now, let&#8217;s make some changes to the list classes to make them (sort of) abstract. Remember, an abstract class is one that cannot be instantiated by itself. For example, you might choose to make a&nbsp;<strong>Fish<\/strong>&nbsp;class abstract, since it&#8217;s very generic. If asked to make an instance of class&nbsp;<strong>Fish<\/strong>, the first question you&#8217;d be likely to ask is &#8220;What kind of fish would you like?&#8221;.&nbsp;<strong>Haddock<\/strong>, or&nbsp;<strong>Flounder<\/strong>&nbsp;would be good, but&nbsp;<strong>Fish<\/strong>&nbsp;is kind of non-specific. Making a class abstract highlights the fact that you can&#8217;t really make an instance of that class, because you need more information.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Conventionally, we make a C++ class abstract by introducing into that class a&nbsp;<em>pure virtual function<\/em>. However, for the moment, at least, I&#8217;m not going to do that. Instead, I&#8217;ll take a different approach so that I can introduce some different ideas and techniques.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><em><strong>Note:<\/strong><\/em>\u00a0We&#8217;re going to be moving things around inside the classes to make access to them more restricted. If you look at my original class definitions, you&#8217;ll see that I placed the sections in each class so that\u00a0<strong>public<\/strong>\u00a0member functions come\u00a0<em><strong>first<\/strong><\/em>, while\u00a0<strong>private<\/strong>\u00a0member functions and data members\u00a0<em><strong>(remember, data members should always be\u00a0private<\/strong><\/em><strong>)\u00a0<\/strong>come\u00a0<em><strong>last<\/strong><\/em>, at the end. Why? To the clients of a class, the most important members are its\u00a0<strong>public<\/strong>\u00a0ones. Ideally, the clients of a class should have no interest in, and certainly not depend on, the\u00a0<strong>private<\/strong>\u00a0parts of a class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We will be adding a&nbsp;<strong>protected<\/strong>&nbsp;section within the class. I place the&nbsp;<strong>protected<\/strong>&nbsp;section&nbsp;<em><strong>between<\/strong><\/em>&nbsp;the&nbsp;<strong>public<\/strong>&nbsp;and&nbsp;<strong>private<\/strong>&nbsp;sections. I&nbsp;<em><strong>strongly<\/strong><\/em>&nbsp;suggest you follow this convention.<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Here&#8217;s what to do:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>In the\u00a0<strong>List<\/strong>\u00a0class:<ol type=\"i\" start=\"1\"><li><em>Move<\/em>\u00a0the constructor,\u00a0<strong>List()<\/strong>, and the member functions,\u00a0<strong>void Append(ListItem &amp;item)<\/strong>,\u00a0\u00a0<strong>ListItem *GetFirst() const<\/strong>, and\u00a0<strong>ListItem *GetLast() const<\/strong>, into a\u00a0\u00a0<strong>protected<\/strong>\u00a0section of the class.<\/li><li><em>Make<\/em>\u00a0the destructor\u00a0<strong>virtual<\/strong>.<\/li><\/ol>This should leave only the destructor and the member functions\u00a0<strong>GetCount()<\/strong>,\u00a0<strong>Purge()<\/strong>, and\u00a0<strong>Dump()<\/strong>\u00a0public\u00a0within the\u00a0<strong>List<\/strong>\u00a0class.<\/li>\n\n\n\n<li>In the\u00a0<strong>ListItem<\/strong>\u00a0class:<ol type=\"i\" start=\"1\"><li><em>Move<\/em>\u00a0the constructor,\u00a0<strong>ListItem(void *data)<\/strong>, and the member functions\u00a0<strong>ListItem *GetNext() const<\/strong>,\u00a0\u00a0<strong>ListItem *GetPrevious() const<\/strong>, and\u00a0<strong>void Add(List &amp;list, ListItem *prevItem)<\/strong>\u00a0into a\u00a0<strong>protected<\/strong>\u00a0section of the class.<\/li><li><em>Remove<\/em>\u00a0the member function\u00a0<strong>void *GetData()<\/strong>, and the data member\u00a0<strong>m_data<\/strong>.<\/li><li>C<em>hange<\/em>\u00a0the constructor to\u00a0<strong>ListItem()<\/strong>\u00a0&#8212; that is, remove the\u00a0<strong>void *data<\/strong>\u00a0argument.<\/li><li><em>Make<\/em>\u00a0the destructor\u00a0<strong>virtual<\/strong>.<\/li><\/ol>This should leave only the destructor and the member functions\u00a0<strong>Remove(), GetList()<\/strong>, and\u00a0<strong>Dump()<\/strong>\u00a0public\u00a0within the\u00a0<strong>ListItem<\/strong>\u00a0class.<\/li>\n\n\n\n<li>In the\u00a0<strong>ListIterator<\/strong>\u00a0class:<ol type=\"i\" start=\"1\"><li><em>Move<\/em>\u00a0the constructor,\u00a0<strong>ListIterator(List &amp;list)<\/strong>, and the member functions\u00a0<strong>ListItem *GetCurrent()<\/strong>,\u00a0<strong>ListItem *GetNext(), ListItem *GetPrevious()<\/strong>\u00a0into a\u00a0<strong>protected<\/strong>\u00a0section of the class.<\/li><li><em>Make<\/em>\u00a0the destructor\u00a0<strong>virtual<\/strong>.<\/li><\/ol>This should leave only the destructor and the member functions\u00a0<strong>bool AtFirst() const<\/strong>, and\u00a0<strong>bool AtLast() const<\/strong>\u00a0public\u00a0within the\u00a0<strong>ListIterator<\/strong>\u00a0class.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Now try compiling the result.<em><strong>&nbsp;[Hmmmm&#8230;. A few compile-time errors, huh? Not to worry, it&#8217;s expected.]<\/strong><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In order to get the&nbsp;<strong>list.cpp<\/strong>&nbsp;file to compile, you will have to add one or two&nbsp;friendship relationships among the three list classes. You should not have to change any code in&nbsp;<strong>list.cpp<\/strong>&nbsp;to make it compile &#8212; only the changes I specified above in&nbsp;<strong>list.h<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, you should expect the other .cpp files\u00a0<em>not<\/em>\u00a0to compile at this point.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, the line in file&nbsp;<strong>test.cpp<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"padding-top:0px;padding-bottom:0px\"><code><strong>List list;<\/strong><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">will produce errors. Why?\u00a0<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_Assignment_Step_2\"><\/span><em>The Assignment (Step 2)<\/em><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_our_Newly_pseudo-Abstract_Classes\"><\/span><em><strong>Using our Newly (pseudo-)Abstract Classes<\/strong><\/em><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">So how are we going to use our new&nbsp;<strong>List<\/strong>,&nbsp;<strong>ListItem<\/strong>, and&nbsp;<strong>ListIterator<\/strong>&nbsp;classes?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Well, we&#8217;re not, directly. We&#8217;ll use them&nbsp;<em>indirectly<\/em>, by writing modified&nbsp;<strong>Wine<\/strong>&nbsp;and&nbsp;<strong>Person<\/strong>&nbsp;classes. In fact, for each one, we&#8217;ll write a set of classes, derived from&nbsp;<strong>ListItem<\/strong>,&nbsp;<strong>List<\/strong>, and&nbsp;<strong>ListIterator<\/strong>. In this way, we can create Person-specific and Wine-specific versions of our List classes, while using inheritance to ensure that we share the code that implements the lists. At the same time, we now have classes that are&nbsp;<em>strongly-typed<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I think you&#8217;ll start to see how this approach can simplify the code you have to write to use these classes. For a start, you no longer have to typecast the data into the proper type; that&#8217;s done for you by the Person-specific and Wine-specific classes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To give you a head start, here is the modified header file for\u00a0<strong>Person<\/strong>,\u00a0<strong>person.h<\/strong>. Class\u00a0<strong>Person<\/strong>\u00a0no longer contains a\u00a0<strong>ListItem<\/strong>\u00a0member, but instead inherits (publicly!) from\u00a0<strong>ListItem<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-995f960e wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  Person.h\n\/\/  Assignment 5: Linked Lists with Polymorphism\n\/\/\n\/\/  Created by Bryan Higgs on 11\/1\/24.\n\/\/\n\n#ifndef Person_h\n#define Person_h\n\n#include &lt;string&gt;\nusing namespace std;\n\n#include &quot;List.h&quot;\n\nclass PersonList; \/\/ Forward declaration\n\nclass Person : public ListItem\n{\npublic:\n  Person(const string &amp;name);\n  Person(const Person &amp;person);\n  virtual ~Person();\n\n  const string &amp;Name() const\n  {\n    return m_name;\n  }\n\n  void Add(PersonList &amp;list, Person *prevPerson);\n\n  void Print() const;\n\n  \/\/ Assignment operator\n  Person &amp;operator=(const Person &amp;person);\n  \n  Person &amp;GetNext() const;\n  Person &amp;GetPrevious() const;\n\nprivate:\n  string m_name;\n};\n\n\/\/ PersonList\nclass PersonList : public List\n{\npublic:\n  PersonList() {}\n  virtual ~PersonList() {}\n\n  void Append(Person &amp;person);\n\n  Person *GetFirst() const;\n  Person *GetLast() const;\n};\n\n\/\/ PersonIterator\nclass PersonIterator : public ListIterator\n{\npublic:\n  PersonIterator(PersonList &amp;list);\n  virtual ~PersonIterator();\n\n  Person *GetCurrent() const;\n  Person *GetNext();\n  Person *GetPrevious();\n};\n\n#endif \/* Person_h *\/\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Person.h<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Assignment 5: Linked Lists with Polymorphism<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 11\/1\/24.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#ifndef<\/span><span style=\"color: #0000FF\"> Person_h<\/span><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#define<\/span><span style=\"color: #0000FF\"> Person_h<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&lt;string&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">using<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">namespace<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&quot;List.h&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">PersonList<\/span><span style=\"color: #000000\">;<\/span><span style=\"color: #008000\"> \/\/ Forward declaration<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> : <\/span><span style=\"color: #0000FF\">public<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">ListItem<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">Person<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">string<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">name<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">Person<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">person<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">virtual<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">~Person<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">string<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #795E26\">Name<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> m_name;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">Add<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #267F99\">PersonList<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #001080\">prevPerson<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Assignment operator<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #AF00DB\">operator=<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">person<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #795E26\">GetNext<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #795E26\">GetPrevious<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">private:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  string m_name;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ PersonList<\/span><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">PersonList<\/span><span style=\"color: #000000\"> : <\/span><span style=\"color: #0000FF\">public<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">List<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">PersonList<\/span><span style=\"color: #000000\">() {}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">virtual<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">~PersonList<\/span><span style=\"color: #000000\">() {}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">Append<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">person<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #795E26\">GetFirst<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #795E26\">GetLast<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ PersonIterator<\/span><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">PersonIterator<\/span><span style=\"color: #000000\"> : <\/span><span style=\"color: #0000FF\">public<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">ListIterator<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">PersonIterator<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #267F99\">PersonList<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">virtual<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">~PersonIterator<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #795E26\">GetCurrent<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #795E26\">GetNext<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Person<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #795E26\">GetPrevious<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#endif<\/span><span style=\"color: #008000\"> \/* Person_h *\/<\/span><\/span><\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Note that I have removed all traces of <strong><code>List<\/code><\/strong>, <strong><code>ListItem<\/code><\/strong>, or <strong><code>ListIterator<\/code><\/strong> from the public interfaces of these classes. The intent it to implement all the functionality of the <strong><code>Person<\/code><\/strong> classes using the functionality provided by those underlying list classes, without exposing that fact to the outside world.<\/p>\n<\/div>\n<\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Heres_What_to_Do\"><\/span><em><strong>Here&#8217;s What to Do:<\/strong><\/em><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Person\"><\/span>Person<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Implement&nbsp;class&nbsp;<strong>Person<\/strong>, in&nbsp;<strong>person.cpp<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a test program to run your&nbsp;<strong>Person<\/strong>&nbsp;class through its paces:<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-995f960e wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:60%\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(3 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  TestPerson.cpp\n\/\/  Assignment 5: Linked Lists with Polymorphism\n\/\/\n\/\/  Created by Bryan Higgs on 11\/1\/24.\n\/\/\n\n#include &lt;iostream&gt;\nusing namespace std;\n\n#include &quot;Person.h&quot;\n\nstatic void display(PersonList &amp;list)\n{\n  cout &lt;&lt; &quot;Contents of list:&quot; &lt;&lt; endl;\n  PersonIterator iter(list);\n  for (Person *person = iter.GetCurrent();\n       person != 0;\n       person = iter.GetNext()\n      )\n  {\n    person-&gt;Print();\n  }\n\n  cout &lt;&lt; &quot;-----Dump------&quot; &lt;&lt; endl;\n  list.Dump();\n  cout &lt;&lt; &quot;---End Dump----&quot; &lt;&lt; endl;\n}\n\nstatic void ListPersons()\n{\n  Person fred(&quot;Fred&quot;);\n  Person mary(&quot;Mary&quot;);\n  Person joe(&quot;Joe&quot;);\n  Person clive(&quot;Clive&quot;);\n  Person nigel(&quot;Nigel&quot;);\n  Person nostradamus(&quot;Nostradamus&quot;);\n  Person einstein(&quot;Einstein&quot;);\n\n  Person *items[] = { &amp;fred, &amp;mary, &amp;joe, &amp;clive,\n                      &amp;nigel, &amp;nostradamus, &amp;einstein };\n\n  Person *person;\n\n  PersonList list;      \/\/ The list of people\n\n  \/\/ The following List iterator is positioned so that\n  \/\/ the list it associates with is empty at the time\n  \/\/ of the association.\n  PersonIterator iter(list);\n  \n  \/\/ Start testing\n\n  cout &lt;&lt; &quot;Empty list...&quot; &lt;&lt; endl;\n  display(list);\n\n  cout &lt;&lt; &quot;Testing Append&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Appending: &quot;;\n  fred.Print();\n  list.Append(fred);\n  display(list);\n\n  cout &lt;&lt; &quot;Testing a second Append&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Appending: &quot;;\n  nigel.Print();\n  list.Append(nigel);\n  display(list);\n\n  cout &lt;&lt; &quot;Testing Add to front&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Adding: &quot;;\n  mary.Print();\n  mary.Add(list, 0);\n  display(list);\n\n  cout &lt;&lt; &quot;Testing Add to end&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Adding: &quot;;\n  joe.Print();\n  joe.Add(list, list.GetLast());\n  display(list);\n\n  cout &lt;&lt; &quot;Testing Add to middle&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Adding: &quot;;\n  clive.Print();\n  clive.Add(list, &amp;mary);\n  display(list);\n\n  cout &lt;&lt; &quot;------------Iterator testing------------&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot;Testing iterator originally set on empty list...&quot; &lt;&lt; endl;\n  for (person = iter.GetCurrent();\n       person != 0;\n       person = iter.GetNext())\n  {\n    person-&gt;Print();\n  }\n\n  cout &lt;&lt; &quot;Now reversing direction on iterator...&quot; &lt;&lt; endl;\n  for (person = iter.GetCurrent();\n       person != 0;\n       person = iter.GetPrevious()\n      )\n  {\n    person-&gt;Print();\n  }\n\n  cout &lt;&lt; &quot;Reversing direction again...&quot; &lt;&lt; endl;\n  for (person = iter.GetCurrent();\n       person != 0;\n       person = iter.GetNext()\n      )\n  {\n    person-&gt;Print();\n  }\n  cout &lt;&lt; &quot;--------End Iterator testing------------&quot; &lt;&lt; endl;\n\n  cout &lt;&lt; &quot;Testing removal from middle&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Removing: &quot;;\n  clive.Print();\n  clive.Remove();\n  display(list);\n\n  cout &lt;&lt; &quot;Testing removal from end&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Removing: &quot;;\n  joe.Print();\n  joe.Remove();\n  display(list);\n\n    cout &lt;&lt; &quot;Testing removal from front&quot; &lt;&lt; endl;\n    cout &lt;&lt; &quot; Removing: &quot;;\n    mary.Print();\n    mary.Remove();\n    display(list);\n\n  cout &lt;&lt; &quot;Testing removal from end&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Removing: &quot;;\n  nigel.Print();\n  nigel.Remove();\n  display(list);\n\n  cout &lt;&lt; &quot;Testing removal of last item&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Removing: &quot;;\n  fred.Print();\n  fred.Remove();\n  display(list);\n\n  \/\/ Finally, we test the actions of the List destructor\n\n  \/\/ First, go through the items to check that they are not in\n  \/\/ a list...\n  cout &lt;&lt; &quot;Checking that removed items do not appear to be in a list&quot; &lt;&lt; endl;\n  int len = sizeof(items)\/sizeof(items[0]);\n  int elem;\n  int errors = 0;\n  for (elem = 0; elem &lt; len; elem++)\n  {\n    if (items[elem]-&gt;GetList() != 0)\n    {\n      errors++;\n      cerr &lt;&lt; &quot;Element &quot; &lt;&lt; elem &lt;&lt; &quot; still in a list&quot; &lt;&lt; endl;\n    }\n    if (items[elem]-&gt;GetNext() != 0)\n    {\n      errors++;\n      cerr &lt;&lt; &quot;Element &quot; &lt;&lt; elem &lt;&lt; &quot; still has a next ptr&quot; &lt;&lt; endl;\n    }\n    if (items[elem]-&gt;GetPrevious() != 0)\n    {\n      errors++;\n      cerr &lt;&lt; &quot;Element &quot; &lt;&lt; elem &lt;&lt; &quot; still has a previous ptr&quot; &lt;&lt; endl;\n    }\n  }\n    \n  \/\/ Now, create the list and populate it from the items\n  cout &lt;&lt; &quot;Checking addition and removal to a dynamic list&quot; &lt;&lt; endl;\n  PersonList *dynList = new PersonList();\n  for (elem = len-1; elem &gt;= 0; elem--)\n  {\n    dynList-&gt;Append(*(items[elem]));\n  }\n  \n  \/\/ Display the list for validation\n  display(*dynList);\n\n  \/\/ Now destroy the list and examine the state of each\n  \/\/ of the items that were in the list\n  cout &lt;&lt; &quot;Destroying dynamic list&quot; &lt;&lt; endl;\n  delete dynList;\n  cout &lt;&lt; &quot;Checking that removed items do not appear to be in a list&quot; &lt;&lt; endl;\n  for (elem = 0; elem &lt; len; elem++)\n  {\n    if (items[elem]-&gt;GetList() != 0)\n    {\n      errors++;\n      cerr &lt;&lt; &quot;Element &quot; &lt;&lt; elem &lt;&lt; &quot; still in a list&quot; &lt;&lt; endl;\n    }\n    if (items[elem]-&gt;GetNext() != 0)\n    {\n      errors++;\n      cerr &lt;&lt; &quot;Element &quot; &lt;&lt; elem &lt;&lt; &quot; still has a next ptr&quot; &lt;&lt; endl;\n    }\n    if (items[elem]-&gt;GetPrevious() != 0)\n    {\n      errors++;\n      cerr &lt;&lt; &quot;Element &quot; &lt;&lt; elem &lt;&lt; &quot; still has a previous ptr&quot; &lt;&lt; endl;\n    }\n  }\n  cout &lt;&lt; errors &lt;&lt; &quot; errors detected&quot; &lt;&lt; endl;\n}\n\nint main(int argc, const char * argv[])\n{\n  ListPersons();\n\n  return 0;\n}\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  TestPerson.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Assignment 5: Linked Lists with Polymorphism<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 11\/1\/24.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&lt;iostream&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">using<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">namespace<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&quot;Person.h&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">static<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #267F99\">PersonList<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Contents of list:&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  PersonIterator <\/span><span style=\"color: #795E26\">iter<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (Person *person = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetCurrent<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       person != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       person = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetNext<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">person<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;-----Dump------&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Dump<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;---End Dump----&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">static<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">ListPersons<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Person <\/span><span style=\"color: #795E26\">fred<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Fred&quot;<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Person <\/span><span style=\"color: #795E26\">mary<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Mary&quot;<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Person <\/span><span style=\"color: #795E26\">joe<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Joe&quot;<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Person <\/span><span style=\"color: #795E26\">clive<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Clive&quot;<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Person <\/span><span style=\"color: #795E26\">nigel<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Nigel&quot;<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Person <\/span><span style=\"color: #795E26\">nostradamus<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Nostradamus&quot;<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Person <\/span><span style=\"color: #795E26\">einstein<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Einstein&quot;<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Person *items[] = { &amp;fred, &amp;mary, &amp;joe, &amp;clive,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                      &amp;nigel, &amp;nostradamus, &amp;einstein };<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Person *person;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  PersonList list;<\/span><span style=\"color: #008000\">      \/\/ The list of people<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ The following List iterator is positioned so that<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ the list it associates with is empty at the time<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ of the association.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  PersonIterator <\/span><span style=\"color: #795E26\">iter<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Start testing<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Empty list...&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing Append&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Appending: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">fred<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Append<\/span><span style=\"color: #000000\">(fred);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing a second Append&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Appending: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">nigel<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Append<\/span><span style=\"color: #000000\">(nigel);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing Add to front&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Adding: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">mary<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">mary<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Add<\/span><span style=\"color: #000000\">(list, <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing Add to end&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Adding: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">joe<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">joe<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Add<\/span><span style=\"color: #000000\">(list, <\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetLast<\/span><span style=\"color: #000000\">());<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing Add to middle&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Adding: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">clive<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">clive<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Add<\/span><span style=\"color: #000000\">(list, &amp;mary);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;------------Iterator testing------------&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing iterator originally set on empty list...&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (person = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetCurrent<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       person != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       person = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetNext<\/span><span style=\"color: #000000\">())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">person<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Now reversing direction on iterator...&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (person = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetCurrent<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       person != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       person = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetPrevious<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">person<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Reversing direction again...&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (person = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetCurrent<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       person != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       person = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetNext<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">person<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;--------End Iterator testing------------&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing removal from middle&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Removing: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">clive<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">clive<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Remove<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing removal from end&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Removing: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">joe<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">joe<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Remove<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing removal from front&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Removing: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">mary<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">mary<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Remove<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing removal from end&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Removing: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">nigel<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">nigel<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Remove<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing removal of last item&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Removing: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">fred<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">fred<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Remove<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Finally, we test the actions of the List destructor<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ First, go through the items to check that they are not in<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ a list...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Checking that removed items do not appear to be in a list&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> len = <\/span><span style=\"color: #0000FF\">sizeof<\/span><span style=\"color: #000000\">(items)\/<\/span><span style=\"color: #0000FF\">sizeof<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">]);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> elem;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> errors = <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (elem = <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">; elem &lt; len; elem++)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #AF00DB\">if<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[elem]-&gt;<\/span><span style=\"color: #795E26\">GetList<\/span><span style=\"color: #000000\">() != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      errors++;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      cerr &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Element &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; elem &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; still in a list&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #AF00DB\">if<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[elem]-&gt;<\/span><span style=\"color: #795E26\">GetNext<\/span><span style=\"color: #000000\">() != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      errors++;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      cerr &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Element &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; elem &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; still has a next ptr&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #AF00DB\">if<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[elem]-&gt;<\/span><span style=\"color: #795E26\">GetPrevious<\/span><span style=\"color: #000000\">() != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      errors++;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      cerr &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Element &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; elem &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; still has a previous ptr&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Now, create the list and populate it from the items<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Checking addition and removal to a dynamic list&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  PersonList *dynList = <\/span><span style=\"color: #AF00DB\">new<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">PersonList<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (elem = len-<\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">; elem &gt;= <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">; elem--)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">dynList<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Append<\/span><span style=\"color: #000000\">(*(<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[elem]));<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Display the list for validation<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(*dynList);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Now destroy the list and examine the state of each<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ of the items that were in the list<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Destroying dynamic list&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">delete<\/span><span style=\"color: #000000\"> dynList;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Checking that removed items do not appear to be in a list&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (elem = <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">; elem &lt; len; elem++)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #AF00DB\">if<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[elem]-&gt;<\/span><span style=\"color: #795E26\">GetList<\/span><span style=\"color: #000000\">() != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      errors++;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      cerr &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Element &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; elem &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; still in a list&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #AF00DB\">if<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[elem]-&gt;<\/span><span style=\"color: #795E26\">GetNext<\/span><span style=\"color: #000000\">() != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      errors++;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      cerr &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Element &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; elem &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; still has a next ptr&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #AF00DB\">if<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[elem]-&gt;<\/span><span style=\"color: #795E26\">GetPrevious<\/span><span style=\"color: #000000\">() != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      errors++;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      cerr &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Element &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; elem &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; still has a previous ptr&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; errors &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; errors detected&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">main<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argc<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">char<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argv<\/span><span style=\"color: #000000\">[])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">ListPersons<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span><\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:40%\">\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong><em>Note:<\/em>\u00a0<\/strong>Of course, the program should work correctly. So test it, and show me the results.<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong><em>Warning:<\/em>\u00a0<\/strong>Do\u00a0<em>not<\/em>\u00a0simply copy the code from\u00a0<strong><code>List<\/code><\/strong>,\u00a0<strong><code>ListItem<\/code><\/strong>, and\u00a0<code><strong>ListIterator<\/strong><\/code>\u00a0into the\u00a0<strong><code>Person<\/code><\/strong>\u00a0and\u00a0<strong><code>Wine<\/code><\/strong>\u00a0classes! This would be to miss the whole point of the exercise! You would not be benefiting from the code reuse you get from a single implementation of the code!<\/p>\n<\/blockquote>\n<\/div>\n<\/div>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Wine\"><\/span>Wine<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Implement a corresponding set of classes for class&nbsp;<strong>Wine<\/strong>, in&nbsp;<strong>wine.h<\/strong>&nbsp;and&nbsp;<strong>wine.cpp<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a test program to run your&nbsp;<strong>Wine<\/strong>&nbsp;class through its paces:<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-995f960e wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:60%\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(3 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  TestWines.cpp\n\/\/  Assignment 5: Linked Lists with Polymorphism\n\/\/\n\/\/  Created by Bryan Higgs on 11\/1\/24.\n\/\/\n\n#include &lt;cstdlib&gt;\n#include &lt;iostream&gt;\nusing namespace std;\n\n#include &quot;Wine.h&quot;\n\nstatic void display(WineList &amp;list)\n{\n  cout &lt;&lt; &quot;Contents of list:&quot; &lt;&lt; endl;\n  WineIterator iter(list);\n  for (Wine *wine = iter.GetCurrent();\n       wine != 0;\n       wine = iter.GetNext()\n      )\n  {\n      wine-&gt;Print();\n  }\n\n  cout &lt;&lt; &quot;-----Dump------&quot; &lt;&lt; endl;\n  list.Dump();\n  cout &lt;&lt; &quot;---End Dump----&quot; &lt;&lt; endl;\n}\n\nstatic void ListWines()\n{\n  Wine beaujolais(&quot;Beaujolais&quot;, 1970);\n  Wine amontillado(&quot;Amontillado&quot;, 1964);\n  Wine riesling(&quot;Riesling&quot;, 1980);\n  Wine gewurztraminer(&quot;Gewurztraminer&quot;, 1993);\n  Wine shiraz(&quot;Shiraz&quot;, 2003);\n  Wine cabernet(&quot;Cabernet Sauvignon&quot;, 2001);\n\n  \/\/ Each item in the following list is an instance\n  \/\/ of ListItem, each pointing to its corresponding\n  \/\/ Wine instance.\n  Wine *items[] = { &amp;beaujolais, &amp;amontillado,\n                    &amp;riesling,   &amp;gewurztraminer,\n                    &amp;shiraz,     &amp;cabernet };\n\n  Wine *wine;     \/\/ Wine pointer used in many places\n\n  WineList list;  \/\/ The list of wines\n\n  \/\/ The following List iterator is positioned so that\n  \/\/ the list it associates with is empty at the time\n  \/\/ of the association.\n  WineIterator iter(list);\n\n  \/\/ Start testing\n\n  cout &lt;&lt; &quot;Empty list...&quot; &lt;&lt; endl;\n  display(list);\n\n  cout &lt;&lt; &quot;Testing Append&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Appending: &quot;;\n  wine = items[0];\n  wine-&gt;Print();\n  list.Append(*items[0]);\n  display(list);\n\n  cout &lt;&lt; &quot;Testing a second Append&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Appending: &quot;;\n  wine = items[4];\n  wine-&gt;Print();\n  list.Append(*items[4]);\n  display(list);\n\n  cout &lt;&lt; &quot;Testing Add to front&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Adding: &quot;;\n  wine = items[1];\n  wine-&gt;Print();\n  items[1]-&gt;Add(list, NULL);\n  display(list);\n\n  cout &lt;&lt; &quot;Testing Add to end&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Adding: &quot;;\n  wine = items[2];\n  wine-&gt;Print();\n  items[2]-&gt;Add(list, list.GetLast());\n  display(list);\n\n  cout &lt;&lt; &quot;Testing Add to middle&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Adding: &quot;;\n  wine = items[3];\n  wine-&gt;Print();\n  items[3]-&gt;Add(list, items[1]);\n  display(list);\n\n  cout &lt;&lt; &quot;------------Iterator testing------------&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot;Testing iterator originally set on empty list...&quot; &lt;&lt; endl;\n  for (wine = iter.GetCurrent();\n       wine != 0;\n       wine = iter.GetNext()\n      )\n  {\n    wine-&gt;Print();\n  }\n\n  cout &lt;&lt; &quot;Now reversing direction on iterator...&quot; &lt;&lt; endl;\n  for (wine = iter.GetCurrent();\n       wine != 0;\n       wine = iter.GetPrevious()\n      )\n  {\n    wine-&gt;Print();\n  }\n\n  cout &lt;&lt; &quot;Reversing direction again...&quot; &lt;&lt; endl;\n  for (wine = iter.GetCurrent();\n       wine != 0;\n       wine = iter.GetNext()\n      )\n  {\n    wine-&gt;Print();\n  }\n  cout &lt;&lt; &quot;--------End Iterator testing------------&quot; &lt;&lt; endl;\n\n  cout &lt;&lt; &quot;Testing removal from middle&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Removing: &quot;;\n  wine = items[3];\n  wine-&gt;Print();\n  items[3]-&gt;Remove();\n  display(list);\n\n  cout &lt;&lt; &quot;Testing removal from end&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Removing: &quot;;\n  wine = items[2];\n  wine-&gt;Print();\n  items[2]-&gt;Remove();\n  display(list);\n\n  cout &lt;&lt; &quot;Testing removal from front&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Removing: &quot;;\n  wine = items[1];\n  wine-&gt;Print();\n  items[1]-&gt;Remove();\n  display(list);\n\n  cout &lt;&lt; &quot;Testing removal from end&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Removing: &quot;;\n  wine = items[4];\n  wine-&gt;Print();\n  items[4]-&gt;Remove();\n  display(list);\n\n  cout &lt;&lt; &quot;Testing removal of last item&quot; &lt;&lt; endl;\n  cout &lt;&lt; &quot; Removing: &quot;;\n  wine = items[0];\n  wine-&gt;Print();\n  items[0]-&gt;Remove();\n  display(list);\n\n  \/\/ Finally, we test the actions of the List destructor\n\n  \/\/ First, go through the items to check that they are not in\n  \/\/ a list...\n  cout &lt;&lt; &quot;Checking that removed items do not appear to be in a list&quot; &lt;&lt; endl;\n  int len = sizeof(items)\/sizeof(items[0]);\n  int elem;\n  int errors = 0;\n  for (elem = 0; elem &lt; len; elem++)\n  {\n    if (items[elem]-&gt;GetList() != 0)\n    {\n      errors++;\n      cerr &lt;&lt; &quot;Element &quot; &lt;&lt; elem &lt;&lt; &quot; still in a list&quot; &lt;&lt; endl;\n    }\n    if (items[elem]-&gt;GetNext() != 0)\n    {\n      errors++;\n      cerr &lt;&lt; &quot;Element &quot; &lt;&lt; elem &lt;&lt; &quot; still has a next ptr&quot; &lt;&lt; endl;\n    }\n    if (items[elem]-&gt;GetPrevious() != 0)\n    {\n      errors++;\n      cerr &lt;&lt; &quot;Element &quot; &lt;&lt; elem &lt;&lt; &quot; still has a previous ptr&quot; &lt;&lt; endl;\n    }\n  }\n    \n  \/\/ Now, create the list and populate it from the items\n  cout &lt;&lt; &quot;Checking addition and removal to a dynamic list&quot; &lt;&lt; endl;\n  WineList *dynList = new WineList();\n  for (elem = len-1; elem &gt;= 0; elem--)\n  {\n    dynList-&gt;Append(*items[elem]);\n  }\n  \n  \/\/ Display the list for validation\n  display(*dynList);\n\n  \/\/ Now destroy the list and examine the state of each\n  \/\/ of the items that were in the list\n  cout &lt;&lt; &quot;Destroying dynamic list&quot; &lt;&lt; endl;\n  delete dynList;\n  cout &lt;&lt; &quot;Checking that removed items do not appear to be in a list&quot; &lt;&lt; endl;\n  for (elem = 0; elem &lt; len; elem++)\n  {\n    if (items[elem]-&gt;GetList() != 0)\n    {\n      errors++;\n      cerr &lt;&lt; &quot;Element &quot; &lt;&lt; elem &lt;&lt; &quot; still in a list&quot; &lt;&lt; endl;\n    }\n    if (items[elem]-&gt;GetNext() != 0)\n    {\n      errors++;\n      cerr &lt;&lt; &quot;Element &quot; &lt;&lt; elem &lt;&lt; &quot; still has a next ptr&quot; &lt;&lt; endl;\n    }\n    if (items[elem]-&gt;GetPrevious() != 0)\n    {\n      errors++;\n      cerr &lt;&lt; &quot;Element &quot; &lt;&lt; elem &lt;&lt; &quot; still has a previous ptr&quot; &lt;&lt; endl;\n    }\n  }\n  cout &lt;&lt; errors &lt;&lt; &quot; errors detected&quot; &lt;&lt; endl;\n}\n\nint main(int argc, const char * argv[])\n{\n  ListWines();\n\n  return 0;\n}\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  TestWines.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Assignment 5: Linked Lists with Polymorphism<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 11\/1\/24.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&lt;cstdlib&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&lt;iostream&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">using<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">namespace<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&quot;Wine.h&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">static<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #267F99\">WineList<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Contents of list:&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  WineIterator <\/span><span style=\"color: #795E26\">iter<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (Wine *wine = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetCurrent<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       wine != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       wine = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetNext<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      <\/span><span style=\"color: #001080\">wine<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;-----Dump------&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Dump<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;---End Dump----&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">static<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">ListWines<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Wine <\/span><span style=\"color: #795E26\">beaujolais<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Beaujolais&quot;<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">1970<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Wine <\/span><span style=\"color: #795E26\">amontillado<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Amontillado&quot;<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">1964<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Wine <\/span><span style=\"color: #795E26\">riesling<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Riesling&quot;<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">1980<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Wine <\/span><span style=\"color: #795E26\">gewurztraminer<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Gewurztraminer&quot;<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">1993<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Wine <\/span><span style=\"color: #795E26\">shiraz<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Shiraz&quot;<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">2003<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Wine <\/span><span style=\"color: #795E26\">cabernet<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Cabernet Sauvignon&quot;<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">2001<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Each item in the following list is an instance<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ of ListItem, each pointing to its corresponding<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Wine instance.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Wine *items[] = { &amp;beaujolais, &amp;amontillado,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                    &amp;riesling,   &amp;gewurztraminer,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                    &amp;shiraz,     &amp;cabernet };<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Wine *wine;<\/span><span style=\"color: #008000\">     \/\/ Wine pointer used in many places<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  WineList list;<\/span><span style=\"color: #008000\">  \/\/ The list of wines<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ The following List iterator is positioned so that<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ the list it associates with is empty at the time<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ of the association.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  WineIterator <\/span><span style=\"color: #795E26\">iter<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Start testing<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Empty list...&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing Append&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Appending: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  wine = <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">];<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">wine<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Append<\/span><span style=\"color: #000000\">(*<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">]);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing a second Append&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Appending: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  wine = <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">];<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">wine<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Append<\/span><span style=\"color: #000000\">(*<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">]);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing Add to front&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Adding: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  wine = <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">];<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">wine<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">]-&gt;<\/span><span style=\"color: #795E26\">Add<\/span><span style=\"color: #000000\">(list, <\/span><span style=\"color: #0000FF\">NULL<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing Add to end&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Adding: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  wine = <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">2<\/span><span style=\"color: #000000\">];<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">wine<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">2<\/span><span style=\"color: #000000\">]-&gt;<\/span><span style=\"color: #795E26\">Add<\/span><span style=\"color: #000000\">(list, <\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetLast<\/span><span style=\"color: #000000\">());<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing Add to middle&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Adding: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  wine = <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">];<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">wine<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">]-&gt;<\/span><span style=\"color: #795E26\">Add<\/span><span style=\"color: #000000\">(list, <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">]);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;------------Iterator testing------------&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing iterator originally set on empty list...&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (wine = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetCurrent<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       wine != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       wine = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetNext<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">wine<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Now reversing direction on iterator...&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (wine = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetCurrent<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       wine != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       wine = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetPrevious<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">wine<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Reversing direction again...&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (wine = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetCurrent<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       wine != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       wine = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetNext<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">wine<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;--------End Iterator testing------------&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing removal from middle&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Removing: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  wine = <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">];<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">wine<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">]-&gt;<\/span><span style=\"color: #795E26\">Remove<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing removal from end&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Removing: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  wine = <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">2<\/span><span style=\"color: #000000\">];<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">wine<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">2<\/span><span style=\"color: #000000\">]-&gt;<\/span><span style=\"color: #795E26\">Remove<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing removal from front&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Removing: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  wine = <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">];<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">wine<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">]-&gt;<\/span><span style=\"color: #795E26\">Remove<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing removal from end&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Removing: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  wine = <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">];<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">wine<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">]-&gt;<\/span><span style=\"color: #795E26\">Remove<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Testing removal of last item&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; Removing: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  wine = <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">];<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">wine<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">]-&gt;<\/span><span style=\"color: #795E26\">Remove<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Finally, we test the actions of the List destructor<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ First, go through the items to check that they are not in<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ a list...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Checking that removed items do not appear to be in a list&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> len = <\/span><span style=\"color: #0000FF\">sizeof<\/span><span style=\"color: #000000\">(items)\/<\/span><span style=\"color: #0000FF\">sizeof<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">]);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> elem;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> errors = <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (elem = <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">; elem &lt; len; elem++)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #AF00DB\">if<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[elem]-&gt;<\/span><span style=\"color: #795E26\">GetList<\/span><span style=\"color: #000000\">() != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      errors++;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      cerr &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Element &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; elem &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; still in a list&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #AF00DB\">if<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[elem]-&gt;<\/span><span style=\"color: #795E26\">GetNext<\/span><span style=\"color: #000000\">() != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      errors++;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      cerr &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Element &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; elem &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; still has a next ptr&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #AF00DB\">if<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[elem]-&gt;<\/span><span style=\"color: #795E26\">GetPrevious<\/span><span style=\"color: #000000\">() != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      errors++;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      cerr &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Element &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; elem &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; still has a previous ptr&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Now, create the list and populate it from the items<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Checking addition and removal to a dynamic list&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  WineList *dynList = <\/span><span style=\"color: #AF00DB\">new<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">WineList<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (elem = len-<\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">; elem &gt;= <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">; elem--)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">dynList<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Append<\/span><span style=\"color: #000000\">(*<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[elem]);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Display the list for validation<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(*dynList);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Now destroy the list and examine the state of each<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ of the items that were in the list<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Destroying dynamic list&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">delete<\/span><span style=\"color: #000000\"> dynList;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Checking that removed items do not appear to be in a list&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (elem = <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">; elem &lt; len; elem++)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #AF00DB\">if<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[elem]-&gt;<\/span><span style=\"color: #795E26\">GetList<\/span><span style=\"color: #000000\">() != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      errors++;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      cerr &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Element &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; elem &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; still in a list&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #AF00DB\">if<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[elem]-&gt;<\/span><span style=\"color: #795E26\">GetNext<\/span><span style=\"color: #000000\">() != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      errors++;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      cerr &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Element &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; elem &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; still has a next ptr&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #AF00DB\">if<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #001080\">items<\/span><span style=\"color: #000000\">[elem]-&gt;<\/span><span style=\"color: #795E26\">GetPrevious<\/span><span style=\"color: #000000\">() != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      errors++;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      cerr &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Element &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; elem &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; still has a previous ptr&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; errors &lt;&lt; <\/span><span style=\"color: #A31515\">&quot; errors detected&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">main<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argc<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">char<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argv<\/span><span style=\"color: #000000\">[])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">ListWines<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span><\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:40%\"><\/div>\n<\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_Assignment_Step_3\"><\/span><em>The Assignment (Step 3)<\/em><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Supporting_Heterogeneous_Lists_of_Related_Items\"><\/span><em>Supporting Heterogeneous Lists of Related Items<\/em><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The above changes improved matters somewhat:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Homogeneous lists are now easier to implement (if a little repetitious)<\/li>\n\n\n\n<li>We now have strong typing, and no need for typecasting in our main code. (If you have any such typecasting in the code your wrote outside of the\u00a0<strong>Person<\/strong>\u00a0and\u00a0<strong>Wine<\/strong>\u00a0classes, then you need to check it;\u00a0 it&#8217;s probably incorrect and\/or unnecessary.)<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">However, we don&#8217;t yet have support for the kind of heterogeneous list that contains items which are not all identical types, but which are related to each other (as in the Employees example, earlier). So let&#8217;s see what we can do to make this possible:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, let&#8217;s come up with a set of related classes:&nbsp;<strong>Employee<\/strong>,&nbsp;<strong>Manager<\/strong>, and&nbsp;<strong>Secretary<\/strong>. Note that&nbsp;<strong>Employee<\/strong>&nbsp;is derived from&nbsp;<strong>Person<\/strong>, and has related classes&nbsp;<strong>EmployeeList<\/strong>&nbsp;and&nbsp;<strong>EmployeeIterator<\/strong>, while&nbsp;<strong>Manager<\/strong>&nbsp;and&nbsp;<strong>Secretary<\/strong>&nbsp;are simply derived from&nbsp;<strong>Employee<\/strong>, and do not have their own list or iterator. With this infrastructure, we can support a heterogeneous list of items which are related to each other: they are all&nbsp;<strong>Employees<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-995f960e wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(3 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  Employee.h\n\/\/  Assignment 5: Linked Lists with Polymorphism\n\/\/\n\/\/  Created by Bryan Higgs on 11\/1\/24.\n\/\/\n\n#ifndef Employee_h\n#define Employee_h\n\n#include &lt;string&gt;\nusing namespace std;\n\n#include &quot;Person.h&quot;\n\nclass EmployeeList;\n\n\/\/ Employee\nclass Employee : public Person\n{\npublic:\n  Employee(const string &amp;name, double salary);\n  Employee(const Employee &amp;emp);\n  virtual ~Employee();\n\n  void Add(EmployeeList &amp;list, Employee *prevEmployee);\n\n  void Print() const;\n  const string &amp;GetPosition() const\n  {\n    return m_position;\n  }\n\nprotected:\n  void SetPosition(const string &amp;position)\n  {\n    m_position = position;\n  }\n\nprivate:\n  double m_salary;\n\n  string m_position; \/\/ Name of position in organization\n};\n\n\/\/ EmployeeList\nclass EmployeeList : public PersonList\n{\npublic:\n  EmployeeList();\n  virtual ~EmployeeList();\n\n  void Append(Employee &amp;emp);\n\n  Employee *GetFirst() const;\n  Employee *GetLast() const;\n};\n\n\/\/ EmployeeIterator\nclass EmployeeIterator : public PersonIterator\n{\npublic:\n  EmployeeIterator(EmployeeList &amp;list);\n  virtual ~EmployeeIterator();\n\n  Employee *GetCurrent() const;\n  Employee *GetNext();\n  Employee *GetPrevious();\n};\n\n\/\/ Other types of Employees\n\nclass Secretary;\n\n\/\/ Manager\nclass Manager : public Employee\n{\n  friend class Secretary;\n\npublic:\n  Manager(const string &amp;name, double salary);\n  virtual ~Manager();\n\n  Secretary *GetSecretary() const;\n  void SetSecretary(Secretary *sec);\n\n  void Print() const;\n\nprivate:\n  \/\/ Don't allow copying or assignment of Managers\n  Manager(const Manager &amp;);\n  Manager &amp;operator=(const Manager &amp;);\n\n  \/\/ Data\n  Secretary *m_secretary;\n};\n\n\/\/ Secretary\nclass Secretary : public Employee\n{\n  friend class Manager;\n\npublic:\n  Secretary(const string &amp;name, double salary);\n  virtual ~Secretary();\n\n  Manager *GetManager() const;\n  void SetManager(Manager *sec);\n\n  void Print() const;\n\nprivate:\n  \/\/ Don't allow copying or assignment of Secretaries\n  Secretary(const Secretary &amp;);\n  Secretary &amp;operator=(const Secretary &amp;);\n\n  \/\/ Data\n  Manager *m_manager;\n};\n\n#endif \/* Employee_h *\/\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Employee.h<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Assignment 5: Linked Lists with Polymorphism<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 11\/1\/24.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#ifndef<\/span><span style=\"color: #0000FF\"> Employee_h<\/span><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#define<\/span><span style=\"color: #0000FF\"> Employee_h<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&lt;string&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">using<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">namespace<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&quot;Person.h&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">EmployeeList<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ Employee<\/span><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Employee<\/span><span style=\"color: #000000\"> : <\/span><span style=\"color: #0000FF\">public<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Person<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">Employee<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">string<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">name<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #0000FF\">double<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">salary<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">Employee<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Employee<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">emp<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">virtual<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">~Employee<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">Add<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #267F99\">EmployeeList<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #267F99\">Employee<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #001080\">prevEmployee<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">string<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #795E26\">GetPosition<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> m_position;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">protected:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">SetPosition<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">string<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">position<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    m_position = position;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">private:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">double<\/span><span style=\"color: #000000\"> m_salary;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  string m_position;<\/span><span style=\"color: #008000\"> \/\/ Name of position in organization<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ EmployeeList<\/span><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">EmployeeList<\/span><span style=\"color: #000000\"> : <\/span><span style=\"color: #0000FF\">public<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">PersonList<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">EmployeeList<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">virtual<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">~EmployeeList<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">Append<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #267F99\">Employee<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">emp<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Employee<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #795E26\">GetFirst<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Employee<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #795E26\">GetLast<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ EmployeeIterator<\/span><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">EmployeeIterator<\/span><span style=\"color: #000000\"> : <\/span><span style=\"color: #0000FF\">public<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">PersonIterator<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">EmployeeIterator<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #267F99\">EmployeeList<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">virtual<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">~EmployeeIterator<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Employee<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #795E26\">GetCurrent<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Employee<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #795E26\">GetNext<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Employee<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #795E26\">GetPrevious<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ Other types of Employees<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Secretary<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ Manager<\/span><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Manager<\/span><span style=\"color: #000000\"> : <\/span><span style=\"color: #0000FF\">public<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Employee<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">friend<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Secretary<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">Manager<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">string<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">name<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #0000FF\">double<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">salary<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">virtual<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">~Manager<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Secretary<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #795E26\">GetSecretary<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">SetSecretary<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #267F99\">Secretary<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #001080\">sec<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">private:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Don&#39;t allow copying or assignment of Managers<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">Manager<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Manager<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Manager<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #AF00DB\">operator=<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Manager<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Data<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Secretary *m_secretary;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ Secretary<\/span><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Secretary<\/span><span style=\"color: #000000\"> : <\/span><span style=\"color: #0000FF\">public<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Employee<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">friend<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Manager<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">Secretary<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">string<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">name<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #0000FF\">double<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">salary<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">virtual<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">~Secretary<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Manager<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #795E26\">GetManager<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">SetManager<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #267F99\">Manager<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #001080\">sec<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">private:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Don&#39;t allow copying or assignment of Secretaries<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">Secretary<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Secretary<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">Secretary<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #AF00DB\">operator=<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Secretary<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Data<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Manager *m_manager;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#endif<\/span><span style=\"color: #008000\"> \/* Employee_h *\/<\/span><\/span><\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Heres_What_to_Do-2\"><\/span><em>Here&#8217;s What to Do:<\/em><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Now implement these classes (in\u00a0<strong>employee.h<\/strong>\u00a0and\u00a0<strong>employee.cpp<\/strong>). Creating <strong><code>Employee<\/code><\/strong>, <code><strong>EmployeeList<\/strong><\/code>, and <code><strong>EmployeeIterator<\/strong><\/code> is just like what you did before to construct <strong><code>Person<\/code><\/strong>, <strong><code>PersonList<\/code><\/strong> and <strong><code>PersonIterator<\/code><\/strong>, except that you derive <strong><code>Employee<\/code><\/strong>, et.al. from <strong><code>Person<\/code><\/strong>, et.al, rather than <strong><code>List<\/code><\/strong>, et.al.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Be sure to make each class&#8217;&nbsp;<strong>Print()<\/strong>&nbsp;function do something different. Here is a starting point for&nbsp;<strong>employee.cpp<\/strong>, to show you what my <strong>Employee::Print()<\/strong> looks like, among other things:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  Employee.cpp\n\/\/  Assignment 5: Linked Lists with Polymorphism\n\/\/\n\/\/  Created by Bryan Higgs on 11\/1\/24.\n\/\/\n\n#include &lt;iostream&gt;\n#include &lt;iomanip&gt;\nusing namespace std;\n\n#include &quot;employee.h&quot;\n\n\/\/ Class Employee\n\nEmployee::Employee(const string &amp;name, double salary)\n  : Person(name), m_salary(salary)\n{\n  SetPosition(&quot;Employee&quot;);\n}\n\nvoid Employee::Print() const\n{\n  cout &lt;&lt; GetPosition().c_str() &lt;&lt; &quot;: &quot; &lt;&lt; Name().c_str()\n       &lt;&lt; &quot;, salary: &quot; &lt;&lt; fixed &lt;&lt; setprecision(2) &lt;&lt; m_salary\n       &lt;&lt; endl;\n}\n\n\/\/ You implement the rest...\n\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Employee.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Assignment 5: Linked Lists with Polymorphism<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 11\/1\/24.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&lt;iostream&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&lt;iomanip&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">using<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">namespace<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&quot;employee.h&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ Class Employee<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #267F99\">Employee<\/span><span style=\"color: #000000\">::<\/span><span style=\"color: #795E26\">Employee<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> string &amp;name, <\/span><span style=\"color: #0000FF\">double<\/span><span style=\"color: #000000\"> salary)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  : <\/span><span style=\"color: #795E26\">Person<\/span><span style=\"color: #000000\">(name), <\/span><span style=\"color: #795E26\">m_salary<\/span><span style=\"color: #000000\">(salary)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">SetPosition<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Employee&quot;<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Employee<\/span><span style=\"color: #000000\">::<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">() <\/span><span style=\"color: #0000FF\">const<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #795E26\">GetPosition<\/span><span style=\"color: #000000\">().<\/span><span style=\"color: #795E26\">c_str<\/span><span style=\"color: #000000\">() &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;: &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #795E26\">Name<\/span><span style=\"color: #000000\">().<\/span><span style=\"color: #795E26\">c_str<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;, salary: &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; fixed &lt;&lt; <\/span><span style=\"color: #795E26\">setprecision<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">2<\/span><span style=\"color: #000000\">) &lt;&lt; m_salary<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ You implement the rest...<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Manager::Print()<\/strong>&nbsp;should print out the&nbsp;<strong>Employee<\/strong>&nbsp;information (using&nbsp;<strong>Employee.Print()<\/strong>), and then print out the secretary name, if any.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Secretary::Print()<\/strong>&nbsp;should print out the&nbsp;<strong>Employee<\/strong>&nbsp;information, and then print out the manager&#8217;s name, if any.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><em><strong>Question<\/strong><\/em>: When you iterate through such a list, do you see the wrong Print() function being called for some items? What do you need to do to make sure that the proper <strong><code>Print()<\/code><\/strong> function is called for each item?<\/p>\n<\/blockquote>\n<\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s a main program to test out your new functionality:<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-995f960e wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:60%\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  TestEmployees.cpp\n\/\/  Assignment 5: Linked Lists with Polymorphism\n\/\/\n\/\/  Created by Bryan Higgs on 11\/1\/24.\n\/\/\n\n#include &lt;iostream&gt;\nusing namespace std;\n\n#include &quot;Employee.h&quot;\n\nstatic void display(EmployeeList &amp;list)\n{\n  cout &lt;&lt; &quot;Contents of list:&quot; &lt;&lt; endl;\n  EmployeeIterator iter(list);\n  for (Employee *employee = iter.GetCurrent();\n       employee != 0;\n       employee = iter.GetNext()\n      )\n  {\n    employee-&gt;Print();\n  }\n\n  cout &lt;&lt; &quot;-----Dump------&quot; &lt;&lt; endl;\n  list.Dump();\n  cout &lt;&lt; &quot;---End Dump----&quot; &lt;&lt; endl;\n}\n\nstatic void ListEmployees()\n{\n  EmployeeList list;\n\n  Employee  FredBloggs(&quot;Fred Bloggs&quot;, 25000);\n  Manager   GenghisKhan(&quot;Genghis Khan&quot;, 105000);\n  Secretary MargaretThatcher(&quot;Margaret Thatcher&quot;, 30000);\n  Manager   BillGates(&quot;Bill Gates&quot;, 42000000);\n  Employee  NewtGingrich(&quot;Newt Gingrich&quot;, 89000);\n  Secretary Madonna(&quot;Madonna&quot;, 5000000);\n\n  Employee *employee[] =\n  {\n    &amp;FredBloggs, &amp;GenghisKhan, &amp;MargaretThatcher,\n    &amp;BillGates, &amp;NewtGingrich, &amp;Madonna\n  };\n\n  GenghisKhan.SetSecretary(&amp;MargaretThatcher);\n  BillGates.SetSecretary(&amp;Madonna);\n\n  for (int i = 0; i &lt; sizeof(employee)\/sizeof(employee[0]); i++)\n  {\n    list.Append(*(employee[i]));\n  }\n\n  EmployeeIterator iter(list);\n\n  for (Employee *e = iter.GetCurrent(); e != 0; e = iter.GetNext())\n  {\n    e-&gt;Print();\n  }\n\n  \/\/ Display the contents of the list\n  display(list);\n}\n\nint main(int argc, const char * argv[])\n{\n  ListEmployees();\n\n  return 0;\n}\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  TestEmployees.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Assignment 5: Linked Lists with Polymorphism<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 11\/1\/24.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&lt;iostream&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">using<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">namespace<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&quot;Employee.h&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">static<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #267F99\">EmployeeList<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">&amp;<\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Contents of list:&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  EmployeeIterator <\/span><span style=\"color: #795E26\">iter<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (Employee *employee = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetCurrent<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       employee != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">       employee = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetNext<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">      )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">employee<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;-----Dump------&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Dump<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;---End Dump----&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">static<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">ListEmployees<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  EmployeeList list;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Employee  <\/span><span style=\"color: #795E26\">FredBloggs<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Fred Bloggs&quot;<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">25000<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Manager   <\/span><span style=\"color: #795E26\">GenghisKhan<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Genghis Khan&quot;<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">105000<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Secretary <\/span><span style=\"color: #795E26\">MargaretThatcher<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Margaret Thatcher&quot;<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">30000<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Manager   <\/span><span style=\"color: #795E26\">BillGates<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Bill Gates&quot;<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">42000000<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Employee  <\/span><span style=\"color: #795E26\">NewtGingrich<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Newt Gingrich&quot;<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">89000<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Secretary <\/span><span style=\"color: #795E26\">Madonna<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #A31515\">&quot;Madonna&quot;<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">5000000<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  Employee *employee[] =<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    &amp;FredBloggs, &amp;GenghisKhan, &amp;MargaretThatcher,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    &amp;BillGates, &amp;NewtGingrich, &amp;Madonna<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  };<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">GenghisKhan<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">SetSecretary<\/span><span style=\"color: #000000\">(&amp;MargaretThatcher);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #001080\">BillGates<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">SetSecretary<\/span><span style=\"color: #000000\">(&amp;Madonna);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> i = <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">; i &lt; <\/span><span style=\"color: #0000FF\">sizeof<\/span><span style=\"color: #000000\">(employee)\/<\/span><span style=\"color: #0000FF\">sizeof<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #001080\">employee<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">]); i++)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">list<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Append<\/span><span style=\"color: #000000\">(*(<\/span><span style=\"color: #001080\">employee<\/span><span style=\"color: #000000\">[i]));<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  EmployeeIterator <\/span><span style=\"color: #795E26\">iter<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">for<\/span><span style=\"color: #000000\"> (Employee *e = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetCurrent<\/span><span style=\"color: #000000\">(); e != <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">; e = <\/span><span style=\"color: #001080\">iter<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">GetNext<\/span><span style=\"color: #000000\">())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #001080\">e<\/span><span style=\"color: #000000\">-&gt;<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Display the contents of the list<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">display<\/span><span style=\"color: #000000\">(list);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">main<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argc<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">char<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argv<\/span><span style=\"color: #000000\">[])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">ListEmployees<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span><\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:40%\">\n<p class=\"wp-block-paragraph\">Note that this function constructs a list of items that are all <code><strong>Employee<\/strong><\/code>s, or of types derived from <strong><code>Employee<\/code><\/strong>s.<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Linked Lists With Polymorphism Why More About Linked Lists? So you thought you&#8217;d seen all you ever wanted to know about linked lists after the last assignment? Read on&#8230; While the previous design worked (at least if you implemented it right&#8230;), it had its drawbacks. Let&#8217;s list some of them: These shortcomings mostly boil down [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":29,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-34","page","type-page","status-publish","hentry"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/34","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/comments?post=34"}],"version-history":[{"count":2,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/34\/revisions"}],"predecessor-version":[{"id":1609,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/34\/revisions\/1609"}],"up":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/29"}],"wp:attachment":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/media?parent=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}