You are on page 1of 20

1

Code : // returns 1 if successful, 0 if queue is full.


//Project Program for Hospital Database Queue if (NumberOfPatients >= MAXPATIENTS)
array. {
// queue is full
#include<iostream.h> return 0;
#include<conio.h> }
#include<string.h> // put in new patient
#include<stdlib.h> else
List[NumberOfPatients] = p;
// define maximum number of patients in a NumberOfPatients++;
queue return 1;
#define MAXPATIENTS 100 }

// define structure for patient data


struct patient int queue::AddPatientAtBeginning (patient p)
{ {
char FirstName[50]; // adds a critically ill patient to the beginning
char LastName[50]; of the queue.
char ID[20]; // returns 1 if successful, 0 if queue is full.
}; int i;
if (NumberOfPatients >= MAXPATIENTS)
{
// define class for queue // queue is full
class queue return 0;
{ }
public:
queue (void); // move all patients one position back in
int AddPatientAtEnd (patient p); queue
int AddPatientAtBeginning (patient p); for (i = NumberOfPatients-1; i >= 0; i--)
patient GetNextPatient (void); {
int RemoveDeadPatient (patient * p); List[i+1] = List[i];
void OutputList (void); }
char DepartmentName[50]; // put in new patient
private: List[0] = p; NumberOfPatients++;
int NumberOfPatients; return 1;
patient List[MAXPATIENTS]; }
};

patient queue::GetNextPatient (void)


// declare member functions for queue {
// gets the patient that is first in the queue.
queue::queue () // returns patient with no ID if queue is empty
{
// constructor int i; patient p;
NumberOfPatients = 0; if (NumberOfPatients == 0) {
} // queue is empty
strcpy(p.ID,"");
return p;}
int queue::AddPatientAtEnd (patient p) // get first patient
{ p = List[0];
// adds a normal patient to the end of the // move all remaining patients one position
queue. forward in queue
2
NumberOfPatients--; for (i=0; i<NumberOfPatients;
for (i=0; i<NumberOfPatients; i++) i++)
{ {
List[i] = List[i+1]; cout << "
} " << List[i].FirstName;
// return patient cout << " " <<
return p; List[i].LastName;
} cout << " " <<
List[i].ID;
}
int queue::RemoveDeadPatient (patient * p) }
{ }
// removes a patient from queue.
// returns 1 if successful, 0 if patient not
found // declare functions used by main:
int i, j, found = 0;
// search for patient patient InputPatient (void)
for (i=0; i<NumberOfPatients; i++) {
{ // this function asks user for patient data.
if (stricmp(List[i].ID, p->ID) == patient p;
0) cout << "
{
// patient found in queue Please enter data for new patient
*p = List[i]; found = 1; First name: ";
// move all following patients cin.getline(p.FirstName,
one position forward in queue sizeof(p.FirstName));
NumberOfPatients--; cout << "
for (j=i; Last name: ";
j<NumberOfPatients; j++) cin.getline(p.LastName,
{ sizeof(p.LastName));
List[j] = cout << "
List[j+1]; Social security number: ";
} cin.getline(p.ID, sizeof(p.ID));
} // check if data valid
} if (p.FirstName[0]==0 || p.LastName[0]==0 ||
return found; p.ID[0]==0)
} {
// rejected
strcpy(p.ID,"");
void queue::OutputList (void) cout << "
{
// lists entire queue on screen Error: Data not valid. Operation cancelled.";
int i; getch();
if (NumberOfPatients == 0) }
{ return p;
cout << " }
Queue is empty";
}
else void OutputPatient (patient * p)
{ {
// this function outputs patient data to the
screen
3
if (p == NULL || p->ID[0]==0) Please enter your choice:";
{ cout << "
cout << "
No patient"; 1: Add normal patient";
return; cout << "
} 2: Add critically ill patient";
else cout << "
cout << " 3: Take out patient for operation";
cout << "
Patient data:"; 4: Remove dead patient from queue";
cout << " cout << "
5: List queue";
First name: " << p->FirstName; cout << "
cout << " 6: Change department or exit
";
Last name: " << p->LastName; // get user choice
cout << " choice = ReadNumber();
// do indicated action
Social security number: " << p->ID; switch (choice)
} {
case 1: // Add normal patient
p = InputPatient();
int ReadNumber() if (p.ID[0])
{ {
// this function reads an integer number from success = q-
the keyboard. >AddPatientAtEnd(p);
// it is used because input with cin >> doesn't clrscr();
work properly! if (success)
char buffer[20]; {
cin.getline(buffer, sizeof(buffer)); cout << "
return atoi(buffer); Patient added:
}
";

void DepartmentMenu (queue * q) }


{ else
// this function defines the user interface with {
menu for one // error
department cout << "
int choice = 0, success; patient p;
while (choice != 6) Error: The queue is full. Cannot add patient:";
{ }
// clear screen OutputPatient(&p);
clrscr(); cout << "
// print menu
cout << " Press any key";
getch();
}
Welcome to department: " << q- break;
>DepartmentName;
cout << " case 2: // Add critically ill patient
p = InputPatient();
4
if (p.ID[0]) if (p.ID[0])
{ {
success = q- success = q-
>AddPatientAtBeginning(p); >RemoveDeadPatient(&p);
clrscr(); clrscr();
if (success) if (success)
{ {
cout << " cout << "
Patient added: Patient removed:

"; ";
} }
else else
{ {
// error // error
cout << " cout << "

Error: The queue is full. Cannot add Error: Cannot find patient:
patient:";
} ";
}
OutputPatient(&p); OutputPatient(&p);
cout << " cout << "

Press any key"; Press any key";


getch(); getch();
} }
break; break;

case 3: // Take out patient for operation case 5: // List queue


p = q->GetNextPatient(); clrscr();
clrscr(); q->OutputList();
if (p.ID[0]) cout << "
{
cout << " Press any key";
Patient to operate: getch(); break;
}
"; }
OutputPatient(&p);} }
else
{
cout << " // main function defining queues and main
There is no patient to operate."; menu
} void main ()
cout << " {
int i, MenuChoice = 0;
Press any key"; // define three queues
getch(); queue departments[3];
break; // set department names
strcpy (departments[0].DepartmentName,
case 4: // Remove dead patient from queue "Heart clinic");
p = InputPatient();
5
strcpy (departments[1].DepartmentName,
"Lung clinic");
strcpy (departments[2].DepartmentName,
"Plastic surgery");
#include<iostream.h>
while (MenuChoice != 4) #include<conio.h>
{ #include<process.h>
// clear screen class all
clrscr(); {
// print menu private:
cout << " struct address
{
int house;
Welcome to Software City Hospital"; char street[30];
cout << " char city[30];
char state[30];
Please enter your choice: char country[30];
"; };
for (i = 0; i < 3; i++) struct age
{ {
// write menu item for int day;
department i int month;
cout << " int year;
" << (i+1) << ": " << };
departments[i].DepartmentName; struct patient_info
} {
cout << " char name[50];
4: Exit address AD1; //nested structure
"; implemented
// get user choice age A1; //nested structure inplemented
MenuChoice = ReadNumber(); int martial_status;
// is it a department name? int reg_no;
if (MenuChoice >= 1 && int bld_group;
MenuChoice <= 3) int sex;
{ }PI[100];
// call submenu for int task;
department protected:
// (using pointer void enter_patient_info();
arithmetics here:) void show_patient_detail();
DepartmentMenu public:
(departments + (MenuChoice-1)); void software_detail();
} void tasks();
} char answer;
} char answer1;
char ch;
int serial;
};

class date
{
private:
int date;
6
int month; {
int year; attempt=0;
public: D1.show_date();
void enter_date(); cout<<"
void show_date();
}; ***HOSPITAL
MANAGEMENT SOFTWARE***"<<"
class dob ";
{ cout<<" By
private: Mustafizur Rohman "<<"
struct dob1 ";
{ cout<<"
int date; **Hospital
int month; Management Tasks**"<<"
int year; ";
int rem; cout<<"
}DOB11[100]; *****************************"<<"
public: ";
void enter_date(); cout<<"
void show_date();
};
Please select a task to do...."<<"
int i=0; ";
int rem; cout<<"
int count;
int regis; 1. Enter a new patient information ."<<"
int attempt; ";
int temp; cout<<"2. View detail of existing patient ."<<"
int show_count=0; ";
cout<<"3. View detail about the
all A1; //object declared program ."<<"
date D1; //object declared ";
dob DOB1; //object declared cout<<"4. Exit from the program ."<<"
";
void main() //other function remain
{ cout<<"
count=0;
cout<<"Welcome to..."<<" Enter your task serail :"<<"
"; ";
cout<<" cin>>task;
switch(task)
***HOSPITAL {
MANAGEMENT SOFTWARE***"<<" case 1:{
"; A1.enter_patient_info();
cout<<" By break;
Mustafizur Rohman "<<" }
"; case 2:{
D1.enter_date(); A1.show_patient_detail();
A1.tasks(); break;
} }
case 3:{
void all::tasks() A1.software_detail();
7
break; cout<<"
}
case 4:{ ***ENTERING INFORMATION
clrscr(); FOR PATIENT SERIAL NUMBER
cout<<" "<<i<<"***"<<"
";
cin.get(ch);
cout<<"
Thank You for trying this Registration Number : "<<PI[i].reg_no<<"
program !!!"<<"
"; ";
cout<<" This is the end of cout<<"Enter the name of patient :"<<"
program...."<<" ";
"; clreol();
cout<<" cin.getline(PI[i].name,50);
cout<<"Sex (1-Male 2-Female) :"<<"
Press any key to exit....."<<" ";
"; clreol();
getch(); cin>>PI[i].sex;
exit(0); while(PI[i].sex!=1&&PI[i].sex!=2)
break; {
} cout<<"Invalid input for sex of
default:{ patient!!!"<<"
clrscr(); ";
cout<<" cout<<"Sex :"<<"
Invalid task serial ."<<" ";
"; clreol();
cout<<"Press any key to continue...."<<" cin>>PI[i].sex;
"; }
getch(); cout<<"
clrscr(); ***ENTERING ADDRESS**"<<"
A1.tasks();
} ";
} cout<<"House number :"<<"
} ";
clreol();
void all::enter_patient_info() cin>>PI[i].AD1.house;
{ while(PI[i].AD1.house<=0)
clrscr(); {
answer='y'; cout<<"Invalid input for house number ."<<"
if(count==0) ";
{ cout<<"Again enter the house number ."<<"
serial=1; ";
} clreol();
else cin>>PI[i].AD1.house;
{ }
i=serial; cin.get(ch);
} cout<<"Street :"<<"
for(i=serial;answer=='y'||answer=='Y';i++) ";
{ clreol();
PI[i].reg_no=i; cin.getline(PI[i].AD1.street,30);
temp=serial; cout<<"City :"<<"
8
"; clreol();
clreol(); cout<<"5. AB+ "<<"
cin.getline(PI[i].AD1.city,30); ";
cout<<"State :"<<" clreol();
"; cout<<"6. AB- "<<"
clreol(); ";
cin.getline(PI[i].AD1.state,30); clreol();
cout<<"Country :"<<" cout<<"7. O+ "<<"
"; ";
clreol(); clreol();
cin.getline(PI[i].AD1.country,30); cout<<"8. O- "<<"
DOB1.enter_date(); ";
//to calculate age clreol();
cin.get(ch); cout<<"Enter :"<<"
cout<<"Martial status(1-Married,2-Not ";
Married ):"<<" clreol();
"; cin>>PI[i].bld_group;
if(count!=0) switch(PI[i].bld_group)
{ {
clreol(); case 1:
} case 2:
cin>>PI[i].martial_status; case 3:
while(PI[i].martial_status<1|| case 4:
PI[i].martial_status>2) case 5:
{ case 6:
cout<<"Invalid input for martial status ."<<" case 7:
"; case 8:{
cout<<"Enter a valid martial status :"<<" break;
"; }
clreol(); default:{
cin>>PI[i].martial_status;
} while(PI[i].bld_group!=1&&PI[i].bld_group!
cin.get(ch); =2&&PI[i].bld_group!=3&&
if(count!=0)
{ PI[i].bld_group!=4&&PI[i].bld_group!
clreol(); =5&&PI[i].bld_group!=6&&
} PI[i].bld_group!
clreol(); =7&&PI[i].bld_group!=8)
cout<<"Blood group :"<<" {
"; clreol();
clreol(); cout<<"Invalid input !"<<"
cout<<"1. A+ "<<" ";
"; cout<<"Blood Group :"<<"
clreol(); ";
cout<<"2. A- "<<" clreol();
"; cin>>PI[i].bld_group;
clreol(); }
cout<<"3. B+ "<<" break;
"; }
clreol(); }
cout<<"4. B- "<<" cin.get(ch);
"; cout<<"
9
Want to enter information for another patient ? ";
"<<" clreol();
"; if(count!=0)
clreol(); {
cin>>answer; clreol();
count++; }
serial++; cin>>DOB11[temp].month;
} }while(DOB11[temp].month<0||
clrscr(); DOB11[temp].month>12);
A1.tasks(); }
} cout<<"Date :";
clreol();
void dob::enter_date() switch(DOB11[temp].month)
{ {
clreol(); case 1:
cout<<" case 3:
case 5:
Date of birth"<<" case 7:
"; case 8:
clreol(); case 10:
cout<<" case 12:{
Year :"; cin>>DOB11[temp].date;
clreol(); while(DOB11[temp].date<1||
clreol(); DOB11[temp].date>31)
cin>>DOB11[temp].year; {
if(DOB11[temp].year<=0|| clreol();
DOB11[temp].year>10000) cout<<"Invalid date !"<<"
{ ";
do cout<<"Again enter the date :"<<"
{ ";
clreol(); clreol();
cout<<"Invalid input for year !"<<" cin>>DOB11[temp].date;
"; }
cout<<"Please enter the year correctly :"<<" break;
"; }
cin>>DOB11[temp].year; case 2:{
}while(DOB11[temp].year<0|| cin>>DOB11[temp].date;
DOB11[temp].year>10000); if(DOB11[temp].year%4==0)
} {
clreol(); while(DOB11[temp].date<0||
cout<<"Month :"; DOB11[temp].date>29)
clreol(); //for leap year
cin>>DOB11[temp].month; {
if(DOB11[temp].month<=0|| clreol();
DOB11[temp].month>12) cout<<"Invalid date !"<<"
{ ";
do cout<<"Again enter the date :"<<"
{ ";
clreol(); clreol();
cout<<"Invalid input for month !"<<" cin>>DOB11[temp].date;
"; }
cout<<"Again enter the month :"<<" }
10
else ";
{ cin>>year;
while(DOB11[temp].date<0|| }while(year<0||year>10000);
DOB11[temp].date>28) }
//for non-leap year cout<<"Month :";
{ cin>>month;
clreol(); if(month<=0||month>12)
cout<<"Invalid date !"<<" {
"; do
cout<<"Again enter the date :"<<" {
"; cout<<"Invalid input for month !"<<"
clreol(); ";
cin>>DOB11[temp].date; cout<<"Again enter the month :"<<"
} ";
} cin>>month;
break; }while(month<0||month>12);
} }
default:{ cout<<"Date :";
cin>>DOB11[temp].date; switch(month)
while(DOB11[temp].date<1|| {
DOB11[temp].date>30) case 1:
{ case 3:
clreol(); case 5:
cout<<"Invalid date !"<<" case 7:
"; case 8:
cout<<"Again enter the date :"<<" case 10:
"; case 12:{
clreol(); cin>>date;
cin>>DOB11[temp].date; while(date<1||date>31)
} {
break; cout<<"Invalid date !"<<"
} ";
} //end of switch cout<<"Again enter the date :"<<"
clreol(); ";
} cin>>date;
}
void date::enter_date() break;
{ }
cout<<" case 2:{
cin>>date;
First of all I need the current date ..."<<" if(year%4==0)
"; {
cout<<" while(date<0||date>29) //for leap year
Year :"; {
cin>>year; cout<<"Invalid date !"<<"
if(year<=0||year>10000) ";
{ cout<<"Again enter the date :"<<"
do ";
{ cin>>date;
cout<<"Invalid input for year !"<<" }
"; }
cout<<"Please enter the year correctly :"<<" else
11
{ switch(rem)
while(date<0||date>28) //for non-leap {
year case 1:{
{ cout<<"st ";
cout<<"Invalid date !"<<" break;
"; }
cout<<"Again enter the date :"<<" case 2:{
"; cout<<"nd ";
cin>>date; break;
} }
} case 3:{
break; cout<<"rd ";
} break;
default:{ }
cin>>date; default:{
while(date<1||date>30) cout<<"th ";
{ break;
cout<<"Invalid date !"<<" }
"; }
cout<<"Again enter the date :"<<" over:
"; switch(month)
cin>>date; {
} case 1:{
break; cout<<"January , ";
} break;
} //end of switch }
} case 2:{
cout<<"February , ";
void date::show_date() //remove the goto break;
ststements in this function }
{ case 3:{
clrscr(); cout<<"March , ";
cout<<"Hello.... break;
It's "; }
cout<<date; case 4:{
rem=date%10; cout<<"April , ";
switch(date) break;
{ }
case 11: case 5:{
case 12: cout<<"May , ";
case 13: break;
case 14: }
case 15: case 6:{
case 16: cout<<"June , ";
case 17: break;
case 18: }
case 19: case 7:{
case 20:{ cout<<"July , ";
cout<<"th "; break;
goto over; }
} case 8:{
} cout<<"August , ";
12
break; {
} cout<<"Male "<<"
case 9:{ ";
cout<<"September , "; clreol();
break; }
} if(PI[regis].sex==2)
case 10:{ {
cout<<"October , "; cout<<"Female "<<"
break; ";
} clreol();
}
case 11:{ cout<<"Blood Group : ";
cout<<"November , "; clreol();
break; switch(PI[regis].bld_group)
} {
case 12:{ case 1:{
cout<<"December , "; clreol();
break; cout<<"A+
} ";
} break;
cout<<year<<" }
"; case 2:{
} clreol();
cout<<"A-
void all::show_patient_detail() ";
{ break;
do }
{ case 3:{
clrscr(); clreol();
cout<<" cout<<"B+
";
Enter registration number :"<<" break;
"; }
clreol(); case 4:{
cin>>regis; clreol();
cin.get(ch); cout<<"B-
show_count++; ";
if(regis>0&®is<serial) break;
{ }
clreol(); case 5:{
cout<<" clreol();
***INFORMATION FOR PATIENT cout<<"AB+
REGISTRATION NUMBER"<<regis<<"*** ";
break;
"; }
clreol(); case 6:{
cout<<"Name : "<<PI[regis].name<<" clreol();
"; cout<<"AB-
clreol(); ";
cout<<"Sex : "; break;
clreol(); }
if(PI[regis].sex==1) case 7:{
13
clreol(); {
cout<<"O+ if(regis==1)
"; {
break; cout<<"
} Database is empty !!!"<<"
case 8:{ ";
clreol(); cout<<"Press any key to exit to main task
cout<<"O- menu..."<<"
"; ";
break; getch();
} clrscr();
} A1.tasks();
clreol(); }
cout<<"Date of birth : "; attempt++;
clreol(); if(attempt==3)
DOB1.show_date(); {
cout<<"Martial Status : "; cout<<"
clreol(); You have entered wrong registration number 3
if(PI[i].martial_status==1) times
{ ."<<"
cout<<"Married "<<" ";
"; cout<<"Access Denied!!! "<<"
clreol(); ";
} cout<<"Please try again later. "<<"
else ";
{ cout<<"Press any key to exit to main task
cout<<"Not married "<<" menu..."<<"
"; ";
clreol(); getch();
} clrscr();
clreol(); A1.tasks();
cout<<" }
**ADDRESS**"<<" clreol();
"; cout<<"
clreol();
cout<<" Sorry, the registration number is invalid ."<<"
House no. : "<<PI[regis].AD1.house; ";
clreol(); cout<<"Press any key to continue...."<<"
cout<<" ";
Street : "<<PI[regis].AD1.street; getch();
clreol(); clreol();
cout<<" A1.show_patient_detail();
City : "<<PI[regis].AD1.city; }
clreol(); clreol();
cout<<" cout<<"
State : "<<PI[regis].AD1.state;
clreol(); Want to see information of another
cout<<" patient :"<<"
Country : "<<PI[regis].AD1.country; ";
clreol(); clreol();
} cin>>answer1;
else }while(answer1=='y'||answer1=='Y');
14
clreol(); cout<<"February , ";
clrscr(); break;
A1.tasks(); }
} case 3:{
cout<<"March , ";
void dob::show_date() break;
{ }
cout<<DOB11[regis].date; case 4:{
rem=DOB11[regis].date%10; cout<<"April , ";
switch(DOB11[regis].date) break;
{ }
case 11: case 5:{
case 12: cout<<"May , ";
case 13: break;
case 14: }
case 15: case 6:{
case 16: cout<<"June , ";
case 17: break;
case 18: }
case 19: case 7:{
case 20:{ cout<<"July , ";
cout<<"th "; break;
goto over; }
} case 8:{
} cout<<"August , ";
switch(rem) break;
{ }
case 1:{ case 9:{
cout<<"st "; cout<<"September , ";
break; break;
} }
case 2:{ case 10:{
cout<<"nd "; cout<<"October , ";
break; break;
} }
case 3:{
cout<<"rd "; case 11:{
break; cout<<"November , ";
} break;
default:{ }
cout<<"th "; case 12:{
break; cout<<"December , ";
} break;
} }
over: }
switch(DOB11[regis].month) cout<<DOB11[regis].year<<"
{ ";
case 1:{ }
cout<<"January , ";
break; void all::software_detail()
} {
case 2:{ clrscr();
15
cout<<" #include<graphics.h>
#include<dos.h>
#include<string.h>
***SOFTWARE
DETAILS*** void intro_screen() // introduction
"; screen graphics
cout<<" {
int left = 50,
Developer : ChetanasProjects top = 200,
"<<"
bottom = top+85,
";
cout<<" Programming Language : C+ depth = 25,
+ "<<" time = 5;
"; /*Set bar styles*/
cout<<" Aim : Simulation setfillstyle(1,BLACK);
of the software used in Hospital"<<" settextstyle( 7, HORIZ_DIR, 8);
";
/*First bar*/
cout<<"
Hope you like it..."<<" for( int i=620; i>left; i-- )
"; {
cout<<" /*Draw bar*/
setcolor(LIGHTRED);
Send your comments to : bar3d( i, top, i+460, bottom, depth, 1 );
chetanaprojects@yahoo.com ."<<"
/*Label the bar*/
";
cout<<" setcolor(RED);
outtextxy( i+10, top-12, "Loading...");
Thank You for trying this program. delay(time);
"<<" /*Delete bar*/
"; setcolor(BLACK);
cout<<"
bar3d( i, top, i+460, bottom, depth, 1 );
}
Press any key to return to the main task /*Last time it must be drawn again and
menu......."<<" not deleted*/
"; setcolor(LIGHTCYAN);
getch(); bar3d( i, top, i+460, bottom, depth, 1 );
A1.tasks();
setcolor(WHITE);
}
outtextxy( i+10, top-12, "Loaded!");
delay(1200);
}
void exit_screen() // exit screen graphics
{
New source code
int left = 50,
top = 200,
#include<stdio.h> bottom = top+85,
#include<fstream.h> depth = 25,
#include<conio.h> time = 5;
#include<process.h> /*Set bar styles*/
setfillstyle(1,BLACK);
16
settextstyle( 7, HORIZ_DIR, 8); void write();
/*First bar*/ void del();
for( int i=620; i>left; i-- ) void search();
{ void input(Patient);
} void output(Patient);
/*Last time it must be drawn again and };
not deleted*/ void Patient::output(Patient read) //
setcolor(LIGHTCYAN); function to show patient
bar3d( i, top, i+460, bottom, depth, 1 ); details
setcolor(RED); {
outtextxy( i+10, top-12, "Thank You"); cout<<"\n Name: ";
/*Set bar styles*/ cout<<read.name;
setfillstyle(1,WHITE); cout<<"\n Date(dd/mm/yy): ";
settextstyle( 7, HORIZ_DIR, 8); cout<<read.date;
/*Set new peimeters*/ cout<<"\n Age: ";
left += 60; cout<<read.age;
top += 120; cout<<"\n Sex(M/F): ";
bottom += 120; cout<<read.sex;
settextstyle( 1, HORIZ_DIR, 4 ); cout<<"\n Address: ";
setcolor(LIGHTCYAN); cout<<read.address;
bar3d( 20, 410, 620, 450 , 15, 1 ); cout<<"\n Phone number: ";
setcolor(BLACK); cout<<read.phoneno;
outtextxy(30,412,"CREATED BY: cout<<"\n Email id: ";
www.icbse.com"); cout<<read.email;
delay(4000); cout<<"\n Blood group: ";
} cout<<read.bloodgr;
/* The folowing class deals with all the cout<<"\n Pulse rate(beats/min): ";
details regarding a cout<<read.pulse;
patient.*/ cout<<"\n Blood pressure(mm Hg): ";
class Patient cout<<read.bloodp;
{ cout<<"\n Temperature(F): ";
long int phoneno; cout<<read.temp;
char date[15]; cout<<"\n Addictions: ";
int age,temp,pulse; cout<<read.addictions;
char bloodp[10]; cout<<"\n Complains: ";
char cout<<read.complains;
name[20],sex[10],address[100],email[30 cout<<"\n Duration: ";
],bloodgr[10]; cout<<read.duration;
char cout<<"\n Respiratory rate(inhalation
addictions[100],complains[100],duratio per min): ";
n[20]; cout<<read.respiratoryrate;
char respiratoryrate[20],symptoms[200]; }
public: void Patient::input(Patient write) //
int opdno; function to read patient's
void display(); details
17
{ {
ofstream outf; clrscr();
outf.open("pdatbase.dat",ios::out| int opd,flag=0;
ios::binary|ios::app); cout<<" Give the opd no:";
cout<<"\n Name: "; cin>>opd;
gets(write.name); ifstream fin;
cout<<"\n Date(dd/mm/yy): "; Patient read;
gets(write.date); fin.open("pdatbase.dat",ios::in|
cout<<"\n Age: "; ios::binary);
cin>>write.age; while(!fin.eof())
cout<<"\n Sex(M/F): "; {
gets(write.sex); fin.read((char*)&read,sizeof(Patient));
cout<<"\n Address: "; if(read.opdno==opd)
gets(write.address); {
cout<<"\n Phone number: "; flag=1;
cin>>write.phoneno; cout<<" Patient's
cout<<"\n Email id: "; opdnumber:"<<read.opdno;
gets(write.email); output(read);
cout<<"\n Blood group: "; cout<<"\n Press any key to continue\n";
gets(write.bloodgr); cin.get();
cout<<"\n Pulse rate(beats/min): "; cin.get();
cin>>write.pulse; break;
cout<<"\n Blood pressure(mm Hg): "; }
cin>>write.bloodp; }
cout<<"\n Temperature(F): "; fin.close();
cin>>write.temp; if(!flag)
cout<<"\n Addictions: "; {
gets(write.addictions); cout<<" No entry exists\n";
cout<<"\n Complains: "; cout<<" Press any key to continue\n";
gets(write.complains); cin.get();
cout<<"\n Duration: "; cin.get();
gets(write.duration); }
cout<<"\n Respiratory rate(inhalation }
per min): "; void Patient::del() // function to delete
gets(write.respiratoryrate); an entry
cout<<"\nSaving........"; {
delay(1200); ifstream fin;
cout<<"\nSaved"; ofstream outf;
delay(1000); clrscr();
outf.write((char*)&write,sizeof(Patient) char cho;
); int opd,flag=0;
outf.close(); cout<<"\nGive the opd number of the
} record to be deleted:";
void Patient::display() // to display a cin>>opd;
patient's details Patient write,read;
18
fin.open("pdatbase.dat",ios::binary| }
ios::in); fin.close();
outf.open("temp.dat",ios::binary| cout<<a<<'\n';
ios::out); write.opdno=a;
while(!fin.eof()) input(write);
{ cin.get();
fin.read((char*)&read,sizeof(Patient)); cin.get();
if(read.opdno==opd) cout<<"\nDo you want to add more
{ entry(y/n):";
flag=1; cin>>cho;
} if(cho=='Y'||cho=='y')
else goto start;
outf.write((char*)&read,sizeof(Patient)); }
} void Patient::search() // function to
if(!flag) search a patient
{ { int i,opdno,flag=0;
cout<<"No entry exists\n"; ifstream fin;
cout<<"Press any key to continue\n"; fin.open("pdatbase.dat",ios::binary|
cin.get(); ios::in);
cin.get(); Patient search;
} clrscr();
fin.close(); cout<<"\n
outf.close(); ******************************";
remove("pdatbase.dat"); cout<<"\n * 1.)Search by OPD no. *";
rename("temp.dat","pdatbase.dat"); cout<<"\n * 2.)Search by Patient
} name.*";
void Patient::write() // function to write cout<<"\n
details in the database ******************************";
{ cout<<"\n Enter your choice:";
start: cin>>i;
clrscr(); switch(i)
char cho; {
Patient write; case 1: clrscr();
cout<<"\t\t\tType the Patient's data\n"; cout<<"Enter the OPD no. of the patient
cout<<" Patient's opdnumber:"; to be searched:";
ifstream fin; cin>>opdno;
int a=0; while(!fin.eof())
fin.open("pdatbase.dat",ios::out| {
ios::binary); fin.read((char*)&search,sizeof(Patient));
while(!fin.eof()) if(search.opdno==opdno)
{ {
fin.read((char*)&write,sizeof(Patient)); flag=1;
if(write.opdno<a) cout<<"Patient's
break; opdnumber:"<<search.opdno;
a++; output(search);
19
cout<<"\n Press any key to continue\n"; cout<<" Wrong choice selected.";
cin.get(); cout<<"\n The program will exit.";
cin.get(); exit(0);
break; }
} fin.close();
} }
if(!flag) // main function begins
{ void main()
cout<<" No entry exists\n"; {
cout<<" Press any key to continue\n"; textcolor(3); //for coloured text
cin.get(); int driver = DETECT,mode;
cin.get(); initgraph(&driver,&mode,"c:\\tc\\bgi");
} intro_screen();
break; closegraph();
case 2: clrscr(); start:
int i,str,temp; clrscr();
char name[20]; Patient p1; //object of class patient
cout<<" Enter the name of the patient to int choice;
be searched: "; char cho;
gets(name); ofstream fout; // object to link the
while(!fin.eof()) program with pdatbase
{ fout.open("pdatbase.dat",ios::binary|
fin.read((char*)&search,sizeof(Patient)); ios::nocreate|ios::app);
temp=strcmp(name,search.name); if(!fout)
if(temp==0) {
{ ofstream fout1;
flag=1; fout1.open("pdatbase.dat",ios::binary);
cout<<" Patient's Patient write;
opdnumber:"<<search.opdno; write.opdno=0;
output(search); fout1.write((char*)&write,sizeof(Patient
cout<<"\n Press any key to continue\n"; ));
cin.get(); fout1.close();
cin.get(); }
break; fout.close();
} cout<<"\t\t\ Red Cross Hospital";
} cout<<"\n
if(!flag) ********************************
{ ************";
cout<<" No entry exists\n"; cout<<"\n\n * 1. View patient details *";
cout<<" Press any key to continue\n"; cout<<"\n\n * 2. Add new patient detail
cin.get(); *";
cin.get(); cout<<"\n\n * 3. Delete a patient details
} *";
break; cout<<"\n\n * 4. Search a patient details
default : clrscr(); *";
20
cout<<"\n\n * 5. Exit *"; goto start;
cout<<"\n }
********************************
************";
cout<<"\n\n Enter your choice:";
cin>>choice;
switch(choice)
{
case 1:{
p1.display();
break;
}
case 2:{
p1.write();
break;
}
case 3:{
p1.del();
break;
}
case 4:{
p1.search();
break;
}
case 5:{
clrscr();
int driver = DETECT,mode;
initgraph(&driver,&mode,"c:\\tc\\bgi");
exit_screen();
closegraph();
cout<<" Press any key to exit.....\n"<<"
";
getch();
exit(0);
break;
}
default:{
clrscr();
cout<<" Invalid choice."<<" ";
cout<<" Press any key to
continue...."<<" ";
getch();
clrscr();
}
}

You might also like