// person.cc #include #include "person.hh" void Read(Person& t) { cout << endl; cout << "Person: " << endl; cout << " name : "; cin >> t.name; cout << " Geburtstag tt mm jjjj : "; cin >> t.geburtstag.tag >> t.geburtstag.monat >> t.geburtstag.jahr; cout << " Gehalt : "; cin >> t.gehalt; return; } void Print(const Person& t) { cout << endl; cout << "Person: " << endl; cout << " name : "; cout << t.name << endl; cout << " Geburtstag tt mm jjjj : "; cout << t.geburtstag.tag << "." << t.geburtstag.monat << "." << t.geburtstag.jahr << endl; cout << " Gehalt : "; cout << t.gehalt << " Euro" << endl; cout << endl; return; } int AgeComp(const Person& a, const Person& b) { int isyoung; Datum da = a.geburtstag, db = b.geburtstag; // temp. Var. erleichtern Lesbarkeit if ( da.jahr != db.jahr ) { isyoung = ( da.jahr < db.jahr ) ? OLDER : YOUNGER; } else if ( da.monat != db.monat ) // Gleiches Jahr ==> weiter mit Monat { isyoung = ( da.monat < db.monat ) ? OLDER : YOUNGER; } else if ( da.tag != db.tag ) // Gleicher Monat ==> weiter mit Tag { isyoung = ( da.tag < db.tag ) ? OLDER : YOUNGER; } else // bleibt bloss noch gleicher Geburtstag uebrig { isyoung = EQUAL_AGE; } return isyoung; } void Sort(const int n, const Person a[], int idx[]) { int i,j,jmin; bool *ba; // temp. array whether a[j] was already sorted // First we allocate and initialze the temp. array ba = new bool [n]; for (i=0; i a[j] not yet sorted { // find the first unsorted element if (jmin == -1) { jmin = j; } // else compare with the actual youngest person // Both tests can be combined if the compiler // exits from an OR-statement in case that the first component is true. // The compilers should behave like that. // Even all three tests could be combined in one single test: // ( (!ba[j]) && ( jmin==-1 || AgeComp(a[j], a[jmin]) == YOUNGER) ) // [see the file person2.cc] else if (AgeComp(a[j], a[jmin]) == YOUNGER ) { jmin = j; } } } idx[i] = jmin; // store index of remaining youngest person ba[jmin] = true; // mark a[jmin] as sorted } // Check whether all persons were sorted (only for debuggung purposes) bool bb = true; for (j=0; j