Expand|Select|Wrap|Line Numbers
- #include <iostream.h>
- #include <fstream.h>
- #include <string.h>
- class Patient
- {
- public:
- char name[15];
- char DOB[10];
- char sex[6];
- char residence[10];
- 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;
- 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";*/
- while (1){
- cout<<"_______________________"<<endl;
- 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<<"_______________________"<<endl;
- 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 << myPatient.record(number)<<endl<<myPatient.name<<endl<<myPatient.DOB<<endl<<myPatient.sex<<endl<<myPatient.residence<<endl
- <<myPatient.fee(cash)<<endl;
- mfile.close();
- }
- else {cout << "Unable to open file";}
- cout<<"Reading from file"<<endl;
- ifstream infile("patient.txt");
- if(infile.is_open())
- {
- infile >> number;
- cout << number << endl;
- infile >> myPatient.name;
- cout << name << endl;
- infile >> myPatient.DOB;
- cout << DOB << endl;
- infile >> myPatient.sex;
- cout << sex<<endl;
- infile >> myPatient.residence;
- cout << residence<<endl;
- infile.close();
- }
- else {
- cout<<"Unable to open file: "<<endl;}
- }
- return 0;
- }