30.01.2019 – Wiederholung: vector, class

#include <iostream>
#include <vector>

using namespace std;

class snowmanobject {

    // Klasse: Blaupause für konkretes Objekt, d.h. Instanz der Klasse
    // Intention von Klassen: Information Hiding und Kapselung

private:
    string tuedeluet;
    int kugeln;

public:

    // Konstruktor
    snowmanobject() {
        // Initialisierung
        this->tuedeluet = "Aloha";
    }

    // Inline-Funktion
    void setName(string newName) {
        this->tuedeluet = newName;
    }

    string getName() {
        return this->tuedeluet;
    }

    void setKugeln(int count) {
        this->kugeln = count;
    }

    int getKugeln() {
        return this->kugeln;
    }

    string farbe;
    bool moehre;
    string hut;
};

int main(int argc, char** argv) {

    cout << endl << "Anzahl Argumente: " << argc;
    cout << endl << "Argument 0: " << argv[0] << endl;

    // Eine Instanz der Klasse snowmanobject
    class snowmanobject schneeperson;

    if (argc > 1) {
        schneeperson.setName(argv[1]);
    } else {
        schneeperson.setName("Henry");
    }

    schneeperson.setKugeln(3);
    schneeperson.farbe = "Weiss";

    vector<snowmanobject> snowmans;

    snowmans.push_back(schneeperson);

    cout << snowmans[0].getName();

    vector<snowmanobject*> yetanothersnomanstorage;
    class snowmanobject *snowptr;

    for (int i = 0; i < 5; i++) {

        snowptr = new snowmanobject;
        snowptr->setKugeln(i);

        yetanothersnomanstorage.push_back(snowptr);
    }

    cout << yetanothersnomanstorage[3]->getKugeln();

    // *** //

    /*
    vector<string> snowman;
    vector<vector<string>> snowmanDB;

    // int meinArray[5][7];

    // Lineare Speicherung der Schneemanneigenschaften
    snowman.push_back("Henry");
    snowman.push_back("3");
    snowman.push_back("Weiss");
    snowman.push_back("Ja!");
    snowman.push_back("Zylinder");

    cout << "Name: " << snowman[0] << endl;
    cout << "Kugeln: " << snowman[1] << endl;
    cout << "Farbe: " << snowman[2] << endl;
    // ...

    for (int i = 0; i < snowman.size(); i++) {
        cout << snowman[i];
    }

    cout << endl << endl;
    snowman.clear();

    // ToDo: Umbauen in zweidimensionalen Vektor!
    snowman.push_back("Henry");
    snowman.push_back("3");
    snowman.push_back("Weiss");
    snowman.push_back("Ja!");
    snowman.push_back("Zylinder");

    snowmanDB.push_back(snowman);

    snowman.clear();

    snowman.push_back("Ursula");
    snowman.push_back("4");
    snowman.push_back("Grau");
    snowman.push_back("Nein!");
    snowman.push_back("Peruanischer Hut");

    snowmanDB.push_back(snowman);

    cout << "Name I: " << snowmanDB[0][0] << endl;
    cout << "Name II: " << snowmanDB[1][0] << endl;

     */

    return 0;
}