Explain what is being done in this specific function: int modify(int r) { Patient patient; long pos,flag=0; fstream file("Record.dat", ios::in | ios::out | ios::binary); file.seekg(10); while(!file.eof()) { pos=file.tellg(); file.read((char*)&patient,sizeof(patient)); if(patient.room_no==r) { cout<<"\n Enter New Details"; cout<<"\n -----------------"; cout<<"\n Name: "; cin>>patient.name; cout<<" Address: "; cin>>patient.address; cout<<" Phone no: "; cin>>patient.phone; cout<<"Age: "; cin>>patient.age; file.seekg(pos); file.write((char*)&patient,sizeof(patient)); cout<<"\n Record is modified....!!"; flag=1; break; } } if(flag==0) cout<<"\n Sorry Room no. not found or vacant...!!"; file.close(); return 0; } int deleteRec(int r) { Patient patient; int flag=0; char ch; ifstream fin("Record.dat", ios::in | ios::binary); fin.seekg(10); ofstream fout("temp.dat", ios::out | ios::trunc | ios::binary); fout.write("RECORD.DAT", 10); while(!fin.eof()) { fin.read((char*)&patient,sizeof(patient)); if(patient.room_no==r) { cout<<"\n Name: "<>ch; if(ch=='n') { fout.write((char*)&patient,sizeof(patient)); flag=1; } } else { fout.write((char*)&patient,sizeof(patient)); } } fin.close(); fout.close(); if(flag==0) { cout<<"\n Sorry room no. not found or vacant...!!"; } else { remove("Record.dat"); rename("temp.dat","Record.dat"); } return 0; } int allocate_room(Patient *patient) { int i, totalRecords = getTotalRecords(); int temp_room = 0; Patient temp_patient; for(i = 0; i < totalRecords; i++) { retrieveRecord(&temp_patient, i); if (temp_patient.service == patient->service) { temp_room++; } } if (temp_room > 4) { return 1; } patient->room_no = temp_room+((patient->service-1)*5)+1; return 0; }
Explain what is being done in this specific function:
int modify(int r) {
Patient patient;
long pos,flag=0;
fstream file("Record.dat", ios::in | ios::out | ios::binary);
file.seekg(10);
while(!file.eof()) {
pos=file.tellg();
file.read((char*)&patient,sizeof(patient));
if(patient.room_no==r) {
cout<<"\n Enter New Details";
cout<<"\n -----------------";
cout<<"\n Name: ";
cin>>patient.name;
cout<<" Address: ";
cin>>patient.address;
cout<<" Phone no: ";
cin>>patient.phone;
cout<<"Age: ";
cin>>patient.age;
file.seekg(pos);
file.write((char*)&patient,sizeof(patient));
cout<<"\n Record is modified....!!";
flag=1;
break;
}
}
if(flag==0)
cout<<"\n Sorry Room no. not found or vacant...!!";
file.close();
return 0;
}
int deleteRec(int r) {
Patient patient;
int flag=0;
char ch;
ifstream fin("Record.dat", ios::in | ios::binary);
fin.seekg(10);
ofstream fout("temp.dat", ios::out | ios::trunc | ios::binary);
fout.write("RECORD.DAT", 10);
while(!fin.eof()) {
fin.read((char*)&patient,sizeof(patient));
if(patient.room_no==r) {
cout<<"\n Name: "<<patient.name;
cout<<"\n Address: "<<patient.address;
cout<<"\n Phone No: "<<patient.phone;
cout<<"\n Age: "<<patient.age;
cout<<"\n\n Do you want to delete this record(y/n): ";
cin>>ch;
if(ch=='n') {
fout.write((char*)&patient,sizeof(patient));
flag=1;
}
} else {
fout.write((char*)&patient,sizeof(patient));
}
}
fin.close();
fout.close();
if(flag==0) {
cout<<"\n Sorry room no. not found or vacant...!!";
} else {
remove("Record.dat");
rename("temp.dat","Record.dat");
}
return 0;
}
int allocate_room(Patient *patient) {
int i, totalRecords = getTotalRecords();
int temp_room = 0;
Patient temp_patient;
for(i = 0; i < totalRecords; i++) {
retrieveRecord(&temp_patient, i);
if (temp_patient.service == patient->service) {
temp_room++;
}
}
if (temp_room > 4) {
return 1;
}
patient->room_no = temp_room+((patient->service-1)*5)+1;
return 0;
}
Step by step
Solved in 2 steps