// This is version 2 of lab test #3 for lab section D2 with TA tests added. // You are to add two new methods to the List class, found on the G: drive. // Information on the methods to add can be found below. // Submit files List.h and List.cpp using the submit program provided. #include "stdstuff.h" #include "List.h" void realMain () { List list, list2, list3, list4, list5, list6, list7, list8, list9; for (int i = 0; i < 15; i++) { list.insert ((i * i) - (8 * i) + 2); } list3.insert(3); list4.insert(4); list5.insert(3); list5.insert(2); list5.insert(6); list5.insert(9); list6.insert(1); list6.insert(5); list7.insert(1); list7.insert(5); list7.insert(2); list8.insert(3); list8.insert(2); list8.insert(6); list8.insert(9); list8.insert(12); list9.insert(3); list9.insert(2); list9.insert(6); list9.insert(9); list9.insert(12); list9.insert(0); // Method "sumEvenValues" returns the sum of the nodes in the list containing even values. // Note that "containing" refers to the *contents* of the node, not its position in the list. // If the list has no even values, it returns 0. // You are to add this method to class "List". // Note that your method should work properly in all circumstances, not just for this // particular list. (Feel free to add additional test cases.) cout << "\nThe sum of even values in list is (should be 128): " << list.sumEvenValues() << "\n\n"; cout << "\nThe sum of even values in list2 is (should be 0): " << list2.sumEvenValues() << "\n\n"; cout << "\nThe sum of even values in list3 is (should be 0): " << list3.sumEvenValues() << "\n\n"; cout << "\nThe sum of even values in list4 is (should be 4): " << list4.sumEvenValues() << "\n\n"; cout << "\nThe sum of even values in list5 is (should be 8): " << list5.sumEvenValues() << "\n\n"; cout << "\nThe sum of even values in list6 is (should be 0): " << list6.sumEvenValues() << "\n\n"; cout << "\nThe sum of even values in list7 is (should be 2): " << list7.sumEvenValues() << "\n\n"; cout << "\nThe sum of even values in list8 is (should be 20): " << list8.sumEvenValues() << "\n\n"; cout << "\nThe sum of even values in list9 is (should be 20): " << list9.sumEvenValues() << "\n\n"; // Method "deleteEveryThirdNode" deletes the 3rd, 6th, 9th, etc. node of the list. // Note that the list starts with the first (not "zeroth") node. // If the list has fewer than three nodes, this method has no effect. // You are to add this method to class "List". // Note that your method should work properly in all circumstances, not just for this // particular list. (Feel free to add additional test cases.) list.deleteEveryThirdNode(); list2.deleteEveryThirdNode(); list3.deleteEveryThirdNode(); list4.deleteEveryThirdNode(); list5.deleteEveryThirdNode(); list6.deleteEveryThirdNode(); list7.deleteEveryThirdNode(); list8.deleteEveryThirdNode(); list9.deleteEveryThirdNode(); cout << "After deleting every third value in list\n (should be: 87 67 35 22 2 -5 -13 -14 -10 5):\n"; list.outputList (); cout << "\n"; cout << "After deleting every third value in list2\n (should be: empty):\n"; list2.outputList (); cout << "\n"; cout << "After deleting every third value in list3\n (should be: 3):\n"; list3.outputList (); cout << "\n"; cout << "After deleting every third value in list4\n (should be: 4):\n"; list4.outputList (); cout << "\n"; cout << "After deleting every third value in list5\n (should be: 9 6 3):\n"; list5.outputList (); cout << "\n"; cout << "After deleting every third value in list6\n (should be: 5 1):\n"; list6.outputList (); cout << "\n"; cout << "After deleting every third value in list7\n (should be: 2 5):\n"; list7.outputList (); cout << "\n"; cout << "After deleting every third value in list8\n (should be: 12 9 2 3):\n"; list8.outputList (); cout << "\n"; cout << "After deleting every third value in list9\n (should be: 0 12 6 2):\n"; list9.outputList (); cout << "\n"; } int main () { try { realMain (); } catch (exception &e) { cout << "Exception occurred " << e.what() << endl; } pause(); return 0; }