Ass9 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CISC 1110 Assignment 9 – Programming an Address Book

Write a complete C++ program (including good comments) that uses classes and arrays of objects to
implement an address book.
You will define at least two classes. One class must have at least three members, and at least one of the
members must be another nested class that you define.
For example, you may create a Contact class with the following information:
person’s name (which is another class), address (also may be another class), home phone, cell phone,
email address, etc.
You will define the class above main() so that you can use it in all the functions. However, the actual
array of objects should be defined in main().
1. Read in data to fill up address book:
In order for the program to begin, you will need to populate the address book. The best way to do this is
to call a function to read in the data from a file. You may fix the amount of entries in the array to make
the programming easier.
Thus, the main function will begin by calling the function readdata sending it two parameters: the array
of objects and n. The function will read information about n objects.
NOTE: we did an example in class in which a function printEmployee accepted an array as a parameter.
For each contact, read in a value for each of the members in the class. The data must be entered in the
input file in the exact order that you read in the members. You can use infile>> to read everything. [If
you choose, you can use gettline() but you will need some calls to cin.ignore()].

2. Print all data to verify that reading worked:


Next, the program will print all the data by calling a function printall, sending it two parameters, the
array of objects and n, the number of filled positions in the array. The function will print info for each
contact in your address book on a new line (NOTE: this function is used for testing purposes – it helps
you make sure that you populated the array properly).
3. Sort address book according to last name
Next, the main function will call a function to sort the address book by last name. (you may assume that
there are no duplicates.)
After sorting, you should print the address book again by calling the print function.
4. Search
Finally, you should read in a value from the keyboard and call a search function to find that item in the
array of contacts. You only need to write one search function, but you may write more if you want to.
Choose an appropriate key to search for, such as lastname.
The search function will receive three parameters: the array of objects, n (number of filled positions in
the array), and the value to search for. The search function will first print the value to search for and
then search for the contact.
The search function will return the index of the item if the value is found, and -1 if it is not found. Upon
returning from the search function to main, your program will print the cell phone number of the
contact that was searched for. If the contact is not found in the array, main should print a message that
it is “not found”.
DATA: Your array should allow for up to 25 contacts. To test the program, have a dataset with at least 5
contacts. Make sure you test on searches that appear in the array and searches that are not found.

You might also like