- 分享
- 0
- 人气
- 0
- 主题
- 6
- 帖子
- 319
- UID
- 256678
- 积分
- 129
- 阅读权限
- 13
- 注册时间
- 2009-8-21
- 最后登录
- 2013-12-16
- 在线时间
- 4090 小时
|
内容 :
我是个初学者。。
有个难题想请大家帮帮忙。。
I need to create a programme with searching function.
这是一个病人资料存库。
我把病人的资料input了这个程式会把资料save进.txt file里。一个病人一个.txt file.
现在我必须
"create a searching function for viewing or retrieving patient's info. suggestion list should be printed out if the keyword searched has more than 1 compatible."
这是我的原本的sourcecode:
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- class Hospital
- { public:
-
- private:
-
- };
- class Patient:public Hospital
- {
- private:
- string name, address, patient_contact_number, names_of_relatives_for_emergency;
- string disease, medication, consultation_history, doctor;
- string referal_letter, guarantee_letter, medic_card, insurance_cover,unknown, a;
- public:
- void personal_information();
- void health_information();
-
- void other_information();
-
- void print_out();
-
- void out_put ();
- };
- main()
- {
- Patient p1;
- int num;
-
- R:
- system("cls");
- cout<<"1. Add new patient's information.\n"
- <<"2. View patient's information.\n"
- <<"3. Exit.\n\n"
- <<"Number :";
- cin>>num;
-
- system("cls");
-
- if (num == 1)
- {
- p1.personal_information();
- p1.health_information();
- p1.other_information();
- p1.out_put();
- goto R;
- system("cls");
- }
- else if (num == 2)
- {
- p1.print_out();
- system("PAUSE");
- system("cls");
- goto R;
- }
- else if(num == 3)
- {
- exit(1);
- }
- else
- {
- cout<<"Invalid Input!"<<endl;
- system("pause");
- system("cls");
- exit (1);
- }
-
- system("cls");
- system("PAUSE");
- system("cls");
-
-
- return 0;}
- void Patient::personal_information()
- {
- cout<<"Please insert your personal information"<<endl;
- cout<<"_______________________________________"<<endl;
-
- cout<<endl;
-
- getline(cin,unknown);
- cout<<"Name : ";
- getline(cin,name);
-
- cout<<"Address : ";
- getline(cin,address);
-
- cout<<"Contact number : ";
- getline(cin,patient_contact_number);
-
- cout<<"Names of relatives for emergency: ";
- getline(cin,names_of_relatives_for_emergency);
-
- cout<<endl;
- }
- void Patient::health_information()
- {
- cout<<"Please insert your health information"<<endl;
- cout<<"_____________________________________"<<endl;
- cout<<endl;
-
- cout<<"Disease : ";
- getline(cin,disease);
-
- cout<<"Medication: ";
- getline(cin,medication);
-
- cout<<"Consultation History: ";
- getline(cin,consultation_history);
-
- cout<<"Doctor-in-charge: ";
- getline(cin,doctor);
-
-
- cout<<endl;
- }
- void Patient::other_information()
- {
- cout<<"Please insert your other information"<<endl;
- cout<<"____________________________________"<<endl;
-
- cout<<endl;
-
- cout<<"Referal letter: ";
- getline(cin,referal_letter);
-
- cout<<"Guarantee letter: ";
- getline(cin,guarantee_letter);
-
- cout<<"Medic Card: ";
- getline(cin,medic_card);
-
- cout<<"Insurance cover: ";
- getline(cin,insurance_cover);
-
-
- cout<<endl;
- }
- void Patient::print_out()
- {
-
- cout<<"You want to view which patient's info?(enter the name)"<<endl;
- cin>>a;
- string FILENAME=a+"'s details.txt";
-
-
- ifstream readingFile;
- readingFile.open(FILENAME.c_str());
-
- if (readingFile.fail())
- {
- cout<<FILENAME<<" opening failed.\a\a\a"<<endl;
- system("pause");
- exit (1);
- }
-
- else {readingFile>>name>>address>>patient_contact_number>>names_of_relatives_for_emergency>>disease>>medication>>consultation_history>>doctor>>referal_letter>>guarantee_letter>>medic_card>>insurance_cover;
-
-
-
- cout<<"\nPersonal Information"<<endl;
- cout<<"--------------------"<<endl;
- cout<<"Name : "<<name<<endl;
- cout<<"Address : "<<address<<endl;
- cout<<"Contact Number : "<<patient_contact_number<<endl;
- cout<<"Name of relatives : "<<names_of_relatives_for_emergency<<endl;;
-
- cout<<endl;
-
- cout<<"Health Information"<<endl;
- cout<<"------------------"<<endl;
- cout<<"Disease : "<<disease<<endl;
- cout<<"Meidcation : "<<medication<<endl;
- cout<<"Consultation history : "<<consultation_history<<endl;
- cout<<"Doctor in Charge : "<<doctor<<endl;
-
- cout<<endl;
-
- //print out other information.
- cout<<"Other Information"<<endl;
- cout<<"------------------"<<endl;
- cout<<"Referal letter : "<<referal_letter<<endl;
- cout<<"Guarantee letter : "<<guarantee_letter<<endl;
- cout<<"Medic card : "<<medic_card<<endl;
- cout<<"Insurance cover : "<<insurance_cover<<endl;
-
- cout<<endl;
- }
- readingFile.close();
- }
-
- void Patient::out_put()
- { string FILENAME=name+"'s details.txt"; ofstream writingFile;
- writingFile.open(FILENAME.c_str());
-
- if(!writingFile.good())
- {cout<<"File could not be opened"<<endl;}
-
- else
- {writingFile<<name<<endl<<address<<endl<<patient_contact_number<<endl<<names_of_relatives_for_emergency<<
- endl<<disease<<endl<<medication<<endl<<consultation_history<<endl<<doctor<<
- referal_letter<<endl<<guarantee_letter<<endl<<medic_card<<endl<<insurance_cover;}
- writingFile.close();
- }
复制代码
请多多指教。。。
请帮帮我。。。
(我的教授喜欢给我们learn in advance, 我们的功课都是还没学过的题目em0027 )
[ 本帖最后由 Yinying422 于 2010-2-3 01:41 AM 编辑 ] |
|