Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need to create and implement a struct and 2 classes (codes already given just ne

ID: 3591778 • Letter: N

Question

Need to create and implement a struct and 2 classes (codes already given just need to make it work with other code), and a task menu for the user in C++. Us info and code below.

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.

For the struct, you may use the following:

struct procedure
{

      Date dateOfProcedure;

            int procedureID;

            int procedureProviderID;

};

For the class Patient, you should have the following interface (public) member functions:

Patient ( const char *, 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 ( const char * ); //check if length of name string is < 32 if not, shorten to 32 letters.

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);

const char * 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();

he following private data members should be defined:

      char ID[33];

      char firstName[15];

      char lastName [15];

      Date birthdate;

      int primaryDoctorID;

      procedure record[100];

      int currentCountOfProcedures; // keeps track of how many procedures have been recorded. if it reaches 500, no //new procedures can be entered.

For the Date class, you may copy what is at the end of this assignment with the following changes:

1.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 object a leap year?

bool endOfMonth( ) const; // is the date of the object 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.

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

}

Explanation / Answer

#include<iostream.h>

#include<conio.h>

#include<string.h>

#include<stdlib.h>

// define maximum number of patients in a queue

#define MAXPATIENTS 100

// define structure for patient data

struct patient

{

char FirstName[50];

char LastName[50];

char ID[20];

};

// define class for queue

class queue

{

public:

queue (void);

int AddPatientAtEnd (patient p);

int AddPatientAtBeginning (patient p);

patient GetNextPatient (void);

int RemoveDeadPatient (patient * p);

void OutputList (void);

char DepartmentName[50];

private:

int NumberOfPatients;

patient List[MAXPATIENTS];

};

// declare member functions for queue

queue::queue ()

{

// constructor

NumberOfPatients = 0;

}

int queue::AddPatientAtEnd (patient p)

{

// adds a normal patient to the end of the queue.

// returns 1 if successful, 0 if queue is full.

if (NumberOfPatients >= MAXPATIENTS)

{

// queue is full

return 0;

}

// put in new patient

else

List[NumberOfPatients] = p; NumberOfPatients++;

return 1;

}

int queue::AddPatientAtBeginning (patient p)

{

// adds a critically ill patient to the beginning of the queue.

// returns 1 if successful, 0 if queue is full.

int i;

if (NumberOfPatients >= MAXPATIENTS)

{

// queue is full

return 0;

}

// move all patients one position back in queue

for (i = NumberOfPatients-1; i >= 0; i--)

{

List[i+1] = List[i];

}

// put in new patient

List[0] = p; NumberOfPatients++;

return 1;

}

patient queue::GetNextPatient (void)

{

// gets the patient that is first in the queue.

// returns patient with no ID if queue is empty

int i; patient p;

if (NumberOfPatients == 0) {

// queue is empty

strcpy(p.ID,"");

return p;}

// get first patient

p = List[0];

// move all remaining patients one position forward in queue

NumberOfPatients--;

for (i=0; i<NumberOfPatients; i++)

{

List[i] = List[i+1];

}

// return patient

return p;

}

int queue::RemoveDeadPatient (patient * p)

{

// removes a patient from queue.

// returns 1 if successful, 0 if patient not found

int i, j, found = 0;

// search for patient

for (i=0; i<NumberOfPatients; i++)

{

if (stricmp(List[i].ID, p->ID) == 0)

{

// patient found in queue

*p = List[i]; found = 1;

// move all following patients one position forward in queue

NumberOfPatients--;

for (j=i; j<NumberOfPatients; j++)

{

List[j] = List[j+1];

}

}

}

return found;

}

void queue::OutputList (void)

{

// lists entire queue on screen

int i;

if (NumberOfPatients == 0)

{

cout << "

Queue is empty";

}

else

{

for (i=0; i<NumberOfPatients; i++)

{

cout << "

" << List[i].FirstName;

cout << " " << List[i].LastName;

cout << " " << List[i].ID;

}

}

}

// declare functions used by main:

patient InputPatient (void)

{

// this function asks user for patient data.

patient p;

cout << "

Please enter data for new patient

First name: ";

cin.getline(p.FirstName, sizeof(p.FirstName));

cout << "

Last name: ";

cin.getline(p.LastName, sizeof(p.LastName));

cout << "

Social security number: ";

cin.getline(p.ID, sizeof(p.ID));

// check if data valid

if (p.FirstName[0]==0 || p.LastName[0]==0 || p.ID[0]==0)

{

// rejected

strcpy(p.ID,"");

cout << "

Error: Data not valid. Operation cancelled.";

getch();

}

return p;

}

void OutputPatient (patient * p)

{

// this function outputs patient data to the screen

if (p == NULL || p->ID[0]==0)

{

cout << "

No patient";

return;

}

else

cout << "

Patient data:";

cout << "

First name: " << p->FirstName;

cout << "

Last name: " << p->LastName;

cout << "

Social security number: " << p->ID;

}

int ReadNumber()

{

// this function reads an integer number from the keyboard.

// it is used because input with cin >> doesn't work properly!

char buffer[20];

cin.getline(buffer, sizeof(buffer));

return atoi(buffer);

}

void DepartmentMenu (queue * q)

{

// this function defines the user interface with menu for one

department

int choice = 0, success; patient p;

while (choice != 6)

{

// clear screen

clrscr();

// print menu

cout << "

Welcome to department: " << q->DepartmentName;

cout << "

Please enter your choice:";

cout << "

1: Add normal patient";

cout << "

2: Add critically ill patient";

cout << "

3: Take out patient for operation";

cout << "

4: Remove dead patient from queue";

cout << "

5: List queue";

cout << "

6: Change department or exit

";

// get user choice

choice = ReadNumber();

// do indicated action

switch (choice)

{

case 1: // Add normal patient

p = InputPatient();

if (p.ID[0])

{

success = q->AddPatientAtEnd(p);

clrscr();

if (success)

{

cout << "

Patient added:

";

}

else

{

// error

cout << "

Error: The queue is full. Cannot add patient:";

}

OutputPatient(&p);

cout << "

Press any key";

getch();

}

break;

case 2: // Add critically ill patient

p = InputPatient();

if (p.ID[0])

{

success = q->AddPatientAtBeginning(p);

clrscr();

if (success)

{

cout << "

Patient added:

";

}

else

{

// error

cout << "

Error: The queue is full. Cannot add

patient:";

}

OutputPatient(&p);

cout << "

Press any key";

getch();

}

break;

case 3: // Take out patient for operation

p = q->GetNextPatient();

clrscr();

if (p.ID[0])

{

cout << "

Patient to operate:

";

OutputPatient(&p);}

else

{

cout << "

There is no patient to operate.";

}

cout << "

Press any key";

getch();

break;

case 4: // Remove dead patient from queue

p = InputPatient();

if (p.ID[0])

{

success = q->RemoveDeadPatient(&p);

clrscr();

if (success)

{

cout << "

Patient removed:

";

}

else

{

// error

cout << "

Error: Cannot find patient:

";

}

OutputPatient(&p);

cout << "

Press any key";

getch();

}

break;

case 5: // List queue

clrscr();

q->OutputList();

cout << "

Press any key";

getch(); break;

}

}

}

// main function defining queues and main menu

void main ()

{

int i, MenuChoice = 0;

// define three queues

queue departments[3];

// set department names

strcpy (departments[0].DepartmentName, "Heart clinic");

strcpy (departments[1].DepartmentName, "Lung clinic");

strcpy (departments[2].DepartmentName, "Plastic surgery");

while (MenuChoice != 4)

{

// clear screen

clrscr();

// print menu

cout << "

Welcome to Software City Hospital";

cout << "

Please enter your choice:

";

for (i = 0; i < 3; i++)

{

// write menu item for department i

cout << "

" << (i+1) << ": " << departments[i].DepartmentName;

}

cout << "

4: Exit

";

// get user choice

MenuChoice = ReadNumber();

// is it a department name?

if (MenuChoice >= 1 && MenuChoice <= 3)

{

// call submenu for department

// (using pointer arithmetics here:)

DepartmentMenu (departments + (MenuChoice-1));

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote