// This is lab test #5 version 1 TA Test Suite // You are to add three new recursive methods to the List class, found on the G: drive. // Information on the methods to add can be found below. // Your methods must work under all circumstances (feel free to add more test cases). // The third method must be recursive. // Submit files List.h and List.cpp. // // Note that this lab is worth a total of 15 (5 marks for each method), // but we will pretend that it's out of 10, i.e. you can get a maximum of 150%! #include "stdstuff.h" #include "List.h" int main () { List list, list2, list3, list4, empty, list5, list6, list7; int i; for (i = 0; i < 15; i++) { list.insert ((i * i) - (8 * i) + 2); } list2.insert(5); list3=list; list4=list; list5.insert(4); list6.insert(-5); list6.insert(2); list7.insert(8); //list.outputList (); // Method "sumMoreThan" returns the sum of the values in the list that are more than // the given value (here 8). If the list contains no values more than the given value, it returns 0. // You are to add this method to class "List" (see above). // Note that your method should work properly in all circumstances, not just for this // particular list and value. Your method can be iterative or recursive. cout << "\nthe sum of values more than 8 is (should be 271): " << list.sumMoreThan(8)<< "\n"; cout << "\nthe sum of values in empty more than -10 (should be 0): " << empty.sumMoreThan(-10)<< "\n"; cout << "\nthe sum of values in [5] more than 2 (should be 5): " << list2.sumMoreThan(2)<< "\n"; cout << "\nthe sum of values in [5] more than 20 (should be 0): " << list2.sumMoreThan(20)<< "\n"; cout << "\nthe sum of values in [2 -5] more than 0 is (should be 2): " << list6.sumMoreThan(0)<< "\n\n"; // Method "duplicateEvens" duplicates every even value in the list. Note that "even" refers // to the contents of the node, not its position in the list. // If the list contains no even values, the method has no effect, i.e. the list is unchanged. // This method *never* quits! // You are to add this method to class "List" (see above). // Note that your method should work properly in all circumstances, not just for this // particular list. Your method can be iterative or recursive. list.duplicateEvens(); cout << "after duplicating every even value the list is:\n"; list.outputList (); cout << "the above should be:\n"; cout << " 86 86 67 50 50 35 22 22 11 2\n"; cout << " 2 -5 -10 -10 -13 -14 -14 -13 -10 -10\n"; cout << " -5 2 2\n"; empty.duplicateEvens(); cout << "\nafter duplicating every even value in the empty list (should be empty):\n"; empty.outputList (); list2.duplicateEvens(); cout << "\nafter duplicating every even value in [5] (should be [5]):\n"; list2.outputList (); list5.duplicateEvens(); cout << "\nafter duplicating every even value in [4] (should be [4 4]):\n"; list5.outputList (); list6.duplicateEvens(); cout << "\nafter duplicating every even value in [2 -5] (should be [2 2 -5]):\n"; list6.outputList (); // Method "isShorterThan" returns true if the first (implicit) lists is shorter than // (i.e. has fewer values than) the other (explicit) list. Otherwise it returns false // (i.e. the first list is longer than or equal to the other list). // You are to add this method to class "List" (see above). // Note that your method should work properly in all circumstances, not just for these // particular lists. Your method must be recursive. if(list2.isShorterThan(list4)) cout << "\nCORRECT: list2 is shorter than list4.\n"; else cout << "\nINCORRECT: list2 is not shorter than list4.\n"; if(list4.isShorterThan(list3)) cout << "\nINCORRECT: list4 is shorter than list3.\n"; else cout << "\nCORRECT: list4 is not shorter than list3.\n"; if(empty.isShorterThan(empty)) cout << "\nINCORRECT: empty is shorter than empty.\n"; else cout << "\nCORRECT: empty is not shorter than empty.\n"; if(list2.isShorterThan(list7)) cout << "\nINCORRECT: list2 is shorter than list7.\n"; else cout << "\nCORRECT: list2 is not shorter than list7.\n"; if(empty.isShorterThan(list2)) cout << "\nCORRECT: empty is shorter than list2.\n"; else cout << "\nINCORRECT: empty is not shorter than list2.\n"; if(list2.isShorterThan(empty)) cout << "\nINCORRECT: list2 is shorter than empty.\n"; else cout << "\nCORRECT: list2 is not shorter than empty.\n"; pause(); return 0; }