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
|
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
class Patient {
private:
string name, ic, contact, dateAppoint;
unsigned age{};
bool gender{}; //false = female, true = male
public:
void setPatient(const string& name_, const string& ic_, const string& contact_, const string& dateAppoint_, unsigned age_, bool gender_) {
name = name_;
ic = ic_;
contact = contact_;
dateAppoint = dateAppoint_;
age = age_;
gender = gender_;
}
void display() const {
cout << name << "\t"
<< ic << "\t\t"
<< contact << "\t\t"
<< dateAppoint << "\t"
<< age << "\t";
cout << (gender ? "Male" : "Female") << "\n";
}
string getName() const { return name; }
string getIc() const { return ic; }
string getContact() const { return contact; }
};
unsigned sortMenu() {
unsigned choice{};
cout << "<<< Sorting Process >>>\n[1] By name\n[2] By IC number\n[3] By contact number\n";
cout << "\nOption: ";
cin >> choice;
return choice;
}
int main() {
const unsigned pnum{ 2 };
Patient pArray[50]{};
//set two existing patient
pArray[0].setPatient("Joyce", "021203-01-1888", "017-5546992", "25-01-2022", 19, 0);
pArray[1].setPatient("Ahmad", "700222-01-2523", "012-3456789", "07-01-2022", 51, 1);
for (unsigned choice2{}; choice2 != 3; ) {
cout << "============= ADMIN MENU =============\n"
<< "\t1. DISPLAY PATIENTS' LIST \n\t2. SORT PATIENTS\n\t3. EXIT\n"
<< "CHOICE: ";
cin >> choice2;
switch (choice2) {
case 1: //display patient list
{
cout << "\n============= PATIENT LIST =============\n"
<< "NAME" << setw(14) << "IC NO." << setw(23) << "CONTACT" << setw(26) << "DATE BOOKED"
<< setw(8) << "AGE" << setw(12) << "GENDER\n";
for (unsigned i = 0; i < pnum; ++i)
pArray[i].display();
cout << "\nNUMBER OF PATIENTS: " << pnum << "\n\n";
}
break;
case 2: //sort patient
{
const auto sortChoice{ sortMenu() };
switch (sortChoice) {
case 1:
cout << "\nSort patient list by name:\n";
sort(pArray, pArray + pnum, [](const auto& p1, const auto& p2) {return p1.getName() < p2.getName(); });
break;
case 2:
cout << "\nSort patient list by IC number:\n";
sort(pArray, pArray + pnum, [](const auto& p1, const auto& p2) {return p1.getIc() < p2.getIc(); });
break;
case 3:
cout << "\nSort patient list by contact number:\n";
sort(pArray, pArray + pnum, [](const auto& p1, const auto& p2) {return p1.getContact() < p2.getContact(); });
break;
default:
cout << "Invalid choice!\n";
break;
}
}
break;
case 3: //exit system
break;
default:
cout << "Invalid choice!\n";
break;
}
}
}
|