{"id":14884,"date":"2023-07-26T15:43:38","date_gmt":"2023-07-26T10:13:38","guid":{"rendered":"http:\/\/myprojectideas.com\/?p=14884"},"modified":"2025-10-10T11:41:59","modified_gmt":"2025-10-10T11:41:59","slug":"hospital-management-system-with-c","status":"publish","type":"post","link":"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/","title":{"rendered":"Hospital Management System with C++"},"content":{"rendered":"<p>This Hospital Management System with C++ simulates the management of patients across different departments in a hospital setting. This system can be used as a starting point for anyone aiming to develop a more comprehensive hospital management system or looking for a hands-on approach to understanding data structures and algorithms, particularly the use of linked lists.<\/p>\n<iframe loading=\"lazy\"  id=\"_ytid_88045\"  width=\"1080\" height=\"607\"  data-origwidth=\"1080\" data-origheight=\"607\" src=\"https:\/\/www.youtube.com\/embed\/SxSR9UoLmlU?enablejsapi=1&autoplay=0&cc_load_policy=0&cc_lang_pref=&iv_load_policy=1&loop=0&rel=1&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=1&\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe>\n<h2>Introduction<\/h2>\n<p>The main objective of this C++ project is to automate the management of a hospital&#8217;s departments and the patients within them, thereby simplifying and speeding up hospital processes. Our system manages four departments, namely the General Clinic, Heart Clinic, Lung Clinic, and Plastic Surgery. For each department, it maintains a queue of patients awaiting treatment, with provisions for adding patients, taking them out for treatment, searching for a specific patient, and displaying the list of patients in a department.<\/p>\n<p>This program also follows a priority scheme based on the criticality of the patient&#8217;s condition. Critically ill patients are added at the beginning of the queue, ensuring they receive treatment on a priority basis. In contrast, regular patients are added at the end of the queue. This queue management follows a first-in, first-out (FIFO) protocol, which means patients are taken out for treatment in the order they were added.<\/p>\n<h2>Objectives<\/h2>\n<p><strong>1. Creating Departments:<\/strong> To establish four departments in the hospital\u2014General Clinic, Heart Clinic, Lung Clinic, and Plastic Surgery. Each department maintains a queue (linked list) of patients waiting for treatment.<\/p>\n<p><strong>2. Patient Management:<\/strong> To add patients to any department. There are two categories of patients &#8211; normal and critically ill. A critically ill patient is always added to the beginning of the queue (prioritizing their treatment), while a normal patient is added to the end of the queue.<\/p>\n<p><strong>3. Searching Patients:<\/strong> To provide the ability to search for a patient within a department using their unique ID.<\/p>\n<p><strong>4. Service Management:<\/strong> When a patient is taken to the doctor, they are removed from the queue. The system follows a first-in, first-out (FIFO) approach, meaning that the patient who arrived first (is at the front of the queue) gets treated first.<\/p>\n<p><strong>5. Displaying Patient List:<\/strong> To display the list of all patients in a particular department, showing details such as ID, name, age, blood group, and gender.<\/p>\n<p><strong>6. Repetitive Actions:<\/strong> The system keeps running until explicitly stopped by the user, allowing for continuous addition, removal, search, and listing of patients in different departments.<\/p>\n<h2>Requirements<\/h2>\n<p>You should have the following pre requisites to build this Hospital Management System with C++<\/p>\n<p><strong><span data-preserver-spaces=\"true\">Knowledge Prerequisites:<\/span><\/strong><\/p>\n<ul>\n<li><strong><span data-preserver-spaces=\"true\">Basic C++ Knowledge:<\/span><\/strong><span data-preserver-spaces=\"true\">\u00a0You need to understand the basics of C++, including variables, data types, operators, loops, and conditionals. This program uses all of these concepts.<\/span><\/li>\n<li><strong><span data-preserver-spaces=\"true\">Advanced C++ Knowledge:<\/span><\/strong><span data-preserver-spaces=\"true\">\u00a0The code also uses more advanced concepts like structures (struct), classes, pointers, and dynamic memory allocation (new and delete). It&#8217;s crucial to understand how these work in C++.<\/span><\/li>\n<li><strong><span data-preserver-spaces=\"true\">File Input\/Output:<\/span><\/strong><span data-preserver-spaces=\"true\">\u00a0The code assumes that data is being read from or written to files. Understanding how C++ handles file I\/O is important.<\/span><\/li>\n<li><strong><span data-preserver-spaces=\"true\">String Manipulation:<\/span><\/strong><span data-preserver-spaces=\"true\">\u00a0Familiarity with string manipulation in C++ is essential, particularly with functions like<em><strong> getline, strcmp, <\/strong><\/em><strong>and<\/strong><em><strong> strcpy.<\/strong><\/em><\/span><\/li>\n<li><strong><span data-preserver-spaces=\"true\">Knowledge of Linked Lists:<\/span><\/strong><span data-preserver-spaces=\"true\">\u00a0The program uses a singly linked list to manage patient data. Linked lists are a fundamental data structure in computer science, so knowing how they work is crucial.<\/span><\/li>\n<\/ul>\n<p><strong><span data-preserver-spaces=\"true\">Software Prerequisites:<\/span><\/strong><\/p>\n<ul>\n<li><strong><span data-preserver-spaces=\"true\">C++ Compiler:<\/span><\/strong><span data-preserver-spaces=\"true\"> You need a compiler to build and run C++ code. The<a href=\"https:\/\/gcc.gnu.org\/\"> GNU Compiler Collection (GCC)<\/a> is a commonly-used free compiler that can handle C++ code.<\/span><\/li>\n<li><strong><span data-preserver-spaces=\"true\">Integrated Development Environment (IDE):<\/span><\/strong><span data-preserver-spaces=\"true\"> While not strictly necessary, an IDE makes writing, building, and debugging C++ code easier. Some popular C++ IDEs include <a href=\"https:\/\/www.codeblocks.org\/\">Code::Blocks<\/a>,<a href=\"https:\/\/projects.eclipse.org\/projects\/tools.cdt\"> Eclipse CDT<\/a>, and <a href=\"https:\/\/visualstudio.microsoft.com\/\">Visual Studio<\/a>.<\/span><\/li>\n<\/ul>\n<p><span data-preserver-spaces=\"true\">The specific IDE you choose doesn&#8217;t significantly impact the code itself as long as the IDE supports C++ development. However, it may affect how you build and run the code. For example, in Visual Studio, you would typically use the built-in &#8220;Build Solution&#8221; and &#8220;Run&#8221; options to build and execute your code, whereas, in Code::Blocks, you would use the &#8220;Build&#8221; and &#8220;Run&#8221; buttons. <\/span><\/p>\n<p><span data-preserver-spaces=\"true\"><strong>Note:<\/strong> <em>Your IDE should be configured to use a C++ compiler (like GCC) to build your code.<\/em><\/span><\/p>\n<h2>Source Code<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">#include&lt;iostream&gt;\r\n\r\n#include&lt;conio.h&gt;\r\n\r\n#include&lt;string.h&gt;\r\n\r\n#include&lt;stdlib.h&gt;\r\n\r\nusing namespace std;\r\n\r\nstruct patient\r\n\r\n{\r\n\r\nlong long ID;\r\n\r\nstring firstname;\r\n\r\nstring lastname;\r\n\r\nint age;\r\n\r\nchar blood[5];\r\n\r\nchar gender;\r\n\r\npatient*next;\r\n\r\n};\r\n\r\nclass linkedqueue\r\n\r\n{\r\n\r\npatient *head,*last;\r\n\r\npublic:\r\n\r\nlinkedqueue() \/\/constructor\r\n\r\n{\r\n\r\nhead=NULL;\r\n\r\nlast=NULL;\r\n\r\n}\r\n\r\npatient input();\r\n\r\nvoid insertatend();\r\n\r\nvoid insertatbeg();\r\n\r\nvoid getpatientout();\r\n\r\nvoid listofpatients();\r\n\r\nint search(int);\r\n\r\nchar departmentname[50];\r\n\r\n};\r\n\r\nint linkedqueue :: search(int item)\r\n\r\n{\r\n\r\nif(head==NULL)\r\n\r\nreturn false;\r\n\r\nelse\r\n\r\n{\r\n\r\nint flag=0;\r\n\r\npatient*p=new patient();\r\n\r\np=head;\r\n\r\nwhile( p-&gt;next!=NULL &amp;&amp; p-&gt;ID!=item )\r\n\r\n{\r\n\r\np=p-&gt;next;\r\n\r\n}\r\n\r\nif(p-&gt;ID==item)\r\n\r\n{\r\n\r\nflag=1;\r\n\r\nreturn true;\r\n\r\n}\r\n\r\nif(flag==0)\r\n\r\nreturn false;\r\n\r\n}\r\n\r\n}\r\n\r\nint readnumber()\r\n\r\n{\r\n\r\nchar b[20];\r\n\r\ncin.getline(b, sizeof(b));\r\n\r\nreturn atoi(b);\r\n\r\n}\r\n\r\npatient linkedqueue :: input()\r\n\r\n{\r\n\r\nint flag=0;\r\n\r\npatient *p=new patient();\r\n\r\ncout &lt;&lt; \"\\n Please enter data for patient\\n\";\r\n\r\ncout&lt;&lt;\"\\n First name : \";\r\n\r\ngetline(cin,p-&gt;firstname);\r\n\r\ncout &lt;&lt; \" Last name : \";\r\n\r\ngetline(cin,p-&gt;lastname);\r\n\r\nagain :\r\n\r\ncout &lt;&lt; \" Blood Group : \";\r\n\r\ncin&gt;&gt;p-&gt;blood;\r\n\r\nif((strcmp(p-&gt;blood,\"A+\")==0)||(strcmp(p-&gt;blood,\"a+\")==0)||(strcmp(p-&gt;blood,\"A-\")==0)||(strcmp(p-&gt;blood,\"a-\")==0)||\r\n\r\n(strcmp(p-&gt;blood,\"B+\")==0)||(strcmp(p-&gt;blood,\"b+\")==0)||(strcmp(p-&gt;blood,\"B-\")==0)||(strcmp(p-&gt;blood,\"b-\")==0)||\r\n\r\n(strcmp(p-&gt;blood,\"O+\")==0)||(strcmp(p-&gt;blood,\"o+\")==0)||(strcmp(p-&gt;blood,\"O-\")==0)||(strcmp(p-&gt;blood,\"o-\")==0)||\r\n\r\n(strcmp(p-&gt;blood,\"AB+\")==0)||(strcmp(p-&gt;blood,\"ab+\")==0)||(strcmp(p-&gt;blood,\"AB-\")==0)||(strcmp(p-&gt;blood,\"ab-\")==0))\r\n\r\nflag=1;\r\n\r\nif(flag==0)\r\n\r\n{\r\n\r\ncout&lt;&lt;\"\\n Invalid Blood Group Try Again..\\n\\n\";\r\n\r\ngoto again;\r\n\r\n}\r\n\r\ncout&lt;&lt;\" Gender(m\/f) : \";\r\n\r\ncin&gt;&gt;p-&gt;gender;\r\n\r\ncout&lt;&lt;\" Age : \";\r\n\r\ncin&gt;&gt;p-&gt;age;\r\n\r\ncout&lt;&lt;\" Mobile number : \";\r\n\r\ncin&gt;&gt;p-&gt;ID;\r\n\r\nif(search(p-&gt;ID))\r\n\r\n{\r\n\r\np-&gt;ID=0;\r\n\r\ncout &lt;&lt; \"\\n Data not valid. Operation cancelled.\";\r\n\r\n}\r\n\r\nreturn *p;\r\n\r\n}\r\n\r\nvoid output(patient *p)\r\n\r\n{\r\n\r\ncout&lt;&lt;\"\\n \\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\";\r\n\r\ncout&lt;&lt;\"\\n Patient data:\\n\";\r\n\r\ncout&lt;&lt;\"\\n First Name : \"&lt;&lt;p-&gt;firstname;\r\n\r\ncout&lt;&lt;\"\\n Last Name : \"&lt;&lt;p-&gt;lastname;\r\n\r\ncout&lt;&lt;\"\\n Gender : \"&lt;&lt;p-&gt;gender;\r\n\r\ncout&lt;&lt;\"\\n Age : \"&lt;&lt;p-&gt;age;\r\n\r\ncout&lt;&lt;\"\\n Blood Group : \"&lt;&lt;p-&gt;blood;\r\n\r\ncout&lt;&lt;\"\\n Mobile Number : \"&lt;&lt;p-&gt;ID;\r\n\r\ncout&lt;&lt;\"\\n\\n \\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\";\r\n\r\n}\r\n\r\nvoid linkedqueue :: insertatbeg()\r\n\r\n{\r\n\r\npatient*p=new patient();\r\n\r\n*p=input();\r\n\r\nif(p-&gt;ID==0)\r\n\r\nreturn;\r\n\r\nif(head==NULL)\r\n\r\n{\r\n\r\nhead=p;\r\n\r\nlast=p;\r\n\r\np-&gt;next=NULL;\r\n\r\n}\r\n\r\nelse\r\n\r\n{\r\n\r\np-&gt;next=head;\r\n\r\nhead=p;\r\n\r\n}\r\n\r\nsystem(\"cls\");\r\n\r\ncout &lt;&lt; \"\\n\\tPatient added:\";\r\n\r\noutput(p);\r\n\r\n}\r\n\r\nvoid linkedqueue:: insertatend()\r\n\r\n{\r\n\r\npatient*p=new patient();\r\n\r\n*p=input();\r\n\r\nif(p-&gt;ID==0)\r\n\r\nreturn;\r\n\r\nif(head==NULL)\r\n\r\n{\r\n\r\nhead=p;\r\n\r\nlast=p;\r\n\r\np-&gt;next=NULL;\r\n\r\n}\r\n\r\nelse\r\n\r\n{\r\n\r\np-&gt;next=NULL;\r\n\r\nlast-&gt;next=p;\r\n\r\nlast=p;\r\n\r\n}\r\n\r\nsystem(\"cls\");\r\n\r\ncout&lt;&lt;\"\\n \\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\";\r\n\r\ncout&lt;&lt;\"\\n |-- HOSPITAL MANAGEMENT SYSTEM --|\";\r\n\r\ncout&lt;&lt;\"\\n \\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\n\";\r\n\r\ncout &lt;&lt;\"\\n ----------PATIENT ADDED-----------\";\r\n\r\noutput(p);\r\n\r\n}\r\n\r\nvoid linkedqueue :: getpatientout()\r\n\r\n{\r\n\r\nsystem(\"cls\");\r\n\r\nif(head==NULL)\r\n\r\n{\r\n\r\ncout&lt;&lt;\"\\n No Patient to operate\";\r\n\r\n}\r\n\r\nelse\r\n\r\n{\r\n\r\npatient*p=new patient();\r\n\r\np=head;\r\n\r\nhead=head-&gt;next;\r\n\r\ncout &lt;&lt; \"\\n Patient to operate:\";\r\n\r\noutput(p);\r\n\r\n}\r\n\r\n}\r\n\r\nvoid linkedqueue :: listofpatients()\r\n\r\n{\r\n\r\nif(head==NULL)\r\n\r\n{\r\n\r\ncout&lt;&lt;\"\\n No patient\";\r\n\r\n}\r\n\r\nsystem(\"cls\");\r\n\r\ncout&lt;&lt;\"\\n \\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\";\r\n\r\ncout&lt;&lt;\"\\n |-- HOSPITAL MANAGEMENT SYSTEM --|\";\r\n\r\ncout&lt;&lt;\"\\n \\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\n\";\r\n\r\npatient*p=new patient;\r\n\r\np=head;\r\n\r\nwhile(p!=NULL)\r\n\r\n{\r\n\r\ncout&lt;&lt;\"\\n Patient data:\\n\";\r\n\r\ncout&lt;&lt;\"\\n First Name : \"&lt;&lt;p-&gt;firstname;\r\n\r\ncout&lt;&lt;\"\\n Last Name : \"&lt;&lt;p-&gt;lastname;\r\n\r\ncout&lt;&lt;\"\\n Gender : \"&lt;&lt;p-&gt;gender;\r\n\r\ncout&lt;&lt;\"\\n Age : \"&lt;&lt;p-&gt;age;\r\n\r\ncout&lt;&lt;\"\\n Blood Group : \"&lt;&lt;p-&gt;blood;\r\n\r\ncout&lt;&lt;\"\\n Mobile Number : \"&lt;&lt;p-&gt;ID;\r\n\r\ncout&lt;&lt;\"\\n\\n \\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\n\";\r\n\r\np=p-&gt;next;\r\n\r\n}\r\n\r\ncout&lt;&lt;\"\\n\";\r\n\r\n}\r\n\r\nvoid departmentmenu (linkedqueue * q)\r\n\r\n{\r\n\r\nint choice = 0, success;\r\n\r\npatient p;\r\n\r\nwhile (choice != 5)\r\n\r\n{\r\n\r\nsystem(\"cls\");\r\n\r\ncout&lt;&lt;\"\\n \\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\";\r\n\r\ncout&lt;&lt;\"\\n |-- HOSPITAL MANAGEMENT SYSTEM --|\";\r\n\r\ncout&lt;&lt;\"\\n \\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\";\r\n\r\ncout&lt;&lt;\"\\n\\n \"&lt;&lt;q-&gt;departmentname;\r\n\r\ncout&lt;&lt;\"\\n [1] Add normal patient\\n\";\r\n\r\ncout&lt;&lt;\" [2] Add critically ill patient\\n\";\r\n\r\ncout&lt;&lt;\" [3] Take patient to Doctor\\n\";\r\n\r\ncout&lt;&lt;\" [4] Display list\\n\";\r\n\r\ncout&lt;&lt;\" [5] Change department or exit\\n\";\r\n\r\ncout&lt;&lt;\"\\n Please enter your choice : \";\r\n\r\nchoice=readnumber();\r\n\r\ncout&lt;&lt;\" \\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\";\r\n\r\nswitch (choice)\r\n\r\n{\r\n\r\ncase 1: q-&gt;insertatend();\r\n\r\ncout &lt;&lt; \"\\n Press any key\";\r\n\r\ngetch();\r\n\r\nbreak;\r\n\r\ncase 2: q-&gt;insertatbeg();\r\n\r\ncout &lt;&lt; \"\\n Press any key\";\r\n\r\ngetch();\r\n\r\nbreak;\r\n\r\ncase 3: q-&gt;getpatientout();\r\n\r\ncout&lt;&lt;\"\\n Press any key\";\r\n\r\ngetch();\r\n\r\nbreak;\r\n\r\ncase 4: system(\"cls\");\r\n\r\nq-&gt;listofpatients();\r\n\r\ncout&lt;&lt;\"\\n Press any key\";\r\n\r\ngetch();\r\n\r\nbreak;\r\n\r\n}\r\n\r\n}\r\n\r\n}\r\n\r\nint main ()\r\n\r\n{\r\n\r\nint i, choice = 0;\r\n\r\nlinkedqueue departments[4];\r\n\r\nwhile(choice!=5)\r\n\r\n{\r\n\r\nstrcpy(departments[0].departmentname,\"GENERAL CLINIC\\n\");\r\n\r\nstrcpy(departments[1].departmentname,\"HEART CLINIC\\n\");\r\n\r\nstrcpy(departments[2].departmentname,\"LUNG CLINIC\\n\");\r\n\r\nstrcpy(departments[3].departmentname,\"PLASTIC SURGERY\\n\");\r\n\r\nsystem(\"cls\");\r\n\r\ncout&lt;&lt;\"\\n \\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\";\r\n\r\ncout&lt;&lt;\"\\n |-- HOSPITAL MANAGEMENT SYSTEM --|\";\r\n\r\ncout&lt;&lt;\"\\n \\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\xcd\\n\\n\";\r\n\r\ncout&lt;&lt;\" Main Menu\\n\\n\";\r\n\r\nfor (i = 0; i &lt; 4; i++)\r\n\r\n{\r\n\r\ncout&lt;&lt;\" \"&lt;&lt;(i+1)&lt;&lt;\": \"&lt;&lt;departments[i].departmentname;\r\n\r\n}\r\n\r\ncout&lt;&lt;\" 5: Exit\";\r\n\r\ncout&lt;&lt;\"\\n\\n Please enter your choice : \";\r\n\r\nchoice=readnumber();\r\n\r\nif(choice&gt;=1 &amp;&amp; choice&lt;=4)\r\n\r\n{\r\n\r\ndepartmentmenu(&amp;departments[choice-1]);\r\n\r\n}\r\n\r\n}\r\n\r\nif(choice==5)\r\n\r\ncout&lt;&lt;\"\\n\\t\\tThank you! \\n\";\r\n\r\nexit(0);\r\n\r\n}<\/pre>\n<h2>Explanation of the Code<\/h2>\n<p><span data-preserver-spaces=\"true\">The provided code is a simulation of a hospital management system using a linked list data structure in C++. Here&#8217;s a summary of what the code is doing:<\/span><\/p>\n<p><span data-preserver-spaces=\"true\"><strong>1. <em>struct patient:<\/em><\/strong> The patient struct stores data for individual patients (ID, name, age, blood group, gender, and a pointer to the next patient).<\/span><\/p>\n<p><span data-preserver-spaces=\"true\"><strong>2.<\/strong><em><strong> class linkedqueue:<\/strong><\/em> The linkedqueue class contains two pointers (head and last) pointing to the first and last patient in the linked list. It also contains the member functions required to perform operations on this linked list:<\/span><\/p>\n<ul>\n<li><span data-preserver-spaces=\"true\"><em><strong>search():<\/strong><\/em> Searches for a patient with a given ID in the linked list.<\/span><\/li>\n<li><span data-preserver-spaces=\"true\"><em><strong>input():<\/strong><\/em> Allows user to input patient information and checks if the entered blood group and ID are valid. The ID is considered invalid if a patient with the same ID already exists.<\/span><\/li>\n<li><span data-preserver-spaces=\"true\"><em><strong>insertatbeg() and insertatend():<\/strong><\/em> Adds a new patient to the beginning or end of the linked list, respectively.<\/span><\/li>\n<li><span data-preserver-spaces=\"true\"><em><strong>getpatientout():<\/strong><\/em> Deletes the first patient from the linked list.<\/span><\/li>\n<li><span data-preserver-spaces=\"true\"><em><strong>listofpatients():<\/strong><\/em> Prints out the data of all patients in the linked list.<\/span><\/li>\n<\/ul>\n<p><strong>3.<\/strong><em><strong> departmentmenu(): <\/strong><\/em><span data-preserver-spaces=\"true\">This function is called for each department and allows the user to perform the following operations:<\/span><\/p>\n<ul>\n<li><span data-preserver-spaces=\"true\">Add a normal patient (insert at end)<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">Add a critically ill patient (insert at beginning)<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">Take patient to the doctor (remove the first patient in the list)<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">Display list of patients<\/span><\/li>\n<\/ul>\n<p><span data-preserver-spaces=\"true\"><strong>4. <em>main():<\/em><\/strong> In the main() function, four departments (general clinic, heart clinic, lung clinic, and plastic surgery) are created as linked queues. Then, in a loop, the user can select a department and call the departmentmenu() function to perform operations on the selected department. The loop continues until the user chooses to exit.<\/span><\/p>\n<h2>Output<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-17489 size-full\" src=\"https:\/\/rudelabs.ai\/blogs\/wp-content\/uploads\/2023\/07\/word-image-14884-1.webp\" alt=\"Hospital Management System with C++\" width=\"681\" height=\"309\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-17491 size-full\" src=\"https:\/\/rudelabs.ai\/blogs\/wp-content\/uploads\/2023\/07\/word-image-14884-2.webp\" alt=\"Hospital Management System with C++\" width=\"481\" height=\"380\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-17492 size-full\" src=\"https:\/\/rudelabs.ai\/blogs\/wp-content\/uploads\/2023\/07\/word-image-14884-3.webp\" alt=\"Hospital Management System with C++\" width=\"466\" height=\"391\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>The idea behind the development of this Hospital management system with C++ is to maintain the records of patients according to their diagnosis information. Our system is interactive, with user-friendly prompts that guide the user through the various operations they can perform. This C++ project serves as a practical tool for learning C++ and exploring how linked lists can be used to manage and manipulate data efficiently in real-world applications.<\/p>\n<p>We can also add more features to this project like Doctor\u2019s records, their availability, appointments, and so on. Thus, developing this project will prove very beneficial for healthcare institutes.<\/p>\n<p><a href=\"https:\/\/rudelabs.ai\/blogs\/category\/c-computer-science\/\"><em><strong>More C++ Projects&gt;&gt;&gt;<\/strong><\/em><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This Hospital Management System with C++ simulates the management of patients across different departments in a hospital setting. This system can be used as a starting point for anyone aiming to develop a more comprehensive hospital management system or looking for a hands-on approach to understanding data structures and algorithms, particularly the use of linked [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":14886,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[16,4,7],"tags":[],"class_list":["post-14884","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-computer-science","category-coding-basics","category-coding-projects"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Hospital Management System with C++ - RUDE LABS<\/title>\n<meta name=\"description\" content=\"The idea behind the development of this Hospital management system with C++ is to maintain the records of patients according to their diagnosis information.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hospital Management System with C++ - RUDE LABS\" \/>\n<meta property=\"og:description\" content=\"The idea behind the development of this Hospital management system with C++ is to maintain the records of patients according to their diagnosis information.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/\" \/>\n<meta property=\"og:site_name\" content=\"RUDE LABS\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-26T10:13:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-10-10T11:41:59+00:00\" \/>\n<meta name=\"author\" content=\"rudelabs.ai\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@rudelabs_in\" \/>\n<meta name=\"twitter:site\" content=\"@rudelabs_in\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rudelabs.ai\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/\"},\"author\":{\"name\":\"rudelabs.ai\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#\/schema\/person\/560bad88bae03cae99a326a46af0c894\"},\"headline\":\"Hospital Management System with C++\",\"datePublished\":\"2023-07-26T10:13:38+00:00\",\"dateModified\":\"2025-10-10T11:41:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/\"},\"wordCount\":1086,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#organization\"},\"image\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/#primaryimage\"},\"thumbnailUrl\":\"\",\"articleSection\":[\"C\/C++\",\"Coding Basics\",\"Coding Projects\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/\",\"url\":\"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/\",\"name\":\"Hospital Management System with C++ - RUDE LABS\",\"isPartOf\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/#primaryimage\"},\"thumbnailUrl\":\"\",\"datePublished\":\"2023-07-26T10:13:38+00:00\",\"dateModified\":\"2025-10-10T11:41:59+00:00\",\"description\":\"The idea behind the development of this Hospital management system with C++ is to maintain the records of patients according to their diagnosis information.\",\"breadcrumb\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/#primaryimage\",\"url\":\"\",\"contentUrl\":\"\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/rudelabs.ai\/blogs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hospital Management System with C++\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#website\",\"url\":\"https:\/\/rudelabs.ai\/blogs\/\",\"name\":\"RUDE LABS\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/rudelabs.ai\/blogs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#organization\",\"name\":\"RUDE LABS\",\"url\":\"https:\/\/rudelabs.ai\/blogs\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/rudelabs.ai\/blogs\/wp-content\/uploads\/2025\/09\/RUDE-LABS.webp\",\"contentUrl\":\"https:\/\/rudelabs.ai\/blogs\/wp-content\/uploads\/2025\/09\/RUDE-LABS.webp\",\"width\":2459,\"height\":414,\"caption\":\"RUDE LABS\"},\"image\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/rudelabs_in\",\"https:\/\/www.linkedin.com\/company\/ru-delabs\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#\/schema\/person\/560bad88bae03cae99a326a46af0c894\",\"name\":\"rudelabs.ai\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4d9f672e72f97294dfb6fac3d78e9f0bb5421a701cd2141cf2a2e540b4d67191?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4d9f672e72f97294dfb6fac3d78e9f0bb5421a701cd2141cf2a2e540b4d67191?s=96&d=mm&r=g\",\"caption\":\"rudelabs.ai\"},\"sameAs\":[\"https:\/\/rudelabs.ai\/blogs\"],\"url\":\"https:\/\/rudelabs.ai\/blogs\/author\/rudelabs-ai\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Hospital Management System with C++ - RUDE LABS","description":"The idea behind the development of this Hospital management system with C++ is to maintain the records of patients according to their diagnosis information.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/","og_locale":"en_US","og_type":"article","og_title":"Hospital Management System with C++ - RUDE LABS","og_description":"The idea behind the development of this Hospital management system with C++ is to maintain the records of patients according to their diagnosis information.","og_url":"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/","og_site_name":"RUDE LABS","article_published_time":"2023-07-26T10:13:38+00:00","article_modified_time":"2025-10-10T11:41:59+00:00","author":"rudelabs.ai","twitter_card":"summary_large_image","twitter_creator":"@rudelabs_in","twitter_site":"@rudelabs_in","twitter_misc":{"Written by":"rudelabs.ai","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/#article","isPartOf":{"@id":"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/"},"author":{"name":"rudelabs.ai","@id":"https:\/\/rudelabs.ai\/blogs\/#\/schema\/person\/560bad88bae03cae99a326a46af0c894"},"headline":"Hospital Management System with C++","datePublished":"2023-07-26T10:13:38+00:00","dateModified":"2025-10-10T11:41:59+00:00","mainEntityOfPage":{"@id":"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/"},"wordCount":1086,"commentCount":0,"publisher":{"@id":"https:\/\/rudelabs.ai\/blogs\/#organization"},"image":{"@id":"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/#primaryimage"},"thumbnailUrl":"","articleSection":["C\/C++","Coding Basics","Coding Projects"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/","url":"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/","name":"Hospital Management System with C++ - RUDE LABS","isPartOf":{"@id":"https:\/\/rudelabs.ai\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/#primaryimage"},"image":{"@id":"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/#primaryimage"},"thumbnailUrl":"","datePublished":"2023-07-26T10:13:38+00:00","dateModified":"2025-10-10T11:41:59+00:00","description":"The idea behind the development of this Hospital management system with C++ is to maintain the records of patients according to their diagnosis information.","breadcrumb":{"@id":"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/rudelabs.ai\/blogs\/hospital-management-system-with-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/rudelabs.ai\/blogs\/"},{"@type":"ListItem","position":2,"name":"Hospital Management System with C++"}]},{"@type":"WebSite","@id":"https:\/\/rudelabs.ai\/blogs\/#website","url":"https:\/\/rudelabs.ai\/blogs\/","name":"RUDE LABS","description":"","publisher":{"@id":"https:\/\/rudelabs.ai\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/rudelabs.ai\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/rudelabs.ai\/blogs\/#organization","name":"RUDE LABS","url":"https:\/\/rudelabs.ai\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rudelabs.ai\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/rudelabs.ai\/blogs\/wp-content\/uploads\/2025\/09\/RUDE-LABS.webp","contentUrl":"https:\/\/rudelabs.ai\/blogs\/wp-content\/uploads\/2025\/09\/RUDE-LABS.webp","width":2459,"height":414,"caption":"RUDE LABS"},"image":{"@id":"https:\/\/rudelabs.ai\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/rudelabs_in","https:\/\/www.linkedin.com\/company\/ru-delabs\/"]},{"@type":"Person","@id":"https:\/\/rudelabs.ai\/blogs\/#\/schema\/person\/560bad88bae03cae99a326a46af0c894","name":"rudelabs.ai","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rudelabs.ai\/blogs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4d9f672e72f97294dfb6fac3d78e9f0bb5421a701cd2141cf2a2e540b4d67191?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d9f672e72f97294dfb6fac3d78e9f0bb5421a701cd2141cf2a2e540b4d67191?s=96&d=mm&r=g","caption":"rudelabs.ai"},"sameAs":["https:\/\/rudelabs.ai\/blogs"],"url":"https:\/\/rudelabs.ai\/blogs\/author\/rudelabs-ai\/"}]}},"_links":{"self":[{"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/posts\/14884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/comments?post=14884"}],"version-history":[{"count":4,"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/posts\/14884\/revisions"}],"predecessor-version":[{"id":17628,"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/posts\/14884\/revisions\/17628"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/media?parent=14884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/categories?post=14884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/tags?post=14884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}