Homework 06
Shape Tree
Due 03/29/2024 at 11:55PM
Objective:
Write a program where a user can maintain a collection of shapes that are organized by their area using a binary search tree data structure. The program must be able to add/remove shapes, read/write to shape files, search for shapes, and perform a variety of other operations.
Requirements:
<<Shape Type 00>>\t<<Shape
Information 00>>\n
<<Shape Type 01>>\t<<Shape Information 00>>\n
…
<<Shape Type N>>\t<<Shape Information N>>\n
Rectangle\t<<Length>>\t<<Width>>\n
Circle\t<<Radius>>\n
Right Triangle\t<<Base>>\t<<Height>>\n
<<Shape Type
00>>\t<<Shape Information 00>>\n
<<Shape Type 01>>\t<<Shape Information 00>>\n
…
<<Shape Type N>>\t<<Shape Information N>>\n
Rectangle\t<<Length>>\t<<Width>>\n
Circle\t<<Radius>>\n
Right Triangle\t<<Base>>\t<<Height>>\n
More Notes:
Example Dialog:
*The following Example Dialog demonstrates the interactions
between a user and ONE possible implementation of the required software’s
front-end / user interface. The software’s front-end / user interface may
be implemented in MANY different ways and will receive full credit as
long as it meets the most minimal of the above requirements. While you may use
the example dialog as a guide, it is strongly encouraged to create the
front-end / user interface in your own way. *
Key |
|
Unhighlighted Text |
Program’s Output |
Highlighted Text |
User’s Input |
Welcome to the Shape Tree!
Enter 1. To Read a Shape Tree from a File.
Enter 2. To Print a Tree Traversal to the Console
Enter 3. To Add a Shape.
Enter 4. To Remove a Shape.
Enter 5. To Search for a Shape.
Enter 6. To Find the Shape with the Max Area.
Enter 7. To Remove All Shapes Greater than an Area.
Enter 8. To Print Shape Tree to File.
Enter 0. To Quit.
1
Enter the file's name
shapes.txt
Printing after Reading In-Order
Right Triangle Base: 2.0 Height: 2.0 Area: 2.0
Right Triangle Base: 3.0 Height: 2.0 Area: 3.0
Circle Radius: 2.0 Area: 12.566370614359172
Rectangle Length: 2.0 Width: 7.0 Area: 14.0
Right Triangle Base: 5.0 Height: 6.0 Area: 15.0
Rectangle Length: 9.0 Width: 2.0 Area: 18.0
Rectangle Length: 5.0 Width: 4.0 Area: 20.0
Rectangle Length: 3.0 Width: 8.0 Area: 24.0
Rectangle Length: 5.0 Width: 5.0 Area: 25.0
Right Triangle Base: 9.0 Height: 9.0 Area: 40.5
Circle Radius: 4.0 Area: 50.26548245743669
Circle Radius: 7.0 Area: 153.93804002589985
Circle Radius: 8.0 Area: 201.06192982974676
Circle Radius: 9.0 Area: 254.46900494077323
Enter 1. To Read a Shape Tree from a File.
Enter 2. To Print a Tree Traversal to the Console
Enter 3. To Add a Shape.
Enter 4. To Remove a Shape.
Enter 5. To Search for a Shape.
Enter 6. To Find the Shape with the Max Area.
Enter 7. To Remove All Shapes Greater than an Area.
Enter 8. To Print Shape Tree to File.
Enter 0. To Quit.
2
Which traversal?
Enter 1. For Pre-order.
Enter 2. For In-order
Enter 3. For Post-order
1
Rectangle Length: 5.0 Width: 4.0 Area: 20.0
Right Triangle Base: 3.0 Height: 2.0 Area: 3.0
Right Triangle Base: 2.0 Height: 2.0 Area: 2.0
Rectangle Length: 2.0 Width: 7.0 Area: 14.0
Circle Radius: 2.0 Area: 12.566370614359172
Right Triangle Base: 5.0 Height: 6.0 Area: 15.0
Rectangle Length: 9.0 Width: 2.0 Area: 18.0
Circle Radius: 4.0 Area: 50.26548245743669
Rectangle Length: 5.0 Width: 5.0 Area: 25.0
Rectangle Length: 3.0 Width: 8.0 Area: 24.0
Right Triangle Base: 9.0 Height: 9.0 Area: 40.5
Circle Radius: 8.0 Area: 201.06192982974676
Circle Radius: 7.0 Area: 153.93804002589985
Circle Radius: 9.0 Area: 254.46900494077323
Enter 1. To Read a Shape Tree from a File.
Enter 2. To Print a Tree Traversal to the Console
Enter 3. To Add a Shape.
Enter 4. To Remove a Shape.
Enter 5. To Search for a Shape.
Enter 6. To Find the Shape with the Max Area.
Enter 7. To Remove All Shapes Greater than an Area.
Enter 8. To Print Shape Tree to File.
Enter 0. To Quit.
3
Enter the type of shape to add
Right triangle
Enter the base followed by the height
36
47
Enter 1. To Read a Shape Tree from a File.
Enter 2. To Print a Tree Traversal to the Console
Enter 3. To Add a Shape.
Enter 4. To Remove a Shape.
Enter 5. To Search for a Shape.
Enter 6. To Find the Shape with the Max Area.
Enter 7. To Remove All Shapes Greater than an Area.
Enter 8. To Print Shape Tree to File.
Enter 0. To Quit.
2
Which traversal?
Enter 1. For Pre-order.
Enter 2. For In-order
Enter 3. For Post-order
2
Right Triangle Base: 2.0 Height: 2.0 Area: 2.0
Right Triangle Base: 3.0 Height: 2.0 Area: 3.0
Circle Radius: 2.0 Area: 12.566370614359172
Rectangle Length: 2.0 Width: 7.0 Area: 14.0
Right Triangle Base: 5.0 Height: 6.0 Area: 15.0
Rectangle Length: 9.0 Width: 2.0 Area: 18.0
Rectangle Length: 5.0 Width: 4.0 Area: 20.0
Rectangle Length: 3.0 Width: 8.0 Area: 24.0
Rectangle Length: 5.0 Width: 5.0 Area: 25.0
Right Triangle Base: 9.0 Height: 9.0 Area: 40.5
Circle Radius: 4.0 Area: 50.26548245743669
Circle Radius: 7.0 Area: 153.93804002589985
Circle Radius: 8.0 Area: 201.06192982974676
Circle Radius: 9.0 Area: 254.46900494077323
Right Triangle Base: 36.0 Height: 47.0 Area: 846.0
Enter 1. To Read a Shape Tree from a File.
Enter 2. To Print a Tree Traversal to the Console
Enter 3. To Add a Shape.
Enter 4. To Remove a Shape.
Enter 5. To Search for a Shape.
Enter 6. To Find the Shape with the Max Area.
Enter 7. To Remove All Shapes Greater than an Area.
Enter 8. To Print Shape Tree to File.
Enter 0. To Quit.
4
Enter the type of shape to remove
Rectangle
Enter the length followed by the width
5
4
Enter 1. To Read a Shape Tree from a File.
Enter 2. To Print a Tree Traversal to the Console
Enter 3. To Add a Shape.
Enter 4. To Remove a Shape.
Enter 5. To Search for a Shape.
Enter 6. To Find the Shape with the Max Area.
Enter 7. To Remove All Shapes Greater than an Area.
Enter 8. To Print Shape Tree to File.
Enter 0. To Quit.
2
Which traversal?
Enter 1. For Pre-order.
Enter 2. For In-order
Enter 3. For Post-order
2
Right Triangle Base: 2.0 Height: 2.0 Area: 2.0
Right Triangle Base: 3.0 Height: 2.0 Area: 3.0
Circle Radius: 2.0 Area: 12.566370614359172
Rectangle Length: 2.0 Width: 7.0 Area: 14.0
Right Triangle Base: 5.0 Height: 6.0 Area: 15.0
Rectangle Length: 9.0 Width: 2.0 Area: 18.0
Rectangle Length: 3.0 Width: 8.0 Area: 24.0
Rectangle Length: 5.0 Width: 5.0 Area: 25.0
Right Triangle Base: 9.0 Height: 9.0 Area: 40.5
Circle Radius: 4.0 Area: 50.26548245743669
Circle Radius: 7.0 Area: 153.93804002589985
Circle Radius: 8.0 Area: 201.06192982974676
Circle Radius: 9.0 Area: 254.46900494077323
Right Triangle Base: 36.0 Height: 47.0 Area: 846.0
Enter 1. To Read a Shape Tree from a File.
Enter 2. To Print a Tree Traversal to the Console
Enter 3. To Add a Shape.
Enter 4. To Remove a Shape.
Enter 5. To Search for a Shape.
Enter 6. To Find the Shape with the Max Area.
Enter 7. To Remove All Shapes Greater than an Area.
Enter 8. To Print Shape Tree to File.
Enter 0. To Quit.
5
Enter the type of shape to Search
Circle
Enter the radius
4
Was the shape in the tree? true
Enter 1. To Read a Shape Tree from a File.
Enter 2. To Print a Tree Traversal to the Console
Enter 3. To Add a Shape.
Enter 4. To Remove a Shape.
Enter 5. To Search for a Shape.
Enter 6. To Find the Shape with the Max Area.
Enter 7. To Remove All Shapes Greater than an Area.
Enter 8. To Print Shape Tree to File.
Enter 0. To Quit.
6
The shape with the max area Right Triangle Base: 36.0 Height: 47.0 Area: 846.0
Enter 1. To Read a Shape Tree from a File.
Enter 2. To Print a Tree Traversal to the Console
Enter 3. To Add a Shape.
Enter 4. To Remove a Shape.
Enter 5. To Search for a Shape.
Enter 6. To Find the Shape with the Max Area.
Enter 7. To Remove All Shapes Greater than an Area.
Enter 8. To Print Shape Tree to File.
Enter 0. To Quit.
7
Enter the maximum area
100
Enter 1. To Read a Shape Tree from a File.
Enter 2. To Print a Tree Traversal to the Console
Enter 3. To Add a Shape.
Enter 4. To Remove a Shape.
Enter 5. To Search for a Shape.
Enter 6. To Find the Shape with the Max Area.
Enter 7. To Remove All Shapes Greater than an Area.
Enter 8. To Print Shape Tree to File.
Enter 0. To Quit.
2
Which traversal?
Enter 1. For Pre-order.
Enter 2. For In-order
Enter 3. For Post-order
2
Right Triangle Base: 2.0 Height: 2.0 Area: 2.0
Right Triangle Base: 3.0 Height: 2.0 Area: 3.0
Circle Radius: 2.0 Area: 12.566370614359172
Rectangle Length: 2.0 Width: 7.0 Area: 14.0
Right Triangle Base: 5.0 Height: 6.0 Area: 15.0
Rectangle Length: 9.0 Width: 2.0 Area: 18.0
Rectangle Length: 3.0 Width: 8.0 Area: 24.0
Rectangle Length: 5.0 Width: 5.0 Area: 25.0
Right Triangle Base: 9.0 Height: 9.0 Area: 40.5
Circle Radius: 4.0 Area: 50.26548245743669
Enter 1. To Read a Shape Tree from a File.
Enter 2. To Print a Tree Traversal to the Console
Enter 3. To Add a Shape.
Enter 4. To Remove a Shape.
Enter 5. To Search for a Shape.
Enter 6. To Find the Shape with the Max Area.
Enter 7. To Remove All Shapes Greater than an Area.
Enter 8. To Print Shape Tree to File.
Enter 0. To Quit.
8
Enter the file's name
newShapes.txt
Enter 1. To Read a Shape Tree from a File.
Enter 2. To Print a Tree Traversal to the Console
Enter 3. To Add a Shape.
Enter 4. To Remove a Shape.
Enter 5. To Search for a Shape.
Enter 6. To Find the Shape with the Max Area.
Enter 7. To Remove All Shapes Greater than an Area.
Enter 8. To Print Shape Tree to File.
Enter 0. To Quit.
0
Goodbye!
Finally:
Submit the files to the CSCE Dropbox (https://dropbox.cse.sc.edu)