Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 1856|回复: 1
打印 上一主题 下一主题

[求助] 搜索Searching Function in C++

[复制链接]

6

主题

0

好友

129

积分

高级会员

Rank: 3Rank: 3Rank: 3

跳转到指定楼层
1#
发表于 2010-2-3 01:33 AM |只看该作者 |倒序浏览
内容 :  
我是个初学者。。
有个难题想请大家帮帮忙。。

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:

  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>

  4. using namespace std;

  5. class Hospital
  6. {     public:
  7.             
  8.       private:
  9.               
  10.          };
  11. class Patient:public Hospital

  12. {
  13. private:
  14.        string name, address, patient_contact_number, names_of_relatives_for_emergency;
  15.        string disease, medication, consultation_history, doctor;
  16.        string referal_letter, guarantee_letter, medic_card, insurance_cover,unknown, a;

  17. public:         
  18.        void personal_information();

  19.        void health_information();
  20.       
  21.        void other_information();
  22.       
  23.        void print_out();
  24.       
  25.        void out_put ();
  26. };

  27. main()
  28. {
  29.     Patient p1;
  30.     int num;
  31.    
  32.     R:
  33.     system("cls");
  34.     cout<<"1. Add new patient's information.\n"
  35.         <<"2. View patient's information.\n"
  36.         <<"3. Exit.\n\n"
  37.         <<"Number :";
  38.     cin>>num;
  39.    
  40.     system("cls");
  41.    
  42.     if (num == 1)
  43.     {
  44.             p1.personal_information();
  45.             p1.health_information();
  46.             p1.other_information();
  47.             p1.out_put();
  48.             goto R;
  49.             system("cls");
  50.     }
  51.     else if (num == 2)
  52.     {
  53.          p1.print_out();
  54.          system("PAUSE");
  55.          system("cls");
  56.          goto R;
  57.     }
  58.     else if(num == 3)
  59.     {
  60.          exit(1);
  61.     }
  62.     else
  63.     {
  64.         cout<<"Invalid Input!"<<endl;
  65.         system("pause");
  66.         system("cls");
  67.         exit (1);
  68.     }
  69.          
  70.     system("cls");

  71.    system("PAUSE");
  72.    system("cls");
  73.    
  74.    
  75.     return 0;}


  76. void Patient::personal_information()
  77. {
  78.      cout<<"Please insert your personal information"<<endl;
  79.      cout<<"_______________________________________"<<endl;
  80.      
  81.      cout<<endl;
  82.      
  83.      getline(cin,unknown);
  84.      cout<<"Name : ";
  85.      getline(cin,name);
  86.      
  87.      cout<<"Address : ";
  88.      getline(cin,address);
  89.      
  90.      cout<<"Contact number : ";
  91.      getline(cin,patient_contact_number);
  92.      
  93.      cout<<"Names of relatives for emergency: ";
  94.      getline(cin,names_of_relatives_for_emergency);
  95.      
  96.      cout<<endl;
  97. }

  98. void Patient::health_information()
  99. {
  100.      cout<<"Please insert your health information"<<endl;
  101.      cout<<"_____________________________________"<<endl;
  102.      cout<<endl;
  103.      
  104.      cout<<"Disease : ";
  105.      getline(cin,disease);
  106.      
  107.      cout<<"Medication: ";
  108.      getline(cin,medication);
  109.      
  110.      cout<<"Consultation History: ";
  111.      getline(cin,consultation_history);
  112.      
  113.      cout<<"Doctor-in-charge: ";
  114.      getline(cin,doctor);
  115.      
  116.      
  117.      cout<<endl;
  118. }

  119. void Patient::other_information()
  120. {
  121.      cout<<"Please insert your other information"<<endl;
  122.      cout<<"____________________________________"<<endl;
  123.      
  124.      cout<<endl;
  125.      
  126.      cout<<"Referal letter: ";
  127.      getline(cin,referal_letter);
  128.      
  129.      cout<<"Guarantee letter: ";
  130.      getline(cin,guarantee_letter);
  131.      
  132.      cout<<"Medic Card: ";
  133.      getline(cin,medic_card);
  134.      
  135.      cout<<"Insurance cover: ";
  136.      getline(cin,insurance_cover);
  137.      
  138.      
  139.      cout<<endl;
  140. }

  141. void Patient::print_out()
  142. {
  143.      
  144.       cout<<"You want to view which patient's info?(enter the name)"<<endl;
  145.     cin>>a;
  146.     string FILENAME=a+"'s details.txt";
  147.    
  148.    
  149.      ifstream readingFile;
  150.      readingFile.open(FILENAME.c_str());
  151.    
  152.      if (readingFile.fail())
  153.      {
  154.         cout<<FILENAME<<" opening failed.\a\a\a"<<endl;
  155.         system("pause");
  156.         exit (1);
  157.      }
  158.      
  159.      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;
  160.      
  161.    
  162.    
  163.      cout<<"\nPersonal Information"<<endl;
  164.      cout<<"--------------------"<<endl;
  165.      cout<<"Name                : "<<name<<endl;
  166.      cout<<"Address             : "<<address<<endl;
  167.      cout<<"Contact Number      : "<<patient_contact_number<<endl;
  168.      cout<<"Name of relatives   : "<<names_of_relatives_for_emergency<<endl;;
  169.      
  170.      cout<<endl;
  171.      
  172.      cout<<"Health Information"<<endl;
  173.      cout<<"------------------"<<endl;
  174.      cout<<"Disease               : "<<disease<<endl;
  175.      cout<<"Meidcation            : "<<medication<<endl;
  176.      cout<<"Consultation history  : "<<consultation_history<<endl;
  177.      cout<<"Doctor in Charge      : "<<doctor<<endl;
  178.      
  179.      cout<<endl;
  180.      
  181.      //print out other information.
  182.      cout<<"Other Information"<<endl;
  183.      cout<<"------------------"<<endl;
  184.      cout<<"Referal letter     : "<<referal_letter<<endl;
  185.      cout<<"Guarantee letter   : "<<guarantee_letter<<endl;
  186.      cout<<"Medic card         : "<<medic_card<<endl;
  187.      cout<<"Insurance cover    : "<<insurance_cover<<endl;
  188.      
  189.      cout<<endl;
  190.      }
  191.      readingFile.close();
  192. }
  193.      
  194. void Patient::out_put()

  195. { string FILENAME=name+"'s details.txt"; ofstream writingFile;
  196.   writingFile.open(FILENAME.c_str());
  197.    
  198.     if(!writingFile.good())  
  199.     {cout<<"File could not be opened"<<endl;}
  200.    
  201.     else
  202.     {writingFile<<name<<endl<<address<<endl<<patient_contact_number<<endl<<names_of_relatives_for_emergency<<
  203.     endl<<disease<<endl<<medication<<endl<<consultation_history<<endl<<doctor<<
  204.     referal_letter<<endl<<guarantee_letter<<endl<<medic_card<<endl<<insurance_cover;}
  205.   writingFile.close();

  206. }
复制代码


请多多指教。。。
请帮帮我。。。
(我的教授喜欢给我们learn in advance, 我们的功课都是还没学过的题目em0027 )

[ 本帖最后由 Yinying422 于 2010-2-3 01:41 AM 编辑 ]




收藏收藏0

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

2#
发表于 2010-2-3 12:18 PM |只看该作者
原帖由 Yinying422 于 2010-2-3 01:33 AM 发表
内容 :  
我是个初学者。。
有个难题想请大家帮帮忙。。

I need to create a programme with searching function.
这是一个病人资料存库。
我把病人的资料input了这个程式会把资料save进.txt file里。一 ...



如果都是 txt 檔案的話, 就必須逐一搜索比對, 個人建議使用資料庫比較方便快捷


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-10-25 10:30 AM , Processed in 0.121603 second(s), 26 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部