Creates a new tree symmetric to the current instance

Assignment Help C/C++ Programming
Reference no: EM131283842

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 <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.

Verified Expert

In this programming assignment we implement five new methods of the Binary Tree ADT developed in class. The new methods are: SumLeaves, NumberOfOdd, MultipleOf, Clone, and DeleteSubtree.

Reference no: EM131283842

Questions Cloud

What about environmentalists or union leaders : Who should and should not serve on a board of directors? What about environmentalists or union leaders? Explain the relationship between corporate governance and social responsibility?
Provide an overview of germanys economy : Provide an overview of Germany's economy. Describe and explain performances trends of the economy based on graphs given, including discussion on the unusual year.
Explain how multiple systems interact to impact individuals : Explain how multiple systems interact to impact individuals. Explain how you, as a social worker, might apply a systems perspective to your work with Lester Johnson. Finally, explain how you might apply a systems perspective to social work practice..
Review the discussion of diffusion theory : Review the discussion of diffusion theory. How might an understanding of the characteristics of innovations help marketers succeed in emerging markets?
Creates a new tree symmetric to the current instance : creates a new tree symmetric to the current instance - Precondition: Tree has been initialized - Postcondition: Function value = a new tree is created that
Functional silos are not appropriate for today organization : Why do you think functional silos are not appropriate for today's organization? Discuss your answer from organizational and technical perspectives. Use terminology from the chapter in the discussion.
Various importance of curriculum theories : Write on the various importance of curriculum theories in vocational and technical education.
What trade-offs are involved in deciding to have a single : What trade-offs are involved in deciding to have a single large, centrally located facility instead of several smaller, and dispersed facilities? Who needs to be involved in this decision?
Assess estee lauders strategy for china : How do women's preferences for cosmetics and beauty care vary from country to country?- Assess Estée Lauder's strategy for China.

Reviews

inf1283842

11/21/2016 4:28:46 AM

kindly make sure that your expert does not live currently in Abu Dhabi more explanation in the file 19513533_1the view.png

len1283842

11/21/2016 3:37:14 AM

Need to complete the full code with the hash for explaining each part in the code (full notation)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.

Write a Review

C/C++ Programming Questions & Answers

  Calculate the cost of carrying additional luggage results

The application used to calculate the cost of carrying additional luggage results in erroneous amount, if the weight of the luggage is a fractional number. Help the development team modify the code snippet so that the cost of carrying additional l..

  Write a program that computes customers

Design the main so that it have a menu that allows theuser to add items to the customer order, and check the customer out by showing the total charges.

  The function should accept the future value

The function should accept the future value, annual interest rate, and number of years as arguments. It should return the present value, which is the amount that you need to deposit today. Demonstrate the function in a program that lets the user expe..

  Problem regarding the command-line parameter

Your program will deal with three input files: a text file to check (the "user file"), a dictionary file containing correct spellings, and a settings file. The words in the user file will be spell-checked, and any resulting corrections written bac..

  Show the orders that produce different values

Provide an example in C++ of an expression whose value depends upon the evaluation order - Show the orders that produce different values and the values they produce.

  Where c is the temperature in degrees celsius

Write a program that takes as input a depth in kilometers inside the earth and displays the temperature at this depth in degrees Celsius and in degrees Fahrenheit.

  Compute the character with maximum number of connections

Compute the character with maximum number of connections print out the result - Network theory has a host of applications. One fun application is to find the central character in a novel.

  Write a program to calculate students average test scores

Write a program to calculate students average test scores

  Identify the number of potential customers for a business

In this programming assignment, you'll identify the number of potential customers for a business. The starter program outputs the number of potential customers in a user­entered age range given a file with people's data

  Multiplying the current balance

The interest is calculated by multiplying the current balance, rate and time period which is one quarter of a year as in this case. A new balance is calculated by adding that interest.

  Write and test the function to implement insert function

Write and test the function void insert(float a[], int& n, float x) This function inserts the item x into the sorted array a of n elements and increments n.

  Write a program that will check a sequence

Using the dictionary of four letter words write a program that will check a sequence of 4 characters entered from the keyboard to determine if it is a word.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd