Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. //class StringArray : public string {
  7. class StringArray {
  8.         vector<string> strings;
  9. public:
  10.         void SortAlphabetically();
  11.         void PrintArray();
  12.         void PushString(string str);
  13. };
  14.  
  15. void StringArray::PushString(const string& r_str) {
  16.         strings.push_back(r_str);
  17. }
  18.  
  19. void StringArray::PrintArray() {
  20.         for(int i=0; i < strings.size(); i++)
  21.                 cout << strings[i] << endl;
  22. }
  23.  
  24. void StringArray::SortAlphabetically() {
  25.         sort(strings.begin(), strings.end());
  26. }
  27.  
  28. int main(void) {
  29.         StringArray sa;
  30.  
  31.         sa.PushString("hello");
  32.         sa.PushString("goodbye");
  33.         sa.PushString("artic");
  34.         sa.PushString("frostic");
  35.         sa.PushString("foo");
  36.         sa.PushString("moo");
  37.         sa.PushString("devil");
  38.  
  39.         sa.PrintArray();
  40.         sa.SortAlphabetically();
  41.         cout << "========" << endl;
  42.         sa.PrintArray();
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement