Purpose and overview:
Imagine that we want to manage a list of birthdays of your family and friends so that we can conveniently sort birthdays, search for birthdays within a given range, store the birthdays in a file, and read them from a file. To accomplish these purposes, well use a vector<DateType> object as a container in the main memory to store and manage the birthday information and use various operators for the DateType class implemented in programming #3 for input, output, and comparisons of dates. In addition, well also adapt the implementation of mergeTwoSortedVectors and mergeSort functions implemented in programming #2 for sorting the birthday information as a vector<DateType> object.
*********************************************************
Step 1. Revise the
functions mergeTwoSortedVectors and
mergeSort in Programming #3 to provide the capability of sorting DateType objects instead of double values:
·
First, make a copy of your entire programming
project for programming #3. Add a
copy of DateType.h and a copy of DateType.cpp
from programming #2 into this project in addition.
·
Add the line #include
"DateType.h " and the line
#include <vector> in the beginning of the .cpp file containing the main function .
Modify the prototype
bool
mergeTwoSortedVectors(vector<double>
& vecA, vector<double> & vecB, vector<double> & vecC)
to bool mergeTwoSortedVectors(vector<DateType> & vecA, vector< DateType > & vecB, vector< DateType > & vecC) and
modify the implementation so that it can
merge two sorted vectors of DateType
objects.
·
Modify
the prototype of
bool
mergeSort(vector<double> & vecToSort)
to bool mergeSort(vector<DateType>
& vecToSort) and
modify the implementation so that it can sort
a vector of DateType objects.
·
Modify
the main function so that the user can enter dates (instead double values) to make sure the newly
modified functions can work well for merging and sorting dates respectively.
Here is an example project (zipped) and an example executable (zipped) of what you should have
by the end of Step~1.
*********************************************************
Step 2. Set up a
new Visual Stidio.
Set
up your new Visual Stidio.
· DateType.h: Just copy the contents of the header file DateType.h of the enhanced DateType class you implemented for programming #2. There is no need to modify it for this programming assignment.
·
DateType.cpp: Copy the contents of the C++ source code file DateType.cpp
of the enhanced DateType class you implemented for programming #2. For
the convenience of doing both file input/output and the console input/output
through the global operators >>
and <<, you should make sure(i) for the global output
operator << if the ostream object output is cout, the output operator
will use slashes as delimiters between month, day, year; otherwise, the output
operator will use spaces as delimiters between or month, day, year, and (ii)
for the global input operator >> if the istream object input is simply
cin, the global input operator will disply promoting messages on screen through
cout while reading the three numbers for day, month, and year from input;
otherwise, the global input operator will silently read the three numbers for
day, month, and year from input. For
example, see the correspdoning code implementating these two operators in the
example project l for Step 1 above.
· dateDB.cpp: Just copy the contents of the main.cpp file containing your revised mergeTwoSortedVectors and mergeSort and main functions in Step 1 above. Well keep mergeTwoSortedVectors and mergeSort functions intact for this programming assignment. But you do need to rewrite the main function according to the specification in the following steps.
*********************************************************
Step 3. Detailed
specification of the main function in dateDB.cpp:
Overview: Your main function in dateDB.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 well use a vector<DateType> object as a container in the main memory to store and manage the date information by using various operators and member functions of the DateType class. See more details below.
Key data structures:
· To dynamically store the information of dates, you should declare in your main function vector<DateType> dateDB; to create a local vector for storing DateType objects. You should also declare in your main function local DateType objects DateType date, 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 numDateRecords; 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 users choice and use a switch statement to do things according to the choice: