Question: C++ In this assignment, you will write a struct plus two simple classes and then write a program that uses them all. The first class
C++
In this assignment, you will write a struct plus two simple classes and then write a program that uses them all. The first class is a Date class. You are given code for this at the end of this assignment, but you must make some modifications. The other is a Patient class; you are given the class definition and you must write the implementation. The program will keep track of patients at a walk-in clinic. For each patient, the clinic keeps a record of all procedures done. This is a good candidate for a class, but to simplify the assignment, we will make a procedure into a struct. We will assume that the clinic has assigned all care providers (doctors, nurses, lab technicians) with IDs and each procedure (office visit, physical exam, blood sample taken, etc.) also has an ID. Each patient will also have an ID
When the user runs the program at the start of the day, it first tries to read in from a binary file called CurrentPatients.txt. It will contain the number of patients(in binary format) followed by binary copies of records for the patients at the clinic . This information should be read and stored in an array of Patient objects. There will be a separate array, initially empty at the start of the program that will store patient records for all patients who are currently checked in at the clinic. It then asks the user to enter the current date and reads it in. It should then presents the user with a simple menu: the letter N to check in a new patient, R for checking in a returning patient, O to check out a patient, I to print out information on a particular patient, P to print the list of patients who have checked in, but not yet checked out, and Q for quitting the program.
The following tasks are done when the appropriate letter is chosen.
N: The new patients first name, last name, and birthdate are asked for and entered. The new patient ID will simply be the incremented count of patients ( first patient will have ID 1, the second, ID 2, etc.) The primary doctors ID is also entered. The new patient object is placed in both arrays: one keeping all patients, and one keeping the patients who checked in today.
R: The returning patients ID is asked for, and the array holding all patients is searched for the patient object. If found, a copy of the patient object is placed in the array for all currently checked in patients. If not found, the user is asked to try again, checking that the correct data was entered, or to treat the patient as a new patient, and the task ends.
O: Using the patients ID, the patient object is found in the array holding currently checked in patients. (If not found, the user is asked to try again, checking that the correct data was entered, or to check in the patient as a new or returning patient, and the task ends.) The procedure record is updated by entering a new entry, with the current date, procedure ID, and provider ID. The up-dated patient object is then removed from the array of currently checked in patients, and replaces the old patient object in the main array. If the update fails, a message is output.
I: Using the patients ID, the main array holding all patients is searched for the patient object. If found the information it holds: the names, birthdate, the primary doctor ID, and a list of all past procedures done (date, procedure ID, procedure provider ID) is printed to the monitor.
P: From the array holding all patients currently checked in, a list is printed in nice readable form, showing the patient ID, first and last names and the primary doctor ID for each.
Q: If the list of patients currently checked in is not empty, the list is printed out and the user asked to keep running the program so they can be checked out. If the list is empty, the program will write the patient objects in the main array to the binary file CurrentPatients.txt. It should overwrite all previous information in the file.
Processing requirements: You need to create and use two classes: the Date class and the Patient class, and a struct called procedure.
For the struct, you may use the following:
struct procedure {
Date dateOfProcedure;
int procedureID;
int procedureProviderID;
};
.
For the Date class, you may copy what is at the end of this assignment with the following changes:
The overloaded operator for += will have the prototype
void operator+=(int); // Does not return anything
2. Both the leapYear and the endOfMonth functions will have no parameters so they will have prototypes
bool leapYear( ) const; // is the year for the date a leap year?
bool endOfMonth( ) const; // is the date the last day of the month?
Note that this will mean that corresponding changes will need to be made for all function definitions that use the two functions.
3. Implement the four get member functions.
For the class Patient, you should have the following interface (public) member functions:
Patient ( int, const char * , const char *, Date, int); //Put in default values
// just as in Date class
//Use the set functions so input values are checked
~Patient();
Patient & setID ( int );
Patient & setFirstName ( const char *); //check if length of name string is <
// 15, if not, shorten to 14 letters.
Patient & setLastName ( const char *); //check if length of name string is <
// 15, if not, shorten to 14 letters.
Patient & setBirthDate ( Date);
Patient & setPrimaryDoctorID (int);
int getID();
const char * getFirstName();
const char * getLastName();
Date getBirthDate();
int getPrimaryDoctorID();
bool enterProcedure(Date procedureDate, int procedureID,
int procedureProviderID);//tries to add a new entry to record array, returns //true if added, false if cannot be added
void printAllProcedures();
The following private data members should be defined:
int ID;
char firstName[15];
char lastName [15];
Date birthdate;
int primaryDoctorID; //Add
procedure record[500];
int currentCountOfProcedures; // keeps track of how many procedures have //been recorded. if it reaches 500, no new procedures can //be entered.
You also may, but do not need to, overload the = operator to copy Patient objects. The examples of Employee class in Section 9.11 (Composition) may help you with the implementations for the class Book.
Assumptions: You may assume that all entries are correct.
Testing: You should perform your own tests to make sure that each component of your program is working. At the end, run it once to enter some new patients, then end the program, then run it again to see that the information has been correctly preserved.
You may have trouble creating large arrays of patient records. You can set the main array holding all records to 20 and the array holding currently checked patients to 10. You can also ask about another way around this problem which uses arrays of pointers to patient records.
Date class (Before changes asked for above)
// Definition of class Date in date.h
#ifndef DATE1_H
#define DATE1_H
#include
#include
using namespace std;
class Date {
friend ostream &operator<<( ostream &, const Date & ); // allows easy output to a ostream
public:
Date( int m = 1, int d = 1, int y = 1900 ); // constructor, note the default values
void setDate( int, int, int ); // set the date
const Date &operator+=( int ); // add days, modify object
bool leapYear( int) const; // is this a leap year?
bool endOfMonth( int ) const; // is this end of month?
int getMonth ( ) const; // You need to implement this
int getDay ( ) const; // You need to implement this
int getYear ( ) const; // You need to implement this
string getMonthString( ) const; // You need to implement this
private:
int month;
int day;
int year;
static const int days[]; // array of days per month
static const string monthName[]; // array of month names
void helpIncrement(); // utility function
};
#endif
// Member function definitions for Date class in separate date.cpp file
#include
#include "date.h"
#include
// Initialize static members at file scope;
// one class-wide copy.
const int Date::days[] = { 0, 31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31 };
const string Date::monthName[] = { "", "January",
"February", "March", "April", "May", "June",
"July", "August", "September", "October",
"November", "December" };
// Date constructor
Date::Date( int m, int d, int y ) { setDate( m, d, y ); }
// Set the date
void Date::setDate( int mm, int dd, int yy )
{
month = ( mm >= 1 && mm <= 12 ) ? mm : 1;
year = ( yy >= 1900 && yy <= 2100 ) ? yy : 1900;
// test for a leap year
if ( month == 2 && leapYear(year ) )
day = ( dd >= 1 && dd <= 29 ) ? dd : 1;
else
day = ( dd >= 1 && dd <= days[ month ] ) ? dd : 1;
}
// Add a specific number of days to a date
const Date &Date::operator+=( int additionalDays )
{
for ( int i = 0; i < additionalDays; i++ )
helpIncrement();
return *this; // enables cascading
}
// If the year is a leap year, return true;
// otherwise, return false
bool Date::leapYear( int testYear ) const
{
if ( testYear % 400 == 0 || ( testYear % 100 != 0 && testYear % 4 == 0 ) )
return true; // a leap year
else
return false; // not a leap year
}
// Determine if the day is the end of the month
bool Date::endOfMonth(int testDay ) const
{
if ( month == 2 && leapYear( year ) )
return (testDay == 29); // last day of Feb. in leap year
else
return (testDay == days[ month ]);
}
// Function to help increment the date
void Date::helpIncrement()
{
if ( ! endOfMonth( day )) { // date is not at the end of the month
day++;
}
else if (month < 12 ) { // date is at the end of the month, but month < 12
day = 1;
++month;
}
else // end of month and year: last day of the year
{
day = 1;
month = 1;
++year;
}
}
// Overloaded output operator
ostream &operator<<( ostream &output, const Date &d )
{
output << d.monthName[ d.month ] << ' '
<< d.day << ", " << d.year;
return output; // enables cascading
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
