Write a c++ program that creates and populate a tree

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

Write a C++ program that creates and populate a tree for an arithmetic expression. Then it should perform an in-order and a post-order traversal on the tree. The input of the program will be a text file with the arithmetic expressions in RPN. The output of the program will be a printout of the arithmetic expression written out in both in-fix and post-fix (Reverse Polish) notations. The program does not need to compute the value of the expressions, only print them out.

Note: - The in-fix notation must have all brackets in the right placesi.e. the in-order traversal must be modified to achieve this.

- The post-fix print out is useful for debugging purposes, as it should look like the original text file.

- You need to use a stack that is able to store Tree pointers. You can modify the Stack we developed in class, or use STL.

Remember that you can use the following algorithm to build the tree out of a file with the post-fix notation:

An algorithm to construct an arithmetic tree

Read in an expression that is already in post-fix notation.
Tree *T1, *T2, *T;  Stack S; //note that S is a stack of pointers to trees
while (expression continues) {
  x = next item from the expression
  if (x is a number) { S.Push(new Tree(x, NULL, NULL)); }
  if (x is an operator) {
     T1 = S.Top();  S.Pop();
     T2 = S.Top();  S.Pop();
     S.Push(new Tree(x, T2, T1));  //note order of T2 and T1
  }
}

T = S.Top();

Submit a one file code on Stream by 6pm on Wednesday 2 of May 2013. Your name and ID number must appear on top of the file as comments.  If you are working in a group then all names and IDs must appear on top of the file as comments. Submit one file per group on Stream.

Reference no: EM13331451

Questions Cloud

Are there any similar situations or problems : Using 'Draft TV Commercials' as your case, complete questions 1, 2, 3, 4, 5, 6, and 8. Do not complete item 7. Here are the question.
Critical analysis assignment : critical analysis in the sense we have to identify similarities and differences in the given six papers and one theme present our findings. it not like rephrasing a paragraph and documenting it.
What is the average intensity of this beam : A 0.45mW laser produces a beam of light with a diameter of 1.5mm. What is the average intensity of this beam
Write a c++ program that creates and populate a tree : Write a C++ program that creates and populate a tree for an arithmetic expression. Then it should perform an in-order and a post-order traversal on the tree.
Critical analysis of a project management plan : Critical analysis of a Project Management Plan
Describe the role of relationship development and management : Describe the role of relationship development and management in effective leadership, and use the concepts in improving leadership effectiveness.
Use a one-dimensional array to solve the following problem : Use a one-dimensional array to solve the following problem: Read in 20 numbers, each of which is between 10 and 100 inclusive.
Research how people and organizations react to change : Research how people and organizations react to change, both positive and negativ

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a program to read only one integer number

Write a program to read ONLY one integer number (your input must be one 3 digit number from 100 to 999), and to think of a number as being ABC (where A, B, and C are the 3 digits of a number)

  Extend the definition of the class clocktype by overloading

a. Extend the definition of the class clockType by overloading the post-increment operator function as a member of the class clockType

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Write a c++ program that displays a table showing the price

write a C++ program that displays a table showing the price of silver and gold.

  Use numbers 0 through 23 to represent hours

Write a C function seconds_since_jan1() that takes the time as six integer arguments (year, month, day, hour,minute, and second) and returns the number of seconds since the beginning of the year. Use numbers 1 through 12 to represent months. Use numb..

  Initialize an array and fill the array with the gpa values.

Write a program in java that asks user input (using a loop) for name of 10 student and the corresponding grade point averages (GPAs). Initialize an array and fill the array with the GPA values.

  Design a phonecall class that holds a phone number

Design a PhoneCall class that holds a phone number to which a call is placed, the length of the call in minutes, and the rate charged per minute. Overload extraction and insertion operators for the class.

  Prints out a multiplication table up to a specification

Create a program using C++ that prints out a multiplcation table up to a specfic limit. The code should prompt the user for the limit and then print out the table.

  Local diner that allows customers to see the diner''s menu

Design a program to be used for a small local diner that allows customers to see the diner's menu and then make their meal selections using the program.The program will also calculate and print an itemized bill.

  Write c++ programs

Write a C++ program to accept distance in kilometers, coverts it to meters and then displays the result. Write a C++ program to find area and circumference of a circle.

  Give students practice in writing and calling their function

To give students practice in writing and calling their own functions. To give students practice in implementing and planning complex programs.

  Write me a function that finds the smallest item in an array

Write me a function that finds the smallest item in an ArrayBag (by reference) and returns true if the arrayBag is not empty and false otherwise.

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