1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct Patient
{
int id;
string name;
int age;
char sex;
//...
Patient(int id_,const string & name_,int age_,char sex_):
id(id_),name(name_),age(age_),sex(sex_){}
struct HasId
{
int id;
HasId(int id_):id(id_){}
bool operator()(const Patient & p)
{
return p.id==id;
}
};
};
void show_menu()
{
cout << "(1) Add Patient\n";
cout << "(2) View Patients\n";
cout << "(3) Remove Patient\n";
cout << "(4) Quit\n" << endl;
}
void add_patient(vector<Patient> & clinic);
void view_patients(vector<Patient> & clinic);
void remove_patient(vector<Patient> & clinic);
int main()
{
int choice;
vector<Patient> clinic;
while(true)
{
cout << "What do you want to do?\n";
show_menu();
cin>>choice;
if (choice==4) break;
switch(choice)
{
case 1:
add_patient(clinic);
break;
case 2:
view_patients(clinic);
break;
case 3:
remove_patient(clinic);
}
}
cout << "\nhit enter to quit";
cin.get();
return 0;
}
void add_patient(vector<Patient> & clinic)
{
int id;
string name;
int age;
char sex;
cout<<"id->";
cin>>id;
cin.get();
cout<<"name->";
getline(cin,name);
cout<<"age->";
cin>>age;
cin.get();
cout<<"sex(M/F)->";
cin>>sex;
clinic.push_back(Patient(id,name,age,sex));
}
void view_patients(vector<Patient> & clinic)
{
for (int i=0; i<clinic.size(); i++)
{
cout << "=-=-=-=-=-=-=-=-=-=-=-=-=" << endl;
cout << clinic[i].id << endl;
cout << clinic[i].name << endl;
cout << clinic[i].age << endl;
cout << clinic[i].sex << endl;
}
cout << "=-=-=-=-=-=-=-=-=-=-=-=-=" << endl;
}
void remove_patient(vector<Patient> & clinic)
{
int id;
cout << "enter id: ";
cin>>id;
vector<Patient>::iterator it;
it=find_if(clinic.begin(),clinic.end(),Patient::HasId(id));
if (it!=clinic.end())
clinic.erase(it);
}
|