I'm stuck because I recieve these errors when I try to compile -
pim.cpp: In method void PIM::search(class basic_string<char,string_char_traits<char>,__default_alloc_template<false,0> >)': pim.cpp:101: member
firstname' is a private member of class Person' pim.cpp:101: member
lastname' is a private member of class Person' pim.cpp:105: no matching function for call to
PIM::print (Person &)'
pim.cpp:47: candidates are: PIM::print(char)
pim.cpp: In method void PIM::save()': pim.cpp:137: no matching function for call to
Person::save ()'
pim.cpp:112: candidates are: Person::save(ofstream &)
pim.cpp: In method void PIM::sort(char)': pim.cpp:166: warning: implicit declaration of function
int isOutOfOrder(...)'
pim.cpp:166: warning: cannot pass objects of type Person' through
...'
pim.cpp:167: parse error before `{'
pim.cpp:175: confused by earlier errors, bailing out
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 PIM::search(string name)
{
int matches = 0;
for (int i = 0; i < numContacts; 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 << address.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();
}
outfile.close();
}
bool Person::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 < numContacts-1; i++)
{
minIndex = i;
for (int j=i+1; j < numContacts; j++)
{
if (isOutOfOrder(contacts[j],field)
{
minIndex=j;
}
}
temp = contacts[i];
contacts[i]=contacts[minIndex];
contacts[minIndex]=temp;
}
}
void PIM::print(char 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 (!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;
cout << "X = Exit" << endl;
cout << "\nEnter choice: ";
cin >> choice;
if (choice == "A" || choice == "a" )
{
pim.contacts[numOfContacts] = save();
numContacts++;
}
else if (choice == "S" || choice == "s")
{
cout << "\nEnter first or last name to find: ";
cin >> name;
pim.search();
}
else if (choice == "P" || choice == "p")
{
cout << "\nSort list by [F]irst or [L]ast name: ";
cin >> field;
pim.print(field);
}
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;
}
Please let me know what to do without changing any of the classes(PIM or Person)