COP3530/Project9/Project9.cpp
2023-07-17 21:30:58 -04:00

102 lines
No EOL
2.7 KiB
C++

// Corey Williams
// COP3530 01Z
// Project 9
/*
Create a Binary Tree of "Circle" objects. Refer to Fig. 6.22 & 6.23 as a guide.
The application must provide a menu for performing the following task.
Add Circle Object to Binary Tree
Search for Circle Object in Binary Tree
Display all Binary Tree Circle Objects
Exit
*/
using namespace std;
#include <iostream>
#include "circle4.h"
#include "genBST.h"
#include <string>
void menu_addObj(BST<Circle>& circleTree) {
string s;
system("cls");
cout << "Enter a number to add a circle of that radius to the tree" << endl
<< "or enter q to return to the main menu." << endl;
while (s != "q" and s != "Q") {
cout << endl << "Input: ";
cin >> s;
try {
Circle tmp(stod(s));
circleTree.insert(tmp);
cout << "Circle of radius " << s << " added to tree." << endl;
}
catch (...) {
cout << "Not a valid entry, please try again. " << endl;
continue;
}
}
}
void menu_search(BST<Circle>& circleTree) {
string s;
system("cls");
cout << "Enter a radius, and a search will be conducted to find a matching element" << endl
<< "or enter q to return to the main menu." << endl;
while (s != "q" and s != "Q") {
cout << endl << "Search Criteria: ";
cin >> s;
try {
Circle tmp(stod(s));
if (circleTree.search(tmp))
cout << "A circle of radius " << s << " exists in the tree." << endl;
else
cout << "No objects with radius " << s << " exist in the tree." << endl;
}
catch (...) {
cout << "Not a valid entry, please try again. " << endl;
continue;
}
}
}
void menu_displayTree(BST<Circle>& circleTree) {
system("cls");
cout << "Tree Objects are:" << endl;
circleTree.inorder();
system("pause");
}
int main()
{
BST<Circle> circleTree;
string menuOpt;
while (menuOpt != "4") {
system("cls");
//Display main options menu
cout << "Main Menu" << endl
<< "1. Add Object to Tree" << endl
<< "2. Search for Existing Object" << endl
<< "3. Display All Tree Objects" << endl
<< "4. Exit Application" << endl << endl
<< "Enter an Option: ";
cin >> menuOpt;
if (menuOpt == "1") menu_addObj(circleTree);
else if (menuOpt == "2") menu_search(circleTree);
else if (menuOpt == "3") menu_displayTree(circleTree);
else if (menuOpt == "4" or menuOpt == "q") return 0;
else {
cout << endl << "Not a valid selection. ";
system("pause");
}
}
}