In lab 19 you created a simple address book that would hold person structs. For
ID: 3570714 • Letter: I
Question
In lab 19 you created a simple address book that would hold person structs. For this assignment I want you to take lab 19 an create a class out of it.
Your class should be called addressBook. The definition for the addressBook should be in the header file. The variables that make up the data section should be put in the private area of the class. The prototypes for the interface functions should be in the public area of the class.
Data Section
You can easily identify the variables that make up the data section from the fact that all of the functions use these variables. You should remember from the lecture material on classes that the data section should be the private section of the class. You should also note that if a variable should not have direct access to it then it should be in the private section. What I mean here is that if a person can directly access a variable from a function outside of the class and if modifying this variable can cause unknown problems to the operation of your class then it should be in the private section of the class.
Prototype Functions
All of the function prototypes should also go in the class. If a function is an interface into the class then it should go in the public section. For this assignment all functions are interfaces so all prototypes should go in the public section of the class.
In The previous step you prototyped all of the functions and put them in the public section of the class definition. The bodies for these functions should go in addressBook.cpp. Don't forget to use the scope resolution operator to relate the function bodies to the prototypes in the class definition.
Constructors
You should have a default and overloaded constructors. The overloaded constructor should take 3-strings which contain the first name, last name, and address for an individual person.
Explanation / Answer
#ifndef _ADDRESSBOOK #define _ADDRESSBOOK #include #include #include using std::string; #include using namespace std; using std::istream; using std::ostream; namespace CJ { const int MAXADDRESS =25; struct PERSON { string fName; string lName; string Address; }; struct PERSONTEMP { char fName[100]; char lName[100]; char Address[100]; }; class addressBook { private: vector people; int head; int tail; public: addressBook(); addressBook(const PERSON &p); addressBook(const PERSON p[], int size); addressBook(char *fName, char *lName, char *address); bool addPerson(const PERSON &p); bool sortcomp(const PERSON& p1, const PERSON& p2); bool getPerson(PERSON &p); bool findPerson(const string& lastName, PERSON& p); bool findPerson(const string& lastName, const string& firstName, PERSON& p); void bubbleSort(int *array,int length); void printBook(); void sort(); void waitKey(); void writeRecord(); void showRecord(); static addressBook *newbookInst(); static addressBook *tempNew; static PERSON *p(); static PERSON *temPerson; friend ostream &operatorRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.