I am creating a program that stores information of hospital patients in a sequential text file..
I want to the program to be able to search for a patient using the patient name already in the text file..
The program is giving me no errors whatsoever so please look into it..
#include <iostream.h>
#include <fstream.h>
#include <string.h>
class Patient
{
public:
char name[15];//name of the patient
char DOB[10];//date of birth of the patient
char sex[6];//the gender of the patient
char residence[10];//the residence of the patient
public:
int record(int number)
{
return number;
}
void setName(char *patName)
{
strcpy(name,patName);
}
void setDOB(char *patDOB)
{
strcpy(DOB,patDOB);
}
void setGender(char *patGender)
{
strcpy(sex,patGender);
}
void setResidence(char *patRes)
{
strcpy(residence,patRes);
}
double fee(double cash)
{
return cash;
}
};
int main()
{
int number;
char name[15];
char DOB[10];
char sex[6];
char residence[10];
double cash;
char sname[15];
cout<<"Enter the name of the patient:"<<endl;/*user enters name to be searched*/
cin>>sname;
ifstream myfile ("patient.txt", ios::in );
if (myfile.is_open())
{
while (!myfile.eof())
{
if (sname==name){
cout<<"This is the file you searched!"<<endl;
myfile>>number>>name>>DOB>>sex>>residence;
}
else {
cout<<name;
}
}
myfile.close();
}
else cout << "Unable to open file";
cout<<"Enter patient Number: "<<endl;
cin>>number;
cout<<"Patient name:"<<endl;
cin>>name;
cout<<"DOB"<<endl;
cin>>DOB;
cout<<"Gender:"<<endl;
cin>>sex;
cout<<"residence:"<<endl;
cin>>residence;
cout<<"fee"<<endl;
cin>>cash;
Patient myPatient;
myPatient.record(number);
myPatient.setName(name);
myPatient.setDOB(DOB);
myPatient.setGender(sex);
myPatient.setResidence(residence);
myPatient.fee(cash);
cout<<"Patient Number: "<<myPatient.record(number)<<endl;
cout<<"Patient Name: "<<myPatient.name<<endl;
cout<<"Patient DOB: "<<myPatient.DOB<<endl;
cout<<"Patient Gender: "<<myPatient.sex<<endl;
cout<<"Patient Residence: "<<myPatient.residence<<endl;
cout<<"Consultation fee: "<<myPatient.fee(cash)<<endl;
ofstream mfile ("patient.txt", ios::out | ios::app );
if (mfile.is_open())
{
mfile <<
number<<endl<<name<<endl<<DOB<<endl<<sex<<endl<<residence<<endl
<<cash<<endl;
mfile.close();
}
else cout << "Unable to open file";
return 0;
}