## New methods of the Binary Tree ADT

### computer science

##### Description

In this programming assignment, you are asked to implement five new methods of the Binary Tree ADT developed in class.

Use recursion when it is possible. The new methods are SumLeaves, NumberOfOdd, MultipleOf, Clone, and DeleteSubtree.

The specifications of these methods are provided below:

int SumLeftLeaves( )

- Function: returns the sum of all the left leaves’ info. - Precondition: Tree has been initialized.

- Postcondition: Function value = sum value of all left leaves’ info. § int NumberOfOdd()

- Function: Returns the number of odd elements that exist in the tree.

- Precondition: Tree has been initialized

- Postcondition: Function value = 0 if no odd element exists in the tree, else it returns the number

of odd elements existing in the tree.

§ bool MultipleOf(int item)

- Function: Checks if the elements stored in the tree are multiple of the item.

- Precondition: Tree and Item have been initialized

- Postcondition: Function value = TRUE if all items of the tree are multiple of the item; FALSE otherwise.

§ BinaryTree SymmetricClone ()

- Function: creates a new tree symmetric to the current instance.

- Precondition: Tree has been initialized - Postcondition: Function value = a new tree is created that

contains elements of the tree with left subtree becoming a right subtree and vice-versa.

§ void DeleteSubtree(intel)

- Function: deletes the subtree having el as a root.

- Precondition: tree and el have been initialized - Postcondition: Function value = all nodes belonging to the

subtree with root el are deleted from the tree

First, double check that the program Assig4.cpp creates correctly the below three trees.

BinaryTree tree1, tree2, tree3, tree4;

tree2.SumLeftLeaves(); returns 10+15=25 tree3.SumLeftLeaves(); returns 60=60

tree1.numberOfOdd(); returns 6 tree2.numberOfOdd(); returns 3 tree3.numberOfOdd(); returns 0

tree1.multipleOf(3); returns FALSE tree2.multipleOf(5); returns TRUE tree3.multipleOf(10); returns TRUE

tree4 = tree2.SymmetricClone(); tree4.Print(InOrder); displays 10, 20, 25, 15, 5, 30, 60, 10,

tree2.deleteSubTree(20); tree2.Print(InOrder); displays 10, 5, 60, 10, 30,

The givin code::

#include <iostream>

#include <iomanip>

using namespace std;

#include "BinaryTree.h"

int main(int argc, char* argv[]) {

BinaryTree tree1, tree2, tree3, tree4;

BTNode *left, *right, *node, *root;

//Creating the special tree1 as shown in the figure provided in the assignment

tree1.insert(10);

root = tree1.Root();

left = new BTNode(7);

node = new BTNode(4, 0, left);

left->parent = node;

right = new BTNode(7);

node = new BTNode(5, root, node, right);

node->left->parent = node;

right->parent = node;

root->left = node;

left = new BTNode(7);

right = new BTNode(25);

node = new BTNode(7, root, left, right);

right->parent = node;

root->right = node;

//Creating the special tree2 as shown in the figure provided in the assignment

tree2.insert(10);

root = tree2.Root();

left = new BTNode(10);

node = new BTNode(60, 0, left);

left->parent = node;

right = new BTNode(30);

node = new BTNode(5, root, node, right);

node->left->parent = node;

right->parent = node;

root->left = node;

left = new BTNode(15);

right = new BTNode(25);

node = new BTNode(20, root, left, right);

right->parent = node;

root->right = node;

//Creating the special tree3 as shown in the figure provided in the assignment

tree3.insert(10);

root = tree3.Root();

left = new BTNode(60);

node = new BTNode(40, 0, left);

left->parent = node;

node = new BTNode(20, root, node);

node->left->parent = node;

root->left = node;

right = new BTNode(50);

node = new BTNode(30, root, 0, right);

right->parent = node;

root->right = node;

cout<<"Tree1 : "; tree1.Print(InOrder);

cout<<"Tree2 : "; tree2.Print(InOrder);

cout<<"Tree3 : "; tree3.Print(InOrder);

system("PAUSE");

return 0;

}

******************************************************************************************************

write the program using C++ visual studio 2013 + versions

i need the full file the header and the cpp files and any other files used make sure that i can run it in any project.