#include "stdstuff.h" #include "Tree.h" /* In this test you are to extend the tree class provided (Tree.h and Tree.cpp on the G: drive). This test has two parts: Part 1: Write a method that returns the number of nodes in the tree that are leaves (i.e. have no children). Part 2: Write a method that prunes a tree to a specfied height by chopping off all branches that extend beyond this height. All nodes removed from the tree must be properly deleted. Memory leaks are not acceptable. For both parts: Running the sample executable and examining the test code below should give the general idea. Note that your code should work in all cases, not just the examples below. You may use recursion. You may write additional private member methods. You may use other methods in the Tree class. Submit files Tree.h and Tree.cpp as assignment #6 of the submit program provided. */ void realMain () { const int SIZE = 11; int data [SIZE] = { 50, 1, 5, 101, 125, 178, 8, 42, 45, 82, 91}; Tree test1; int i; Tree t1; cout << "\nThis tree has " << t1.getNumLeaves() << " leaves:\n"; t1.display(); t1.insert(7); t1.insert(2); t1.insert(9); t1.insert(11); cout << "\nThis tree has " << t1.getNumLeaves() << " leaves:\n"; t1.display(); t1.insert(8); t1.insert(5); t1.insert(1); cout << "\nThis tree has " << t1.getNumLeaves() << " leaves:\n"; t1.display(); for (i = 0; i < SIZE; i++) test1.insert(data[i]); cout << "\n\nTree before pruning:\n"; test1.display(); test1.prune (5); cout << "\nTree after pruning to a height of 5:\n"; test1.display(); test1.prune (2); cout << "\nTree after pruning to a height of 2:\n"; test1.display(); test1.prune (0); cout << "\nTree after pruning to a height of 0:\n"; test1.display(); cout << "\n"; } int main () { try { realMain (); } catch (exception &e) { // catches all uncaught exceptions cout << "\nException <" << e.what() << "> occurred.\n"; } pause (); return 0; }