Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- class Contact {
- private:
- long int number;
- unsigned int areaCode;
- std::string firstName, lastName, fullName;
- public:
- Contact(const long int, const int, const std::string, const std::string);
- friend std::ostream& operator << (std::ostream &os, const Contact c1);
- std::string getLast (void) const { return lastName; }
- std::string getFirst (void) const { return firstName; }
- char getLastC (void) const { return lastName[0]; }
- char getFirstC(void) const { return firstName[0]; }
- };
- Contact::Contact(const long int n, const int aC, const std::string fN, const std::string lN)
- : number(n), areaCode(aC), firstName(fN), lastName(lN), fullName(firstName+' '+lastName) { }
- std::ostream& operator << (std::ostream &os, const Contact c1) {
- return (os << c1.fullName << ": (" << c1.areaCode << ")" << c1.number);
- }
- void organizeList(std::vector<Contact> &);
- void printList(std::vector<Contact>);
- int main(void) {
- std::vector<Contact> vContacts;
- Contact c1(9365421, 479, "Nick", "Ashley");
- Contact c2(1010778, 800, "James", "Pac");
- Contact c3(8324561, 671, "Jordan", "Berry");
- vContacts.push_back(c1);
- vContacts.push_back(c2);
- vContacts.push_back(c3);
- organizeList(vContacts);
- printList(vContacts);
- return 0;
- }
- void organizeList(std::vector<Contact> &c1) {
- std::vector<Contact>::iterator iter = c1.begin();
- std::vector<Contact> temp;
- for(char a = 'A'; a <= 'Z'; ++a) {
- for(iter; iter != c1.end(); ++iter) {
- if((*iter).getLastC() == a)
- temp.push_back(*iter);
- }
- }
- while(!c1.empty())
- c1.pop_back();
- for(iter = temp.begin(); iter != temp.end(); ++iter)
- c1.push_back(*iter);
- }
- void printList(std::vector<Contact> c1) {
- std::vector<Contact>::iterator iter = c1.begin();
- for(iter; iter != c1.end(); ++iter)
- std::cout << (*iter) << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment