Guest User

g

a guest
Aug 6th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. class Contact {
  6.     private:
  7.         long int number;
  8.         unsigned int areaCode;
  9.         std::string firstName, lastName, fullName;
  10.     public:
  11.         Contact(const long int, const int, const std::string, const std::string);
  12.         friend std::ostream& operator << (std::ostream &os, const Contact c1);
  13.         std::string getLast  (void) const { return lastName;     }
  14.         std::string getFirst (void) const { return firstName;    }
  15.         char        getLastC (void) const { return lastName[0];  }
  16.         char        getFirstC(void) const { return firstName[0]; }
  17. };
  18.  
  19. Contact::Contact(const long int n, const int aC, const std::string fN, const std::string lN)
  20.     : number(n), areaCode(aC), firstName(fN), lastName(lN), fullName(firstName+' '+lastName) { }
  21.  
  22. std::ostream& operator << (std::ostream &os, const Contact c1) {
  23.     return (os << c1.fullName << ": (" << c1.areaCode << ")" << c1.number);
  24. }
  25.  
  26. void organizeList(std::vector<Contact> &);
  27. void printList(std::vector<Contact>);
  28.  
  29. int main(void) {
  30.     std::vector<Contact> vContacts;
  31.     Contact c1(9365421, 479, "Nick", "Ashley");
  32.     Contact c2(1010778, 800, "James", "Pac");
  33.     Contact c3(8324561, 671, "Jordan", "Berry");
  34.     vContacts.push_back(c1);
  35.     vContacts.push_back(c2);
  36.     vContacts.push_back(c3);
  37.     organizeList(vContacts);
  38.     printList(vContacts);
  39.     return 0;
  40. }
  41.  
  42. void organizeList(std::vector<Contact> &c1) {
  43.     std::vector<Contact>::iterator iter = c1.begin();
  44.     std::vector<Contact> temp;
  45.     for(char a = 'A'; a <= 'Z'; ++a) {
  46.         for(iter; iter != c1.end(); ++iter) {
  47.             if((*iter).getLastC() == a)
  48.                 temp.push_back(*iter);
  49.         }
  50.     }
  51.     while(!c1.empty())
  52.         c1.pop_back();
  53.     for(iter = temp.begin(); iter != temp.end(); ++iter)
  54.         c1.push_back(*iter);
  55. }
  56.  
  57. void printList(std::vector<Contact> c1) {
  58.     std::vector<Contact>::iterator iter = c1.begin();
  59.     for(iter; iter != c1.end(); ++iter)
  60.         std::cout << (*iter) << std::endl;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment