KDT85

hospital

Dec 15th, 2022 (edited)
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.78 KB | None | 0 0
  1. //This program is hospital management system using object-oriented programming.
  2. #include<iostream>
  3. #include<fstream>
  4. #include <limits>
  5. #ifdef _WIN32
  6. #include <Windows.h>
  7. #else
  8. #include <unistd.h>
  9. #endif
  10. #include <string>
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include <vector>
  14. #include <ctime>
  15. #include <filesystem>
  16.  
  17. using namespace std;
  18.  
  19. class Menu {
  20.     string data[10] = {};
  21.     int size = 10;
  22. public:
  23.     Menu(string st[], int z)
  24.     {
  25.         for (int i = 0; i < z; i++)
  26.         {
  27.             cout << st[i] << endl;
  28.             data[i] = st[i];
  29.         }
  30.         size = z;
  31.     }
  32.     Menu(string one, int z)
  33.     {
  34.         cout << one << endl;
  35.         cout << z << endl;
  36.         for (int i = 0; i < z; i++)
  37.             data[i] = one;
  38.     }
  39.     /* {
  40.  
  41.         int i = 0;
  42.         int c = 0;
  43.         int j = 0;
  44.  
  45.         while (one[i] != 0)
  46.         {
  47.             data[c][j] = one[i];
  48.             if (one[i] == '\n')
  49.             {
  50.                 data[c][j] = 0;
  51.                 c++;
  52.                 j = 0;
  53.             }
  54.             i++;
  55.             j++;
  56.         }
  57.         size = z;
  58.     } */
  59.  
  60.     void show(string title) {
  61.         cout << endl << "========= " << title << " MENU   =============";
  62.         cout << size;
  63.         for (int i = 0; i < size; i++)
  64.         {
  65.             cout << endl << i + 1 << " - " << data[i];
  66.             //cout << endl << data[i];
  67.         }
  68.         cout << endl << "===================================";
  69.  
  70.     }
  71.     int choice()
  72.     {
  73.         int c;
  74.  
  75.         cout << endl << "Enter your choice number: ";
  76.         cin >> c;
  77.         return c;
  78.     }
  79. };
  80. class Person
  81. {
  82. public:
  83.     // write the data for class person
  84.     int id;
  85.     string name;
  86.     char gender;
  87.     int dob;
  88.     string address;
  89.  
  90. public:
  91.     // define constructors
  92.     Person()
  93.     {
  94.         id = 1;
  95.         name = "person_name";
  96.         gender = 'm';
  97.         dob = 12345678;
  98.         address = "qwerty";
  99.  
  100.     }
  101.     Person(const Person& p)
  102.     {
  103.     }
  104.     Person(int id, string name, char gender, int dob, string address)
  105.     {
  106.     }
  107.     void print()
  108.     {
  109.     }
  110. };
  111. // use inheritance to make Patient class based on Person class
  112.  
  113. class Patient :public Person
  114. {
  115. public:
  116.     string illness;
  117.     string admission_date;
  118.     Patient() :Person()
  119.     {
  120.     }
  121.     Patient(int id, string name, char gender, int dob, string address,
  122.         string illness, string  admission_date)
  123.         : Person(id, name, gender, dob, address)
  124.     {
  125.  
  126.     }
  127.     Patient(const Patient& p) : Person(p.id, p.name, p.gender, p.dob, p.address)
  128.     {
  129.  
  130.     }
  131.     void print()
  132.     {
  133.         Person::print();
  134.  
  135.  
  136.     }
  137. };
  138. // use inheritance to make Personel class based on Person class
  139.  
  140. class Personnel :public Person
  141. {
  142. public:
  143.     string staff_post;
  144.     string staff_expertise;
  145.     Personnel() :Person()
  146.     {}
  147.     Personnel(int id, string name, char gender, int dob, string address,
  148.         string staff_post, string   staff_expertise)
  149.         : Person(id, name, gender, dob, address)
  150.     {
  151.  
  152.     }
  153.     Personnel(const Personnel& p) : Person(p.id, p.name, p.gender, p.dob, p.address)
  154.     {
  155.  
  156.     }
  157.     void print()
  158.     {
  159.         Person::print();
  160.  
  161.  
  162.     }
  163. };
  164.  
  165. class Hospital_Class
  166. {
  167. public:
  168.     vector < Patient> pList;
  169.     vector < Personnel> staffList;
  170.     // adds a Patient to Plist
  171.     void add(Patient p)
  172.     {
  173.         pList.push_back(p);
  174.         cout << "Patient added to list" << endl;
  175.  
  176.         Sleep(900);
  177.     }
  178.     //adds a Personnel to stafflist
  179.     void add(Personnel p2)
  180.     {
  181.         staffList.push_back(p2);
  182.  
  183.  
  184.     }
  185.     // saves personnel list into file
  186.     void save(vector < Personnel> list)
  187.     {
  188.         ofstream personnelFile;
  189.     }
  190.     // saves patient list into file
  191.     void save(vector < Patient> list)
  192.     {
  193.  
  194.     }
  195.     // update Patient list
  196.     void update(vector <Patient> list)
  197.     {
  198.     }
  199.     // update Personnel list
  200.     void update(vector <Personnel> list)
  201.     {
  202.  
  203.     }
  204.     // display all data of patient list
  205.     void display(vector< Patient> plist)
  206.     {
  207.         for (int i = 0; i < pList.size(); i++)
  208.         {
  209.             cout << "id = " << pList[i].id << endl;
  210.             cout << "name = " << pList[i].name << endl;
  211.             /*      cout << "gender = " << pList[i].gender << endl;
  212.                         cout << "date of birth = " << pList[i].dob << endl;
  213.                         cout << "address = " << pList[i].address << endl;
  214.                         cout << "illness = " << pList[i].illness << endl;
  215.                         cout << "admission date = " << pList[i].admission_date << endl;*/
  216.  
  217.  
  218.         }
  219.  
  220.  
  221.     }
  222.     // display all data of personnel list
  223.     void display(vector< Personnel> list)
  224.     {
  225.         for (int i = 0; i < staffList.size(); i++)
  226.         {
  227.             cout << staffList[i].name << endl;
  228.         }
  229.  
  230.     }
  231.     // read an id and delete its information from both memory and database of patients
  232.     void remove(vector <Patient> list)
  233.     {
  234.  
  235.     }
  236.     // read an id and delete its information from both memory and database of personnel
  237.  
  238.     void remove(vector <Personnel> list)
  239.     {
  240.  
  241.     }
  242.     // sets information of the Hopspital
  243.     void ourinfoset()
  244.     {
  245.  
  246.     }
  247.     // displays information of the hospital
  248.     void displayInfo()
  249.     {
  250.  
  251.     }
  252.     // reads information of patients and personnel from file and stores them in memory
  253.     void initialize()
  254.     {
  255.         ifstream patientFile, personnelFile;
  256.         Patient p;
  257.  
  258.         patientFile.open("Patient.txt");
  259.         personnelFile.open("Personnel.txt");
  260.         while (!patientFile.eof())
  261.         {
  262.             if (!(patientFile >> p.id)) break;
  263.             if (!(patientFile >> p.name)) break;
  264.             if (!(patientFile >> p.gender))break;
  265.             if (!(patientFile >> p.dob))break;
  266.             if (!(patientFile >> p.address))break;
  267.             if (!(patientFile >> p.illness))break;
  268.             if (!(patientFile >> p.admission_date))break;
  269.             pList.push_back(p);
  270.         }
  271.  
  272.         patientFile.close();
  273.         Personnel p2;
  274.         while (!personnelFile.eof())
  275.         {
  276.             if (!(personnelFile >> p2.id)) break;
  277.             if (!(personnelFile >> p2.name))break;
  278.             if (!(personnelFile >> p2.gender))break;
  279.             if (!(personnelFile >> p2.dob)) break;
  280.             if (!(personnelFile >> p2.address)) break;
  281.             if (!(personnelFile >> p2.staff_post)) break;
  282.             if (!(personnelFile >> p2.staff_expertise)) break;
  283.             staffList.push_back(p2);
  284.         }
  285.         personnelFile.close();
  286.     }
  287.     // read data for a personnel from keyboard
  288.     Personnel read(Personnel p)
  289.     {
  290.         cout << "Enter personnel id: ";
  291.         cin >> p.id;
  292.         cout << "Enter personnel name: ";
  293.         cin >> p.name;
  294.         /*      cout << "Enter personnel gender: ";
  295.                 cin >> p.gender;
  296.                 cout << "Enter personnel date of birth (DDMMYYYY): ";
  297.                 cin >> p.dob;
  298.                 cout << "Enter personnel address: ";
  299.                 cin >> p.address;
  300.                 cout << "Enter personnel post: ";
  301.                 cin >> p.staff_post;
  302.                 cout << p.staff_post << endl;
  303.                 cout << "Enter personnel expertise: ";
  304.                 cin >> p.staff_expertise;
  305.                 cout << p.staff_expertise << endl;*/
  306.         add(p);
  307.         return p;
  308.     }
  309.  
  310.  
  311.     // read data for a patient from keyboard
  312.  
  313.     Patient read(Patient p)
  314.     {
  315.         cout << "Enter patient id: ";
  316.         cin >> p.id;
  317.         cout << p.id << endl;
  318.         cout << "Enter patient name: ";
  319.         cin >> p.name;
  320.         cout << p.name << endl;
  321.         /*      cout << "Enter patient gender: ";
  322.                 cin >> p.gender;
  323.                 cout << p.gender << endl;
  324.                 cout << "Enter patient date of birth (DDMMYYYY): ";
  325.                 cin >> p.dob;
  326.                 cout << p.dob << endl;
  327.                 cout << "Enter patient address: ";
  328.                 cin >> p.address;
  329.                 cout << p.address << endl;
  330.                 cout << "Enter patient illness: ";
  331.                 cin >> p.illness;
  332.                 cout << p.illness << endl;
  333.                 cout << "Enter patient admission date (DDMMYYYY): ";
  334.                 cin >> p.admission_date;
  335.                 cout << p.admission_date << endl;*/
  336.  
  337.         add(p);
  338.         return p;
  339.     }
  340.  
  341.     void main_menu()
  342.     {
  343.         int Selection;
  344.         string arr[] = { "Patient Management", "Personnel Management", "Display Information", "Setting", "Shutdown" };
  345.         int size = sizeof(arr) / sizeof(arr[0]);
  346.         Menu mainMenu(arr, size);
  347.  
  348.         do
  349.         {
  350.             clearScreen();
  351.             mainMenu.show("HOSPITAL MANAGEMENT SYSTEM MAIN");
  352.             Selection = mainMenu.choice();
  353.             switch (Selection)
  354.             {
  355.             case 1: patientManagemnt(); break;
  356.             case 2: personnelManegment(); break;
  357.             case 3: displayInfo(); break;
  358.             case 4: setting(); break;
  359.             case 5: shutdown(0);
  360.             default:
  361.                 cout << "Invalid input!\nPlease select correct option. \n";
  362.                 Sleep(900);
  363.                 cin.clear();
  364.                 cin.ignore(100, '\n');
  365.                 break;
  366.             }
  367.         } while (1);
  368.  
  369.     }
  370.     void personnelManegment()
  371.     {
  372.         int Selection;
  373.         string arr[] = { "Add", "Update", "Delete", "Display", "Back to Main Menu" };
  374.         int size = sizeof(arr) / sizeof(arr[0]);
  375.         Menu pMenu(arr, size);
  376.  
  377.         Personnel p;
  378.         do {
  379.             clearScreen();
  380.             pMenu.show("PERSONEL MANAGEMENT PATIENT");
  381.             Selection = pMenu.choice();
  382.             switch (Selection)
  383.             {
  384.  
  385.             case 1:
  386.                 read(p);
  387.                 break;
  388.             case 2:
  389.                 update(staffList);
  390.                 break;
  391.             case 3:
  392.                 remove(staffList);
  393.                 break;
  394.             case 4:
  395.                 display(staffList);
  396.                 _getch();
  397.                 break;
  398.             case 5: return;
  399.             default:
  400.                 cout << "Invalid input!\nPlease select correct option. \n";
  401.                 Sleep(900);
  402.                 cin.clear();
  403.                 cin.ignore(100, '\n');
  404.                 break;
  405.             }
  406.         } while (1);
  407.  
  408.     }
  409.     void patientManagemnt()
  410.     {
  411.         int Selection;
  412.         string arr[] = { "Add", "Update", "Delete", "Display", "Back to Main Menu" };
  413.         int size = sizeof(arr) / sizeof(arr[0]);
  414.         Menu pMenu(arr, size);
  415.  
  416.  
  417.         Patient p;
  418.         do
  419.         {
  420.             clearScreen();
  421.             pMenu.show("PATIENT MANAGEMENT");
  422.             Selection = pMenu.choice();
  423.             switch (Selection)
  424.             {
  425.             case 1:
  426.                 read(p);
  427.                 break;
  428.  
  429.             case 2:
  430.                 update(pList);
  431.                 break;
  432.             case 3:
  433.                 remove(pList);
  434.                 break;
  435.             case 4:
  436.                 display(pList);
  437.                 _getch();
  438.                 break;
  439.             case 5: return;
  440.  
  441.             default:
  442.                 cout << "Invalid input!\nPlease select correct option. \n";
  443.                 Sleep(600);
  444.                 cin.clear();
  445.                 cin.ignore(100, '\n');
  446.                 break;
  447.             }
  448.         } while (1);
  449.  
  450.     }
  451.     void setting()
  452.     {
  453.         int Selection;
  454.         string arr[] = { "Set Hospital Information", "Back to Main Menu" };
  455.         int size = sizeof(arr) / sizeof(arr[0]);
  456.         Menu pMenu(arr, size);
  457.  
  458.  
  459.         do {
  460.             clearScreen();
  461.             pMenu.show("HOSPITAL SETTIENG");
  462.             Selection = pMenu.choice();
  463.             switch (Selection)
  464.             {
  465.             case 1:
  466.                 ourinfoset();
  467.                 break;
  468.             case 2: return;
  469.  
  470.             default:
  471.                 cout << "Invalid input!\nPlease select correct option. \n";
  472.                 Sleep(600);
  473.                 cin.clear();
  474.                 cin.ignore(100, '\n');
  475.                 break;
  476.             }
  477.         } while (1);
  478.  
  479.  
  480.     }
  481.     void clearScreen()
  482.     {
  483.         //system("CLS");
  484.     };
  485.     void shutdown(int x)
  486.     {
  487.         exit(x);
  488.     }
  489. };
  490. int main()
  491. {
  492.  
  493.     Hospital_Class hospital;
  494.     hospital.initialize();
  495.     hospital.main_menu();
  496. }
  497.  
Advertisement
Add Comment
Please, Sign In to add comment