Why My function browse () and order() don't work when I choose choice 2 or 6 ??? would you check it please for me ? Thanks #include #include #include using namespace std; #define M 100 int count = 0; struct AddressBook { string FullName; string Birthday; string Address; string Email; string PhoneNumber; } Person[M]; void WriteToFile (); void add (); void browse (); void searchByName (); void searchByBirthday (); void removeContact (); void order (); int main () { int choice; do { cout << "Please Enter Your Choise: \n"; cout <<" 1-Add New Person\n 2-Browse\n 3-Search By Full Name \n 4-Search By Birthday \n 5-Remove a Person" << "\n 6-Alphabetical Order \n 7-Exit\n"; cin >> choice; switch (choice) { case 1: add (); break; case 2: browse (); break; case 3: searchByName (); break; case 4: searchByBirthday (); break; case 5: removeContact (); break; case 6: order (); break; case 7: return 0; } } while (count < M); return 0; } void WriteToFile (string FullName, string Birthday, string Address, string PhoneNumber, string Email) { ofstream contactFile ("outFile.txt", ios::out | ios::app); if (contactFile.is_open ()) { contactFile << "Name: " << FullName << "\n"; contactFile << "Date of Birth: " << Birthday << "\n"; contactFile << "Address " << Address << "\n"; contactFile << "Email: " << Email << "\n"; contactFile << "Phone Number: " << PhoneNumber << "\n"; } contactFile.close(); } void add () { cout << "Person's Name:"; cin >> Person[count].FullName; cout << "Person's Birthday:"; cin >> Person[count].Birthday; cout << "Person's Address:"; cin >> Person[count].Address; cout << "Person's Email:"; cin >> Person[count].Email; cout << "Person's Phone Number:"; cin >> Person[count].PhoneNumber; WriteToFile(Person[count].FullName, Person[count].Birthday, Person[count].Address, Person[count].Email, Person[count]. PhoneNumber); count++; cout << "\n"; } void browse () { cout << "\nName \t Birthday \t Address \t Email \t Phone\n"; for (int i = 0; i < count; i++) cout << Person[i].FullName << "\t" << Person[i].Birthday << "\t" << Person[i].Address << "\t" << Person[i].Email << "\t" << Person[i].PhoneNumber << "\t" << "\n"; } void searchByName () { string FullName; bool found = false; int i; cout << "Enter name:"; cin >> FullName; for (i = 0; i < count; i++) { if (FullName == Person[i].FullName) { cout << Person[i].FullName << "\t" << Person[i]. Birthday << "\t" << Person[i].Address << "\t" << Person[i]. Email << "\t" << Person[i].PhoneNumber << "\t" << "\n"; found = true; break; } } if (!found) { cout << FullName << "was not found \n"; } } void searchByBirthday () { string B; bool found = false; int i; cout << " Enter Person's Birthday:"; cin >> B; for (i = 0; i < count; i++) { if (Person[i].Birthday == B) { cout << Person[i].FullName << "\t" << Person[i]. Birthday << "\t" << Person[i].Address << "\t" << Person[i]. Email << "\t" << Person[i].PhoneNumber << "\t" << "\n"; found = true; break; } } cout << "\n"; if (!found) { cout << "No result\n"; } } void removeContact () { browse (); int delChoice; cout << "Enter Contact to be deleted by index no" << endl; cin >> delChoice; for (int i = delChoice - 1; i < count - 1; i++) { Person[i].FullName = Person[i + 1].FullName; Person[i].Birthday = Person[i + 1].Birthday; Person[i].Address = Person[i + 1].Address; Person[i].Email = Person[i + 1].Email; Person[i].PhoneNumber = Person[i + 1].PhoneNumber; } count--; cout << "AddressBook after deletion is " << endl; browse (); } void order () { int i, j; AddressBook temp; if (count >= 2){ for (i = 0; i < count; i++) { for (j = 0; j < count - 1; j++) { if (Person[j].FullName > Person[j + 1].FullName) { temp = Person[j]; Person[j] = Person[j + 1]; Person[j + 1] = temp; } } } cout << "\n"; } browse (); }
Why My function browse () and order() don't work when I choose choice 2 or 6 ??? would you check it please for me ?
Thanks
#include<iostream>
#include <fstream>
#include<string>
using namespace std;
#define M 100
int count = 0;
struct AddressBook
{
string FullName;
string Birthday;
string Address;
string Email;
string PhoneNumber;
}
Person[M];
void WriteToFile ();
void add ();
void browse ();
void searchByName ();
void searchByBirthday ();
void removeContact ();
void order ();
int main ()
{
int choice;
do {
cout << "Please Enter Your Choise: \n";
cout <<" 1-Add New Person\n 2-Browse\n 3-Search By Full Name \n 4-Search By Birthday \n 5-Remove a Person"
<< "\n 6-Alphabetical Order \n 7-Exit\n";
cin >> choice;
switch (choice)
{
case 1:
add ();
break;
case 2:
browse ();
break;
case 3:
searchByName ();
break;
case 4:
searchByBirthday ();
break;
case 5:
removeContact ();
break;
case 6:
order ();
break;
case 7:
return 0;
}
} while (count < M);
return 0;
}
void WriteToFile (string FullName, string Birthday, string Address, string PhoneNumber,
string Email)
{
ofstream contactFile ("outFile.txt", ios::out | ios::app);
if (contactFile.is_open ())
{
contactFile << "Name: " << FullName << "\n";
contactFile << "Date of Birth: " << Birthday << "\n";
contactFile << "Address " << Address << "\n";
contactFile << "Email: " << Email << "\n";
contactFile << "Phone Number: " << PhoneNumber << "\n";
}
contactFile.close();
}
void add ()
{
cout << "Person's Name:";
cin >> Person[count].FullName;
cout << "Person's Birthday:";
cin >> Person[count].Birthday;
cout << "Person's Address:";
cin >> Person[count].Address;
cout << "Person's Email:";
cin >> Person[count].Email;
cout << "Person's Phone Number:";
cin >> Person[count].PhoneNumber;
WriteToFile(Person[count].FullName, Person[count].Birthday, Person[count].Address,
Person[count].Email, Person[count]. PhoneNumber);
count++;
cout << "\n";
}
void browse ()
{
cout << "\nName \t Birthday \t Address \t Email \t Phone\n";
for (int i = 0; i < count; i++)
cout << Person[i].FullName << "\t" << Person[i].Birthday << "\t"
<< Person[i].Address << "\t" << Person[i].Email << "\t"
<< Person[i].PhoneNumber << "\t" << "\n";
}
void searchByName ()
{
string FullName;
bool found = false;
int i;
cout << "Enter name:";
cin >> FullName;
for (i = 0; i < count; i++)
{
if (FullName == Person[i].FullName)
{
cout << Person[i].FullName << "\t" << Person[i].
Birthday << "\t" << Person[i].Address << "\t" << Person[i].
Email << "\t" << Person[i].PhoneNumber << "\t" << "\n";
found = true;
break;
}
}
if (!found)
{
cout << FullName << "was not found \n";
}
}
void searchByBirthday ()
{
string B;
bool found = false;
int i;
cout << " Enter Person's Birthday:";
cin >> B;
for (i = 0; i < count; i++)
{
if (Person[i].Birthday == B)
{
cout << Person[i].FullName << "\t" << Person[i].
Birthday << "\t" << Person[i].Address << "\t" << Person[i].
Email << "\t" << Person[i].PhoneNumber << "\t" << "\n";
found = true;
break;
}
}
cout << "\n";
if (!found)
{
cout << "No result\n";
}
}
void removeContact ()
{
browse ();
int delChoice;
cout << "Enter Contact to be deleted by index no" << endl;
cin >> delChoice;
for (int i = delChoice - 1; i < count - 1; i++)
{
Person[i].FullName = Person[i + 1].FullName;
Person[i].Birthday = Person[i + 1].Birthday;
Person[i].Address = Person[i + 1].Address;
Person[i].Email = Person[i + 1].Email;
Person[i].PhoneNumber = Person[i + 1].PhoneNumber;
}
count--;
cout << "AddressBook after deletion is " << endl;
browse ();
}
void order ()
{
int i, j;
AddressBook temp;
if (count >= 2){
for (i = 0; i < count; i++) {
for (j = 0; j < count - 1; j++) {
if (Person[j].FullName > Person[j + 1].FullName)
{
temp = Person[j];
Person[j] = Person[j + 1];
Person[j + 1] = temp;
}
}
}
cout << "\n";
}
browse ();
}
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)