Hello ! Would look whats wrong with my program. When I add a contact the others names which they are in the Txt file be deleted and I can't figure out what went wrong.    Contact'sBook.txt: Name: Salma Date of Birth: 780123 Address Falkenberg Email: ghsa@yahoo.com Phone Number: 87654321 Name: Ingrid Date of Birth: 720312 Address Stockholm Email: asde@live.com Phone Number: 9865431 Name: Adam Date of Birth: 671231 Address Göteborg Email: gadfl@outlook.com Phone Number: 765432   The Program : #include #include #include using namespace std; #define M 100 int count=0; struct AddressBook{ string FullName; int Birthday; string Address; string Email; int PhoneNumber; } Person [M]; void WriteToFile(); void add(); void browse(); void searchByName(); void searchByBirthday(); void removeContact(); void order(); int main(){ fstream file; file.open("Contact'sBook.txt"); 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 5- Remove a Person" << "\n6- Alphabetical Order \n7-Exit\n"; cin >> choice; switch(choice){ case 1: add(); case 2: browse();break; case 3: searchByName(); case 4: searchByBirthday(); case 5: removeContact(); case 6: order(); break; case 7: return 0; } } while (count < M ); return 0; } void WriteToFile(string FullName, int Birthday, string Address, int PhoneNumber, string Email) { ofstream contactFile ("Contact'sBook.txt"); 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"; } else{ cout << "Error 23 Contact your Administrator :D." << endl; } //return 0; } 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; cout<<"\n"; WriteToFile(Person[count].FullName,Person[count].Birthday, Person[count].Address,Person[count].PhoneNumber,Person[count].Email); count ++; } void browse(){ cout << "Name\n"; for(int i =0; i < count;i++) cout << Person[i].FullName<<"\t"<< Person[i].Birthday<<"\t"<> FullName; for(i=0;i> B; for (i=0; i> 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 " < Person[j+1].FullName){ temp=Person[j]; Person[j]=Person[j+1]; Person[j+1]= temp; } } } cout << "\n"; out:browse(); }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Hello !

Would look whats wrong with my program. When I add a contact the others names which they are in the Txt file be deleted and I can't figure out what went wrong. 

 

Contact'sBook.txt:

Name: Salma
Date of Birth: 780123
Address Falkenberg
Email: ghsa@yahoo.com
Phone Number: 87654321

Name: Ingrid
Date of Birth: 720312
Address Stockholm
Email: asde@live.com
Phone Number: 9865431

Name: Adam
Date of Birth: 671231
Address Göteborg
Email: gadfl@outlook.com
Phone Number: 765432

 

The Program :

#include<iostream>
#include <fstream>
#include<string>
using namespace std;
#define M 100
int count=0;
struct AddressBook{
string FullName;
int Birthday;
string Address;
string Email;
int PhoneNumber;
}
Person [M];
void WriteToFile();
void add();
void browse();
void searchByName();
void searchByBirthday();
void removeContact();
void order();
int main(){
fstream file;

file.open("Contact'sBook.txt");
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 5- Remove a Person" << "\n6- Alphabetical Order \n7-Exit\n";
cin >> choice;
switch(choice){
case 1: add();
case 2: browse();break;
case 3: searchByName();
case 4: searchByBirthday();
case 5: removeContact();
case 6: order(); break;
case 7: return 0;

}
}
while (count < M );
return 0;

}
void WriteToFile(string FullName, int Birthday, string Address, int PhoneNumber, string Email)
{
ofstream contactFile ("Contact'sBook.txt");
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";
}
else{
cout << "Error 23 Contact your Administrator :D." << endl;
}

//return 0;
}

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;
cout<<"\n";
WriteToFile(Person[count].FullName,Person[count].Birthday, Person[count].Address,Person[count].PhoneNumber,Person[count].Email);
count ++;
}
void browse(){
cout << "Name\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";
cout<<"\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;

}
}
if(!found){
cout << FullName << "was not found \n";
}


}
void searchByBirthday() {

int 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;
}
}
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) goto out;
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";
out:browse();
}

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY