Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 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(string str) {
  16.         strings.push_back(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.         for(int i=0; i < strings.size(); i++)
  27.                 cout << strings[i] << endl;
  28. }
  29.  
  30. int main(void) {
  31.         StringArray sa;
  32.  
  33.         sa.PushString("hello");
  34.         sa.PushString("goodbye");
  35.         sa.PushString("artic");
  36.         sa.PushString("frostic");
  37.         sa.PushString("foo");
  38.         sa.PushString("moo");
  39.         sa.PushString("devil");
  40.  
  41.         sa.PrintArray();
  42.         sa.SortAlphabetically();
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement