Advertisement
Guest User

Untitled

a guest
May 25th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.15 KB | None | 0 0
  1. /*
  2.  plz help m ....getting problem in braces in void main and want to add do while loop in main cases....
  3. plz help....
  4. */
  5. //Hospital Management System
  6. #include<stdio.h>
  7. #include<conio.h>
  8. #include<fstream.h>
  9. #include<stdlib.h>
  10. #include<dos.h>
  11. #include<string.h>
  12. #include<iomanip.h>
  13. #include<process.h>
  14. #include<ctype.h>
  15. #include <iostream.h>
  16. //class to deal with patient data
  17.  
  18. int ch_main;
  19. class patient
  20.     {
  21.     private:
  22.         int   patient_no;
  23.         char  patient_time[8];
  24.         char  patient_name[30];
  25.         char  patient_address[60];
  26.         char  patient_room_type[10];
  27.         char  patient_phone[15];
  28.         char  patient_date[11];
  29.     protected :
  30.         int  patient_room_number;
  31.     public :
  32.         patient() : patient_no(0),patient_room_number(0)
  33.             {
  34.             patient_name[0] = 0;
  35.             patient_phone[0] = 0;
  36.             patient_address[0] = 0;
  37.             patient_date[0] = 0;
  38.             patient_room_type[0] = 0;
  39.             patient_date[0] = 0;
  40.             patient_time[0] = 0;
  41.             }
  42.     char getdata();
  43.     void showdata();
  44.     int pno(){return patient_no;}
  45.     };
  46.  
  47. //class to deal with staff data
  48. class staff
  49.     {
  50.     private:
  51.         int    staff_no;
  52.         float  staff_salary;
  53.         char   staff_name[30];
  54.         char   staff_phone[15];
  55.         char   staff_mobile[15];
  56.         char   staff_address[50];
  57.         char   staff_position[20];
  58.         char   staff_date_joining[11];
  59.     public:
  60.         staff() :   staff_no(0),staff_salary(0.0)
  61.             {
  62.             staff_name[0] = 0;
  63.             staff_phone[0] = 0;
  64.             staff_mobile[0] = 0;
  65.             staff_date_joining[0] = 0;
  66.             staff_address[0] = 0;
  67.             staff_position[0] = 0;
  68.             }
  69.         char staff_getdata();
  70.         void staff_showdata();
  71.         int sno() { return staff_no;}
  72.     };
  73.  
  74. class room : protected patient
  75.     {
  76.  
  77.  
  78.     };
  79.  
  80. char patient :: getdata()
  81.      {
  82.      clrscr();
  83.      char cRet = 0;
  84.      textcolor(RED);
  85.      cprintf("CHECK IN A PATIENT++");
  86.      gotoxy(5,5);
  87.      cout<<"Please enter patient number        : ";
  88.      cin>>patient_no;
  89.      cin.ignore();
  90.      gotoxy(5,9);
  91.      cout<<"Please enter patient full name       : ";
  92.      cin.getline(patient_name, sizeof(patient_name));
  93.      gotoxy(5,13);
  94.      cout<<"Please enter patient phone number    : ";
  95.      cin.getline(patient_phone, sizeof(patient_phone));
  96.      gotoxy(5,17);
  97.      cout<<"Please enter patient address(r)    : ";
  98.      cin.getline(patient_address, sizeof(patient_address));
  99.      gotoxy(5,21);
  100.      cout<<"Please enter patient check in time : ";
  101.      cin.getline(patient_time, sizeof(patient_time));
  102.      gotoxy(5,25);
  103.      cout<<"Please enter date                  : ";
  104.      cin.getline(patient_date, sizeof(patient_date));
  105.      gotoxy(5,29);
  106.      cout<<"Please enter patient room number     : ";
  107.      cin>>patient_room_number;
  108.      cin.ignore();
  109.      gotoxy(5,33);
  110.      cout<<"Please enter room type 'AC/NAC/ICU': ";
  111.      cin.getline(patient_room_type, sizeof(patient_room_type));
  112.      do {
  113.         gotoxy(5,37);
  114.         cout<<"Continue? (y/n) ";
  115.         cRet = getch();
  116.         }while(tolower(cRet)!='y'&&tolower(cRet) != 'n');
  117.      return cRet;
  118.      }
  119.  
  120. void patient :: showdata()
  121.      {
  122.      clrscr();
  123.      textcolor(RED);
  124.      cprintf("Patient Details\n\n");
  125.      gotoxy(5,5);
  126.      cout<<"Patient Number           :    "<<patient_no;
  127.      gotoxy(5,9);
  128.      cout<<"Patient Name             :    "<<patient_name;
  129.      gotoxy(5,13);
  130.      cout<<"Patient Phone Number     :    "<<patient_phone;
  131.      gotoxy(5,17);
  132.      cout<<"Patient Address(r)       :    "<<patient_address;
  133.      gotoxy(5,21);
  134.      cout<<"Patient check in time    :    "<<patient_time;
  135.      gotoxy(5,25);
  136.      cout<<"Patient check in date    :    "<<patient_date;
  137.      gotoxy(5,29);
  138.      cout<<"Patient room             :    "<<patient_room_number;
  139.      gotoxy(5,33);
  140.      cout<<"Patient room type        :    "<<patient_room_type;
  141.      gotoxy(5,37);
  142.      cout<<"Continue? (y/n)       :    ";
  143.      }
  144.  
  145. char staff :: staff_getdata()
  146.      {
  147.      clrscr();
  148.      cout<<"Staff Data";
  149.      gotoxy(5,5);
  150.      cout<<"Please enter employee number             : ";
  151.      cin>>staff_no;
  152.      cin.ignore();
  153.      gotoxy(5,9);
  154.      cout<<"Please enter employee name           : ";
  155.      cin.getline(staff_name, sizeof(staff_name));
  156.      gotoxy(5,13);
  157.      cout<<"Please enter employee phone number(r) :";
  158.      cin.getline(staff_phone, sizeof(staff_phone));
  159.      gotoxy(5,17);
  160.      cout<<"Please enter employee mobile         : ";
  161.      cin.getline(staff_mobile, sizeof(staff_mobile));
  162.      gotoxy(5,21);
  163.      cout<<"Please enter employee address(r)     : ";
  164.      cin.getline(staff_address,sizeof(staff_address));
  165.      gotoxy(5,25);
  166.      cout<<"Please enter date of joining         : ";
  167.      cin.getline(staff_date_joining, sizeof(staff_date_joining));
  168.      gotoxy(5,29);
  169.      cout<<"Please enter employee position       : ";
  170.      cin.getline(staff_position, sizeof(staff_position));
  171.      gotoxy(5,33);
  172.      cout<<"Please enter employee salary         : ";
  173.      cin>>staff_salary;
  174.      cin.ignore();
  175.      char cRet = 0;
  176.      do {
  177.          cRet = 0;
  178.          gotoxy(5,37);
  179.          cout<<"Continue? (y/n)                          : ";
  180.          cRet = tolower(getch());
  181.          } while(cRet!='n'&&cRet!='y');
  182.      return cRet;
  183.      }
  184.  
  185. void message(const char *szPerson, const char *szNumber, int iNo)
  186.     {
  187.     cout<<"There is no "
  188.             << szPerson
  189.             << " with "
  190.             << szNumber
  191.             << " "
  192.             << iNo
  193.             << " in our Database";
  194.     }
  195.  
  196. void staff :: staff_showdata()
  197.     {
  198.     clrscr();
  199.     gotoxy(5,5);
  200.     cout<<"Employee number            :"<<staff_no;
  201.     gotoxy(5,9);
  202.     cout<<"Employee name              :"<<staff_name;
  203.     gotoxy(5,13);
  204.     cout<<"Employee phone number(r)   :"<<staff_phone;
  205.     gotoxy(5,17);
  206.     cout<<"Employee mobile number     :"<<staff_mobile;
  207.     gotoxy(5,21);
  208.     cout<<"Employee address           :"<<staff_address;
  209.     gotoxy(5,25);
  210.     cout<<"Employee date of joining   :"<<staff_date_joining;
  211.     gotoxy(5,29);
  212.     cout<<"Employee postion           :"<<staff_position;
  213.     gotoxy(5,33);
  214.     cout<<"Employee salary            :"<<staff_salary;
  215.     }
  216.  
  217. void write_patient()
  218.  {
  219.  patient p;
  220.  fstream f1;
  221.  f1.open("patient.dat",ios::app|ios::binary);
  222.  char ch;
  223.  do{
  224.         ch = p.getdata();
  225.         f1.write((char*)&p,sizeof(p));
  226.         }while(ch=='y');
  227.  
  228.  f1.close();
  229.  }
  230.  
  231. void write_staff()
  232.     {
  233.     staff s;
  234.     fstream f2;
  235.     f2.open("staff.dat",ios::app|ios::binary);
  236.     char ch_staff;
  237.     do {
  238.          ch_staff = s.staff_getdata();
  239.          f2.write((char*)&s,sizeof(s));
  240.         }while(ch_staff=='y');
  241.     }
  242.  
  243. void read_patient()
  244.     {
  245.     char cInput = 0;
  246.     patient p;
  247.     fstream f1;
  248.     f1.open("patient.dat",ios::in|ios::binary);
  249.     do {
  250.          f1.read((char*)&p,sizeof(p));
  251.          p.showdata();
  252.          cInput = getch();
  253.          switch(cInput)
  254.              {
  255.              case 'y':
  256.              case 'Y':
  257.                 break;
  258.              case 'n':
  259.              case 'N':
  260.                 break;
  261.              default: cout << "Please enter n or y" << endl;
  262.                 break;
  263.              }
  264.         }while(!(f1.eof()||toupper(cInput)=='N'));
  265.     f1.close();
  266.     }
  267.  
  268. void read_staff()
  269.     {
  270.     staff s;
  271.     fstream f2;
  272.     char cInput = 0;
  273.     f2.open("staff.dat",ios::in|ios::binary);
  274.     if (!f2.bad()){
  275.          do {
  276.                 f2.read((char*)&s,sizeof(s));
  277.                 s.staff_showdata();
  278.                 cInput = getch();
  279.                 switch(cInput){
  280.                      case 'y':
  281.                      case 'Y':
  282.                          break;
  283.                      case 'n':
  284.                      case 'N':
  285.                          break;
  286.                      default: cout << "Please enter n or y" << endl;
  287.                          break;
  288.                         }
  289.              } while(!f2.eof());
  290.             f2.close();
  291.             }
  292.         }
  293.  
  294. void search_patient()
  295.     {
  296.     clrscr();
  297.     patient p;
  298.     int patient2_no,flag=0;
  299.     fstream f1;
  300.     f1.open("patient.dat",ios::in|ios::binary);
  301.     gotoxy(10,15);
  302.     cout<<"Please enter patient number you want which you want to search ";
  303.     cin>>patient2_no;
  304.     while(!f1.eof()){
  305.         f1.read((char*)&p,sizeof(p));
  306.         if(p.pno()==patient2_no) {
  307.             p.showdata();
  308.             flag=1;
  309.             break;
  310.             }
  311.         }
  312.     f1.close();
  313.     if(!flag){
  314.         clrscr();
  315.         gotoxy(10,19);
  316.         message("patient", "patient #", patient2_no);
  317.         gotoxy(10,23);
  318.         cout <<"Any key to continue!";
  319.         }
  320.     getch();
  321.     }
  322.  
  323. void search_staff()
  324.     {
  325.     clrscr();
  326.     staff s;
  327.     int staff2_no,flag_staff=0;
  328.     fstream f2;
  329.     f2.open("staff.dat",ios::in|ios::binary);
  330.     gotoxy(10,15);
  331.     cout<<"Please enter employee number you want to search ";
  332.     cin>>staff2_no;
  333.     cin.ignore();
  334.     while(!f2.eof()){
  335.         f2.read((char*)&s,sizeof(s));
  336.         if(s.sno()==staff2_no){
  337.             s.staff_showdata();
  338.             flag_staff=1;
  339.             }
  340.         }
  341.     f2.close();
  342.     if(!flag_staff){
  343.         clrscr();
  344.         gotoxy(10,19);
  345.         message("staff", "employee #", staff2_no);
  346.         gotoxy(10,23);
  347.         cout << "Any Key to continue! " ;
  348.         }
  349.     getch();
  350.     }
  351.  
  352. void del_patient()
  353.     {
  354.     clrscr();
  355.     patient p;
  356.     fstream f1,f11;
  357.     f11.open("temp.dat",ios::out|ios::binary);
  358.     f1.open("patient.dat",ios::in|ios::binary);
  359.  
  360.     int patient2_no,flag=0;
  361.     gotoxy(10,15);
  362.     cout<<"Please enter patient number which you want to delete ";
  363.     cin>>patient2_no;
  364.     while(!f1.eof())
  365.         {
  366.         f1.read((char*)&p,sizeof(p));
  367.         if(p.pno()!=patient2_no){
  368.             f11.write((char*)&p,sizeof(p));
  369.             }
  370.          else{
  371.             flag=1;
  372.             }
  373.         }
  374.     f1.close();
  375.     f11.close();
  376.     if(!flag){
  377.         remove("temp.dat");
  378.         gotoxy(10,19);
  379.         message("patient", "Record #", patient2_no);
  380.         }
  381.     else {
  382.         remove("patient.dat");
  383.         rename("temp.dat","patient.dat");
  384.         }
  385.     gotoxy(10,23);
  386.     cout << "Any key to continue!";
  387.     getch();
  388.     }
  389.  
  390. void del_staff()
  391.     {               clrscr();
  392.     staff s;
  393.     fstream f2,f22;
  394.     f22.open("temp_staff.dat",ios::out|ios::binary);
  395.     f2.open("staff.dat",ios::in|ios::binary);
  396.     int staff2_no,flag_staff=0;
  397.     gotoxy(20,15);
  398.     cout<<"Please enter staff number which you want to delete ";
  399.     cin>>staff2_no;
  400.     while(!f2.eof()){
  401.         f2.read((char*)&s,sizeof(s));
  402.         if(s.sno()!=staff2_no){
  403.             f22.write((char*)&s,sizeof(s));
  404.             }
  405.         else{
  406.             flag_staff=1;
  407.             }
  408.         }
  409.     f2.close();
  410.     f22.close();
  411.     if(!flag_staff) {
  412.         remove("temp_staff.dat");
  413.         gotoxy(20,19);
  414.         message("staff", "employee", staff2_no);
  415.         }
  416.     else {
  417.         remove("staff.dat");
  418.         rename("temp_staff.dat","staff.dat");
  419.         }
  420.     gotoxy(20,23);
  421.     cout << "Any Key to continue! " ;
  422.     getch();
  423.     }
  424.  
  425. void update_patient()
  426.     {
  427.     patient p;
  428.     fstream f1;
  429.     int patient2_no = 0,
  430.     record_patient=0,
  431.     flag = 0;
  432.     clrscr();
  433.     f1.open("patient.dat",ios::in|ios::out|ios::binary);
  434.     gotoxy(10,15);
  435.     cout<<"Please enter patient number which you want to modify";
  436.     cin>>patient2_no;
  437.     while(!f1.eof()){
  438.         f1.read((char*)&p,sizeof(p));
  439.         ++record_patient;
  440.         if(p.pno()==patient2_no) {
  441.             flag = 1;
  442.             //p.showdata();
  443.             p.getdata();
  444.             f1.seekp((record_patient-1)*sizeof(patient));
  445.             f1.write((char*)&p,sizeof(p));
  446.             break;
  447.             }
  448.         }
  449.     f1.close();
  450.     if(!flag){
  451.         gotoxy(10,19);
  452.         message("patient", "Record #", patient2_no);
  453.         gotoxy(10,23);
  454.         cout<<"Any Key to continue!";
  455.         }
  456.     getch();
  457.     }
  458.  
  459. void update_staff()
  460.     {
  461.     staff   s;
  462.     fstream f2;
  463.     int staff2_no,record_staff=0,flag_staff=0;
  464.     clrscr();
  465.     f2.open("staff.dat",ios::in|ios::out|ios::binary);
  466.     gotoxy(10,15);
  467.     cout<<"Please enter staff number which you want to modify";
  468.     cin>>staff2_no;
  469.     while(!f2.eof())
  470.         {
  471.         f2.read((char*)&s,sizeof(s));
  472.         ++record_staff;
  473.         if(s.sno()==staff2_no){
  474.             flag_staff=1;
  475.             gotoxy(20,2);
  476.             cout<<"Please enter new data";
  477.             //s.staff_showdata();
  478.             s.staff_getdata();
  479.             f2.seekp((record_staff-1)*sizeof(patient));
  480.             f2.write((char*)&s,sizeof(s));
  481.             break;
  482.             }
  483.         }
  484.     f2.close();
  485.     if(!flag_staff){
  486.         gotoxy(10,19);
  487.         message("staff", "employee #", staff2_no);
  488.         gotoxy(10,23);
  489.         cout<<"Any Key to continue!";
  490.         }
  491.     getch();
  492.     }
  493.  
  494. char main_choice()
  495.      {
  496.     clrscr();
  497.      char ch_main = 0;
  498.      gotoxy(20,7);
  499.      cout<<"1.Information related to patient";
  500.      gotoxy(20,9);
  501.      cout<<"2.Information related to employee";
  502.      gotoxy(20,11);
  503.      cout <<"3.Quit program";
  504.      do {
  505.          gotoxy(20,14);
  506.          cout<<"Please enter your choice (1/2/3) ";
  507.          ch_main = getch();
  508.          }while (ch_main <'1' || ch_main > '3');
  509.      return ch_main;
  510.      }
  511.  
  512. void patient_menu()
  513.     {
  514.     clrscr();
  515.     int ch_patient;
  516.     gotoxy(20,7);
  517.     cout<<"1.Add a patient record";
  518.     gotoxy(20,9);
  519.     cout<<"2.Display a patient record";
  520.     gotoxy(20,11);
  521.     cout<<"3.Search a patient record";
  522.     gotoxy(20,13);
  523.     cout<<"4.Delete a patient record";
  524.     gotoxy(20,15);
  525.     cout<<"5.Modify a patient record";
  526.     gotoxy(20,17);
  527.     cout<<"6.Exit";
  528.     gotoxy(20,19);
  529.     cout<<"7.Back to Main Menu";
  530.     gotoxy(20,23);
  531.     cout<<"Please enter your choice ";
  532.     cin>>ch_patient;
  533.     switch(ch_patient){
  534.         case 1:
  535.             write_patient();
  536.             break;
  537.         case 2:
  538.             read_patient();
  539.             break;
  540.         case 3:
  541.             search_patient();
  542.             break;
  543.         case 4:
  544.             del_patient();
  545.             break;
  546.         case 5:
  547.             update_patient();
  548.             break;
  549.         case 6:
  550.             exit(0);
  551.             break;
  552.         case 7:
  553.             main_choice();
  554.             break;
  555.             }
  556.     }
  557.  
  558. void staff_menu()
  559.     {
  560.     int ch_staff;
  561.     clrscr();
  562.     gotoxy(20,7);
  563.     cout<<"1.Add a employee record";
  564.     gotoxy(20,9);
  565.     cout<<"2.Display a employee record";
  566.     gotoxy(20,11);
  567.     cout<<"3.Search a employee record";
  568.     gotoxy(20,13);
  569.     cout<<"4.Delete a employee record";
  570.     gotoxy(20,15);
  571.     cout<<"5.Modify a employee record";
  572.     gotoxy(20,17);
  573.     cout<<"6.Back to Main Menu";
  574.     gotoxy(20,19);
  575.     cout<<"7.Exit";
  576.     gotoxy(20,23);
  577.     cout<<"Please enter your choice ";
  578.     cin>>ch_staff;
  579.     switch(ch_staff)
  580.          {
  581.          case 1:
  582.              write_staff();
  583.              break;
  584.          case 2:
  585.              read_staff();
  586.              break;
  587.          case 3:
  588.              search_staff();
  589.              break;
  590.          case 4:
  591.              del_staff();
  592.              break;
  593.          case 5:
  594.              update_staff();
  595.              break;
  596.          case 6:
  597.              main_choice();
  598.              break;
  599.          case 7:
  600.              exit(0);
  601.              }
  602.      }
  603.  
  604. int main()
  605.     { //closed
  606.     char ch_main = 0;
  607.  
  608.     clrscr();
  609.     char ch;
  610.     do {
  611.         ch_main = 0;
  612.         ch_main = main_choice();
  613.         switch(ch_main) {
  614.             case '1':
  615.                 patient_menu();
  616.                 break;
  617.             case '2':
  618.                 staff_menu();
  619.                 break;
  620.             case '3':
  621.                 break;
  622.          default:
  623.              cout << "Please enter 1, 2, or 3" << endl;
  624.              break;
  625.              }//switch1 closed
  626.         }while(ch_main != '3');
  627.     return EXIT_SUCCESS;
  628.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement