Programming assignment #8

Developing a simple contact-information database program

 

Purpose:

We would like to define and implement a ContactInfo class and use objects of this ContactInfo class to store and process the contact information of people. You will need to use the DateType class and the C++ string class in the implementation of a ContactInfo class. We’ll then use this ContactInfo class as a building block in implementing a simple contact information database program.

 

What to do:

  1. Download the basic code framework: Download this zip file and unzip it to get a project containing the basic code to work on. You will also find DateType.h and DateType.cpp included in it. You should replace these tow files with your own version of DateType.h and DateType.cpp instead.
  2. Understand the design of the ContactInfo class: Look at the interface (i.e. the member functions and data members) of the ContactInfo class as defined and commented  in ContactInfo.h to understand what kind of data are stored in a ContactInfo object and what kind of services (member functions) a ContactInfo object can do for you.
  3. Implement the of the ContactInfo class: ContactInfo.cpp contains the implementation details of the member functions of the ContactInfo class. The implementation there is not completed yet. You have to fill in code to complete the implementation of these member functions according to the specification comments of these member functions in ContactInfo.h. Regarding the implementations of the relational operator >  and others like < and <=,  we define a total order over ContactInfo objects by defining  that C1 > C2  is true if and only if  either  we have C1.CompareFullName (C2) = = GREATER or  we have C1.SameFullName (C2) = = true and  C1.CompareBirthday (C2) = = GREATER.
  4. Test the implementation of your ContactInfo class: The main function in ContactTest.cpp given to you is intended as the test ground for testing whether your implementation of the ContactInfo class is sound. At the moment, we have a vector of ContactInfo objects (initialized to hold 5 ContactInfo objects) to serve as a contact-information database. The code in the main function then does some basic operations such as reading the contact information of 5 persons into the database, display the contact information of these people from the database, search the database for the contact information of persons of a particular name, and search the database to find out the contact information of all people born on a particular date. You should add similar code to extensively test your implementation in Step 3 above.
  5. Incorporate and revise the functions mergeTwoSortedVectors and mergeSort similar to what you did in Programming #2 or #5 into ContactTest.cpp to provide the capability of sorting ContactInfo objects instead of double values or dateType objects:  First, make a copy of these two functions from programming #2 or #5 into ContactTest.cpp in this project.  Modify the prototype bool mergeTwoSortedVectors(vector<double> & vecA, vector<double> & vecB, vector<double> & vecC) to bool mergeTwoSortedVectors(vector< ContactInfo e> & vecA, vector< ContactInfo > & vecB, vector< ContactInfo e > & vecC) and  modify the implementation so that it can merge two sorted vectors of ContactInfo objects. Modify the prototype of bool mergeSort(vector<double> & vecToSort) to bool mergeSort(vector< ContactInfo > & vecToSort) and modify the implementation so that it can sort a vector of ContactInfo objects. Add code in the main function to test and verify that the newly modified  functions can work well for merging and sorting ContactInfo objects.
  6. Implement your own very simple contact information database program: Make a copy of ContactTest.cpp in the project folder and name it ContactDB.cpp.  Under Visual studio, remove ContactTest.cpp from the project and add ContactDB.cpp into the project. Then totally rewrite the main function in ContactDB.cpp to provide a menu serving as a simple database user interface similar to what you did for Program#5. See the details in the following.
  7. Extensively test all the services provided by your program.

 

Detailed specification of the main function in ContactDB.cpp:

Overview:  Your main function in Contact.cpp should provide services to read dates from the keyboard or files, save the dates into files, search for dates within a given range of dates, and sort dates in order. To accomplish these purposes, in the main function we’ll use a vector<ContactInfo> object as a container in the main memory to store and manage the date information by using various operators and member functions of the ContactInfo class. See more details below.

Key data structures:

·        To dynamically store the information of dates, you should declare in your main function ”  vector<ContactInfo> contactDB;  ” to create a local vector for storing ContactInfo objects.  You should also declare in your main function a local ContactInfo object like aContact, local string objects like “ string  aFirstName, aLAstName;” and  DateType objects like  “ DateType  dBegin, dEnd;  ” for storing temporary date information.

·        Add the line #include <fstream> in the beginning of the .cpp file for file I/O support. In the main function, you should declare a character array char filename[20] for storing the file name given by the user. You should declare two file handles ifstream fin; and ofstream fout; for file input/output purposes respectively. You should also declare in your main function local integer variable  “ int  numContsctInfoRecords;  ” for temporarily storing the information of the number of date records involved in the file I/O.

 

Service menu: The main function should set up a loop that would repeatedly display a menu to prompt the user to choose one of the following services:

 

Implementation of the services: On each iteration of that loop, the program should read the user’s choice and use a switch statement to do things according to the choice:

 

 

 

Reference:

·        Vector class: Member Functions with no iterators used:

back

Returns a reference to the last element of the vector.

capacity

Returns the number of elements that the vector could contain without allocating more storage.

clear

Erases the elements of the vector.

empty

Tests if the vector container is empty.

front

Returns a reference to the first element in a vector.

max_size

Returns the maximum length of the vector.

pop_back

Deletes the element at the end of the vector.

push_back

Add an element to the end of the vector.

resize

Specifies a new size for a vector.

reserve

Reserves a minimum length of storage for a vector object.

size

Returns the number of elements in the vector.

swap

Exchanges the elements of two vectors.

vector

Constructs a vector of a specific size or with elements of a specific value or with a specific allocator or as a copy of some other vector.

 

·        Vector class: Member Functions with iterators used:

begin

Returns a random-access iterator to the first element in the container.

end

Returns a random-access iterator that points just beyond the end of the vector.

erase

Removes an element or a range of elements in a vector from specified positions.

insert

Inserts an element or a number of elements into the vector at a specified position.

 

 

·        See MSDN on all the vector class members here