I have to create a program that enable insert of patient record and edit patient record when prompt. The two function suppose to read data from and write data to data file (eg: patient.txt)
When the connection to data file is open, user will able to edit the data inside the text file and save it again so program will be able to display updated data. Now the problem is I don't know how to implement the changePatient() function with the data file. Below is my code:
void change_patient() //change the name, appointment benefit, or drug benefit of a patient
{
ofstream changePatient;
do{
changePatient.open("Patient.txt", ios::app);
if (! changePatient)
{
cout<<" Error! The file you request does not exist.";
}
else{
cout<<"Select the patient you wish to edit.";
}
if(changePatient.close())
{
cout<<"Save record?"; //Save Record
cin>>choice;
}
if((choice == 'Y') || (choice == 'y'))
{
changePatient<<patientID<<"\t"<<patientName<<"\t"<<a_benefit<<"\t"<<d_benefit<<endl;
cout<<"Your record has been saved successfully!"<<endl;
}
elseif((choice == 'N') || (choice == 'n'))
{
cout<<"Do you want to add another patient?: "<<endl;
cin>>choice; //Enter another patient record
}
}while ((choice == 'Y')||(choice == 'y')); //while user input 'Y' or 'y'
}
I not sure how to allow user to edit the text file by giving some prompt operation. Can anyone sort me some idea?