Question: C++ programming (Selection Structures,arrays,files,functions,repetition,loop statmentts) A hospital has several branches in a city. Implement a well-structured C program to enable the management of patients and
C++ programming (Selection Structures,arrays,files,functions,repetition,loop statmentts)
A hospital has several branches in a city. Implement a well-structured C program to enable the management of patients and doctors. The information is kept in a hospitalInfo.txt text-file of the form:where each line of the text-file contains a unique branch ID, total number of patients admitted in that branch, and number of doctors in that branch. The maximum number of patients that can be accommodated in a branch is 50 and the maximum number of doctors in each branch is 5. Your program must define these as constants. Your program must have the following main menu: 1. Display total no. of patients and doctors for all branches 2. Display no. of patients and doctors for a particular branch 3. Admit patients to a particular branch 4. Discharge patients from a particular branch 5. Add doctor(s) to a branch 6. Transfer doctor(s) from one branch to another 7. Close a particular branch 8. Exit Please select your choice: the program must loop as long as option 8 has not been selected. It must display an appropriate error message if an invalid choice is entered. After executing each of the options 1 to 7, the program must pause and display the message: Press Enter key to continue . . . the program must clear the screen and display the main menu after pressing the Enter key. Each of the options 1 to 7 must be implemented in a separate function. The code for Press Enter key to continue . . . must also be implemented as a separate function. Note: The above menus are minimum but you are free to add more like removing doctors, adding branches etc. with proper functionality. The options must have the following behaviors:
Option 1: Display total no. of patients and doctors for all branches It displays the patients and doctors information of all branches. The option must be implemented by reading directly from hospitalInfo.txt text-file. It then waits for the Enter key to be pressed before returning control to the main menu:
Option 2: Display no. of patients and doctors for a particular branch It prompts for and reads a branch ID. It then searches for this branch ID in the hospitalInfo.txt text-file. If the branch is not found an appropriate error message is displayed, otherwise; the branch information is displayed. In both cases, the option waits for the Enter key to be pressed before returning control to the main menu
Option 3. Admit patients to a particular branch It prompts for and reads a branch ID and the number of patients to admit. If the number is zero or negative an appropriate error message is displayed; otherwise it searches for this branch ID in the hospitalInfo.txt text-file. If the branch ID is not found an appropriate error message is displayed. If the number of patients to add is not valid an appropriate error message is displayed. Also the error is displayed if the number of patients is more than the maximum allowed as defined by constant; otherwise the branch patients are updated and the new number of patients are displayed:
Option 4: Discharge patients from a particular branch It prompts for and reads a branch ID and the number of patients to discharge. If the number of patients is zero or negative an appropriate error message is displayed, otherwise it searches for this branch ID in the hospitalInfo.txt text-file. If the branch ID is not found or if the current number of patients is not sufficient an appropriate error message is displayed, otherwise; the contents of the text-file are copied into two parallel 1D-arrays (count the number of lines in the text-file, and use this number as the size of each of the arrays). The number of patients in the branch is updated, and the hospitalInfo.txt text-file is then updated and the new number of patients is displayed:
Options 5. Add doctor(s) to a branch It prompts for and reads a branch ID and the number of doctors to add. If the number is zero or negative an appropriate error message is displayed; otherwise it searches for this branch ID in the hospitalInfo.txt text-file. If the branch ID is not found an appropriate error message is displayed. If the number of doctors to add is not valid an appropriate error message is displayed. Also the error is displayed if the number of doctors is more than the maximum allowed as defined by constant; otherwise the branch doctors are updated and the new number of doctors is displayed:
Options 6. Transfer doctor(s) from one branch to another It prompts for and reads a from and to branch IDs and the number of doctors to transfer. If the number of doctors is zero or negative an appropriate error message is displayed, otherwise it searches for the branch IDs in the hospitalInfo.txt text-file. If any of the branch ID is not found or if the current number of doctors is not sufficient an appropriate error message is displayed. The transferred doctors must not exceed the maximium number of allowed doctors in a branch (defined as constant) and also it must not allow to have 0 doctors in From branch. If all validation passes, the hospitalInfo.txt text-file is updated and the new number of doctors is displayed for both branches.
Options 7. Close a particular branch To implement option 6, search the text-file for the branch ID of the branch to be deleted, keeping track of its line number in the file. If the branch ID does not exist or if the number of patients in the branch is not zero (ignoring number of doctors), display an error; otherwise read the information from the text-file into parallel 1D-arrays (count the number of lines in the text-file, and use this number as the size of each of the arrays), then overwrite the text-file with the contents of the arrays, but skipping the branch you want to delete. Make sure you write the last line without generating an extra blank line at the end of the textfile.
Options 8. Exit It terminates the program.
Hint: ? When you update the hospitalInfo.txt text-file, make sure you do not insert a blank line at the end of the file, because this will generate reading errors. Write the last file line without generating . ? Use system(cls) to clear the screen especially when you want to display the menu again
Note: ? Your project must be general; it must work for any number of lines in hospitalInfo.txt ? You must implement some functions that take one or more arguments. A project with functions having no arguments is not a good solution. ? You may use other functions in your program, like countLines, searchForID, updateTextFile, loadToArrays, etc.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
