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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
| #include <iostream>
#include <sstream>
std::string my_itoa(int a) {
std::string ss = "";
int x;
char i;
while(a) {
x = (a % 10);
a /= 10;
i = ('0' + x);
ss = (i + ss);
}
return ss;
}
struct Blood_Group {
public:
typedef enum s_group {
group_O = 0,
group_A,
group_B,
group_AB
} t_group;
typedef enum s_rhesus {
rhesus_plus = 0,
rhesus_minus
} t_rhesus;
public:
Blood_Group(t_group input_group, t_rhesus input_rhesus) : group(input_group),
rhesus(input_rhesus) {}
public:
friend std::ostream& operator<<(std::ostream&, const Blood_Group&);
private:
t_group group;
t_rhesus rhesus;
};
class Date {
public:
Date() : is_valid(false) {}
public:
friend std::ostream& operator<<(std::ostream&, const Date&);
bool set_date(unsigned int input_year, unsigned char input_month, unsigned char input_day) {
bool input_is_valid;
// Basic valid : not correct
input_is_valid = (((input_month >= 1) && (input_month <= 12)) && ((input_day >= 1) && (input_day <= 31)));
if (input_is_valid) {
year = input_year;
month = input_month;
day = input_day;
is_valid = true;
}
return input_is_valid;
}
private:
unsigned int year;
unsigned char month;
unsigned char day;
bool is_valid;
};
class Patient {
public:
Patient(std::string input_first_name,
std::string input_last_name,
Blood_Group input_blood_group) :
first_name(input_first_name), last_name(input_last_name),
blood_group(input_blood_group) {}
public:
// XXX : no final endl
friend std::ostream& operator<<(std::ostream&, const Patient&);
bool set_birth_date(unsigned int input_year, unsigned char input_month, unsigned char input_day) {
return birth_date.set_date(input_year, input_month, input_day);
}
bool set_phone_number(const std::string input_phone_number) {
bool result;
// if ( phone_number_is_valid(input_phone_number) ) {
phone_number = input_phone_number;
result = true;
// } else {
// result = false;
// }
return result;
}
bool set_social_number(const std::string input_social_number) {
bool result;
// if ( social_number_is_valid(input_social_number) ) {
social_number = input_social_number;
result = true;
// } else {
// result = false;
// }
return result;
}
private:
std::string first_name;
std::string last_name;
Date birth_date;
std::string phone_number;
std::string social_number;
Blood_Group blood_group;
};
std::ostream& operator<<(std::ostream& os, const Blood_Group& blood_group) {
switch(blood_group.group) {
case Blood_Group::group_O: os << "O"; break;
case Blood_Group::group_A: os << "A"; break;
case Blood_Group::group_B: os << "B"; break;
case Blood_Group::group_AB: os << "AB"; break;
}
switch(blood_group.rhesus) {
case Blood_Group::rhesus_plus: os << "+"; break;
case Blood_Group::rhesus_minus: os << "-"; break;
}
return os;
}
std::ostream& operator<<(std::ostream& os, const Date& date) {
if (date.is_valid) {
os << my_itoa(date.day) << "/" << my_itoa(date.month) << "/" << my_itoa(date.year);
} else {
os << "[invalid date]";
}
return os;
}
// XXX : no final endl
std::ostream& operator<<(std::ostream& os, const Patient& p) {
os << p.first_name << " " << p.last_name << std::endl
<< "Birth Date: " << p.birth_date << std::endl
<< "Phone Number: " << p.phone_number << std::endl
<< "Social Number: " << p.social_number << std::endl
<< "Blood Group: " << p.blood_group;
return os;
}
int main(/*int argc, char* argv[]*/)
{
Patient p("Salvator", "Mundi", Blood_Group(Blood_Group::group_AB, Blood_Group::rhesus_minus));
p.set_phone_number("0987654321");
p.set_social_number("177097645103210");
p.set_birth_date(1970, 12, 1);
std::cout << p << std::endl;
return 0;
} |
Partager