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 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
|
#include <iostream>
#include <exception>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
template<class T>
class collection
{
private:
T* _elements;
int * _max;
int * _currentElements;
public:
collection()
{
_max = new int(10);
_currentElements = new int(0);
_elements = new T[*_max];
}
collection(const collection<T> &obj)
{
_max = new int(*(obj._max));
_currentElements = new int(*(obj.currentElements));
_elements = new T[*_max];
for (int i = 0; i < *_currentElements; i++)
_elements[i] = obj._elements[i];
}
int GetCurrentElements() const
{
return *_currentElements;
}
int GetMax() const
{
return *_max;
}
~collection()
{
delete _elements;
delete _max;
delete _currentElements;
}
void AddElement(const T obj)
{
if(*_currentElements == *_max)
throw exception ("collection is full!");
else
{
bool exist = false;
for (int i = 0; i < *_currentElements; i++)
{
if (_elements[i] == obj._elements[i])
{
exist = true;
break;
}
}
if (!exist)
{
_elements[*_currentElements] = T (obj);
(*_currentElements)++;
}
}
}
bool RemoveElement(int location)
{
if((*_currentElements)==0)
{
throw exception ("collection is empty!");
return false;
}
if(location<=0 || lokacija>*_currentElements)
{
throw exception ("Location is outside the rank!");
return false;
}
if( location != *_currentElements)
{
for (int i=location-1; i<GetCurrentElements()-1; i++)
{
_elements[i] = _elements[i+1];
}
}
_elements[*_currentElements]= NULL;
(*_currentElements)--;
}
bool operator==(collection <T> &org)
{
for (int i=0; i< *_currentElements; i++)
{
if((*(_elements[i]))!=(*(org._elements[i]))) return false;
return true;
}
}
T& operator [](int index)
{
return (*_elements[index]);
}
friend ostream& operator<<(ostream &out, const collection <T> &obj)
{
out<<"current Elements: "<<*(obj._currentElements)<<endl;
out<<"Max elements: "<<*(obj._max)<<endl;
for (int i=0; i<*_currentElements;i++)
{
out<<*_elements[i];
}
return out;
}
};
class examination
{
string _diagnosis;
float _payment;
public:
examination()
{
_diagnosis = "no name";
_payment = 0;
}
examination(string diagnosis, float payment)
{
_diagnosis = diagnosis;
_payment = payment;
}
~examination()
{
}
string GetDiagnosis()
{
return _diagnosis;
}
float GetPayment()
{
return _payment;
}
void SetDiagnosis(string d)
{
_diagnosis=d;
}
void SetPayment(float p)
{
_payment=p;
}
bool operator == (examination &p)
{
if (_diagnosis == p.GetDiagnosis() && _payment == p.GetPayment())
return true;
return false;
}
void Info()
{
cout<<"Diagnosis: "<<this->_diagnosis<<endl;
cout<<"Payment: "<<this->_payment;
}
};
class patient
{
protected:
const int _patientID;
char * _name;
collection<examination> _examinationOfThePatient;
public:
patient():_patientID(0)
{
this->_name = new char[strlen("N/A") + 1];
strcpy(this->_name, "N/A");
}
patient(const int patientID, char* name ) : _patientID(patientID)
{
this->_name=new char [strlen(name)+1];
strcpy(this->_name,name);
}
patient (const patient &obj) : _patientID(obj._patientID)
{
this->_name = new char[strlen(obj._name)+1];
strcpy(this->_name, obj._name);
this->_examinationOfThePatient=obj._examinationOfThePatient;
}
~patient()
{
delete [] this->_name;
this->_name = NULL;
}
int GetPatientID() const
{
return this->_patientID;
}
char* GetName()
{
return this->_name;
}
void SetName(char* name)
{
delete [] this->_name;
this->_name=new char[strlen(name)+1];
strcpy(this->_name,name);
}
examination operator[] (int location)
{
return _examinationOfThePatient[location];
}
int NumberOfExamination()
{
return _examinationOfThePatient.GetCurrentElements();
}
void AddExamination(examination diagnosis)
{
if (diagnosis.GetPayment() == 0)
throw exception("Please make your payment");
bool exist = false;
for (int i = 0; i < _examinationOfThePatient.GetCurrentElements(); i++)
{
examination tempExamination = _examinationOfThePatient[i];
if(tempExamination == diagnosis)
{
exist = true;
break;
}
}
if(!exist)
_examinationOfThePatient.AddElement(diagnosis);
}
bool RemoveExamination(int location)
{
bool remove = false;
try
{
this->_examinationOfThePatient.RemoveElement(location);
remove = true;
}
catch (exception &e)
{
remove = false;
}
return remove;
}
friend ostream& operator <<(ostream &out, const patient &obj)
{
out<<"patient ID: "<<obj._patientID<<endl;
out<<"Name of the patient: "<<obj._name<<endl;
return out;
}
};
class ForeignPatient : public patient
{
private:
char * _citizen;
public:
ForeignPatient():patient()
{
this->_citizen=new char[strlen("N/A")+1];
strcpy(this->_citizen, "N/A");
}
ForeignPatient(int pacID, char* n, char* cit):patient(pacID, n)
{
this->_citizen=new char[strlen(cit)+1];
strcpy(this->_citizen, cit);
}
~ForeignPatient()
{
delete [] this->_citizen;
this->_citizen=NULL;
}
char* GetCitizen() const { return this->_citizen; }
void SetCitizen(char *cit)
{
delete [] this->_citizen;
this->_citizen=new char[strlen(cit)+1];
strcpy(this->_citizen, cit);
}
string patientInfo()
{
stringstream myStream;
myStream<<"PatientID: "<< this->GetPatientID()<<endl<< " "<<"Name: "<< this->GetName()<< endl<< " "<<"Citizen: "<<this->_citizen;
return myStream.str();
}
};
vector<examination> operator()(patient& patient, float minPayment, float maxPayment)
{
vector<examination> examinations;
for (int i = 0; i < patient.NumberOfExamination(); i++)
{
if(patient[i].GetPayment() >= minPayment && patient[i].GetPayment() <= maxPayment)
examinations.push_back(patient[i]);
}
return examinations;
}
void main()
{
try
{
examination s1("pneumonia", 100);
examination s2("carcinoma", 200);
patient p1(222, "Man");
patient p2(333, "Lady");
p1.AddExamination(s1);
p2.AddExamination(s2);
p1.RemoveExamination(1);
}
catch (exception &e)
{
cout<<"Error: "<<e.what()<<endl;
}
}
|