CSE1CPP 2018 Assignment Part B

C++ Assignment Help, C++ Programming Help

CSE1CPP 2018 Assignment Part B

Problem Description

The Take Care Of You Hospital has a number of different medical departments. Each department takes care of a different area of the overall medical care. For example, there is an Emergency Department, a Cardiology Department, a Physiotherapy Department and so on.

Each Department has a limited capacity. That is, they can only take a certain number of patients at one time. The capacity varies between Departments. Patients, when they come into a Department have a treatment level. This is a number between 1 and 5. This determines the order in which they are treated. 5 being the most urgent, 1 being the least urgent.

As each new patient comes to a Department, they are inserted in the correct order for treatment.

Take Care Of You Hospital would now like you to write a program to deal with the above. Problem Implementation

As Take Care Of You Hospital would like the program as soon as possible, some files have been provided for you. These arecentral.h, central.cpp, meddept.h, meddept.cpp,

patient.h , patient.cpp, findDepartment.h, findDepartment.cpp sortPatient.h, sortPatient.cpp and makefile.

So long as you use the files provided, then using the makefile will compile all of the files into a C++ program.

To run the program, after it successfully compiles, just type hospital

These files can be copied by typing this command on latcs8

cp ~csilib/cse1cpp/assignB/* .

(don't forget the . (dot) for your current directory)

READ THE WHOLE DOCUMENT FIRST.

class MedDept

This class is for the Medical Departments.

The MedDept class has the following attributes:

name this is text and is the unique name of a Medical Department. This can be more than one word

capacity this is an integer and is the maximum number of patients that can be in that Department at one time.

treatmentType this is text and describes the function of the Department.

Can be more than one word.

The MedDept class requires the following functionality:

A default constructor

An overloaded constructor that takes values for all 3 attributes as parameters.

A copy constructor.

A constructor that takes just one argument, the name of the Department, the reason for this will become obvious a bit later.

(when you write the ofstream friend operator for MedDept).

A destructor that indicates that it expects not to throw any exceptions. (This is not required but is good practice.)

overloaded friend functions for ostream, ofstream, istream and ifstream

A number of accessor functions that return read-only information about the attributes of the MedDept class. These are provided as inline functions in the

.h file. You do not need to write them.

The overloaded ostream function displays information about the MedDept object to the screen, see the example runs of the program later in this document.

What we want to be able to do is just give cout (an ostream object already) a MedDept object and C++ will use the code in the overloaded ostream operator to display the details to the screen.

Similarly, we want to use the overloaded istream operator to enter information into a MedDept object (one instantiated with the default constructor call) from the user using the keyboard.

This also applies to the file input/output versions, ifstream and ofstream. We want to be able to hand a default MedDept object to the ifstream operator to fill up with information from a text file, or hand a MedDept object that has values for all its fields and to an ofstream operator and write the values of those attributes to a text file.

Be careful when writing any and all classes that need to be written to text files (saved) that you follow, exactly, the format of the input file, see pages 7 and 8

We have to be able to use your output files as input files the next time the program is run.

class Patient

This class is about the Patients.

The Patient class has the following attributes:

name this is text and is the name of the patient. This can be more than one word.

CPP Assignment Part B Semester 2 - due: 10:00 am Mon Oct 22nd this is the first and final hand in date p. 5 of 15

UR this is an integer and is the unique patient identifier number.

bloodType this is text and is the blood type of a patient. Blood types are listed below.

tLevel this is an integer and is a number between 1 and 5 (inclusive). Every patient

in every Department is assigned a tLevel and this determines the order in which they are treated in the Department, as described above.

The Patient class requires the following functionality:

A default constructor.

overloaded friend functions for ostream, istream, ifstream and ofstream.

The overloaded ostream function displays information about the Patient object to the screen, see the example runs of the program later in this document. What we want to be able to do is just give cout (an ostream object already) a Patient object and C++ will use the code in the overloaded ostream operator to display the details to the screen.

Similarly, we want to use the overloaded istream operator to enter information into a Patient object from the user using the keyboard.

The ofstream and ifstream operators do the same function, just writing out to a text file or reading in from a text file.

an accessor method to return the treatment level, the tLevel. This has been coded for you as an inline function in the patient.h file.

The above 2 classes are the main classes in this assignment, there are 2 other classes, the findDepartment and sortPatient classes that will be explained later. These are the function object classes.

There is no inheritance anywhere in this assignment.

Whilst there is definitely more than one way to solve this assignment, the above description, and the start up files that are supplied, suggest that a solution could be

to use a map. The key would be theMedDept class. There is only one MedDept with that

name in the Hospital. Using a map would automatically sort the MedDept objects and we can easily check if a MedDept with a certain name has already been entered.

The value part of the map is a vector of Patients.

We looked at this idea in lecture 16

The above is not the only way to solve the problem, it is one way. You are free to come up with a completely different way of writing this assignment, provided it does the job and meets all our software engineering requirement. Such as not having publicly accessible attributes or variables.

If you do decide to follow this idea, then this is where you develop the findDepartment.h and .cpp files and use the resultant object as a function object as the third argument for the map.

Recall that C++ doesn't know how to sort MedDept objects into their correct places in the map when they are inserted. This is where the function object is used, it tells C++ how sort MedDept objects. See lecture / workshop 09.

Then there is the main driver program, central.cpp, which starts by declaring a map withMedDept as the key and a vector of Patients as the value. Again reread the previous paragraph about using this or your own data structures.

Program functionality

The program starts by prompting (asking) the user for the name of input text file. The format of this file is shown on pages 7 and 8

File line

Meaning

Emergency

This is the unique name of a Department (MedDept)

7

This is the capacity of the Department

Emergency Care

This is the treatment type of the Department (what the

Department does)

3

This is the number of Patient records that follow the

Department record. Remember to write this number

back to the text file when you chose the save to file

option.

First Person

This is the name of a Patient

2345

This is the UR number of the Patient

O-

This is the blood type of the Patient

4

This is the treatment level of the Patient

Fifth Person

This is the name of a Patient

10885

This is the UR number of the Patient

AB+

This is the blood type of the Patient

3

This is the treatment level of the Patient

Sixth Person

This is the name of a Patient

2891

This is the UR number of the Patient

B-

This is the blood type of the Patient

2

This is the treatment level of the Patient

Physiotherapy

This is the unique name of a Department (MedDept)

3

This is the capacity of the Department

Physio Treatment

This is the treatment type of the Department (what the

Department does)

2

This is the number of Patient records that follow the

Department record. Remember to write this number

back to the text file when you chose the save to file

option.

Second Person

This is the name of a Patient

64589

This is the UR number of the Patient

O+

This is the blood type of the Patient

3

This is the treatment level of the Patient

Third Person

This is the name of a Patient

97109

This is the UR number of the Patient

O-

This is the blood type of the Patient

1

This is the treatment level of the Patient

If the file exists, and it may not exist, then the format of the file is guaranteed to be correct.

The first 3 lines of a MedDept record, is the information needed for instantiating a MedDept object. The fourth line is not entered into any objects, it just tells us how many Patients follow the MedDept information.

Each Patient record consists of 4 lines as detailed above.

There can be any number of MedDept records in the file. If the file exists, assume that there is at least oneMedDept record (not necessarily with any Patients) in the text file.

You must not hard code the input (or output) file name, the user must be able to enter any file name.

Once the input file has been read into the data structure, then the file is closed and all interactions with the program are with the map or whichever data structure you have used.

After the input file has been read into the data structure that you are using, then the user is presented with a menu, as shown:

Welcome to the Hospital Main Menu

1. Add Department

2. Add Patient

3. Display

4. Save to a text file

5. Close the program Enter choice >>

1. Add Department

Selecting this menu choice prompts (asks) the user to enter information about a new Department. Firstly the user enters the name of the Department. If that name has not been used before, then the user is asked for thecapacity of the Department and the treatment type (what the Department actually does).

If you are following the suggested map data structure, then, as this is the first time that this Department has been entered into the map, create a vector of Patients (it will be empty of course) and insert the pair into the map. (see lecture 16).

If you are using your own data structure then you will apply the appropriate initializations no Patient information is entered in this menu choice.

If the Department name entered by the user is already in use, then an appropriate

message is displayed to the screen, no more questions are asked and the program returns to the main menu.

2. Add Patient

Choosing this menu option, the user is first asked for thename of a Department. If there is no Department with that name, then an appropriate message is displayed

to the screen, no more questions are asked and the program returns to the main menu.

If the Department is found, then there is one more check. Can this Department take another Patient?. That is, is the Department already at capacity.

If the Department is at full capacity , then an appropriate message is displayed to the screen, no more questions are asked and the program returns to the main menu.

If the Department name is correct and the Department is not at full capacity, then the user is asked for the name of thePatient, the UR identifier, thebloodtype and the treatment level.

That Patient is then added to thevector of Patients for that Department.

Based on the treatment level the Patient needs to be inserted into the correct place in the vector. You could develop the sortPatient.h and .cpp files to provide a function object to use when you sort the vector. Recall that the

vector doesn't know how to sort Patient objects.

Assume that all this information is entered correctly.

3. Display

Choosing this menu option displays the contents of the map (or whatever data structure you are using) to the screen. See the sample runs later in this document for an idea on the format. Note, you do not have to follow this format. The output has to be easily readable though.

If the Department has no Patients, then this must be displayed to the screen, otherwise, the Patients, in the their treatment order are displayed.

( Why did we chose a vector instead of a priority_queue ? )

4. Save to a text file

Choosing this menu option, the user is prompted (asked) for the name of an output text file. This can be the same file as the input file, or it can be a different file. Provided that the file can be opened, then the contents of the map is written to the text file.

Be sure to use the same format as the input file, see pages 7 and 8.

Recall that we have to be able to use this output file as an input file the next time that the program is run.

Remember to write the number of Patients to the output file. You will need this figure when you read in the input file. It will tell you how Patient records there are

after a MedDept record.

Choosing this option does NOT close the program. This option can be chosen at any time while the program is running.

5. Exit the program

This menu option closes the program. It does not ask the user if they want to save the changes to the map (or whatever data structure you have chosen).

Sample run of the program

Note that not every condition is shown in the sample below, because a condition is not shown does NOT mean that it must not be implemented, or that it will not be tested and marked.

User input is in bold

> hospital

Enter file name >> a1.dat

Welcome to the Hospital Main Menu

1. Add Department

2. Add Patient

3. Display

4. Save to a text file

5. Close the program Enter choice >> 3

Department: Emergency

Capacity: 7

Function: Emergency Care

This department currently has 3 patients Can take 4 more patients

Here are the list of patients for this Department Patient:

[ name: First Person UR: 2345

Blood Type: O- T Level 4

]

Patient:

[ name: Fifth Person UR: 10885

Blood Type: AB+ T Level 3

]

Patient:

[ name: Sixth Person UR: 2891

Blood Type: B- T Level 2

]

Department: Physiotherapy Function: Physio Treatment

Capacity: 3

This department currently has 2 patients

Can take 1 more patients

Here are the list of patients for this Department Patient:

[ name: Second Person UR: 64589

Blood Type: O+ T Level 3

]

Patient:

[ name: Third Person UR: 97109

Blood Type: O- T Level 1

]

Welcome to the Hospital Main Menu

1. Add Department

2. Add Patient

3. Display

4. Save to a text file

5. Close the program Enter choice >> 1

Enter the Department name >> Neuro Surgery Enter capacity >> 4

Enter Department function >> Neuro surgery Welcome to the Hospital Main Menu

1. Add Department

2. Add Patient

3. Display

4. Save to a text file

5. Close the program Enter choice >> 3

Department: Emergency Function: Emergency Care

Capacity: 7

This department currently has 3 patients

Can take 4 more patients

Here are the list of patients for this Department Patient:

[ name: First Person UR: 2345

Blood Type: O- T Level 4

]

Patient:

[ name: Fifth Person UR: 10885

Blood Type: AB+ T Level 3

]

Patient:

[ name: Sixth Person UR: 2891

Blood Type: B- T Level 2

]

Department: Neuro Surgery Function: Neuro surgery

Capacity: 4

CPP Assignment Part B Semester 2 - due: 10:00 am Mon Oct 22nd this is the first and final hand in date p. 11 of 15

This Department has no patients

Department: Physiotherapy Function: Physio Treatment

Capacity: 3

This department currently has 2 patients

Can take 1 more patients

Here are the list of patients for this Department Patient:

[ name: Second Person UR: 64589

Blood Type: O+ T Level 3

]

Patient:

[ name: Third Person UR: 97109

Blood Type: O- T Level 1

]

Welcome to the Hospital Main Menu

1. Add Department

2. Add Patient

3. Display

4. Save to a text file

5. Close the program Enter choice >> 1

Enter the Department name >> Emergency This Department already exists Welcome to the Hospital Main Menu

1. Add Department

2. Add Patient

3. Display

4. Save to a text file

5. Close the program Enter choice >> 2

Enter department name >> Physiotherapy

Enter patient name >> Fourth Person

Enter the UR number (int) >> 445590

Enter blood type >> O-

Enter t level (int) >> 2

Welcome to the Hospital Main Menu

1. Add Department

2. Add Patient

3. Display

4. Save to a text file

5. Close the program Enter choice >> 3

Department: Emergency Function: Emergency Care

Capacity: 7

This department currently has 3 patients

Can take 4 more patients

Here are the list of patients for this Department Patient:

[ name: First Person UR: 2345

Blood Type: O- T Level 4

]

Patient:

[ name: Fifth Person UR: 10885

Blood Type: AB+ T Level 3

]

Patient:

[ name: Sixth Person UR: 2891

Blood Type: B- T Level 2

]

Department: Neuro Surgery Function: Neuro surgery

Capacity: 4

This Department has no patients

Department: Physiotherapy Function: Physio Treatment

Capacity: 3

This department currently has 3 patients

Can take 0 more patients

Here are the list of patients for this Department Patient:

[ name: Second Person UR: 64589

Blood Type: O+ T Level 3

]

Patient:

[ name: Fourth Person UR: 445590

Blood Type: O- T Level 2

]

Patient:

[ name: Third Person UR: 97109

Blood Type: O- T Level 1

]

Welcome to the Hospital Main Menu

1. Add Department

2. Add Patient

3. Display

4. Save to a text file

5. Close the program Enter choice >> 2

Enter department name >> Physiotherapy

This Department is at capacity, cannot take any more patients Welcome to the Hospital Main Menu

1. Add Department

2. Add Patient

3. Display

4. Save to a text file

5. Close the program Enter choice >> 4

Enter file name >> b1.dat

Welcome to the Hospital Main Menu

1. Add Department

2. Add Patient

3. Display

4. Save to a text file

5. Close the program

Enter choice >> 5

When you enter MedDept (Department)names, assume that the user enters the name exactly as is already in the text file/map. That is, you do not need to check for the same name just in a different combination of upper case and lower case.

You do need to check that you cannot add a Department with same name as an existing Department. Even though UR numbers are supposed to be unique, your program does not need to check for this. Assume that the user always enters a unique UR number.

Electronic Submission of the Source Code

Submit all the C++ files that you have developed in the tasks above. The code has to run under Unix on the latcs8 machine.

You submit your files from your latcs8 account. Make sure you are in the same directory as the files you are submitting. Submit each file separately using the submit command.

submit CPP central.h

submit CPP central.cpp

submit CPP findDepartment.h

submit CPP findDepartment.cpp

submit CPP meddept.h

submit CPP meddept.cpp

submit CPP patient.h

submit CPP patient.cpp

submit CPP sortPatient.h

submit CPP sortPatient.cpp

submit CPP makefile

After submitting the files, you can run the following command that lists the files submitted from your account:

verify

You can submit the same filename as many times as you like before the assignment deadline; the previously submitted copy will be replaced by the latest one.

Please make sure that you have read page 2 about the submission close off date and time and the compulsory requirement to attend the execution test in Week 12

Failure to do both of these things will result in your assignment be awarded a mark of 0, regardless of the correctness of the program.

Execution test marks are provisional and subject to final plagiarism checks and checks on the compliance of your code to this assignment document.

As such final assignment marks may be lower or withdrawn completely.

Final Notes: - transferring files between Windows and Unix

Be very careful transferring files from Windows to Unix. If you do transfer a file from Windows to Unix open the file, in Unix, using vi.

For example, if you transferred a file named b.txt from Windows to Unix

open the file in Unix with the command

vi –b b.txt

you will (might) see a lot of ^M's at the end of each line.

These MUST be removed using the command shown below or else your input file will have too many newline characters and will not translate properly. That is, your code will not correctly read the input file.

Your code will work on Windows but NOT on Unix.

Still in vi, in command mode (press the Esc key first) do the following

:%s/ctrl-v ctrl-m//g

ctrl-v ctrl-m means hold down the control key and with the control key down press v then press m.

Final, final notes

Don't let anyone look at your code and definitely don't give anyone a copy of your code. The plagiarism checker will pick up that the assignments are the same and you will both get 0 (it doesn't matter if you can explain all your code).

There will be consultation sessions for the assignment, the times will be posted on LMS, if you have problems come to consultation.

And a final, final, final note, "eat the dragon in little bits". Do a little bit every night; before you know it you will be finished. The assignment is marked with running code, so you are better to have 1 or 2 parts completed that actually compile and run, rather than a whole lot of code that doesn't compile.

Answer Detail

Get This Answer

Invite Tutor