Question
C++ binary search tree. It should take names and birthdays from user and Remove one entry Modify one entry Search for one entry List everyone
C++ binary search tree. It should take names and birthdays from user and
Remove one entry
Modify one entry
Search for one entry
List everyone in the database that satisfy a given criteria. For example, list people born in a given month.
Save information to a file.
Retrieve information from a file.
It gives me a lot of errors and the functions are not running well. I need help to complete cases and their functions.
#include
#include
using namespace std;
struct node
{
//int data;
string birthday;
string name;
//int date, month;
struct node* left;
struct node* right;
};
typedef node*nodeptr;
void setroot(nodeptr&head, string name, string birthday);
void insert(nodeptr head, string name, string birthday);
void search(nodeptr head);
nodeptr deletenode(nodeptr root, string name, string birthday);
void modifynode(nodeptr head, string name, string birthday);
/*****************************************************************************/
void main()
{
nodeptr head;
int value;
int choice;
string name;
string date, month, year;
string birthday;
cout << "Please enter the name" << endl;
cin >> name;
cout << "Please enter the birthday" << endl;
cin >> month >> date >> year;
birthday = date + month + year;
setroot(head, name, birthday);
do
{
cout << "Enter 1 for insert" << endl;
cout << "Enter 2 for modify" << endl;
cout << "enter 3 for delete" << endl;
cout << "Enter 4 for search" << endl;
cout << "Enter 5 for exit" << endl;
cin >> choice;
switch (choice)
{
case 1:
cout << "Please enter the name" << endl;
cin >> name;
cout << "Please enter the birthday" << endl;
cin >> month >> date >> year;;
insert(head, name, birthday);
break;
case 2:
break;
case 3:
//string name;
cout << "What namedo you want to delete" << endl;
cin >> name;
head = deletenode(head, name, birthday);
break;
case 4:
search(head);
cout << endl;
break;
case 5:
cout << "Exiting programe" << endl;
system("pause");
break;
}
} while (choice != 5);
}
void setroot(nodeptr&head, string name, string birthday)
{
head = new node;
head->name = name;
head->birthday = birthday;
head->left = nullptr;
head->right = nullptr;
}
void insert(nodeptr head, string name, string birthday)
{
nodeptr here = head;
if (here != nullptr)
{
while ((here->left != nullptr) && (here->right != nullptr))
{
if (name> here->name)
here = here->right;
else if (birthday < here->birthday)
here = here->left;
else
{
cout << "name already exists. did not add" << endl;
return;
}
}
}
}
void search(nodeptr head)
{
search(head);
cout << endl;
}
nodeptr deletenode(nodeptr root, string name, string birthday)
{
cout << "What name do you want to delete" << endl;
cin >> name;
root = deletenode(root, name, birthday);
return root;
}
void modifynode(nodeptr head, string name, string birthday)
{
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started