Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- //class StringArray : public string {
- class StringArray {
- vector<string> strings;
- public:
- void SortAlphabetically();
- void PrintArray();
- void PushString(string str);
- };
- void StringArray::PushString(string str) {
- strings.push_back(str);
- }
- void StringArray::PrintArray() {
- for(int i=0; i < strings.size(); i++)
- cout << strings[i] << endl;
- }
- void StringArray::SortAlphabetically() {
- sort(strings.begin(), strings.end());
- for(int i=0; i < strings.size(); i++)
- cout << strings[i] << endl;
- }
- int main(void) {
- StringArray sa;
- sa.PushString("hello");
- sa.PushString("goodbye");
- sa.PushString("artic");
- sa.PushString("frostic");
- sa.PushString("foo");
- sa.PushString("moo");
- sa.PushString("devil");
- sa.PrintArray();
- sa.SortAlphabetically();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement