Write a program that maintains the names, birth dates, phone numbers of your fri
ID: 3599665 • Letter: W
Question
Write a program that maintains the names, birth dates, phone numbers of your friends and relatives.
Create an input file with the information of one person per line and in the order listed above. (Put at least 20 people in the list). If I have time I will create and send you an input file - but meantime use your own. Names will be first name, last name (separated by a space). Birth dates will be in the form 04/01/2017. Phone numbers will be of the form 312-255-2000
Create a class called Person . An object of this class will contain the info for one person. To compare two Person objects, compare their last names.
You are to create a binary search tree of person objects.
Once the tree is created, the user should be able to input from the keyboard in order to:
1. enter another person
2. modify the info for a person
3. search this tree for all the data for a person . This means you print out all the data for the person.
4. The user should also be able to list everyone in the tree (and their info)
5. search for (and list) all the people who were born in a certain month
Your input is in a file. IT IS INCORRECT to input it into an array and then create a tree from the array. Some of you have done this in the labs, but although you get the right answer it is still BAD PRACTICE. Imagine you have 1 million records, putting them into an array and also a tree occupies twice as much space as you need, and you will quickly run out of space. You have to think about how efficient your programs are - not just whether you get the correct output.
Input File:
Bilal Alharsha 04/01/1993 312-255-2000
Ahmad Alshair 05/02/1992 345-233-4893
Ahmad Alzubi 06/03/1995 232-254-2230
Christopher Beck 07/04/1989 234-445-8594
William Burbatt 08/05/1992 435-645-7847
Maria Calderas 09/06/1993 234-654-5678
Roberto Cervantes 10/07/1995 342-565-2543
Nicholas Chiocca 11/08/1993 324-567-1231
Greg Cudzich 12/09/1993 876-897-8890
Daniel Delgado 01/10/1995 373-432-2345
Francisco Espinoza 04/01/1998 456-657-5677
Ismael Fernandez 05/02/2005 235-987-7894
Siobhan Finnerty 06/03/1992 345-765-0989
Rene Haskins 07/04/1990 768-463-7686
Miguel Ibarra 08/05/1900 654-765-4536
David Jones 09/06/1992 809-456-4567
Kenneth Koronkiewicz 01/23/1990 234-654-7686
Nicholas Lozano 02/11/1980 768-097-5674
Husain Mahmood 03/22/1996 546-324-3451
Scott Marzana 03/12/1996 123-456-5675
Jean Mehta 04/01/1993 432-524-7457
Iyman Mustafa 05/05/1992 234-678-8643
Jose Paz 12/01/1992 541-589-8475
Explanation / Answer
source Code:
-----------------------------
#include<iostream>
#include<string.h>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;
int size = 23;
struct Person_Records
{
char fName[100];
char lName[100];
char date_birth[12];
char mobile[15];
};
Person_Records array[100];
class Person
{
public:
char first_name[100];
char last_name[100];
char datebirth[12];
char mobile[16];
public:
void addRecord()
{
size++;
cout<<" Please Enter First Name:"<<endl;
cin>>first_name;
strcpy(array[size].fName,first_name);
cout<<" please enter The Last Name:"<<endl;
cin>>last_name;
strcpy(array[size].lName,last_name);
cout<<" Please Enter Date of Birth:"<<endl;
cin>>datebirth;
strcpy(array[size].date_birth,datebirth);
cout<<" Please Enter The Mobile Number:"<<endl;
cin>>mobile;
strcpy(array[size].mobile,mobile);
cout<<" New Records added Successfully:"<<endl;
}
public:
void display()
{
cout<<"FirstName LastName Date Birth Mobile"<<endl;
cout<<"------------------------------------------------------------------------------------------"<<endl;
for(int i=1;i<=size;i++)
{
cout<<array[i].fName<<" "<<array[i].lName<<" "<<array[i].date_birth<<" "<<array[i].mobile<<endl;
}
cout<<"------------------------------------------------------------------------------------------"<<endl;
}
public:
int search(char name[])
{
for(int i=1;i<=size;i++)
{
if(!(strcmp(name,array[i].lName)))
{
return i;
}
}
return -1;
}
public:
void modify(char lname[],int position)
{
cout<<" Please Enter The New Records"<<endl;
cout<<" Please Enter New First Name:"<<endl;
cin>>first_name;
strcpy(array[position].fName,first_name);
cout<<" please enter The Last Name:"<<endl;
cin>>last_name;
strcpy(array[position].lName,last_name);
cout<<" Please Enter Date of Birth:"<<endl;
cin>>datebirth;
strcpy(array[position].date_birth,datebirth);
cout<<" Please Enter The Mobile Number:"<<endl;
cin>>mobile;
strcpy(array[position].mobile,mobile);
cout<<" Records Modified Successfully:"<<endl;
}
};
int main()
{
Person obj;
ifstream myfile;
int option;
int retval;
char lastname[100];
myfile.open("person_details.txt");
for(int i = 1; i <= size; i++)
{
myfile>>array[i].fName;
myfile>>array[i].lName;
myfile>>array[i].date_birth;
myfile>>array[i].mobile;
}
cout<<"The Content From The File is:"<<endl;
cout<<" "<<endl;
cout<<"FirstName LastName Date Birth Mobile"<<endl;
cout<<"------------------------------------------------------------------------------------------"<<endl;
for(int i=1;i<=size;i++)
{
cout<<array[i].fName<<" "<<array[i].lName<<" "<<array[i].date_birth<<" "<<array[i].mobile<<endl;
}
cout<<"------------------------------------------------------------------------------------------"<<endl;
cout<<""<<endl;
while(true)
{
cout<<" -----------------"<<endl;
cout<<" ***** MENU ****"<<endl;
cout<<" 1.Add a New Record:"<<endl;
cout<<" 2.Modify Details of Person:"<<endl;
cout<<" 3.Display All Records:"<<endl;
cout<<" 4.Search Person Record:"<<endl;
cout<<" 5.Exit"<<endl;
cout<<" Select Any Option:"<<endl;
cin>>option;
switch(option)
{
case 1:
obj.addRecord();
break;
case 2:
cout<<" Please Enter the Last Name of A Person:"<<endl;
cin>>lastname;
retval=obj.search(lastname);
if(retval!=-1)
{
obj.modify(lastname,retval);
}
else
{
cout<<"The Details are Not Found:"<<endl;
}
break;
case 3:
obj.display();
break;
case 4:
cout<<" Please Enter the Last Name of A Person to Search:"<<endl;
cin>>lastname;
retval=obj.search(lastname);
if(retval==-1)
{
cout<<" The Person Details are not Found: "<<endl;
}
else
{
cout<<" The Details are Found:"<<endl;
cout<<"FirstName LastName Date Birth Mobile"<<endl;
cout<<"------------------------------------------------------------------------------------------"<<endl;
cout<<array[retval].fName<<" "<<array[retval].lName<<" "<<array[retval].date_birth<<" "<<array[retval].mobile<<endl;
}
break;
case 5:
exit(0);
}
}
return 0;
}
sample output:
-------------------------
The Content From The File is:
FirstName LastName Date Birth Mobile
------------------------------------------------------------------------------------------
Bilal Alharsha 04/01/1993 312-255-2000
Ahmad Alshair 05/02/1992 345-233-4893
Ahmad Alzubi 06/03/1995 232-254-2230
Christoph Beck 07/04/1989 234-445-8594
William Burbatt 08/05/1992 435-645-7847
Maria Calderas 09/06/1993 234-654-5678
Roberto Cervantes 10/07/1995 342-565-2543
Nicholas Chiocca 11/08/1993 324-567-1231
Greg Cudzich 12/09/1993 876-897-8890
Daniel Delgado 01/10/1995 373-432-2345
Francisco Espinoza 04/01/1998 456-657-5677
Ismael Fernandez 05/02/2005 235-987-7894
Siobhan Finnerty 06/03/1992 345-765-0989
Rene Haskins 07/04/1990 768-463-7686
Miguel Ibarra 08/05/1900 654-765-4536
David Jones 09/06/1992 809-456-4567
Kenneth Koronkiewicz 01/23/1990 234-654-7686
Nicholas Lozano 02/11/1980 768-097-5674
Husain Mahmood 03/22/1996 546-324-3451
Scott Marzana 03/12/1996 123-456-5675
Jean Mehta 04/01/1993 432-524-7457
Iyman Mustafa 05/05/1992 234-678-8643
Jose Paz 12/01/1992 541-589-8475
------------------------------------------------------------------------------------------
-----------------
***** MENU ****
1.Add a New Record:
2.Modify Details of Person:
3.Display All Records:
4.Search Person Record:
5.Exit
Select Any Option:
1
Please Enter First Name:
venkanna
please enter The Last Name:
koothada
Please Enter Date of Birth:
13/03/1993
Please Enter The Mobile Number:
994-946-8557
New Records added Successfully:
-----------------
***** MENU ****
1.Add a New Record:
2.Modify Details of Person:
3.Display All Records:
4.Search Person Record:
5.Exit
Select Any Option:
3
FirstName LastName Date Birth Mobile
------------------------------------------------------------------------------------------
Bilal Alharsha 04/01/1993 312-255-2000
Ahmad Alshair 05/02/1992 345-233-4893
Ahmad Alzubi 06/03/1995 232-254-2230
Christoph Beck 07/04/1989 234-445-8594
William Burbatt 08/05/1992 435-645-7847
Maria Calderas 09/06/1993 234-654-5678
Roberto Cervantes 10/07/1995 342-565-2543
Nicholas Chiocca 11/08/1993 324-567-1231
Greg Cudzich 12/09/1993 876-897-8890
Daniel Delgado 01/10/1995 373-432-2345
Francisco Espinoza 04/01/1998 456-657-5677
Ismael Fernandez 05/02/2005 235-987-7894
Siobhan Finnerty 06/03/1992 345-765-0989
Rene Haskins 07/04/1990 768-463-7686
Miguel Ibarra 08/05/1900 654-765-4536
David Jones 09/06/1992 809-456-4567
Kenneth Koronkiewicz 01/23/1990 234-654-7686
Nicholas Lozano 02/11/1980 768-097-5674
Husain Mahmood 03/22/1996 546-324-3451
Scott Marzana 03/12/1996 123-456-5675
Jean Mehta 04/01/1993 432-524-7457
Iyman Mustafa 05/05/1992 234-678-8643
Jose Paz 12/01/1992 541-589-8475
venkanna koothada 13/03/1993 994-946-8557
------------------------------------------------------------------------------------------
-----------------
***** MENU ****
1.Add a New Record:
2.Modify Details of Person:
3.Display All Records:
4.Search Person Record:
5.Exit
Select Any Option:
4
Please Enter the Last Name of A Person to Search:
Paz
The Details are Found:
FirstName LastName Date Birth Mobile
------------------------------------------------------------------------------------------
Jose Paz 12/01/1992 541-589-8475
-----------------
***** MENU ****
1.Add a New Record:
2.Modify Details of Person:
3.Display All Records:
4.Search Person Record:
5.Exit
Select Any Option:
2
Please Enter the Last Name of A Person:
Paz
Please Enter The New Records
Please Enter New First Name:
prudhvi
please enter The Last Name:
kumar
Please Enter Date of Birth:
21/08/1994
Please Enter The Mobile Number:
951-153-8997
Records Modified Successfully:
-----------------
***** MENU ****
1.Add a New Record:
2.Modify Details of Person:
3.Display All Records:
4.Search Person Record:
5.Exit
Select Any Option:
3
FirstName LastName Date Birth Mobile
------------------------------------------------------------------------------------------
Bilal Alharsha 04/01/1993 312-255-2000
Ahmad Alshair 05/02/1992 345-233-4893
Ahmad Alzubi 06/03/1995 232-254-2230
Christoph Beck 07/04/1989 234-445-8594
William Burbatt 08/05/1992 435-645-7847
Maria Calderas 09/06/1993 234-654-5678
Roberto Cervantes 10/07/1995 342-565-2543
Nicholas Chiocca 11/08/1993 324-567-1231
Greg Cudzich 12/09/1993 876-897-8890
Daniel Delgado 01/10/1995 373-432-2345
Francisco Espinoza 04/01/1998 456-657-5677
Ismael Fernandez 05/02/2005 235-987-7894
Siobhan Finnerty 06/03/1992 345-765-0989
Rene Haskins 07/04/1990 768-463-7686
Miguel Ibarra 08/05/1900 654-765-4536
David Jones 09/06/1992 809-456-4567
Kenneth Koronkiewicz 01/23/1990 234-654-7686
Nicholas Lozano 02/11/1980 768-097-5674
Husain Mahmood 03/22/1996 546-324-3451
Scott Marzana 03/12/1996 123-456-5675
Jean Mehta 04/01/1993 432-524-7457
Iyman Mustafa 05/05/1992 234-678-8643
prudhvi kumar 21/08/1994 951-153-8997
venkanna koothada 13/03/1993 994-946-8557
------------------------------------------------------------------------------------------
-----------------
***** MENU ****
1.Add a New Record:
2.Modify Details of Person:
3.Display All Records:
4.Search Person Record:
5.Exit
Select Any Option:5
--------------------------------
Process exited after 295.5 seconds with return value 0
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.