OOP AdressBook Errors in main
Feb 9, 2013 at 9:18pm UTC
I'm almost done with this program but I am stumped on the errors I'm getting in main. Any help would be appreciated.
Here are the errors:
error C3861: 'addPerson': identifier not found
error C3861: 'getPerson': identifier not found
error C3861: 'findPerson': identifier not found
error C3861: 'findPerson': identifier not found
error C3861: 'printBook': identifier not found
main:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
#include <iostream>
#include <cstdlib>
#include <conio.h>
#include "addressbook.h"
using namespace std;
int printMenu();
void waitKey();
const int ADDPERSON = 1;
const int GETPERSON = 2;
const int FINDLAST = 3;
const int FINDBOTH = 4;
const int PRINT = 5;
const int EXIT = 0;
int main()
{
addressBook* instance;
int selection;
PERSON p;
bool status;
char lName[50];
char fName[50];
selection = printMenu();
while (selection != EXIT )
{
switch (selection)
{
case ADDPERSON :
cout << "Enter First Name " << endl;
cin >> p.fName;
cout << "Enter last Name " << endl;
cin >> p.lName;
cout << "Enter Address " << endl;
cin >> p.Address;
status = addPerson(p); //ERROR
if (status == false )
cout << "Sorry There is no more room in the address book " << endl;
else
cout << "Thanks for your Entry " << endl;
waitKey();
break ;
case GETPERSON :
status = getPerson(p); //ERROR
if (status)
cout << p.fName << "\t" << p.lName << " " << p.Address << endl;
else
cout << "Sorry The address book is empty " << endl;
waitKey();
break ;
case FINDLAST :
cout << "Enter a last name " << endl;
cin >> lName;
status = findPerson(lName,p); //ERROR
if (status)
cout << p.fName << "\t" << p.lName << " " << p.Address << endl;
else
cout << "Sorry, Name not found " << endl;
waitKey();
break ;
case FINDBOTH :
cout << "Enter last name " << endl;
cin >> lName;
cout << "Enter first name " << endl;
cin >> fName;
status = findPerson(lName, fName,p); //ERROR
if (status)
cout << p.fName << "\t" << p.lName << " " << p.Address << endl;
else
cout << "Sorry, Name not found " << endl;
waitKey();
break ;
case PRINT :
printBook(); //ERROR
waitKey();
break ;
case EXIT :
cout << "Thanks for using the address book " << endl;
exit(0);
}
selection = printMenu();
}
}
int printMenu()
{
int selection;
system("CLS" );
cout << "1. Add A Person" << endl;
cout << "2. Get A Person " << endl;
cout << "3. Find A person By Last Name " << endl;
cout << "4. Find A person By First and Last Name " << endl;
cout << "5. Print the address book" << endl;
cout << "0. Exit this program " << endl;
cin >> selection;
return selection;
}
void waitKey()
{
cout << "Press a key to continue " << endl;
while (!kbhit())
;
getch();
fflush(stdin);
}
header file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#ifndef _ADDRESSBOOK
#define _ADDRESSBOOK
const int MAXADDRESS = 25;
struct PERSON
{
char fName[25];
char lName[25];
char Address[100];
};
class addressBook
{
private :
PERSON people[MAXADDRESS];
int head;
int tail;
public :
addressBook();
bool addPerson(const PERSON &p);
bool getPerson(PERSON &p);
bool findPerson(char *lastName, PERSON &p);
bool findPerson(char *lastName, char *firstName, PERSON &p);
void printBook();
static addressBook *Instance();
};
#endif
addressBook.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#include <iostream>
#include "addressBook.h"
using namespace std;
addressBook::addressBook()
{
head = 0;
tail = -1;
}
bool addressBook::addPerson(const PERSON &p)
{
if (head < MAXADDRESS)
{
people[head] = p;
head++;
if (tail == -1)
tail++;
return true ;
}
return false ;
}
bool addressBook::getPerson(PERSON &p)
{
if (tail >=0)
{
if (tail >= head)
tail = 0;
p = people[tail];
tail++;
return true ;
}
return false ;
}
bool addressBook::findPerson(char *lastName, PERSON &p)
{
for (int i = 0; i < head; i++)
{
if (!stricmp(people[i].lName, lastName))
{
p = people[i];
return true ;
}
}
return false ;
}
bool addressBook::findPerson(char *lastName, char *firstName, PERSON &p)
{
for (int i = 0; i < head; i++)
{
if (!stricmp(people[i].lName, lastName) && !stricmp(people[i].fName, firstName))
{
p = people[i];
return true ;
}
}
return false ;
}
void addressBook::printBook()
{
for (int i = 0; i < head; i++)
{
cout << people[i].fName << "\t" << people[i].lName << "\t" << people[i].Address << endl;
}
}
Feb 9, 2013 at 9:28pm UTC
You have to call the getPerson function on an addressBook object. Same with the other functions that are members of addressBook.
Last edited on Feb 9, 2013 at 9:37pm UTC
Feb 10, 2013 at 8:09am UTC
Ahh, stupid mistake. I fixed it. Thanks for your time Perter87.
Topic archived. No new replies allowed.