A basic appointment-information
management program
Purpose:
This is essentially the enhanced version of Programming #5A.
Instead of a database for managing DateType
objects regarding dates, here we would like to have a database for managing
appointments. For this purpose, we
need to define and implement an Appointment class and use objects of
this Appointment class to store and process the appointment information
of people. You will need to use the DateType
class and the C++ string class in
the implementation of an Appointment class. Well then use this Appointment
class as a building block in implementing a simple appointment information
database program.
What to do:
- 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 should copy and paste your own DateType.h
and DateType.cpp files from
Programming #2 to replace the empty DateType.h
and DateType.cpp files
included in it.
- Understand the design of the Appointment class: Look at the interface (i.e. the member
functions and data members) of the Appointment class as defined and
commented in Appointment.h to understand what kind of data are
stored in a Appointment object and what kind of services (member
functions) an Appointment object can do for you.
- Complete the implementation of the Appointment class: Appointment.cpp contains
the implementation details of the member functions of the Appointment
class. The implementation there is not completed yet. You have to fill in
code in Appointment.cpp to complete the implementation of these
member functions according to the
specification comments of these member functions in Appointment.h. For
example, you need to implement the relational operator > and others like < and <= so that
we can compare Appointment objects. For any two Appointment objects, we consider C1 < C2 as true when the appointment date
recorded in C1 is less than that in C2. If C1 and C2 have the same
appointment day, then the order of C1 and C2 is determined based on the
alphabetical order of their full names (i.e. comparing the last name first
and then comparing the first name if they happen to have the same last
name). In other words, C1 < C2
is true either (i) when the logic expression C1.CompareAppointment (C2) = = GREATER is true or (ii) when
the logic expression C1.SameAppointmentDay
(C2) = = true && C1.CompareFullName
(C2) = = GREATER is true.
- Test the implementation of your Appointment class: The main
function in AppointmentTest.cpp given to you is intended as the test ground for testing
whether your implementation of the Appointment class is sound. At
the moment, we have a vector of Appointment objects (initialized to
hold 5 Appointment objects) to serve as a appointment-information
database. The code in the main function then does some basic operations
such as reading the appointment information of 5 persons into the
database, display the appointment information of these people from the
database, search the database for the appointment information of persons
of a particular name, and search the database to find out the appointment
information of all people born on a particular date. You should add
similar code to extensively test your implementation in Step 3 above.
- Incorporate and
revise the functions mergeTwoSortedVectors
and mergeSort similar to what you did in Programming #3 and #5A into AppointmentTest.cpp
to provide the capability of
sorting a vector of Appointment
objects instead of a vector of double
values: First, make a
copy of those two functions from programming #3 or #5A into AppointmentTest.cpp in this
project. Modify the prototype bool mergeTwoSortedVectors(vector<double> & vecA,
vector<double> & vecB, vector<double> & vecC) to bool mergeTwoSortedVectors(vector<
Appointment >
& vecA, vector< Appointment
> & vecB, vector< Appointment > & vecC) and
modify the implementation so that it can merge two sorted vectors
of Appointment objects. Modify
the prototype of bool mergeSort(vector<double> & vecToSort) to bool mergeSort(vector<
Appointment >
& vecToSort) and modify the implementation so that it can sort a vector of Appointment objects. Add
your own code in the main function to create a vector of Appointment objects and then test to verify
that the newly modified functions can work well for merging and sorting Appointment objects.
- Implement your own very simple
appointment information database program in AppointmentDB.cpp: After you are sure
your new implementation of the merge sort stuff does work, make a copy of
AppointmentTest.cpp in the
project folder and name it AppointmentDB.cpp. Under Visual studio, remove AppointmentTest.cpp
from the project and add AppointmentDB.cpp into the project.
Then totally rewrite the main function in AppointmentDB.cpp to
provide a menu serving as a simple database user interface similar
to what you did for Program#5A. Please
carefully examine the details provided in the section below on Detailed
specification of the main function in AppointmentDB.cpp.
- Testing and
submission: Extensively test all the services
provided by your program. When you are sure things are working perfectly, you are done, submit all your source code files (all .h and .cpp
files) and the self-evaluation report as a zip file under Canvas.
Detailed specification of the main function in AppointmentDB.cpp:
Overview: Your main function in Appointment.cpp
should provide services to read appointment information from the keyboard or
files, save appointment information into files, search for appointment
information within a given range of dates, and sort appointments in order. To
accomplish these purposes, in the main function well use a vector<Appointment> object as a
container in the main memory to store and manage the date information by using
various operators and member functions of the Appointment class. See more details below.
Key data
structures:
·
To dynamically store the information of
appointments, you should declare in your main function vector<Appointment>
appointmentDB; to create a local vector for
storing Appointment objects. You should also declare in your main function
a local Appointment object like
aAppointment, 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 string string filename 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 numAppointmentRecords;
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:
- K:
to read an Appointment object
manually Keyed in by the user and
store it (i.e. push_back) in the
end of the vector appointmentDB,
- R:
to clear the vector appointmentDB into an empty vector first and
then Read information of
Appointment objects from a file specified by the users into the vector appointmentDB,
- D:
to Display all the Appointment
objects currently stored in the vector appointmentDB to the screen,
- M:
to Modify one of the
Appointment objects by reading a new Appointment object from the keyboard
to overwrite the contents of an existing Appointment object (specified by the user) in the vector appointmentDB,
- X:
to eXclude one of the
Appointment objects by removing it from the vector appointmentDB,
- W:
to Write the Appointment
objects currently stored in the vector appointmentDB into a file
specified by the user,
- A to Find and display Appointment objects
with appointment days falling
between two dates specified by the user,
- E to Find
and display Appointment objects with appointment days within the
same week
of the date specified by the user,
- N
to Find and display Appointment objects with the full Name given
by the user,
- S:
to Sort the Appointment
objects currently stored in the vector appointmentDB in order,
- Q: to Quit
the program.
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:
- If the choice is K: the program should ask the local Appointment object aAppointment to read in a new
record of appointment information (i.e.
cin >> aAppointment; ) and then add the Appointment object into the end of the vector appointmentDB
(i.e. appointmentDB.push_back(aAppointment); ).
- If the choice is R: the program should ask the user to
provide the name of an input file (e.g. dates.txt), and read the file name into the string variable filename (i.e. cin >> filename; ).
The program should then open that file through the input file
object fin (i.e. fin.open(filename ); ) and read the
first integer from the file into umAppointmentRecords (i.e.
fin >>
umAppointmentRecords; ), and the program should check
to make sure this number is non-negative. The program should clear appointmentDB (i.e. appointmentDB.clear( ); ) to an empty vector, and
then set up a loop that iterates for umAppointmentRecords
iterations to repeatedly read in a Appointment
object from the file into the local
Appointment object aAppointment (i.e. fin
>> aAppointment;
) and then add the appointment into the end of the vector appointmentDB
(i.e. appointmentDB.push_back(aAppointment); ). After the loop
is finished, the program should close that file (i.e. fin.close( ); ).
- If the choice is D: the program should set up a loop to display each
element appointmentDB [i]
in the vector appointmentDB (i.e. cout
<< appointmentDB[i] ; ).
- If the choice is M: the program should ask the user the index
i of the date in appointmentDB[i] he/she wants to modify, read the index as an integer from
the user, check to make sure i is non-negative and less than appointmentDB.size( ), and read the new
appointment information into appointmentDB[i] (i.e. cin >> appointmentDB[i] ; ).
- If the choice is X: the program should ask the user the index
i of the date in appointmentDB[i] he/she wants to exclude, read the index as an integer from
the user, check to make sure i is non-negative and less than appointmentDB.size( ), and then erase the object
from the vector by calling the erase method (i.e. appointmentDB.erase(appointmentDB.begin(
)+ i;
).
- If the choice is W: the program should ask the user to
provide the name of an output file (e.g. appointments.txt), and read the file name into a string
variable filename (i.e. cin >> filename; ). The program should then open that
file through the output file object fout
(i.e. fout.open(filename ); ) and write the
size of appointmentDB into the
file (i.e. fout << appointmentDB.size( ); ). The program should then set up a loop that iterates
for appointmentDB.size( ) iterations to
repeatedly write each element appointmentDB[i]
into the file (i.e. fout
<< appointmentDB[i]);
). After the loop is finished, the program should close that
file (i.e. fout.close( ); ).
- If the choice is N, the program should ask the user to
provide the first name and the last name (i.e. cin >> aFirstName; and cin >>
aLastName; ), and then the program
should set up a loop to check each
element appointmentDB[i]
in the vector appointmentDB and display the contents of appointmentDB[i] if appointmentDB[i] has the same first name and
the last name (i.e. if appointmentDB[i].SameFullName(aFirsttName,
aLastName) = = true).
- If the choice is A, the program should ask the user to
provide the beginning date and the ending date of the date range (i.e. cin >> dBegin; and cin >>
dEnd; ), and then the
program should set up a loop to
check each element appointmentDB[i]
in the vector appointmentDB and display the contents of appointmentDB[i] if the appointment date of appointmentDB[i] is within the range (i.e.
if appointmentDB[i].CompareAppointmentDay( dBegin)!=
LESS && appointmentDB[i].CompareAppointmentDay(
dEnd)!= GREATER is true).
- If the choice is E, the program should ask the user to
provide the date d, and then the
program should set up a loop to
check each element appointmentDB[i]
in the vector appointmentDB and display the contents of appointmentDB[i] if the appointment falls
within the same week of d.
- For this assignment, lets use the
convention that counts Sunday as the first day of the week and Saturday
as the last day of the week. To accomplish the task of option E,
you need to first determine the beginning date dBegin (a Sunday)
and the ending date dEnd (a Saturday) of the week that contains
the date d.
- Note that
you can have Sunday 5/3/2015 as a reference date. Store 5/3/2015 in a date dReference and you can
calculate the number of days between d and 5/3/2015 as dReference
d. You can then easily
find out the beginning date dBegin (a Sunday) and the
ending date dEnd (a Saturday) of the week that contains the date d
according to the value of (dReference d )%7. (Think about it.)
- For
example, (dReference d )%7 equals 3 when d is 5/20/2015. Therefore dBegin
should equal d-3,
which is Sunday 5/17/2015, while dEnd should equal dBegin +6, which is Saturday 5/23/2015.
- If the choice is S, the program should call the mergeSort function
sort the dates in order (i.e. mergeSort(appointmentDB
); ).
- If the choice is Q, the program will output a thank-you
message, exit the loop, and end the program.
Reference:
You can click the individual
member function below to access the related sample code in the online MSDN
documents.
·
Vector class: Non-iterator member functions
(no iterators used):
vector
|
Constructs a vector of a specific size or with elements of
a specific value or as a copy of some other vector.
|
size
|
Returns the number of elements in the vector.
|
clear
|
Erases the elements of the vector.
|
empty
|
Tests if the vector container is empty.
|
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.
|
swap
|
Exchanges the elements of two vectors.
|
|
|
·
Vector class: iterator-related member
functions (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.
|
·
You can click this
link to see the full list of the vector class members.