Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this lab you are going to construct functionality to create a simple address

ID: 3570507 • Letter: F

Question

For this lab you are going to construct functionality to create a simple address book. Conceptually, the address book uses a structure to hold information about a person and an array of structures to hold multiple persons (people).

It should compile to something similar like

1. Add a Person

                                2. Get a Person

                                3. Find by Last Name

                                4. Find by First and Last Name

                                5. Print the book

                                0 exit

                                1

                                Enter the First Name

                                Brandon

                                Enter the Last Name

                                Jones

                                Enter the address

                                993 East Ct

                                Reno, Nevada 29984

                                Press Key to Continue

The instructions below:

Visually think of the address book like so:

When you add a person to the Address Book you add a structure with the information about the person to the end of the array:

When you get a person, you get the first person in the address book. With each successive call to get a person, you get the next person in the array. For instance the first call to get a person you will get "Joe Smith" when you make the second call to get a person you would get "Jane Doe" so on and so forth. After you get the last person from the array the next call to get a person will start over at the beginning ("Joe Smith" in this case).

Details:

This lab is intended to prepare you to start working with object oriented programming. This means defining classes and creating objects. A class is an encapsulation of data and functions that operate on that data. An object is an instance of a class. Since we haven't covered how to create a class we are going to simulate it. How do we do that? Well hopefully it will be simple.

First off we need to determine what the data section is. In this case it is going to be the array that holds the structs (people). Because the functions you write need to operate on the data in some way you are going to have to put this array in global scope. This way all of the functions have direct access to array without it having to be passed around. One thing of note and that is if we think about this from main's perspective main should not know how the data is stored or what it is stored in. All main should know is that if you use the addPerson function you can add a person to the address book. This is what we call a public interface to private data. Since we are putting the array in global scope in addressBook.cpp we pseudo encapsulate it. This means that only addressBook functions have access to the array and variable in global scope. Of course since it is in global scope there is a way around this but again, we are simulating.

When you add a person struct to the end of the array you are going to need to keep track of where you put it. This way you have an idea of where the end of the array is so that you can add the next person. You are also going to need to do this for the beginning of the array so that you know where to get the next person from. This means that along with the array that you have in global scope you are also going to have to create a couple of int variables to be used as indexes to keep track of where you are in the array. A suggestion here would be to call these variables head and tail.

Ok, so you should have three files

Here is how things should flow for the addPerson function:



Here is how things should flow for the getPerson function:

*This is circular so if have 5 people in the address book and you call get person in a loop 25 times from main all five people will be returned five times.

Here is how the findPerson functions should flow:


Conceptually what you are creating is a circular queue that holds structs. Because you need to know where the next available spot in the array is you will need an index. This should be in the global section of addresBook.cpp. You are actually probably going to need two indexes, one to keep track of what is being added, and one that keeps track of what is being removed.

There are four functions and I can tell you that each of these can be written in about 5 or 6 lines of code.

What not to do

Using any of the following will drop your grade for this assignment by 70%

*If you want to create a function called printBook it is acceptable to have cout in that function but not in any others.

Explanation / Answer

#include #include "header.h" int maincounter = 0; int getcount = 0; using namespace std; void addPerson(struct person &add); void getPerson(struct person &get); void findPerson (struct person &find); void findPerson (struct person &findlast, struct person &findfirst); person bookArray[MaxPeople]; //This is the main "address book" array int main() { char *last = new char[20]; char *first = new char[20]; char choice; person add; person getStruct; cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote