SlideShare a Scribd company logo
Question: I need help with c++ Simple Classes Assigment. i get this code working but i have to
change my setID from numbers in loop{1,2,3,4,5} to setID to *char which it have to start with
lastName, then lastName, then year of birth.
c++ Simple Classes Assignment
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, which is formed by the last name
concatenated with the first name and the year of birth. All other IDs (care providers, procedures)
will be just integers.
When the user runs the program at the start of the day, it first tries to read in from a binary file
called CurrentPatients.dat. 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 patient’s first name, last name, and birthdate are asked for and entered. The new
patient ID will be the last name concatenated with the first name and the year of birth. (Example:
SmithJohn1998) The primary doctor’s 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 patient’s 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 returned to the main menu after asking them to
either try R again, making sure the correct ID was entered, or choose N to enter the patient as a
new patient.
O: Using the patient’s ID, the patient object is found in the array holding currently checked in
patients. (If not found, the user is returned to the main menu after asking them to either try O
again, making sure the correct ID was entered, or choose N or R to check in the patient as a new
or returing patient.) 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 patient’s 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 patient.
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.dat. It should
overwrite all previous information in the file.
//Date1.h
#ifndef Date_h
#define Date_h
#include
#include
using namespace std;
class Date1
{
friend ostream &operator<<(ostream& , const Date1 &);
public:
Date1(int m1 = 1, int d1 = 1, int y1 = 1900);
void setDate1(int, int, int);
bool leapYear1() const;
bool endOfMonth1() const;
int getMonth1() const
{
return month1;
}
int getDay1() const
{
return day1;
}
int getYear1() const
{
return year1;
}
string getMonthString1() const;
void operator+=(int);
Date1& operator=(Date1 other1);
private:
int month1;
int day1;
int year1;
static const int days1[];
static const string monthName1[];
void helpIncrement1();
};
#endif
//Date1.cpp
#include
#include "Date1.h"
#include
const int Date1::days1[] =
{
0, 31, 28,
31, 30, 31,
30, 31, 31,
30, 31, 30, 31
};
const string Date1::monthName1[] =
{ "", "January", "February", "March",
"April", "May", "June", "July",
"August", "September",
"October", "November", "December"
};
Date1::Date1(int m1, int d1, int y1)
{
setDate1(m1, d1, y1);
}
void Date1::setDate1(int mm1, int dd1, int yy1)
{
month1 = (mm1 >= 1 && mm1 <= 12) ? mm1 : 1;
year1 = (yy1 >= 1900 && yy1 <= 2100) ? yy1 : 1900;
if (month1 == 2 && leapYear1())
day1 = (dd1 >= 1&& dd1 <= 29) ? dd1 : 1;
else
day1 = (dd1 >= 1&& dd1 <= days1[month1]) ? dd1 : 1;
}
void Date1::operator+=(int additionalDays1)
{
for (int i1 = 0; i1 < additionalDays1; i1++)
helpIncrement1();
}
bool Date1::leapYear1() const
{
if (year1 % 400 == 0 || (year1 % 100 != 0&& year1 % 4 == 0))
return true;
else
return false;
}
bool Date1::endOfMonth1() const
{
if (month1 == 2 && leapYear1())
return (day1 == 29);
else
return (day1 == days1[month1]);
}
void Date1::helpIncrement1()
{
if (!endOfMonth1())
{
day1++;
}
else if (month1 < 12)
{
day1 = 1;
++month1;
}
else
{
day1 = 1;
month1 = 1;
++year1;
}
}
Date1& Date1::operator=(Date1 other1)
{
day1 = other1.day1;
month1 = other1.month1;
year1 = other1.year1;
return *this;
}
ostream &operator<<(ostream &output1, const Date1& d1)
{
output1 << d1.monthName1[d1.month1]<< ' ' << d1.day1 << ", " << d1.year1;
return output1;
}
string Date1::getMonthString1() const
{
return monthName1[month1];
}
//Patient1.h
#ifndef Patient_h
#define Patient_h
#include "Date1.h"
#include
struct procedure1
{
Date1 dateOfProcedure1;
int procedureID1;
int procedureProviderID1;
};
class Patient1
{
private:
int ID1;
char firstName1[15];
char lastName1[15];
Date1 birthdate1;
int primaryDoctorID1;
procedure1 record1[500];
int currentCountOfProcedures1;
public:
Patient1(int, const char *, const char *, Date1, int);
Patient1() : ID1(0), firstName1{}, lastName1{}, birthdate1(0, 0, 0), primaryDoctorID1(0) {};
void setID1(int);
void setFirstName1(const char *);
void setLastName1(const char *);
void setBirthDate1(Date1);
void setPrimaryDoctorID1(int);
int getID1();
const char * getFirstName1();
const char * getLastName1();
Date1 getBirthDate1();
int getPrimaryDoctorID1();
Patient1& operator=(Patient1 other1);
bool enterProcedure1(Date1 procedureDate1, int procedureID1, int procedureProviderID1);
void printAllProcedures1();
};
#endif
//Patient1.cpp
#include "Patient1.h"
#include
using namespace std;
Patient1::Patient1(int id1, const char * first1, const char *last1, Date1 birth1, int doctor1)
{
setID1(id1);
setFirstName1(first1);
setLastName1(last1);
setBirthDate1(birth1);
setPrimaryDoctorID1(doctor1);
};
void Patient1::setID1(int id1)
{
ID1 = id1;
}
void Patient1::setFirstName1(const char * first1)
{
if (strlen(first1) > 15)
strncpy_s(firstName1, first1, 14);
else
strcpy_s(firstName1, first1);
}
void Patient1::setLastName1(const char * last1)
{
if (strlen(last1) > 15)
strncpy_s(lastName1, last1, 14);
else
strcpy_s(lastName1, last1);
}
void Patient1::setBirthDate1(Date1 birth1)
{
birthdate1 = birth1;
}
void Patient1::setPrimaryDoctorID1(int doctor1)
{
primaryDoctorID1 = doctor1;
}
int Patient1::getID1()
{
return ID1;
}
const char * Patient1::getFirstName1()
{
return firstName1;
}
const char * Patient1::getLastName1()
{
return lastName1;
}
Date1 Patient1::getBirthDate1()
{
return birthdate1;
}
int Patient1::getPrimaryDoctorID1()
{
return primaryDoctorID1;
}
bool Patient1::enterProcedure1(Date1 procedureDate1, int procedureID1, int
procedureProviderID1)
{
if (currentCountOfProcedures1 > 500)
{
cout << "Can't add more procedures" << endl;
return false;
}
else
{
record1[currentCountOfProcedures1].dateOfProcedure1 = procedureDate1;
record1[currentCountOfProcedures1].procedureID1 = procedureID1;
record1[currentCountOfProcedures1].procedureProviderID1 = procedureProviderID1;
currentCountOfProcedures1++;
return true;
}
}
void Patient1::printAllProcedures1()
{
cout << "Procedures of the patient"<< endl;
for (int i1 = 0; i1 < currentCountOfProcedures1; i1++)
{
cout << "Procedure-Date: " << record1[i1].dateOfProcedure1 << endl;
cout << "Procedure-ID: " << record1[i1].procedureID1 << endl;
cout << "Provider-ID: "<< record1[i1].procedureProviderID1 << endl;
}
}
Patient1& Patient1::operator=(Patient1 other1)
{
ID1 = other1.ID1;
strcpy_s(firstName1, other1.firstName1);
strcpy_s(lastName1, other1.lastName1);
birthdate1 = other1.birthdate1;
primaryDoctorID1 = other1.primaryDoctorID1;
for (int i1 = 0; i1 < other1.currentCountOfProcedures1; i1++)
{
record1[i1] = other1.record1[i1];
}
currentCountOfProcedures1 = other1.currentCountOfProcedures1;
return *this;
}
//Menu.cpp
#include
#include
#include "Patient1.h"
#include "Date1.h"
using namespace std;
void Menu1();
void Remove1(Patient1 checkIn1[], int& count1, int index1);
int main(int argc, const char * argv[])
{
Patient1 checkIn1[10];
Patient1 patient1[20];
char choice1;
int i1 = 0;
int id1 = 0,
doctor1 = 0,
countAll1 = 0,
count1 = 0;
int day1, month1, year1;
char first1[15], last1[15];
Date1 birthdate1, current1;
bool found1 = false;
ifstream inFile1;
inFile1.open("CurrentPatients1.txt", ios::in | ios::binary);
if (inFile1.is_open())
{
inFile1.read((char*)&countAll1, sizeof(int));
for (int i1 = 0; i1 < countAll1; i1++)
{
inFile1.read((char*)&patient1[i1], sizeof(Patient1));
}
inFile1.close();
}
cout << "Enter present date" << endl;
cout << "Day: ";
cin >> day1;
cout << "Month: ";
cin >> month1;
cout << "Year: ";
cin >> year1;
current1.setDate1(month1, day1, year1);
do
{
Menu1();
cin >> choice1;
switch (choice1)
{
case 'A':
cout<< "---------------------------" << endl;
cout<< "Check-In a new patient" << endl << endl;
cout<< "Patient-ID: ";
cout<< countAll1 + 1 << endl;
checkIn1[count1].setID1(countAll1 + 1);
cout<< "First name: ";
cin>> first1;
checkIn1[count1].setFirstName1(first1);
cout<< "Last name: ";
cin>> last1;
checkIn1[count1].setLastName1(last1);
cout<< "Doctor-ID: ";
cin>> doctor1;
checkIn1[count1].setPrimaryDoctorID1(doctor1);
cout<< "Birthdate " << endl;
cout<< "Day: ";
cin>> day1;
cout<< "Month: ";
cin>> month1;
cout<< "Year: ";
cin>> year1;
birthdate1.setDate1(month1, day1, year1);
checkIn1[count1].setBirthDate1(birthdate1);
patient1[countAll1] = checkIn1[count1];
count1++;
countAll1++;
break;
case 'B':
cout<< "---------------------------" << endl;
cout<< "Check-In a returning patient" << endl << endl;
found1 = false;
i1 = 0;
do
{
cout << "Enter Patient-ID: ";
cin >> id1;
do
{
if (patient1[i1].getID1() == id1)
{
checkIn1[count1] = patient1[i1];
count1++;
found1 = true;
}
i1++;
} while (!found1 && i1 < countAll1);
if (!found1)
{
cout << "Not available"<< endl;
cout << "Check-In as a new patient? N or Y: ";
cin >> choice1;
}
} while (!found1 && choice1 == 'N');
break;
case 'C':
found1 = false;
cout<< "---------------------------" << endl;
cout<< "Check-Out a patient" << endl;
i1 = 0;
do
{
cout << "Enter Checked-Out patient-ID: ";
cin >> id1;
do
{
if (checkIn1[i1].getID1() == id1)
{
cout<< "Provider-ID: ";
cin>> doctor1;
cout<< "Procedure-ID: ";
cin>> id1;
cout<< checkIn1[i1].enterProcedure1(current1, id1, doctor1);
for (int j = 0; j < countAll1; j++)
if (patient1[j].getID1() == checkIn1[i1].getID1())
{
patient1[j].enterProcedure1(current1, id1, doctor1);
cout << j;
cout << "Patient-ID: " << j + 1<< " Checked-Out" << endl << endl;
}
Remove1(checkIn1, count1, i1);
found1 = true;
}
i1++;
} while (!found1 && i1 < count1);
if (!found1)
{
cout << "Not available"<< endl;
cout << "Checked-In as a new patient / Checked-In as a returning patient? N or Y:
";
cin >> choice1;
}
} while (!found1 && choice1 == 'N');
break;
case 'D':
found1 = false;
cout<< "---------------------------" << endl;
cout<< "Display all info of the patient" << endl << endl;
cout<< "Enter Patient-ID: ";
cin>> id1;
i1 = 0;
do
{
if (patient1[i1].getID1() == id1)
{
cout << "Patient-ID "<< patient1[i1].getID1() << endl;
cout << "Name: "<< patient1[i1].getFirstName1() << " " <<
patient1[i1].getLastName1() << endl;
cout << "Birthdate: "<< patient1[i1].getBirthDate1() << endl;
cout << "Doctor-ID: "<< patient1[i1].getPrimaryDoctorID1() << endl;
patient1[i1].printAllProcedures1();
found1 = true;
}
i1++;
} while (!found1 && i1 < countAll1);
if (!found1)
cout << "Not available" << endl;
break;
case 'E':
cout<< "---------------------------" << endl;
cout<< "Patient checked-in yet not checked-out" << endl<< endl;
if (count1> 0)
{
for (int i1 = 0; i1 < count1; i1++)
{
cout << "Patient-ID "<< checkIn1[i1].getID1() << endl;
cout << "Name: "<< checkIn1[i1].getFirstName1() << " " <<
checkIn1[i1].getLastName1() << endl;
cout << "Birthdate: "<< checkIn1[i1].getBirthDate1() << endl;
cout << "Doctor-ID: "<< checkIn1[i1].getPrimaryDoctorID1() << endl << endl;
}
}
else
cout << "All patients checked-out"<< endl << endl;
break;
case 'F':
cout<< "---------------------------" << endl;
if (count1 == 0)
{
ofstream outFile;
outFile.open("CurrentPatients1.txt", ios::out | ios::binary);
if (outFile.is_open())
{
outFile.write((char*)&countAll1, sizeof(int));
for (int i1 = 0; i1 < countAll1; i1++)
outFile.write((char*)&patient1[i1], sizeof(Patient1));
outFile.close();
cout << "Finish"<< endl;
}
}
else
{
for (int i1 = 0; i1 < count1; i1++)
{
cout << checkIn1[i1].getID1() << endl;
cout << checkIn1[i1].getFirstName1() << " " << checkIn1[i1].getLastName1() <<
endl;
cout << checkIn1[i1].getBirthDate1() << endl;
cout << checkIn1[i1].getPrimaryDoctorID1() << endl;
}
choice1 = 'A';
}
break;
}
} while (choice1 != 'F' && choice1 != 'f');
return 0;
}
void Menu1()
{
cout << "-------------------------------"<< endl;
cout << "Menu" << endl;
cout << "A : Check-in new patient"<< endl;
cout << "B : Check-in returning patient"<< endl;
cout << "C : Check-out a patient" << endl;
cout << "D : Display info of a patient"<< endl;
cout << "E : Display list of patients who checked-in yet not checked-out" << endl;
cout << "F : Quit" << endl;
cout << "Enter choice (A, B, C, D, E, F): ";
}
void Remove1(Patient1 checkIn1[], int& count1, int index1)
{
for (int i1 = index1; i1 < count1; i1++)
checkIn1[i1] = checkIn1[i1 + 1];
count1--;
}
Solution
#ifndef Date_h
#define Date_h
#include
#include
using namespace std;
class Date1
{
friend ostream &operator<<(ostream& , const Date1 &);
public:
Date1(int m1 = 1, int d1 = 1, int y1 = 1900);
void setDate1(int, int, int);
bool leapYear1() const;
bool endOfMonth1() const;
int getMonth1() const
{
return month1;
}
int getDay1() const
{
return day1;
}
int getYear1() const
{
return year1;
}
string getMonthString1() const;
void operator+=(int);
Date1& operator=(Date1 other1);
private:
int month1;
int day1;
int year1;
static const int days1[];
static const string monthName1[];
void helpIncrement1();
};
#endif
//Date1.cpp
#include
#include "Date1.h"
#include
const int Date1::days1[] =
{
0, 31, 28,
31, 30, 31,
30, 31, 31,
30, 31, 30, 31
};
const string Date1::monthName1[] =
{ "", "January", "February", "March",
"April", "May", "June", "July",
"August", "September",
"October", "November", "December"
};
Date1::Date1(int m1, int d1, int y1)
{
setDate1(m1, d1, y1);
}
void Date1::setDate1(int mm1, int dd1, int yy1)
{
month1 = (mm1 >= 1 && mm1 <= 12) ? mm1 : 1;
year1 = (yy1 >= 1900 && yy1 <= 2100) ? yy1 : 1900;
if (month1 == 2 && leapYear1())
day1 = (dd1 >= 1&& dd1 <= 29) ? dd1 : 1;
else
day1 = (dd1 >= 1&& dd1 <= days1[month1]) ? dd1 : 1;
}
void Date1::operator+=(int additionalDays1)
{
for (int i1 = 0; i1 < additionalDays1; i1++)
helpIncrement1();
}
bool Date1::leapYear1() const
{
if (year1 % 400 == 0 || (year1 % 100 != 0&& year1 % 4 == 0))
return true;
else
return false;
}
bool Date1::endOfMonth1() const
{
if (month1 == 2 && leapYear1())
return (day1 == 29);
else
return (day1 == days1[month1]);
}
void Date1::helpIncrement1()
{
if (!endOfMonth1())
{
day1++;
}
else if (month1 < 12)
{
day1 = 1;
++month1;
}
else
{
day1 = 1;
month1 = 1;
++year1;
}
}
Date1& Date1::operator=(Date1 other1)
{
day1 = other1.day1;
month1 = other1.month1;
year1 = other1.year1;
return *this;
}
ostream &operator<<(ostream &output1, const Date1& d1)
{
output1 << d1.monthName1[d1.month1]<< ' ' << d1.day1 << ", " << d1.year1;
return output1;
}
string Date1::getMonthString1() const
{
return monthName1[month1];
}
//Patient1.h
#ifndef Patient_h
#define Patient_h
#include "Date1.h"
#include
struct procedure1
{
Date1 dateOfProcedure1;
int procedureID1;
int procedureProviderID1;
};
class Patient1
{
private:
int ID1;
char firstName1[15];
char lastName1[15];
Date1 birthdate1;
int primaryDoctorID1;
procedure1 record1[500];
int currentCountOfProcedures1;
public:
Patient1(int, const char *, const char *, Date1, int);
Patient1() : ID1(0), firstName1{}, lastName1{}, birthdate1(0, 0, 0), primaryDoctorID1(0) {};
void setID1(int);
void setFirstName1(const char *);
void setLastName1(const char *);
void setBirthDate1(Date1);
void setPrimaryDoctorID1(int);
int getID1();
const char * getFirstName1();
const char * getLastName1();
Date1 getBirthDate1();
int getPrimaryDoctorID1();
Patient1& operator=(Patient1 other1);
bool enterProcedure1(Date1 procedureDate1, int procedureID1, int procedureProviderID1);
void printAllProcedures1();
};
#endif
//Patient1.cpp
#include "Patient1.h"
#include
using namespace std;
Patient1::Patient1(int id1, const char * first1, const char *last1, Date1 birth1, int doctor1)
{
setID1(id1);
setFirstName1(first1);
setLastName1(last1);
setBirthDate1(birth1);
setPrimaryDoctorID1(doctor1);
};
void Patient1::setID1(int id1)
{
ID1 = id1;
}
void Patient1::setFirstName1(const char * first1)
{
if (strlen(first1) > 15)
strncpy_s(firstName1, first1, 14);
else
strcpy_s(firstName1, first1);
}
void Patient1::setLastName1(const char * last1)
{
if (strlen(last1) > 15)
strncpy_s(lastName1, last1, 14);
else
strcpy_s(lastName1, last1);
}
void Patient1::setBirthDate1(Date1 birth1)
{
birthdate1 = birth1;
}
void Patient1::setPrimaryDoctorID1(int doctor1)
{
primaryDoctorID1 = doctor1;
}
int Patient1::getID1()
{
return ID1;
}
const char * Patient1::getFirstName1()
{
return firstName1;
}
const char * Patient1::getLastName1()
{
return lastName1;
}
Date1 Patient1::getBirthDate1()
{
return birthdate1;
}
int Patient1::getPrimaryDoctorID1()
{
return primaryDoctorID1;
}
bool Patient1::enterProcedure1(Date1 procedureDate1, int procedureID1, int
procedureProviderID1)
{
if (currentCountOfProcedures1 > 500)
{
cout << "Can't add more procedures" << endl;
return false;
}
else
{
record1[currentCountOfProcedures1].dateOfProcedure1 = procedureDate1;
record1[currentCountOfProcedures1].procedureID1 = procedureID1;
record1[currentCountOfProcedures1].procedureProviderID1 = procedureProviderID1;
currentCountOfProcedures1++;
return true;
}
}
void Patient1::printAllProcedures1()
{
cout << "Procedures of the patient"<< endl;
for (int i1 = 0; i1 < currentCountOfProcedures1; i1++)
{
cout << "Procedure-Date: " << record1[i1].dateOfProcedure1 << endl;
cout << "Procedure-ID: " << record1[i1].procedureID1 << endl;
cout << "Provider-ID: "<< record1[i1].procedureProviderID1 << endl;
}
}
Patient1& Patient1::operator=(Patient1 other1)
{
ID1 = other1.ID1;
strcpy_s(firstName1, other1.firstName1);
strcpy_s(lastName1, other1.lastName1);
birthdate1 = other1.birthdate1;
primaryDoctorID1 = other1.primaryDoctorID1;
for (int i1 = 0; i1 < other1.currentCountOfProcedures1; i1++)
{
record1[i1] = other1.record1[i1];
}
currentCountOfProcedures1 = other1.currentCountOfProcedures1;
return *this;
}
//Menu.cpp
#include
#include
#include "Patient1.h"
#include "Date1.h"
using namespace std;
void Menu1();
void Remove1(Patient1 checkIn1[], int& count1, int index1);
int main(int argc, const char * argv[])
{
Patient1 checkIn1[10];
Patient1 patient1[20];
char choice1;
int i1 = 0;
int id1 = 0,
doctor1 = 0,
countAll1 = 0,
count1 = 0;
int day1, month1, year1;
char first1[15], last1[15];
Date1 birthdate1, current1;
bool found1 = false;
ifstream inFile1;
inFile1.open("CurrentPatients1.txt", ios::in | ios::binary);
if (inFile1.is_open())
{
inFile1.read((char*)&countAll1, sizeof(int));
for (int i1 = 0; i1 < countAll1; i1++)
{
inFile1.read((char*)&patient1[i1], sizeof(Patient1));
}
inFile1.close();
}
cout << "Enter present date" << endl;
cout << "Day: ";
cin >> day1;
cout << "Month: ";
cin >> month1;
cout << "Year: ";
cin >> year1;
current1.setDate1(month1, day1, year1);
do
{
Menu1();
cin >> choice1;
switch (choice1)
{
case 'A':
cout<< "---------------------------" << endl;
cout<< "Check-In a new patient" << endl << endl;
cout<< "Patient-ID: ";
cout<< countAll1 + 1 << endl;
checkIn1[count1].setID1(countAll1 + 1);
cout<< "First name: ";
cin>> first1;
checkIn1[count1].setFirstName1(first1);
cout<< "Last name: ";
cin>> last1;
checkIn1[count1].setLastName1(last1);
cout<< "Doctor-ID: ";
cin>> doctor1;
checkIn1[count1].setPrimaryDoctorID1(doctor1);
cout<< "Birthdate " << endl;
cout<< "Day: ";
cin>> day1;
cout<< "Month: ";
cin>> month1;
cout<< "Year: ";
cin>> year1;
birthdate1.setDate1(month1, day1, year1);
checkIn1[count1].setBirthDate1(birthdate1);
patient1[countAll1] = checkIn1[count1];
count1++;
countAll1++;
break;
case 'B':
cout<< "---------------------------" << endl;
cout<< "Check-In a returning patient" << endl << endl;
found1 = false;
i1 = 0;
do
{
cout << "Enter Patient-ID: ";
cin >> id1;
do
{
if (patient1[i1].getID1() == id1)
{
checkIn1[count1] = patient1[i1];
count1++;
found1 = true;
}
i1++;
} while (!found1 && i1 < countAll1);
if (!found1)
{
cout << "Not available"<< endl;
cout << "Check-In as a new patient? N or Y: ";
cin >> choice1;
}
} while (!found1 && choice1 == 'N');
break;
case 'C':
found1 = false;
cout<< "---------------------------" << endl;
cout<< "Check-Out a patient" << endl;
i1 = 0;
do
{
cout << "Enter Checked-Out patient-ID: ";
cin >> id1;
do
{
if (checkIn1[i1].getID1() == id1)
{
cout<< "Provider-ID: ";
cin>> doctor1;
cout<< "Procedure-ID: ";
cin>> id1;
cout<< checkIn1[i1].enterProcedure1(current1, id1, doctor1);
for (int j = 0; j < countAll1; j++)
if (patient1[j].getID1() == checkIn1[i1].getID1())
{
patient1[j].enterProcedure1(current1, id1, doctor1);
cout << j;
cout << "Patient-ID: " << j + 1<< " Checked-Out" << endl << endl;
}
Remove1(checkIn1, count1, i1);
found1 = true;
}
i1++;
} while (!found1 && i1 < count1);
if (!found1)
{
cout << "Not available"<< endl;
cout << "Checked-In as a new patient / Checked-In as a returning patient? N or Y:
";
cin >> choice1;
}
} while (!found1 && choice1 == 'N');
break;
case 'D':
found1 = false;
cout<< "---------------------------" << endl;
cout<< "Display all info of the patient" << endl << endl;
cout<< "Enter Patient-ID: ";
cin>> id1;
i1 = 0;
do
{
if (patient1[i1].getID1() == id1)
{
cout << "Patient-ID "<< patient1[i1].getID1() << endl;
cout << "Name: "<< patient1[i1].getFirstName1() << " " <<
patient1[i1].getLastName1() << endl;
cout << "Birthdate: "<< patient1[i1].getBirthDate1() << endl;
cout << "Doctor-ID: "<< patient1[i1].getPrimaryDoctorID1() << endl;
patient1[i1].printAllProcedures1();
found1 = true;
}
i1++;
} while (!found1 && i1 < countAll1);
if (!found1)
cout << "Not available" << endl;
break;
case 'E':
cout<< "---------------------------" << endl;
cout<< "Patient checked-in yet not checked-out" << endl<< endl;
if (count1> 0)
{
for (int i1 = 0; i1 < count1; i1++)
{
cout << "Patient-ID "<< checkIn1[i1].getID1() << endl;
cout << "Name: "<< checkIn1[i1].getFirstName1() << " " <<
checkIn1[i1].getLastName1() << endl;
cout << "Birthdate: "<< checkIn1[i1].getBirthDate1() << endl;
cout << "Doctor-ID: "<< checkIn1[i1].getPrimaryDoctorID1() << endl << endl;
}
}
else
cout << "All patients checked-out"<< endl << endl;
break;
case 'F':
cout<< "---------------------------" << endl;
if (count1 == 0)
{
ofstream outFile;
outFile.open("CurrentPatients1.txt", ios::out | ios::binary);
if (outFile.is_open())
{
outFile.write((char*)&countAll1, sizeof(int));
for (int i1 = 0; i1 < countAll1; i1++)
outFile.write((char*)&patient1[i1], sizeof(Patient1));
outFile.close();
cout << "Finish"<< endl;
}
}
else
{
for (int i1 = 0; i1 < count1; i1++)
{
cout << checkIn1[i1].getID1() << endl;
cout << checkIn1[i1].getFirstName1() << " " << checkIn1[i1].getLastName1() <<
endl;
cout << checkIn1[i1].getBirthDate1() << endl;
cout << checkIn1[i1].getPrimaryDoctorID1() << endl;
}
choice1 = 'A';
}
break;
}
} while (choice1 != 'F' && choice1 != 'f');
return 0;
}
void Menu1()
{
cout << "-------------------------------"<< endl;
cout << "Menu" << endl;
cout << "A : Check-in new patient"<< endl;
cout << "B : Check-in returning patient"<< endl;
cout << "C : Check-out a patient" << endl;
cout << "D : Display info of a patient"<< endl;
cout << "E : Display list of patients who checked-in yet not checked-out" << endl;
cout << "F : Quit" << endl;
cout << "Enter choice (A, B, C, D, E, F): ";
}
void Remove1(Patient1 checkIn1[], int& count1, int index1)
{
for (int i1 = index1; i1 < count1; i1++)
checkIn1[i1] = checkIn1[i1 + 1];
count1--;
}

More Related Content

PDF
Below is my program, I just have some issues when I want to check ou.pdf
PDF
programming Code in C thatloops requesting information about patie.pdf
DOCX
Hospital management system
PDF
In this programming assignment, you will be creating a Health Inform.pdf
PDF
KingsleyUsen_HospitalDatabase
PDF
Implement in C++Create a class named Doctor that has three member .pdf
PDF
Design various classes and write a program to computerize the billing.pdf
DOCX
Brinkley – Over HereChanges during WWII led to an .docx
Below is my program, I just have some issues when I want to check ou.pdf
programming Code in C thatloops requesting information about patie.pdf
Hospital management system
In this programming assignment, you will be creating a Health Inform.pdf
KingsleyUsen_HospitalDatabase
Implement in C++Create a class named Doctor that has three member .pdf
Design various classes and write a program to computerize the billing.pdf
Brinkley – Over HereChanges during WWII led to an .docx

Similar to Question I need help with c++ Simple Classes Assigment. i get this .pdf (20)

PDF
HQR Framework optimization for predicting patient treatment time in big data
PDF
HQR Framework optimization for predicting patient treatment time in big data
PDF
Conway Regional Hospital has recently hired you to help them.pdf
DOCX
Insurance Optimization
PDF
Hospital management project_BY RITIKA SAHU.
DOCX
ECE 263264                     Fall 2016 Final Project  .docx
PDF
Hello. Im creating a class called Bill. I need to design the class.pdf
PDF
In C++ 154 Define a base class called Person The .pdf
PDF
Kupdf.com 292609858 computer-science-c-project-on-hospital-management-system-...
PDF
Programming code in C must be C loops reque.pdf
PDF
Hello. Im working on an assignment that tests inheritance and comp.pdf
PDF
How to manage your Experimental Protocol with Basic Statistics
PDF
Computer Science class 12
PPTX
Creating Equal Cost Groups for Trauma Patients in Hospitals in Israel
PDF
Portfolio Three
PPTX
Project presentation sowjanya_132
PDF
Portfolio3
PPTX
Blue Modern Illustrated COVID-19 Medical Presentation.pptx
DOCX
Hospital Managment System Project Proposal
PPTX
Medical Billing Database
HQR Framework optimization for predicting patient treatment time in big data
HQR Framework optimization for predicting patient treatment time in big data
Conway Regional Hospital has recently hired you to help them.pdf
Insurance Optimization
Hospital management project_BY RITIKA SAHU.
ECE 263264                     Fall 2016 Final Project  .docx
Hello. Im creating a class called Bill. I need to design the class.pdf
In C++ 154 Define a base class called Person The .pdf
Kupdf.com 292609858 computer-science-c-project-on-hospital-management-system-...
Programming code in C must be C loops reque.pdf
Hello. Im working on an assignment that tests inheritance and comp.pdf
How to manage your Experimental Protocol with Basic Statistics
Computer Science class 12
Creating Equal Cost Groups for Trauma Patients in Hospitals in Israel
Portfolio Three
Project presentation sowjanya_132
Portfolio3
Blue Modern Illustrated COVID-19 Medical Presentation.pptx
Hospital Managment System Project Proposal
Medical Billing Database
Ad

More from exxonzone (19)

PDF
An employee is assigned to one department and a department may have m.pdf
PDF
10 Points ntilfy cach of the the contour signatures shown on the map .pdf
PDF
Describe the principal cash transfer tools-Wire Transfer-EDT-E.pdf
PDF
Which sentence contains an infinitive AWill you take the package to.pdf
PDF
Whats the Schema Table Column Row Attribute Entity Pri.pdf
PDF
Which of the following groups produce sporangia on leaves (Mark all.pdf
PDF
What is tax research What is the purpose of conducting tax research.pdf
PDF
What is a social networking analysisa) represents the interconnec.pdf
PDF
BiopsychologyWhy sleep (psychology) is interestingSolutionS.pdf
PDF
The following question does not require any knowledge of statistics t.pdf
PDF
Do antidepressants help A researcher studied the effect of an an.pdf
PDF
Shensen and colleagues were interested in studying older adults.pdf
PDF
Much of the heat that drives convection in the mantlea. Is generat.pdf
PDF
In explaining what we now call evolution, Darwin often used the phra.pdf
PDF
Las Homework 4 Spotlight Figure 27.18 Diagnosis of Acid-Base Disorde.pdf
PDF
Check all that are characteristics of cardiac muscle. Cells are .pdf
PDF
How electrical devices produce complex waveforms. Describe.Solut.pdf
PDF
#ifndef RATIONAL_H   if this compiler macro is not defined #def.pdf
PDF
Goldstein and brown were lucky. If they had used the JD allele to co.pdf
An employee is assigned to one department and a department may have m.pdf
10 Points ntilfy cach of the the contour signatures shown on the map .pdf
Describe the principal cash transfer tools-Wire Transfer-EDT-E.pdf
Which sentence contains an infinitive AWill you take the package to.pdf
Whats the Schema Table Column Row Attribute Entity Pri.pdf
Which of the following groups produce sporangia on leaves (Mark all.pdf
What is tax research What is the purpose of conducting tax research.pdf
What is a social networking analysisa) represents the interconnec.pdf
BiopsychologyWhy sleep (psychology) is interestingSolutionS.pdf
The following question does not require any knowledge of statistics t.pdf
Do antidepressants help A researcher studied the effect of an an.pdf
Shensen and colleagues were interested in studying older adults.pdf
Much of the heat that drives convection in the mantlea. Is generat.pdf
In explaining what we now call evolution, Darwin often used the phra.pdf
Las Homework 4 Spotlight Figure 27.18 Diagnosis of Acid-Base Disorde.pdf
Check all that are characteristics of cardiac muscle. Cells are .pdf
How electrical devices produce complex waveforms. Describe.Solut.pdf
#ifndef RATIONAL_H   if this compiler macro is not defined #def.pdf
Goldstein and brown were lucky. If they had used the JD allele to co.pdf
Ad

Recently uploaded (20)

PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Institutional Correction lecture only . . .
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Classroom Observation Tools for Teachers
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Pharma ospi slides which help in ospi learning
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
human mycosis Human fungal infections are called human mycosis..pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Anesthesia in Laparoscopic Surgery in India
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Microbial diseases, their pathogenesis and prophylaxis
Institutional Correction lecture only . . .
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Classroom Observation Tools for Teachers
GDM (1) (1).pptx small presentation for students
Computing-Curriculum for Schools in Ghana
Pharma ospi slides which help in ospi learning
Microbial disease of the cardiovascular and lymphatic systems
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
01-Introduction-to-Information-Management.pdf
Complications of Minimal Access Surgery at WLH
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF

Question I need help with c++ Simple Classes Assigment. i get this .pdf

  • 1. Question: I need help with c++ Simple Classes Assigment. i get this code working but i have to change my setID from numbers in loop{1,2,3,4,5} to setID to *char which it have to start with lastName, then lastName, then year of birth. c++ Simple Classes Assignment 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, which is formed by the last name concatenated with the first name and the year of birth. All other IDs (care providers, procedures) will be just integers. When the user runs the program at the start of the day, it first tries to read in from a binary file called CurrentPatients.dat. 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 patient’s first name, last name, and birthdate are asked for and entered. The new patient ID will be the last name concatenated with the first name and the year of birth. (Example: SmithJohn1998) The primary doctor’s 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 patient’s 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 returned to the main menu after asking them to either try R again, making sure the correct ID was entered, or choose N to enter the patient as a new patient. O: Using the patient’s ID, the patient object is found in the array holding currently checked in
  • 2. patients. (If not found, the user is returned to the main menu after asking them to either try O again, making sure the correct ID was entered, or choose N or R to check in the patient as a new or returing patient.) 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 patient’s 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 patient. 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.dat. It should overwrite all previous information in the file. //Date1.h #ifndef Date_h #define Date_h #include #include using namespace std; class Date1 { friend ostream &operator<<(ostream& , const Date1 &); public: Date1(int m1 = 1, int d1 = 1, int y1 = 1900); void setDate1(int, int, int); bool leapYear1() const; bool endOfMonth1() const; int getMonth1() const { return month1; } int getDay1() const { return day1;
  • 3. } int getYear1() const { return year1; } string getMonthString1() const; void operator+=(int); Date1& operator=(Date1 other1); private: int month1; int day1; int year1; static const int days1[]; static const string monthName1[]; void helpIncrement1(); }; #endif //Date1.cpp #include #include "Date1.h" #include const int Date1::days1[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; const string Date1::monthName1[] = { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
  • 4. }; Date1::Date1(int m1, int d1, int y1) { setDate1(m1, d1, y1); } void Date1::setDate1(int mm1, int dd1, int yy1) { month1 = (mm1 >= 1 && mm1 <= 12) ? mm1 : 1; year1 = (yy1 >= 1900 && yy1 <= 2100) ? yy1 : 1900; if (month1 == 2 && leapYear1()) day1 = (dd1 >= 1&& dd1 <= 29) ? dd1 : 1; else day1 = (dd1 >= 1&& dd1 <= days1[month1]) ? dd1 : 1; } void Date1::operator+=(int additionalDays1) { for (int i1 = 0; i1 < additionalDays1; i1++) helpIncrement1(); } bool Date1::leapYear1() const { if (year1 % 400 == 0 || (year1 % 100 != 0&& year1 % 4 == 0)) return true; else return false; } bool Date1::endOfMonth1() const { if (month1 == 2 && leapYear1()) return (day1 == 29);
  • 5. else return (day1 == days1[month1]); } void Date1::helpIncrement1() { if (!endOfMonth1()) { day1++; } else if (month1 < 12) { day1 = 1; ++month1; } else { day1 = 1; month1 = 1; ++year1; } } Date1& Date1::operator=(Date1 other1) { day1 = other1.day1; month1 = other1.month1; year1 = other1.year1; return *this; } ostream &operator<<(ostream &output1, const Date1& d1) { output1 << d1.monthName1[d1.month1]<< ' ' << d1.day1 << ", " << d1.year1; return output1; }
  • 6. string Date1::getMonthString1() const { return monthName1[month1]; } //Patient1.h #ifndef Patient_h #define Patient_h #include "Date1.h" #include struct procedure1 { Date1 dateOfProcedure1; int procedureID1; int procedureProviderID1; }; class Patient1 { private: int ID1; char firstName1[15]; char lastName1[15]; Date1 birthdate1; int primaryDoctorID1; procedure1 record1[500]; int currentCountOfProcedures1; public: Patient1(int, const char *, const char *, Date1, int); Patient1() : ID1(0), firstName1{}, lastName1{}, birthdate1(0, 0, 0), primaryDoctorID1(0) {}; void setID1(int); void setFirstName1(const char *); void setLastName1(const char *);
  • 7. void setBirthDate1(Date1); void setPrimaryDoctorID1(int); int getID1(); const char * getFirstName1(); const char * getLastName1(); Date1 getBirthDate1(); int getPrimaryDoctorID1(); Patient1& operator=(Patient1 other1); bool enterProcedure1(Date1 procedureDate1, int procedureID1, int procedureProviderID1); void printAllProcedures1(); }; #endif //Patient1.cpp #include "Patient1.h" #include using namespace std; Patient1::Patient1(int id1, const char * first1, const char *last1, Date1 birth1, int doctor1) { setID1(id1); setFirstName1(first1); setLastName1(last1); setBirthDate1(birth1); setPrimaryDoctorID1(doctor1); }; void Patient1::setID1(int id1) { ID1 = id1; } void Patient1::setFirstName1(const char * first1) { if (strlen(first1) > 15) strncpy_s(firstName1, first1, 14); else
  • 8. strcpy_s(firstName1, first1); } void Patient1::setLastName1(const char * last1) { if (strlen(last1) > 15) strncpy_s(lastName1, last1, 14); else strcpy_s(lastName1, last1); } void Patient1::setBirthDate1(Date1 birth1) { birthdate1 = birth1; } void Patient1::setPrimaryDoctorID1(int doctor1) { primaryDoctorID1 = doctor1; } int Patient1::getID1() { return ID1; } const char * Patient1::getFirstName1() { return firstName1; } const char * Patient1::getLastName1() { return lastName1; } Date1 Patient1::getBirthDate1() { return birthdate1; } int Patient1::getPrimaryDoctorID1()
  • 9. { return primaryDoctorID1; } bool Patient1::enterProcedure1(Date1 procedureDate1, int procedureID1, int procedureProviderID1) { if (currentCountOfProcedures1 > 500) { cout << "Can't add more procedures" << endl; return false; } else { record1[currentCountOfProcedures1].dateOfProcedure1 = procedureDate1; record1[currentCountOfProcedures1].procedureID1 = procedureID1; record1[currentCountOfProcedures1].procedureProviderID1 = procedureProviderID1; currentCountOfProcedures1++; return true; } } void Patient1::printAllProcedures1() { cout << "Procedures of the patient"<< endl; for (int i1 = 0; i1 < currentCountOfProcedures1; i1++) { cout << "Procedure-Date: " << record1[i1].dateOfProcedure1 << endl; cout << "Procedure-ID: " << record1[i1].procedureID1 << endl; cout << "Provider-ID: "<< record1[i1].procedureProviderID1 << endl; } } Patient1& Patient1::operator=(Patient1 other1) { ID1 = other1.ID1; strcpy_s(firstName1, other1.firstName1);
  • 10. strcpy_s(lastName1, other1.lastName1); birthdate1 = other1.birthdate1; primaryDoctorID1 = other1.primaryDoctorID1; for (int i1 = 0; i1 < other1.currentCountOfProcedures1; i1++) { record1[i1] = other1.record1[i1]; } currentCountOfProcedures1 = other1.currentCountOfProcedures1; return *this; } //Menu.cpp #include #include #include "Patient1.h" #include "Date1.h" using namespace std; void Menu1(); void Remove1(Patient1 checkIn1[], int& count1, int index1); int main(int argc, const char * argv[]) { Patient1 checkIn1[10]; Patient1 patient1[20]; char choice1; int i1 = 0; int id1 = 0, doctor1 = 0, countAll1 = 0, count1 = 0; int day1, month1, year1; char first1[15], last1[15]; Date1 birthdate1, current1; bool found1 = false; ifstream inFile1; inFile1.open("CurrentPatients1.txt", ios::in | ios::binary);
  • 11. if (inFile1.is_open()) { inFile1.read((char*)&countAll1, sizeof(int)); for (int i1 = 0; i1 < countAll1; i1++) { inFile1.read((char*)&patient1[i1], sizeof(Patient1)); } inFile1.close(); } cout << "Enter present date" << endl; cout << "Day: "; cin >> day1; cout << "Month: "; cin >> month1; cout << "Year: "; cin >> year1; current1.setDate1(month1, day1, year1); do { Menu1(); cin >> choice1; switch (choice1) { case 'A': cout<< "---------------------------" << endl; cout<< "Check-In a new patient" << endl << endl; cout<< "Patient-ID: "; cout<< countAll1 + 1 << endl; checkIn1[count1].setID1(countAll1 + 1); cout<< "First name: "; cin>> first1; checkIn1[count1].setFirstName1(first1); cout<< "Last name: "; cin>> last1; checkIn1[count1].setLastName1(last1);
  • 12. cout<< "Doctor-ID: "; cin>> doctor1; checkIn1[count1].setPrimaryDoctorID1(doctor1); cout<< "Birthdate " << endl; cout<< "Day: "; cin>> day1; cout<< "Month: "; cin>> month1; cout<< "Year: "; cin>> year1; birthdate1.setDate1(month1, day1, year1); checkIn1[count1].setBirthDate1(birthdate1); patient1[countAll1] = checkIn1[count1]; count1++; countAll1++; break; case 'B': cout<< "---------------------------" << endl; cout<< "Check-In a returning patient" << endl << endl; found1 = false; i1 = 0; do { cout << "Enter Patient-ID: "; cin >> id1; do { if (patient1[i1].getID1() == id1) { checkIn1[count1] = patient1[i1]; count1++; found1 = true; } i1++; } while (!found1 && i1 < countAll1); if (!found1)
  • 13. { cout << "Not available"<< endl; cout << "Check-In as a new patient? N or Y: "; cin >> choice1; } } while (!found1 && choice1 == 'N'); break; case 'C': found1 = false; cout<< "---------------------------" << endl; cout<< "Check-Out a patient" << endl; i1 = 0; do { cout << "Enter Checked-Out patient-ID: "; cin >> id1; do { if (checkIn1[i1].getID1() == id1) { cout<< "Provider-ID: "; cin>> doctor1; cout<< "Procedure-ID: "; cin>> id1; cout<< checkIn1[i1].enterProcedure1(current1, id1, doctor1); for (int j = 0; j < countAll1; j++) if (patient1[j].getID1() == checkIn1[i1].getID1()) { patient1[j].enterProcedure1(current1, id1, doctor1); cout << j; cout << "Patient-ID: " << j + 1<< " Checked-Out" << endl << endl; } Remove1(checkIn1, count1, i1); found1 = true; } i1++;
  • 14. } while (!found1 && i1 < count1); if (!found1) { cout << "Not available"<< endl; cout << "Checked-In as a new patient / Checked-In as a returning patient? N or Y: "; cin >> choice1; } } while (!found1 && choice1 == 'N'); break; case 'D': found1 = false; cout<< "---------------------------" << endl; cout<< "Display all info of the patient" << endl << endl; cout<< "Enter Patient-ID: "; cin>> id1; i1 = 0; do { if (patient1[i1].getID1() == id1) { cout << "Patient-ID "<< patient1[i1].getID1() << endl; cout << "Name: "<< patient1[i1].getFirstName1() << " " << patient1[i1].getLastName1() << endl; cout << "Birthdate: "<< patient1[i1].getBirthDate1() << endl; cout << "Doctor-ID: "<< patient1[i1].getPrimaryDoctorID1() << endl; patient1[i1].printAllProcedures1(); found1 = true; } i1++; } while (!found1 && i1 < countAll1); if (!found1) cout << "Not available" << endl; break; case 'E': cout<< "---------------------------" << endl;
  • 15. cout<< "Patient checked-in yet not checked-out" << endl<< endl; if (count1> 0) { for (int i1 = 0; i1 < count1; i1++) { cout << "Patient-ID "<< checkIn1[i1].getID1() << endl; cout << "Name: "<< checkIn1[i1].getFirstName1() << " " << checkIn1[i1].getLastName1() << endl; cout << "Birthdate: "<< checkIn1[i1].getBirthDate1() << endl; cout << "Doctor-ID: "<< checkIn1[i1].getPrimaryDoctorID1() << endl << endl; } } else cout << "All patients checked-out"<< endl << endl; break; case 'F': cout<< "---------------------------" << endl; if (count1 == 0) { ofstream outFile; outFile.open("CurrentPatients1.txt", ios::out | ios::binary); if (outFile.is_open()) { outFile.write((char*)&countAll1, sizeof(int)); for (int i1 = 0; i1 < countAll1; i1++) outFile.write((char*)&patient1[i1], sizeof(Patient1)); outFile.close(); cout << "Finish"<< endl; } } else { for (int i1 = 0; i1 < count1; i1++) { cout << checkIn1[i1].getID1() << endl; cout << checkIn1[i1].getFirstName1() << " " << checkIn1[i1].getLastName1() <<
  • 16. endl; cout << checkIn1[i1].getBirthDate1() << endl; cout << checkIn1[i1].getPrimaryDoctorID1() << endl; } choice1 = 'A'; } break; } } while (choice1 != 'F' && choice1 != 'f'); return 0; } void Menu1() { cout << "-------------------------------"<< endl; cout << "Menu" << endl; cout << "A : Check-in new patient"<< endl; cout << "B : Check-in returning patient"<< endl; cout << "C : Check-out a patient" << endl; cout << "D : Display info of a patient"<< endl; cout << "E : Display list of patients who checked-in yet not checked-out" << endl; cout << "F : Quit" << endl; cout << "Enter choice (A, B, C, D, E, F): "; } void Remove1(Patient1 checkIn1[], int& count1, int index1) { for (int i1 = index1; i1 < count1; i1++) checkIn1[i1] = checkIn1[i1 + 1]; count1--; } Solution #ifndef Date_h #define Date_h #include
  • 17. #include using namespace std; class Date1 { friend ostream &operator<<(ostream& , const Date1 &); public: Date1(int m1 = 1, int d1 = 1, int y1 = 1900); void setDate1(int, int, int); bool leapYear1() const; bool endOfMonth1() const; int getMonth1() const { return month1; } int getDay1() const { return day1; } int getYear1() const { return year1; } string getMonthString1() const; void operator+=(int); Date1& operator=(Date1 other1); private: int month1; int day1; int year1; static const int days1[]; static const string monthName1[]; void helpIncrement1(); }; #endif //Date1.cpp
  • 18. #include #include "Date1.h" #include const int Date1::days1[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; const string Date1::monthName1[] = { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; Date1::Date1(int m1, int d1, int y1) { setDate1(m1, d1, y1); } void Date1::setDate1(int mm1, int dd1, int yy1) { month1 = (mm1 >= 1 && mm1 <= 12) ? mm1 : 1; year1 = (yy1 >= 1900 && yy1 <= 2100) ? yy1 : 1900; if (month1 == 2 && leapYear1()) day1 = (dd1 >= 1&& dd1 <= 29) ? dd1 : 1; else day1 = (dd1 >= 1&& dd1 <= days1[month1]) ? dd1 : 1; } void Date1::operator+=(int additionalDays1)
  • 19. { for (int i1 = 0; i1 < additionalDays1; i1++) helpIncrement1(); } bool Date1::leapYear1() const { if (year1 % 400 == 0 || (year1 % 100 != 0&& year1 % 4 == 0)) return true; else return false; } bool Date1::endOfMonth1() const { if (month1 == 2 && leapYear1()) return (day1 == 29); else return (day1 == days1[month1]); } void Date1::helpIncrement1() { if (!endOfMonth1()) { day1++; } else if (month1 < 12) { day1 = 1; ++month1; } else { day1 = 1; month1 = 1;
  • 20. ++year1; } } Date1& Date1::operator=(Date1 other1) { day1 = other1.day1; month1 = other1.month1; year1 = other1.year1; return *this; } ostream &operator<<(ostream &output1, const Date1& d1) { output1 << d1.monthName1[d1.month1]<< ' ' << d1.day1 << ", " << d1.year1; return output1; } string Date1::getMonthString1() const { return monthName1[month1]; } //Patient1.h #ifndef Patient_h #define Patient_h #include "Date1.h" #include struct procedure1 { Date1 dateOfProcedure1; int procedureID1; int procedureProviderID1; };
  • 21. class Patient1 { private: int ID1; char firstName1[15]; char lastName1[15]; Date1 birthdate1; int primaryDoctorID1; procedure1 record1[500]; int currentCountOfProcedures1; public: Patient1(int, const char *, const char *, Date1, int); Patient1() : ID1(0), firstName1{}, lastName1{}, birthdate1(0, 0, 0), primaryDoctorID1(0) {}; void setID1(int); void setFirstName1(const char *); void setLastName1(const char *); void setBirthDate1(Date1); void setPrimaryDoctorID1(int); int getID1(); const char * getFirstName1(); const char * getLastName1(); Date1 getBirthDate1(); int getPrimaryDoctorID1(); Patient1& operator=(Patient1 other1); bool enterProcedure1(Date1 procedureDate1, int procedureID1, int procedureProviderID1); void printAllProcedures1(); }; #endif //Patient1.cpp #include "Patient1.h" #include using namespace std; Patient1::Patient1(int id1, const char * first1, const char *last1, Date1 birth1, int doctor1) {
  • 22. setID1(id1); setFirstName1(first1); setLastName1(last1); setBirthDate1(birth1); setPrimaryDoctorID1(doctor1); }; void Patient1::setID1(int id1) { ID1 = id1; } void Patient1::setFirstName1(const char * first1) { if (strlen(first1) > 15) strncpy_s(firstName1, first1, 14); else strcpy_s(firstName1, first1); } void Patient1::setLastName1(const char * last1) { if (strlen(last1) > 15) strncpy_s(lastName1, last1, 14); else strcpy_s(lastName1, last1); } void Patient1::setBirthDate1(Date1 birth1) { birthdate1 = birth1; } void Patient1::setPrimaryDoctorID1(int doctor1) { primaryDoctorID1 = doctor1; }
  • 23. int Patient1::getID1() { return ID1; } const char * Patient1::getFirstName1() { return firstName1; } const char * Patient1::getLastName1() { return lastName1; } Date1 Patient1::getBirthDate1() { return birthdate1; } int Patient1::getPrimaryDoctorID1() { return primaryDoctorID1; } bool Patient1::enterProcedure1(Date1 procedureDate1, int procedureID1, int procedureProviderID1) { if (currentCountOfProcedures1 > 500) { cout << "Can't add more procedures" << endl; return false; } else { record1[currentCountOfProcedures1].dateOfProcedure1 = procedureDate1; record1[currentCountOfProcedures1].procedureID1 = procedureID1; record1[currentCountOfProcedures1].procedureProviderID1 = procedureProviderID1; currentCountOfProcedures1++; return true;
  • 24. } } void Patient1::printAllProcedures1() { cout << "Procedures of the patient"<< endl; for (int i1 = 0; i1 < currentCountOfProcedures1; i1++) { cout << "Procedure-Date: " << record1[i1].dateOfProcedure1 << endl; cout << "Procedure-ID: " << record1[i1].procedureID1 << endl; cout << "Provider-ID: "<< record1[i1].procedureProviderID1 << endl; } } Patient1& Patient1::operator=(Patient1 other1) { ID1 = other1.ID1; strcpy_s(firstName1, other1.firstName1); strcpy_s(lastName1, other1.lastName1); birthdate1 = other1.birthdate1; primaryDoctorID1 = other1.primaryDoctorID1; for (int i1 = 0; i1 < other1.currentCountOfProcedures1; i1++) { record1[i1] = other1.record1[i1]; } currentCountOfProcedures1 = other1.currentCountOfProcedures1; return *this; } //Menu.cpp #include #include #include "Patient1.h" #include "Date1.h" using namespace std; void Menu1(); void Remove1(Patient1 checkIn1[], int& count1, int index1);
  • 25. int main(int argc, const char * argv[]) { Patient1 checkIn1[10]; Patient1 patient1[20]; char choice1; int i1 = 0; int id1 = 0, doctor1 = 0, countAll1 = 0, count1 = 0; int day1, month1, year1; char first1[15], last1[15]; Date1 birthdate1, current1; bool found1 = false; ifstream inFile1; inFile1.open("CurrentPatients1.txt", ios::in | ios::binary); if (inFile1.is_open()) { inFile1.read((char*)&countAll1, sizeof(int)); for (int i1 = 0; i1 < countAll1; i1++) { inFile1.read((char*)&patient1[i1], sizeof(Patient1)); } inFile1.close(); } cout << "Enter present date" << endl; cout << "Day: "; cin >> day1; cout << "Month: "; cin >> month1; cout << "Year: "; cin >> year1; current1.setDate1(month1, day1, year1); do
  • 26. { Menu1(); cin >> choice1; switch (choice1) { case 'A': cout<< "---------------------------" << endl; cout<< "Check-In a new patient" << endl << endl; cout<< "Patient-ID: "; cout<< countAll1 + 1 << endl; checkIn1[count1].setID1(countAll1 + 1); cout<< "First name: "; cin>> first1; checkIn1[count1].setFirstName1(first1); cout<< "Last name: "; cin>> last1; checkIn1[count1].setLastName1(last1); cout<< "Doctor-ID: "; cin>> doctor1; checkIn1[count1].setPrimaryDoctorID1(doctor1); cout<< "Birthdate " << endl; cout<< "Day: "; cin>> day1; cout<< "Month: "; cin>> month1; cout<< "Year: "; cin>> year1; birthdate1.setDate1(month1, day1, year1); checkIn1[count1].setBirthDate1(birthdate1); patient1[countAll1] = checkIn1[count1]; count1++; countAll1++; break; case 'B': cout<< "---------------------------" << endl; cout<< "Check-In a returning patient" << endl << endl;
  • 27. found1 = false; i1 = 0; do { cout << "Enter Patient-ID: "; cin >> id1; do { if (patient1[i1].getID1() == id1) { checkIn1[count1] = patient1[i1]; count1++; found1 = true; } i1++; } while (!found1 && i1 < countAll1); if (!found1) { cout << "Not available"<< endl; cout << "Check-In as a new patient? N or Y: "; cin >> choice1; } } while (!found1 && choice1 == 'N'); break; case 'C': found1 = false; cout<< "---------------------------" << endl; cout<< "Check-Out a patient" << endl; i1 = 0; do { cout << "Enter Checked-Out patient-ID: "; cin >> id1; do { if (checkIn1[i1].getID1() == id1)
  • 28. { cout<< "Provider-ID: "; cin>> doctor1; cout<< "Procedure-ID: "; cin>> id1; cout<< checkIn1[i1].enterProcedure1(current1, id1, doctor1); for (int j = 0; j < countAll1; j++) if (patient1[j].getID1() == checkIn1[i1].getID1()) { patient1[j].enterProcedure1(current1, id1, doctor1); cout << j; cout << "Patient-ID: " << j + 1<< " Checked-Out" << endl << endl; } Remove1(checkIn1, count1, i1); found1 = true; } i1++; } while (!found1 && i1 < count1); if (!found1) { cout << "Not available"<< endl; cout << "Checked-In as a new patient / Checked-In as a returning patient? N or Y: "; cin >> choice1; } } while (!found1 && choice1 == 'N'); break; case 'D': found1 = false; cout<< "---------------------------" << endl; cout<< "Display all info of the patient" << endl << endl; cout<< "Enter Patient-ID: "; cin>> id1; i1 = 0; do {
  • 29. if (patient1[i1].getID1() == id1) { cout << "Patient-ID "<< patient1[i1].getID1() << endl; cout << "Name: "<< patient1[i1].getFirstName1() << " " << patient1[i1].getLastName1() << endl; cout << "Birthdate: "<< patient1[i1].getBirthDate1() << endl; cout << "Doctor-ID: "<< patient1[i1].getPrimaryDoctorID1() << endl; patient1[i1].printAllProcedures1(); found1 = true; } i1++; } while (!found1 && i1 < countAll1); if (!found1) cout << "Not available" << endl; break; case 'E': cout<< "---------------------------" << endl; cout<< "Patient checked-in yet not checked-out" << endl<< endl; if (count1> 0) { for (int i1 = 0; i1 < count1; i1++) { cout << "Patient-ID "<< checkIn1[i1].getID1() << endl; cout << "Name: "<< checkIn1[i1].getFirstName1() << " " << checkIn1[i1].getLastName1() << endl; cout << "Birthdate: "<< checkIn1[i1].getBirthDate1() << endl; cout << "Doctor-ID: "<< checkIn1[i1].getPrimaryDoctorID1() << endl << endl; } } else cout << "All patients checked-out"<< endl << endl; break; case 'F': cout<< "---------------------------" << endl; if (count1 == 0) {
  • 30. ofstream outFile; outFile.open("CurrentPatients1.txt", ios::out | ios::binary); if (outFile.is_open()) { outFile.write((char*)&countAll1, sizeof(int)); for (int i1 = 0; i1 < countAll1; i1++) outFile.write((char*)&patient1[i1], sizeof(Patient1)); outFile.close(); cout << "Finish"<< endl; } } else { for (int i1 = 0; i1 < count1; i1++) { cout << checkIn1[i1].getID1() << endl; cout << checkIn1[i1].getFirstName1() << " " << checkIn1[i1].getLastName1() << endl; cout << checkIn1[i1].getBirthDate1() << endl; cout << checkIn1[i1].getPrimaryDoctorID1() << endl; } choice1 = 'A'; } break; } } while (choice1 != 'F' && choice1 != 'f'); return 0; } void Menu1() { cout << "-------------------------------"<< endl; cout << "Menu" << endl; cout << "A : Check-in new patient"<< endl; cout << "B : Check-in returning patient"<< endl; cout << "C : Check-out a patient" << endl; cout << "D : Display info of a patient"<< endl;
  • 31. cout << "E : Display list of patients who checked-in yet not checked-out" << endl; cout << "F : Quit" << endl; cout << "Enter choice (A, B, C, D, E, F): "; } void Remove1(Patient1 checkIn1[], int& count1, int index1) { for (int i1 = index1; i1 < count1; i1++) checkIn1[i1] = checkIn1[i1 + 1]; count1--; }