Advertisement
silentkiler029

Question-06-c

Nov 2nd, 2021
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. // ---( c )---
  2. class addressBookType : extPersonType {
  3. private:
  4.     std::vector < extPersonType > v;
  5.  
  6. public:
  7.     void sortByLastName() {
  8.         for( int i = 0; i < v.size(); i++ ) {
  9.             for( int j = i + 1; j < v.size(); j++ ) {
  10.                 if( v[i].getLastName() > v[j].getLastName ) {
  11.                     extPersonType temp;
  12.                     temp = v[i];
  13.                     v[i] = v[j];
  14.                     v[j] = temp;
  15.                 }
  16.             }
  17.         }
  18.     }
  19.     bool searchByLastName( string s ) {
  20.         for( int i = 0; i < v.size(); i++ ) {
  21.             if( v[i].getLastName() == s ) {
  22.                 return true;
  23.             }
  24.         }
  25.         return false;
  26.     }
  27.     void printInfo( int index ) {
  28.         if( v[index].getStreet() != "" ) {
  29.             std::cout << "Address: " << getStreet() << ", " << getCity() << ", " << getState() << ", " << getZIP << endl;
  30.         }
  31.         if( v[index].getPhoneNumber() != "" ) {
  32.             std::cout << "Phone Number: " << v[index].getPhoneNumber();
  33.         }
  34.         if( v[index].getDateOfBirth() != NULL ) {
  35.             std::cout << "Date of Birth: " << v[index].getDateOfBirth() << endl;
  36.         }
  37.     }
  38.     void printBetween( string lastName1, string lastName2 ) {
  39.         for( int i = 0; i < v.size(); i++ ) {
  40.             string s = v[i].getLastName();
  41.             if( s >= lastName1 && s <= lastName2 ) {
  42.                 std::cout << v[i].getFirstName << " " << s << endl;
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement