Kapitel 9 - Programm 8 - SCHABL3.CPP

zurück…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
    // Kapitel 9 - Programm 8 - SCHABL3.CPP
#include <stdio.h>
#include "datum.h"

const int MAXGROESZE = 128;

template<class JEDER_TYP>
class Stapel
{
    JEDER_TYP Array[MAXGROESZE];
    int StapelZeiger;
    public:
    Stapel(void) { StapelZeiger = 0; };
    void Lege(JEDER_TYP EinDat) { Array[StapelZeiger++] = EinDat; };
    JEDER_TYP Nimm(void)    { return Array[--StapelZeiger]; };
    int Leer(void)       { return (StapelZeiger == 0); };
};

char Name[] = "Johann Gottlieb Fichte";

int main(void)
{
    Stapel<char *> charStapel;
    Stapel<Datum *> KlassenStapel;
    Datum Kuh, Schwein, Hund, Extra;

    KlassenStapel.Lege(&Kuh);
    KlassenStapel.Lege(&Schwein);
    KlassenStapel.Lege(&Hund);
    KlassenStapel.Lege(&Extra);

    charStapel.Lege("Das ist Zeile 1");
    charStapel.Lege("Das ist die zweite Zeile");
    charStapel.Lege("Das ist die dritte Zeile");
    charStapel.Lege(Name);

    for (int Index = 0 ; Index < 4 ; Index++)
    {
        Extra = *KlassenStapel.Nimm();
        printf("Datum = %d %d %d\n", Extra.HoleMonat(),
                Extra.HoleTag(), Extra.HoleJahr());
    };

    printf("\n     Zeichenketten\n");
    do
    {
        printf("%s\n", charStapel.Nimm());
    } while (!charStapel.Leer());

    return 0;
}


// Ergebnis beim Ausführen
//
// Datum = 3 14 97
// Datum = 3 14 97
// Datum = 3 14 97
// Datum = 3 14 97
//
//    Zeichenketten
// Johann Gottlieb Fichte
// Das ist die dritte Zeile
// Das ist die zweite Zeile
// Das ist Zeile 1

zurück…