Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- plz help m ....getting problem in braces in void main and want to add do while loop in main cases....
- plz help....
- */
- //Hospital Management System
- #include<stdio.h>
- #include<conio.h>
- #include<fstream.h>
- #include<stdlib.h>
- #include<dos.h>
- #include<string.h>
- #include<iomanip.h>
- #include<process.h>
- #include<ctype.h>
- #include <iostream.h>
- //class to deal with patient data
- int ch_main;
- class patient
- {
- private:
- int patient_no;
- char patient_time[8];
- char patient_name[30];
- char patient_address[60];
- char patient_room_type[10];
- char patient_phone[15];
- char patient_date[11];
- protected :
- int patient_room_number;
- public :
- patient() : patient_no(0),patient_room_number(0)
- {
- patient_name[0] = 0;
- patient_phone[0] = 0;
- patient_address[0] = 0;
- patient_date[0] = 0;
- patient_room_type[0] = 0;
- patient_date[0] = 0;
- patient_time[0] = 0;
- }
- char getdata();
- void showdata();
- int pno(){return patient_no;}
- };
- //class to deal with staff data
- class staff
- {
- private:
- int staff_no;
- float staff_salary;
- char staff_name[30];
- char staff_phone[15];
- char staff_mobile[15];
- char staff_address[50];
- char staff_position[20];
- char staff_date_joining[11];
- public:
- staff() : staff_no(0),staff_salary(0.0)
- {
- staff_name[0] = 0;
- staff_phone[0] = 0;
- staff_mobile[0] = 0;
- staff_date_joining[0] = 0;
- staff_address[0] = 0;
- staff_position[0] = 0;
- }
- char staff_getdata();
- void staff_showdata();
- int sno() { return staff_no;}
- };
- class room : protected patient
- {
- };
- char patient :: getdata()
- {
- clrscr();
- char cRet = 0;
- textcolor(RED);
- cprintf("CHECK IN A PATIENT++");
- gotoxy(5,5);
- cout<<"Please enter patient number : ";
- cin>>patient_no;
- cin.ignore();
- gotoxy(5,9);
- cout<<"Please enter patient full name : ";
- cin.getline(patient_name, sizeof(patient_name));
- gotoxy(5,13);
- cout<<"Please enter patient phone number : ";
- cin.getline(patient_phone, sizeof(patient_phone));
- gotoxy(5,17);
- cout<<"Please enter patient address(r) : ";
- cin.getline(patient_address, sizeof(patient_address));
- gotoxy(5,21);
- cout<<"Please enter patient check in time : ";
- cin.getline(patient_time, sizeof(patient_time));
- gotoxy(5,25);
- cout<<"Please enter date : ";
- cin.getline(patient_date, sizeof(patient_date));
- gotoxy(5,29);
- cout<<"Please enter patient room number : ";
- cin>>patient_room_number;
- cin.ignore();
- gotoxy(5,33);
- cout<<"Please enter room type 'AC/NAC/ICU': ";
- cin.getline(patient_room_type, sizeof(patient_room_type));
- do {
- gotoxy(5,37);
- cout<<"Continue? (y/n) ";
- cRet = getch();
- }while(tolower(cRet)!='y'&&tolower(cRet) != 'n');
- return cRet;
- }
- void patient :: showdata()
- {
- clrscr();
- textcolor(RED);
- cprintf("Patient Details\n\n");
- gotoxy(5,5);
- cout<<"Patient Number : "<<patient_no;
- gotoxy(5,9);
- cout<<"Patient Name : "<<patient_name;
- gotoxy(5,13);
- cout<<"Patient Phone Number : "<<patient_phone;
- gotoxy(5,17);
- cout<<"Patient Address(r) : "<<patient_address;
- gotoxy(5,21);
- cout<<"Patient check in time : "<<patient_time;
- gotoxy(5,25);
- cout<<"Patient check in date : "<<patient_date;
- gotoxy(5,29);
- cout<<"Patient room : "<<patient_room_number;
- gotoxy(5,33);
- cout<<"Patient room type : "<<patient_room_type;
- gotoxy(5,37);
- cout<<"Continue? (y/n) : ";
- }
- char staff :: staff_getdata()
- {
- clrscr();
- cout<<"Staff Data";
- gotoxy(5,5);
- cout<<"Please enter employee number : ";
- cin>>staff_no;
- cin.ignore();
- gotoxy(5,9);
- cout<<"Please enter employee name : ";
- cin.getline(staff_name, sizeof(staff_name));
- gotoxy(5,13);
- cout<<"Please enter employee phone number(r) :";
- cin.getline(staff_phone, sizeof(staff_phone));
- gotoxy(5,17);
- cout<<"Please enter employee mobile : ";
- cin.getline(staff_mobile, sizeof(staff_mobile));
- gotoxy(5,21);
- cout<<"Please enter employee address(r) : ";
- cin.getline(staff_address,sizeof(staff_address));
- gotoxy(5,25);
- cout<<"Please enter date of joining : ";
- cin.getline(staff_date_joining, sizeof(staff_date_joining));
- gotoxy(5,29);
- cout<<"Please enter employee position : ";
- cin.getline(staff_position, sizeof(staff_position));
- gotoxy(5,33);
- cout<<"Please enter employee salary : ";
- cin>>staff_salary;
- cin.ignore();
- char cRet = 0;
- do {
- cRet = 0;
- gotoxy(5,37);
- cout<<"Continue? (y/n) : ";
- cRet = tolower(getch());
- } while(cRet!='n'&&cRet!='y');
- return cRet;
- }
- void message(const char *szPerson, const char *szNumber, int iNo)
- {
- cout<<"There is no "
- << szPerson
- << " with "
- << szNumber
- << " "
- << iNo
- << " in our Database";
- }
- void staff :: staff_showdata()
- {
- clrscr();
- gotoxy(5,5);
- cout<<"Employee number :"<<staff_no;
- gotoxy(5,9);
- cout<<"Employee name :"<<staff_name;
- gotoxy(5,13);
- cout<<"Employee phone number(r) :"<<staff_phone;
- gotoxy(5,17);
- cout<<"Employee mobile number :"<<staff_mobile;
- gotoxy(5,21);
- cout<<"Employee address :"<<staff_address;
- gotoxy(5,25);
- cout<<"Employee date of joining :"<<staff_date_joining;
- gotoxy(5,29);
- cout<<"Employee postion :"<<staff_position;
- gotoxy(5,33);
- cout<<"Employee salary :"<<staff_salary;
- }
- void write_patient()
- {
- patient p;
- fstream f1;
- f1.open("patient.dat",ios::app|ios::binary);
- char ch;
- do{
- ch = p.getdata();
- f1.write((char*)&p,sizeof(p));
- }while(ch=='y');
- f1.close();
- }
- void write_staff()
- {
- staff s;
- fstream f2;
- f2.open("staff.dat",ios::app|ios::binary);
- char ch_staff;
- do {
- ch_staff = s.staff_getdata();
- f2.write((char*)&s,sizeof(s));
- }while(ch_staff=='y');
- }
- void read_patient()
- {
- char cInput = 0;
- patient p;
- fstream f1;
- f1.open("patient.dat",ios::in|ios::binary);
- do {
- f1.read((char*)&p,sizeof(p));
- p.showdata();
- cInput = getch();
- switch(cInput)
- {
- case 'y':
- case 'Y':
- break;
- case 'n':
- case 'N':
- break;
- default: cout << "Please enter n or y" << endl;
- break;
- }
- }while(!(f1.eof()||toupper(cInput)=='N'));
- f1.close();
- }
- void read_staff()
- {
- staff s;
- fstream f2;
- char cInput = 0;
- f2.open("staff.dat",ios::in|ios::binary);
- if (!f2.bad()){
- do {
- f2.read((char*)&s,sizeof(s));
- s.staff_showdata();
- cInput = getch();
- switch(cInput){
- case 'y':
- case 'Y':
- break;
- case 'n':
- case 'N':
- break;
- default: cout << "Please enter n or y" << endl;
- break;
- }
- } while(!f2.eof());
- f2.close();
- }
- }
- void search_patient()
- {
- clrscr();
- patient p;
- int patient2_no,flag=0;
- fstream f1;
- f1.open("patient.dat",ios::in|ios::binary);
- gotoxy(10,15);
- cout<<"Please enter patient number you want which you want to search ";
- cin>>patient2_no;
- while(!f1.eof()){
- f1.read((char*)&p,sizeof(p));
- if(p.pno()==patient2_no) {
- p.showdata();
- flag=1;
- break;
- }
- }
- f1.close();
- if(!flag){
- clrscr();
- gotoxy(10,19);
- message("patient", "patient #", patient2_no);
- gotoxy(10,23);
- cout <<"Any key to continue!";
- }
- getch();
- }
- void search_staff()
- {
- clrscr();
- staff s;
- int staff2_no,flag_staff=0;
- fstream f2;
- f2.open("staff.dat",ios::in|ios::binary);
- gotoxy(10,15);
- cout<<"Please enter employee number you want to search ";
- cin>>staff2_no;
- cin.ignore();
- while(!f2.eof()){
- f2.read((char*)&s,sizeof(s));
- if(s.sno()==staff2_no){
- s.staff_showdata();
- flag_staff=1;
- }
- }
- f2.close();
- if(!flag_staff){
- clrscr();
- gotoxy(10,19);
- message("staff", "employee #", staff2_no);
- gotoxy(10,23);
- cout << "Any Key to continue! " ;
- }
- getch();
- }
- void del_patient()
- {
- clrscr();
- patient p;
- fstream f1,f11;
- f11.open("temp.dat",ios::out|ios::binary);
- f1.open("patient.dat",ios::in|ios::binary);
- int patient2_no,flag=0;
- gotoxy(10,15);
- cout<<"Please enter patient number which you want to delete ";
- cin>>patient2_no;
- while(!f1.eof())
- {
- f1.read((char*)&p,sizeof(p));
- if(p.pno()!=patient2_no){
- f11.write((char*)&p,sizeof(p));
- }
- else{
- flag=1;
- }
- }
- f1.close();
- f11.close();
- if(!flag){
- remove("temp.dat");
- gotoxy(10,19);
- message("patient", "Record #", patient2_no);
- }
- else {
- remove("patient.dat");
- rename("temp.dat","patient.dat");
- }
- gotoxy(10,23);
- cout << "Any key to continue!";
- getch();
- }
- void del_staff()
- { clrscr();
- staff s;
- fstream f2,f22;
- f22.open("temp_staff.dat",ios::out|ios::binary);
- f2.open("staff.dat",ios::in|ios::binary);
- int staff2_no,flag_staff=0;
- gotoxy(20,15);
- cout<<"Please enter staff number which you want to delete ";
- cin>>staff2_no;
- while(!f2.eof()){
- f2.read((char*)&s,sizeof(s));
- if(s.sno()!=staff2_no){
- f22.write((char*)&s,sizeof(s));
- }
- else{
- flag_staff=1;
- }
- }
- f2.close();
- f22.close();
- if(!flag_staff) {
- remove("temp_staff.dat");
- gotoxy(20,19);
- message("staff", "employee", staff2_no);
- }
- else {
- remove("staff.dat");
- rename("temp_staff.dat","staff.dat");
- }
- gotoxy(20,23);
- cout << "Any Key to continue! " ;
- getch();
- }
- void update_patient()
- {
- patient p;
- fstream f1;
- int patient2_no = 0,
- record_patient=0,
- flag = 0;
- clrscr();
- f1.open("patient.dat",ios::in|ios::out|ios::binary);
- gotoxy(10,15);
- cout<<"Please enter patient number which you want to modify";
- cin>>patient2_no;
- while(!f1.eof()){
- f1.read((char*)&p,sizeof(p));
- ++record_patient;
- if(p.pno()==patient2_no) {
- flag = 1;
- //p.showdata();
- p.getdata();
- f1.seekp((record_patient-1)*sizeof(patient));
- f1.write((char*)&p,sizeof(p));
- break;
- }
- }
- f1.close();
- if(!flag){
- gotoxy(10,19);
- message("patient", "Record #", patient2_no);
- gotoxy(10,23);
- cout<<"Any Key to continue!";
- }
- getch();
- }
- void update_staff()
- {
- staff s;
- fstream f2;
- int staff2_no,record_staff=0,flag_staff=0;
- clrscr();
- f2.open("staff.dat",ios::in|ios::out|ios::binary);
- gotoxy(10,15);
- cout<<"Please enter staff number which you want to modify";
- cin>>staff2_no;
- while(!f2.eof())
- {
- f2.read((char*)&s,sizeof(s));
- ++record_staff;
- if(s.sno()==staff2_no){
- flag_staff=1;
- gotoxy(20,2);
- cout<<"Please enter new data";
- //s.staff_showdata();
- s.staff_getdata();
- f2.seekp((record_staff-1)*sizeof(patient));
- f2.write((char*)&s,sizeof(s));
- break;
- }
- }
- f2.close();
- if(!flag_staff){
- gotoxy(10,19);
- message("staff", "employee #", staff2_no);
- gotoxy(10,23);
- cout<<"Any Key to continue!";
- }
- getch();
- }
- char main_choice()
- {
- clrscr();
- char ch_main = 0;
- gotoxy(20,7);
- cout<<"1.Information related to patient";
- gotoxy(20,9);
- cout<<"2.Information related to employee";
- gotoxy(20,11);
- cout <<"3.Quit program";
- do {
- gotoxy(20,14);
- cout<<"Please enter your choice (1/2/3) ";
- ch_main = getch();
- }while (ch_main <'1' || ch_main > '3');
- return ch_main;
- }
- void patient_menu()
- {
- clrscr();
- int ch_patient;
- gotoxy(20,7);
- cout<<"1.Add a patient record";
- gotoxy(20,9);
- cout<<"2.Display a patient record";
- gotoxy(20,11);
- cout<<"3.Search a patient record";
- gotoxy(20,13);
- cout<<"4.Delete a patient record";
- gotoxy(20,15);
- cout<<"5.Modify a patient record";
- gotoxy(20,17);
- cout<<"6.Exit";
- gotoxy(20,19);
- cout<<"7.Back to Main Menu";
- gotoxy(20,23);
- cout<<"Please enter your choice ";
- cin>>ch_patient;
- switch(ch_patient){
- case 1:
- write_patient();
- break;
- case 2:
- read_patient();
- break;
- case 3:
- search_patient();
- break;
- case 4:
- del_patient();
- break;
- case 5:
- update_patient();
- break;
- case 6:
- exit(0);
- break;
- case 7:
- main_choice();
- break;
- }
- }
- void staff_menu()
- {
- int ch_staff;
- clrscr();
- gotoxy(20,7);
- cout<<"1.Add a employee record";
- gotoxy(20,9);
- cout<<"2.Display a employee record";
- gotoxy(20,11);
- cout<<"3.Search a employee record";
- gotoxy(20,13);
- cout<<"4.Delete a employee record";
- gotoxy(20,15);
- cout<<"5.Modify a employee record";
- gotoxy(20,17);
- cout<<"6.Back to Main Menu";
- gotoxy(20,19);
- cout<<"7.Exit";
- gotoxy(20,23);
- cout<<"Please enter your choice ";
- cin>>ch_staff;
- switch(ch_staff)
- {
- case 1:
- write_staff();
- break;
- case 2:
- read_staff();
- break;
- case 3:
- search_staff();
- break;
- case 4:
- del_staff();
- break;
- case 5:
- update_staff();
- break;
- case 6:
- main_choice();
- break;
- case 7:
- exit(0);
- }
- }
- int main()
- { //closed
- char ch_main = 0;
- clrscr();
- char ch;
- do {
- ch_main = 0;
- ch_main = main_choice();
- switch(ch_main) {
- case '1':
- patient_menu();
- break;
- case '2':
- staff_menu();
- break;
- case '3':
- break;
- default:
- cout << "Please enter 1, 2, or 3" << endl;
- break;
- }//switch1 closed
- }while(ch_main != '3');
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement