Hey this is my second time posting here, I have another question to ask. I wanted to write a text file recording the patient's particular and medical fees. But I encounter 2 problems.
1) I am using 2 different classes, class Patient and class Fee and using inheritence doesnt solve the problem.
2) I try to seperate the file this way although I think it's wrong.
void Patient::Invoice0(void)
{ ofstream outFile;
outFile.open("Patient Fee.txt");
outFile<<"Seng Tock Tan Hospital"<<endl;
outFile<<"Name : "<<name<<endl<<"NRIC : "<<NRIC<<endl<<"Phone Number : "<<phoneNumber<<endl;
outFile.close();
}
void Fee::Invoice(void)
{
ofstream outFile;
outFile.open("Patient Fee.txt");
//outFile<<"Seng Tock Tan Hospital"<<endl;
//outFile<<"Name : "<<name<<endl<<"NRIC : "<<NRIC<<endl<<"Phone Number : "<<phoneNumber<<endl;
outFile<<setfill('*')<<setw(90)<<"\n\t\t\tPatient' Fee schedule"<<endl;
outFile<<setfill('*')<<setw(66)<<"*\n";
outFile<<"\t\t\tCLASS OF WARD ACCOMONDATION\n";
outFile<<setfill('*')<<setw(66)<<"\n";
outFile<<"\t\t\t"<<"A\t\t"<<"B\t\t"<<"C\t\t\n";
outFile<<"Acute Ward\t"<<"\t$230"<<"\t\t$150"<<"\t\t$75\n";
outFile<<"Intensive care unit"<<"\t$500"<<"\t\t$300"<<"\t\t$150\n";
outFile<<"Consultation Fee"<<"\t$50"<<"\t\t$40"<<"\t\t$25\n";
outFile<<"Total\t\t"<<"\t$780"<<"\t\t$490"<<"\t\t$250\n";
outFile<<setfill('*')<<setw(66)<<"\n\n";
outFile<<"You have choosed Ward "<<choice<<endl;
outFile<<"This ward will cost you $"<<price<<endl<<endl<<endl;
outFile<<"You had stayed in this hospital for "<<day<<" days."<<endl;
outFile<<setfill('*')<<setw(80)<<"\n\t\t\tOther Fees"<<endl;
outFile<<setfill('*')<<setw(67)<<"*\n";
outFile<<"Type 1:Back surgery\t$7800\nType 2:Ear surgery\t$4900\nType 3:Plastic surgery\t$5000\nType 4:Nose surgery\t$3500\nType 5:Leg surgery\t$6000\n";
outFile<<setfill('*')<<setw(67)<<"\n";
outFile<<"You have choosed surgery type "<<surgery<<endl;
outFile<<"This will cost you another $"<<others<<endl<<endl<<endl;
outFile<<setfill('~')<<setw(67)<<"\n";
outFile<<"Type 1:A\t$1000\nType 2:B\t$2500\nType 3:C\t$1500\nType 4:D\t$1700\nType 5:E\t$600\n";
outFile<<"You have choosed surgery type "<<surgery<<endl;
outFile<<"This will cost you another $"<<others<<endl<<endl<<endl;
outFile<<setfill('~')<<setw(67)<<"\n\n\n";
outFile<<"The total payment is $"<<Total;
outFile.close();
}
Because the second function might just overwrite the first.
Note: There's no error while building or compiling, but the output only shows the second function and totally ignoring the first.
May i ask what's the difference between ofstream and fstream? Or are they the same?
I can't believe the school took out the ios::ate flag from the chapter, it's going to be so useful and efficient since we are dealing with classes. tsk.
void Patient::Invoice0(void)
{
fstream outFile;
outFile.open("Patient Fee.txt");
outFile<<"Seng Tock Tan Hospital"<<endl;
outFile<<"Name : "<<name<<endl<<"NRIC : "<<NRIC<<endl<<"Phone Number : "<<phoneNumber<<endl<<endl;
outFile.close();
}
void Fee::Invoice(void)
{
fstream outFile;
outFile.open("Patient Fee.txt", fstream::in|fstream::app);
outFile<<endl<<endl;
outFile<<setfill('*')<<setw(80)<<"\n\t\t\tPatient' Fee schedule"<<endl;
outFile<<setfill('*')<<setw(66)<<"*\n";
outFile<<"\t\t\tCLASS OF WARD ACCOMONDATION\n";
outFile<<setfill('*')<<setw(66)<<"\n";
outFile<<"\t\t\t"<<"A\t\t"<<"B\t\t"<<"C\t\t\n";
outFile<<"Acute Ward\t"<<"\t$230"<<"\t\t$150"<<"\t\t$75\n";
outFile<<"Intensive care unit"<<"\t$500"<<"\t\t$300"<<"\t\t$150\n";
outFile<<"Consultation Fee"<<"\t$50"<<"\t\t$40"<<"\t\t$25\n";
outFile<<"Total\t\t"<<"\t$780"<<"\t\t$490"<<"\t\t$250\n";
outFile<<setfill('*')<<setw(66)<<"\n\n";
outFile<<"You have choosed Ward "<<choice<<endl;
outFile<<"This ward will cost you $"<<price<<endl<<endl<<endl;
outFile<<"You had stayed in this hospital for "<<day<<" days."<<endl;
outFile<<setfill('*')<<setw(80)<<"\n\t\t\tOther Fees"<<endl;
outFile<<setfill('*')<<setw(67)<<"*\n";
outFile<<"Type 1:Back surgery\t$7800\nType 2:Ear surgery\t$4900\nType 3:Plastic surgery\t$5000\nType 4:Nose surgery\t$3500\nType 5:Leg surgery\t$6000\n";
outFile<<setfill('*')<<setw(67)<<"\n";
outFile<<"You have choosed surgery type "<<surgery<<endl;
outFile<<"This will cost you another $"<<others<<endl<<endl<<endl;
outFile<<setfill('~')<<setw(67)<<"\n";
outFile<<"Type 1:A\t$1000\nType 2:B\t$2500\nType 3:C\t$1500\nType 4:D\t$1700\nType 5:E\t$600\n";
outFile<<"You have choosed medication type "<<medication<<endl;
outFile<<"This will cost you another $"<<med<<endl<<endl<<endl;
outFile<<setfill('~')<<setw(67)<<"\n\n\n";
outFile<<"The total payment is $"<<Total;
outFile.close();
}
There's a problem. My textfile will not overwrite the previous data with ios::trunc flag. It continues on and on, i want it to start on a fresh page everytime it resets. Any solutions?