I'm clueless as to how to fix the errors in this contact information manager program. please help. Thanks in advanced
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct Date
{
int month, day, year;
};
struct Address
{
string street, city, state, zipcode;
};
class Person
{
private:
string firstname, lastname, homephone, mobilephone, email;
Address address;
Date birthdate;
public:
string getFirstName() { return firstname; }
string getLastName() { return lastname; }
void load(ifstream& infile);
void save(ofstream& outfile);
void enter();
void print();
bool isOutOfOrder(Person p, char field);
};
#define PIM_SIZE 100
class PIM
{
private:
Person contacts[PIM_SIZE];
int numContacts;
void sort(char field);
public:
void load();
void save();
void add(Person p);
void search(string name);
void print(char field);
};
void Person::enter()
{
cin.ignore (100,'\n');
cout << "\nEnter first name: ";
getline(cin, firstname);
cout << "Enter last name: ";
getline(cin, lastname);
cout << "Enter street: ";
getline(cin, address.street);
cout << "Enter city: ";
getline(cin, address.city);
cout << "Enter state: ";
getline(cin, address.state);
cout << "Enter zip code: ";
getline(cin, address.zipcode);
cout << "Enter home phone: ";
getline(cin, homephone);
cout << "Enter mobile phone: ";
getline(cin, mobilephone);
cout << "Enter email: ";
getline(cin, email);
cout << "Enter birth month: ";
cin >> birthdate.month;
cout << "Enter birth day: ";
cin >> birthdate.day;
cout << "Enter birth year: ";
cin >> birthdate.year;
}
void Person::print()
{
cout << firstname << " " << lastname << endl;
cout << address.street <<endl;
cout << address.city <<", "
<< address.state
<< " " << address.zipcode <<endl;
cout << "Home: " << homephone << " "
<< "Mobile: " << mobilephone << endl;
cout << email << endl;
cout << "Birthday: " << birthdate.month << "/"
<< birthdate.day << "/"
<< birthdate.year << endl;
}
void searchContacts(PIM pim.contacts[], int count)
{
int matches = 0;
string name;
cout << "\nEnter first or last name to find: ";
cin >> name;
for (int i = 0; i < count; i++)
{
if (contacts[i].firstname == name) || contacts[i].lastname == name))
{
matches++;
cout << "\nContact " << (i + 1) << ":" << endl;
print(contacts[i]);
}
}
cout << "\nTotal number of matching contacts: " << matches << endl;
}
void Person::save(ofstream& outfile)
{
outfile << firstname << endl;
outfile << lastname << endl;
outfile << street <<endl;
outfile << address.city <<endl
<< address.state <<endl
<< address.zipcode <<endl;
outfile << homephone << endl
<< mobilephone << endl;
outfile << email << endl;
outfile << birthdate.month << endl
<< birthdate.day << endl
<< birthdate.year << endl;
}
void PIM::save()
{
ofstream outfile;
outfile.open("contacts.txt");
outfile << numContacts << endl;
for (int i = 0; i < numContacts; i++)
{
contacts[i].save(contacts.txt);
}
outfile.close();
}
bool Peron::isOutOfOrder(Person p, char field)
{
if (field == 'F')
{
return (firstname < p.firstname);
}
else
{
return (lastname < p.lastname);
}
}
void PIM::sort(char field)
{
Person temp;
int minIndex;
for (int i=0; i<count-1; i++)
{
minIndex = i;
for (int j=i+1; j<count; j++)
{
if (isOutOfOrder(contacts[j],field)
{
minIndex=j;
}
}
temp = contacts[i];
contacts[i]=contacts[minIndex];
contacts[minIndex]=temp;
}
}
void printContacts (Person contacts[], int count)
{
char field;
cout << "\nSort list by [F]irst or [L]ast name: ";
cin >> field;
sort(field);
for (int i = 0; i < count; i++)
{
cout << "\nContact " << (i + 1) << ":" << endl;
print(pim.contacts[i]);
}
cout << "\nTotal number of contacts: " << count << endl;
}
int main()
{
int numContacts = 0;
int arraySize = 100; //always have space for extra 100 contacts
PIM contacts;
ifstream infile;
infile.open("contacts.txt");
if (!infile.fail())
{
infile >> numContacts;
}
contacts[arraySize];
//if "contacts.txt" is already there read in all the information
//to the array of contacts
if (!infile.fail())
{
for (int i = 0; i < numContacts; i++)
{
contacts[i].load;
}
infile.close();
}
cout << "Personal information manager\n";
string choice;
int contactNum;
do
{
cout << "\nA = Add contact" << endl;
cout << "S = Search for contact" << endl;
cout << "P = Print contacts" << endl; //change to lab 8
cout << "X = Exit" << endl;
cout << "\nEnter choice: ";
cin >> choice;
if (choice == "A" || choice == "a" ) //add contact
{
pim.contacts[numOfContacts] = save();
numContacts++;
}
else if (choice == "S" || choice == "s") //search for contact
{
search(contacts, numContacts);
}
else if (choice == "P" || choice == "p") //change to lab 8
{
printContacts(contacts, numContacts);
}
else if (choice!= "X" && choice != "x")
{
cout << "Invalide choice!\n";
}
}
while (choice != "X" && choice != "x");
saveContacts(contacts, numContacts);
cout << "\nContact information saved.\n";
return 0;
}
string Person::getFirstName()
{
return firstname;
}
string Person::getLastName()
{
return lastname;
}
void Person::load(ifstream& infile)
{
infile.ignore();
getline(infile, firstname);
getline(infile, lastname);
getline(infile, address.street);
getline(infile, address.city);
getline(infile, address.state);
getline(infile, address.zipcode);
getline(infile, homephone);
getline(infile, mobilephone);
getline(infile, email);
infile >> birthdate.month;
infile >> birthdate.day;
infile >> birthdate.year;
}