Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

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 exist 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 item.
- Precondition: Tree and Item have been initialized
- Postcondition: Function value = TRUE if all items of the tree are multiple of item; FALS E 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(int el)
- 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
#include

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.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M92038539
  • Price:- $75

Priced at Now at $75, Verified Solution

Have any Question?


Related Questions in C/C++

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As