<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Daten via operator&amp;lt;&amp;lt; in Textfile speichern]]></title><description><![CDATA[<p>Hallo alle zusammen!<br />
Folgendes Problem:<br />
Ich habe eine Klasse Tier, welche eine abstrakte Basisklasse von vielen anderen Tieren ist.<br />
Dann hab ich vector&lt;tier*&gt; x mit meinen Tieren gefüllt (Ausgabe funktioniert)und nun soll ich den Vektor in ein Textfile speichern. Ich steh auf der Leitung. Wahrscheinlich ist die Lösung wirklich einfach aber ich weiß nicht weiter. Was soll ich machen? Bitte helft mir.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/305166/daten-via-operator-lt-lt-in-textfile-speichern</link><generator>RSS for Node</generator><lastBuildDate>Sat, 27 Jun 2026 01:08:04 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/305166.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 22 Jun 2012 16:10:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Daten via operator&amp;lt;&amp;lt; in Textfile speichern on Fri, 22 Jun 2012 16:10:31 GMT]]></title><description><![CDATA[<p>Hallo alle zusammen!<br />
Folgendes Problem:<br />
Ich habe eine Klasse Tier, welche eine abstrakte Basisklasse von vielen anderen Tieren ist.<br />
Dann hab ich vector&lt;tier*&gt; x mit meinen Tieren gefüllt (Ausgabe funktioniert)und nun soll ich den Vektor in ein Textfile speichern. Ich steh auf der Leitung. Wahrscheinlich ist die Lösung wirklich einfach aber ich weiß nicht weiter. Was soll ich machen? Bitte helft mir.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2226259</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2226259</guid><dc:creator><![CDATA[priesn]]></dc:creator><pubDate>Fri, 22 Jun 2012 16:10:31 GMT</pubDate></item><item><title><![CDATA[Reply to Daten via operator&amp;lt;&amp;lt; in Textfile speichern on Fri, 22 Jun 2012 16:17:55 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Du musst halt deiner Tier Klasse und den davon abgeleiteten Klassen Funktionen zum Schreiben in eine Textdatei spendieren (virtual) und die dann aufrufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2226262</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2226262</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Fri, 22 Jun 2012 16:17:55 GMT</pubDate></item><item><title><![CDATA[Reply to Daten via operator&amp;lt;&amp;lt; in Textfile speichern on Fri, 22 Jun 2012 16:40:23 GMT]]></title><description><![CDATA[<p>priesn schrieb:</p>
<blockquote>
<p>(Ausgabe funktioniert)</p>
</blockquote>
<p>was meinst Du damit genau?<br />
Wenn die Ausgabe aller Tiere auf der Konsole (std::cout) funktioniert, so funktioniert sie genauso in ein Textfile.<br />
Statt:</p>
<pre><code class="language-cpp">for( ..alle Tiere.. )
        cout &lt;&lt; *tier ...;
</code></pre>
<p>schreibst Du</p>
<pre><code class="language-cpp">ofstream file(&quot;textfile.txt&quot;);
    for( ..alle Tiere.. )
        file &lt;&lt; *tier ..; // genau wie oben
</code></pre>
<p><code>ofstream file</code> ist ein <code>std::ostream</code> , genau wie <code>std::cout</code> ein <code>std::ostream</code> ist. Ist die Antwort, die Du wolltest?</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2226267</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2226267</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Fri, 22 Jun 2012 16:40:23 GMT</pubDate></item><item><title><![CDATA[Reply to Daten via operator&amp;lt;&amp;lt; in Textfile speichern on Sat, 23 Jun 2012 07:29:03 GMT]]></title><description><![CDATA[<p>Werner Salomon schrieb:</p>
<blockquote>
<p>Statt:</p>
<pre><code class="language-cpp">for( ..alle Tiere.. )
        cout &lt;&lt; *tier ...;
</code></pre>
<p>schreibst Du</p>
<pre><code class="language-cpp">ofstream file(&quot;textfile.txt&quot;);
    for( ..alle Tiere.. )
        file &lt;&lt; *tier ..; // genau wie oben
</code></pre>
<p><code>ofstream file</code> ist ein <code>std::ostream</code> , genau wie <code>std::cout</code> ein <code>std::ostream</code> ist. Ist die Antwort, die Du wolltest?</p>
</blockquote>
<p>Ich glaube, dass ist das was ich will.</p>
<p>Kann das so irgendwie funktionieren?</p>
<pre><code class="language-cpp">vector&lt;tier*&gt; x;
      //dann speicher ich da ein paar Tiere rein
      ofstream file(&quot;output.txt&quot;);
      for (size_t i=0; i&lt;x.size(); ++i)
    {
        file &lt;&lt; x[i];
    }
</code></pre>
<p>wobei ich das schon habe:</p>
<pre><code class="language-cpp">ostream&amp; operator&lt;&lt;(ostream&amp; s, const tier&amp; rhs)
{
    rhs.PrettyPrint(s);
    return s;
}
</code></pre>
<p>und</p>
<pre><code class="language-cpp">void tier::PrettyPrint(ostream&amp; s) const
{
    s &lt;&lt; &quot;Name des Tieres: &quot;&lt;&lt; name &lt;&lt;endl;
    s &lt;&lt; &quot;Geburtsdatum: &quot;&lt;&lt; geb &lt;&lt;endl;
    s &lt;&lt; &quot;Gewicht des Tieres: &quot;&lt;&lt;kg&lt;&lt;&quot; kg&quot;&lt;&lt;endl;
  // usw...
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2226375</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2226375</guid><dc:creator><![CDATA[priesn]]></dc:creator><pubDate>Sat, 23 Jun 2012 07:29:03 GMT</pubDate></item><item><title><![CDATA[Reply to Daten via operator&amp;lt;&amp;lt; in Textfile speichern on Sat, 23 Jun 2012 07:39:48 GMT]]></title><description><![CDATA[<p>Ah sorry funktioniert ja schon. Ich hab dann noch eine andere Frage:</p>
<p>manchmal hängt sich alles auf wenn ich</p>
<pre><code class="language-cpp">vector&lt;tier*&gt; x;
    x.push_back(&amp;a);
    x.push_back(&amp;b);
    x.push_back(&amp;c);
    x.push_back(&amp;d);
    x.push_back(&amp;e);
    x.push_back(new pute(&quot;Josef&quot;, datum(13,6,1999),37.2,7.2)); //das hier verwende

    Ausgabe(x);

    cout&lt;&lt;&quot;Anzahl der Kuehe: &quot;&lt;&lt;kuh::cow&lt;&lt;endl;

    cout&lt;&lt;&quot;\nAeltestes Tier: &quot;&lt;&lt;endl;
    auto it=min_element(x.begin(),x.end(),Geb_aelter);
    cout&lt;&lt;endl&lt;&lt;**it&lt;&lt;endl;

    cout&lt;&lt;&quot;Wertvollstes Tier: &quot;&lt;&lt;endl;
    it=min_element(x.begin(),x.end(),wertvoller);
    cout&lt;&lt;endl&lt;&lt;**it;
    cout&lt;&lt;&quot;.........wird verkauft\n&quot;&lt;&lt;endl;

    delete *it;
    x.erase(it);
</code></pre>
<p>wenn ich es auskommentiere, dann funktioniert soweit wieder alles. Aber es kann sein, dass sich wieder alles aufhängt bei delete *it; dann mach ich oben den Kommentar weg und es funktioniert wieder. An was kann das liegen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2226376</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2226376</guid><dc:creator><![CDATA[priesn]]></dc:creator><pubDate>Sat, 23 Jun 2012 07:39:48 GMT</pubDate></item><item><title><![CDATA[Reply to Daten via operator&amp;lt;&amp;lt; in Textfile speichern on Sat, 23 Jun 2012 08:16:50 GMT]]></title><description><![CDATA[<p>priesn schrieb:</p>
<blockquote>
<p>An was kann das liegen?</p>
</blockquote>
<p>An ganz vielen Dingen. Zeig mal ein vollständiges Programm, an dem man den Fehler nachvollziehen kann. Siehe auch dritter Link in meiner Signatur.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2226381</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2226381</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sat, 23 Jun 2012 08:16:50 GMT</pubDate></item><item><title><![CDATA[Reply to Daten via operator&amp;lt;&amp;lt; in Textfile speichern on Sat, 23 Jun 2012 15:52:21 GMT]]></title><description><![CDATA[<p>ich verwende code::blocks 10.05<br />
-std=c++0x<br />
also mein komplettes programm ist<br />
sorry wegen des langen codes, aber ich hab nicht so viel zeit ihn zu reduzieren, da ich für die uni auch andere sachen machen muss</p>
<pre><code class="language-cpp">// main.cpp
#include &quot;schaf.h&quot;
#include &quot;huhn.h&quot;
#include &lt;vector&gt;
#include &lt;algorithm&gt;
#include &lt;numeric&gt;
#include &lt;fstream&gt;

void Ausgabe(const vector&lt;tier*&gt;&amp; v)
{
  for (size_t i=0; i&lt;v.size(); ++i)
    {
        v[i]-&gt;PrettyPrint(cout);
    }
}

bool Geb_aelter(const tier* a, const tier* b)
{
    return a-&gt;Getdatum()&lt;  b-&gt;Getdatum();
}
bool wertvoller(const tier* a, const tier* b)
{
    return a-&gt;wert()&gt;b-&gt;wert();
}

float WERT(float result, tier* a)
{
    return result+a-&gt;wert();
}
int main()
{
    kuh a(&quot;Resi&quot;, datum(21,1,2006), 600, 30, 5, 0.9);
    //a.PrettyPrint(cout);

    kuh b(&quot;Heidi&quot;, datum(21,1,2006), 735, 30, 5, 0.9);
    //b.PrettyPrint(cout);

    pute c(&quot;Putput&quot;, datum(19,1,2005), 20, 6);
    //c.PrettyPrint(cout);

    huhn d(&quot;Pipipi&quot;, datum(5,5,2009), 7, 5.6, 30, 0.1);
    //d.PrettyPrint(cout);

    schaf e(&quot;Meeeeh&quot;, datum(24,12,2009), 90, 15, 4.5, 1.6, 1, 2);
    //e.PrettyPrint(cout);
    //cout&lt;&lt;&quot;Viecher insgesamt: &quot;&lt;&lt;tier::n&lt;&lt;endl;
    //cout&lt;&lt;&quot;Gesamte Beinanzahl: &quot;&lt;&lt;vierbeiner::baz4+zweibeiner::baz2&lt;&lt;endl&lt;&lt;endl;

    vector&lt;tier*&gt; x;
    x.push_back(&amp;a);
    x.push_back(&amp;b);
    x.push_back(&amp;c);
    x.push_back(&amp;d);
    x.push_back(&amp;e);
    x.push_back(new pute(&quot;Josef&quot;, datum(13,6,1999),37.2,7.2));
    //x.back()-&gt;PrettyPrint(cout);
    //cout&lt;&lt;endl&lt;&lt; *x.back()&lt;&lt;endl;

    Ausgabe(x);

    cout&lt;&lt;&quot;Anzahl der Kuehe: &quot;&lt;&lt;kuh::cow&lt;&lt;endl;

    cout&lt;&lt;&quot;\nAeltestes Tier: &quot;&lt;&lt;endl;
    auto it=min_element(x.begin(),x.end(),Geb_aelter);
    cout&lt;&lt;endl&lt;&lt;**it&lt;&lt;endl;

    cout&lt;&lt;&quot;Wertvollstes Tier: &quot;&lt;&lt;endl;
    it=min_element(x.begin(),x.end(),wertvoller);
    cout&lt;&lt;endl&lt;&lt;**it;
    cout&lt;&lt;&quot;.........wird verkauft\n&quot;&lt;&lt;endl;

    delete *it;
    x.erase(it);

    cout&lt;&lt;&quot;Gesamtwert der Tiere: &quot;&lt;&lt;accumulate(x.begin(),x.end(),0.0,WERT)&lt;&lt;&quot; Euro&quot;&lt;&lt;endl;
    cout&lt;&lt;&quot;Gesamte Beinanzahl: &quot;&lt;&lt;vierbeiner::baz4+zweibeiner::baz2&lt;&lt;endl;

    ofstream file(&quot;output.txt&quot;);
      for (size_t i=0; i&lt;x.size(); ++i)
    {
        file &lt;&lt; *x[i];
    }
    return 0;
}
</code></pre>
<pre><code class="language-cpp">//datum.h
#ifndef DATUM_H
#define DATUM_H
#include &lt;iostream&gt;

using namespace std;

class datum
{
    public:
        /** Default constructor */
        datum();
        datum(int tag, int monat, int jahr);
        /** Default destructor */
        virtual ~datum();
        /** Access t
         * \return The current value of t
         */
        virtual int Gett() const { return t; }
        /** Set t
         * \param val New value to set
         */
        virtual void Sett(int val) { t = val; }
        /** Access m
         * \return The current value of m
         */
        virtual int Getm()  const { return m; }
        /** Set m
         * \param val New value to set
         */
        virtual void Setm(int val) { m = val; }
        /** Access j
         * \return The current value of j
         */
        virtual int Getj()  const { return j; }
        /** Set j
         * \param val New value to set
         */
        virtual void Setj(unsigned int val) { j = val; }

        bool operator&lt;(const datum&amp; rhs) const{return (j&lt;rhs.j||(j==rhs.j&amp;&amp;m&lt;rhs.m)||(j==rhs.j&amp;&amp;m==rhs.m&amp;&amp;t&lt;rhs.t));};
        bool operator&gt; (const datum&amp; rhs) const{return (j&gt;rhs.j||(j==rhs.j&amp;&amp;m&gt;rhs.m)||(j==rhs.j&amp;&amp;m==rhs.m&amp;&amp;t&gt;rhs.t));};
        bool operator== (const datum&amp; rhs) const{return (j==rhs.j&amp;&amp;m==rhs.m&amp;&amp;t==rhs.t);};
    protected:
    private:
        int t; //!&lt; Member variable &quot;t&quot;
        int m; //!&lt; Member variable &quot;m&quot;
        int j; //!&lt; Member variable &quot;j&quot;
};
ostream&amp; operator&lt;&lt;(ostream&amp; s, const datum&amp; rhs);
#endif // DATUM_H
</code></pre>
<pre><code class="language-cpp">//datum.cpp
#include &quot;datum.h&quot;

datum::datum()
: t(0), m(0), j(0)
{

}
datum::datum(int tag, int monat, int jahr)
: t(tag), m(monat), j(jahr)
{
    if(t&lt;1)
    t=1;
    if(m&lt;1)
    m=1;
    if(t&gt;28&amp;&amp;m==2)
    t=28;
    if(t&gt;30&amp;&amp;(m==4||m==6||m==9||m==11))
    t=30;
    if(t&gt;31&amp;&amp;(m==1||m==3||m==5||m==7||m==8||m==10||m&gt;=12))
    t=31;
    if(m&gt;12)
    m=12;
    if(j&gt;2012)
    j=2012;

}

datum::~datum()
{
    //dtor
}

ostream&amp; operator&lt;&lt;(ostream&amp; s, const datum&amp; rhs)
{
    s &lt;&lt;  rhs.Gett()&lt;&lt; &quot;.&quot;&lt;&lt;rhs.Getm()&lt;&lt;&quot;.&quot;&lt;&lt;rhs.Getj();
    return s;
}
</code></pre>
<pre><code class="language-cpp">//tier.h
#ifndef TIER_H
#define TIER_H

#include &quot;datum.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;

using namespace std;

class tier
{
    public:

        static int n;
        /** Default constructor */
        tier(const string Name, const datum&amp; Geburtsdatum, float Gewicht);
        /** Default destructor */
        virtual ~tier();
        /** Copy constructor
         *  \param other Object to copy from
         */
        tier(const tier&amp; other);
        /** Access name
         * \return The current value of name
         */
        const string Getname() const { return name; }
        /** Access geb
         * \return The current value of geb
         */
        const datum Getgeb() const { return geb; }
        /** Access kg
         * \return The current value of kg
         */
        float Getkg() const { return kg; }
        /** Set kg
         * \param val New value to set
         */
        void Setkg(float val) { kg = val; }

        datum Getdatum()  const { return geb; }

        virtual float wert() const {return 0.0f;}

        virtual void PrettyPrint(ostream&amp; s) const;

    protected:
    private:
        const string name; //!&lt; Member variable &quot;name&quot;
        const datum geb; //!&lt; Member variable &quot;geb&quot;
        float kg; //!&lt; Member variable &quot;kg&quot;
};
ostream&amp; operator&lt;&lt;(ostream&amp; s, const tier&amp; rhs);

#endif // TIER_H
</code></pre>
<pre><code class="language-cpp">//tier.cpp
#include &quot;tier.h&quot;

int tier::n=0;

tier::tier(const string Name, const datum&amp; Geburtsdatum, float Gewicht)
: name(Name), geb(Geburtsdatum), kg(Gewicht)
{
    n++;
    //ctor
}

tier::~tier()
{
    n--;
    //dtor
}

tier::tier(const tier&amp; other)
{
    //copy ctor
}

ostream&amp; operator&lt;&lt;(ostream&amp; s, const tier&amp; rhs)
{
    rhs.PrettyPrint(s);
    return s;
}

void tier::PrettyPrint(ostream&amp; s) const
{
    s &lt;&lt; &quot;Name des Tieres: &quot;&lt;&lt; name &lt;&lt;endl;
    s &lt;&lt; &quot;Geburtsdatum: &quot;&lt;&lt; geb &lt;&lt;endl;
    s &lt;&lt; &quot;Gewicht des Tieres: &quot;&lt;&lt;kg&lt;&lt;&quot; kg&quot;&lt;&lt;endl;
}
</code></pre>
<pre><code class="language-cpp">//vierbeiner.h
#ifndef VIERBEINER_H
#define VIERBEINER_H

#include &quot;tier.h&quot;

class vierbeiner : public tier
{
    public:
    static int baz4;
        /** Default constructor */
        vierbeiner(const string Name, const datum Geburtsdatum, float Gewicht);
        /** Default destructor */
        virtual ~vierbeiner();
        int Getbaz4() const { return baz4; }
    protected:
    private:

};

#endif // VIERBEINER_H
</code></pre>
<pre><code class="language-cpp">//vierbeiner.cpp
#include &quot;vierbeiner.h&quot;

int vierbeiner::baz4(0);

vierbeiner::vierbeiner(const string Name, const datum Geburtsdatum, float Gewicht)
: tier(Name, Geburtsdatum, Gewicht)
{
   baz4+=4;
}

vierbeiner::~vierbeiner()
{
    baz4-=4;
}
</code></pre>
<pre><code class="language-cpp">//zweibeiner.h
#ifndef ZWEIBEINER_H
#define ZWEIBEINER_H

#include &quot;tier.h&quot;

class zweibeiner : public tier
{
    public:
    static int baz2;
        /** Default constructor */
        zweibeiner(const string Name, const datum&amp; Geburtsdatum, float Gewicht);
        /** Default destructor */
        virtual ~zweibeiner();
        /** Access baz
         * \return The current value of baz
         */
        int Getbaz2() const { return baz2; }
    protected:
    private:
};

#endif // ZWEIBEINER_H
</code></pre>
<pre><code class="language-cpp">//zweibeiner.cpp
#include &quot;zweibeiner.h&quot;

int zweibeiner::baz2(0);
zweibeiner::zweibeiner(const string Name, const datum&amp; Geburtsdatum, float Gewicht)
: tier(Name, Geburtsdatum, Gewicht)
{
    baz2+=2;
    //ctor
}

zweibeiner::~zweibeiner()
{
    baz2-=2;
    //dtor
}
</code></pre>
<pre><code class="language-cpp">//kuh.h
#ifndef KUH_H
#define KUH_H

#include &quot;vierbeiner.h&quot;

class kuh : public vierbeiner
{
    public:
        static int cow;
        /** Default constructor */
        kuh(const string Name, const datum Geburtsdatum, float Gewicht, float Milchleistung, float Fleischpreis, float Milchpreis);
        /** Default destructor */
        virtual ~kuh();

        float Getliter() const { return liter; }
        void Setliter(int val) { liter = val; }
        float Getfleischpreis() const {return fleischpreis;}
        void Setfleischpreis(int val) { fleischpreis = val; }
        float Getmilchpreis() const { return milchpreis; }
        void Setmilchpreis(int val) { milchpreis = val; }

        void PrettyPrint(ostream&amp; s) const;

        float wert() const { return liter*milchpreis+fleischpreis*tier::Getkg();}
    protected:
    private:
        float liter; //!&lt; Member variable &quot;liter&quot;
        float fleischpreis;
        float milchpreis;
};
ostream&amp; operator&lt;&lt;(ostream&amp; s, const kuh&amp; rhs);

#endif // KUH_H
</code></pre>
<pre><code class="language-cpp">//kuh.cpp
#include &quot;kuh.h&quot;
int kuh::cow(0);

kuh::kuh(const string Name, const datum Geburtsdatum, float Gewicht, float Milchleistung, float Fleischpreis, float Milchpreis)
:vierbeiner(Name, Geburtsdatum, Gewicht), liter(Milchleistung), fleischpreis(Fleischpreis), milchpreis(Milchpreis)
{
    cow++;

    //ctor
}

kuh::~kuh()
{
    cow--;
    //dtor
}

void kuh::PrettyPrint(ostream&amp; s) const
{
    s&lt;&lt; &quot;Kuh: &quot;&lt;&lt;endl;
    tier::PrettyPrint(s);
    s &lt;&lt; &quot;Milchleistung/Monat: &quot;&lt;&lt; liter&lt;&lt;&quot; Liter&quot;&lt;&lt;endl;
    s &lt;&lt; &quot;Fleischpreis: &quot; &lt;&lt; kuh::Getfleischpreis()&lt;&lt;&quot; Euro&quot;&lt;&lt;endl;
    s&lt;&lt; &quot;Milchpreis: &quot; &lt;&lt; kuh::Getmilchpreis()&lt;&lt;&quot; Euro&quot;&lt;&lt;endl;
    s&lt;&lt; &quot;Aktueller Wert: &quot;&lt;&lt;wert()&lt;&lt;&quot; Euro&quot;&lt;&lt;endl;
    s&lt;&lt; &quot;Beinanzahl: &quot;&lt;&lt;vierbeiner::baz4%4+4&lt;&lt;endl&lt;&lt;endl;
}

ostream&amp; operator&lt;&lt;(ostream&amp; s, const kuh&amp; rhs)
{
    rhs.PrettyPrint(s);
    return s;
}
</code></pre>
<pre><code class="language-cpp">//schaf.h
#ifndef SCHAF_H
#define SCHAF_H

#include &quot;kuh.h&quot;

class schaf : public kuh
{
    public:
        static int sheep;
        /** Default constructor */
        schaf(const string Name, const datum Geburtsdatum, float Gewicht, float Milchleistung, float Fleischpreis, float Milchpreis, float Wolle, float Wollpreis);
        /** Default destructor */
        virtual ~schaf();
        float Getwolle() const { return wolle; }
        void Setwolle(float val) { wolle = val; }
        float Getwollpreis() const { return wollpreis; }
        void Setwollpreis(float val) { wollpreis = val; }
        void PrettyPrint(ostream&amp; s) const;
        float wert() const {return kuh::wert()+wolle*wollpreis;}
    protected:
    private:
    float wolle;
    float wollpreis;
};

ostream&amp; operator&lt;&lt;(ostream&amp; s, const schaf&amp; rhs);

#endif // SCHAF_H
</code></pre>
<pre><code class="language-cpp">//schaf.cpp
#include &quot;schaf.h&quot;
int schaf::sheep(0);
schaf::schaf(const string Name, const datum Geburtsdatum, float Gewicht, float Milchleistung, float Fleischpreis, float Milchpreis, float Wolle, float Wollpreis)
: kuh(Name, Geburtsdatum, Gewicht, Milchleistung, Fleischpreis, Milchpreis), wolle(Wolle), wollpreis(Wollpreis)
{
    kuh::cow--;
    sheep++;
    //ctor
}

schaf::~schaf()
{
    kuh::cow++;
    sheep--;
    //dtor
}

void schaf::PrettyPrint(ostream&amp; s) const
{
    s&lt;&lt;&quot;Schaf: &quot;&lt;&lt;endl;
    tier::PrettyPrint(s);
    s&lt;&lt;&quot;Milchleistung: &quot;&lt;&lt; kuh::Getliter()&lt;&lt;&quot; Liter&quot;&lt;&lt;endl;
    s&lt;&lt;&quot;Fleischpreis: &quot;&lt;&lt; kuh::Getfleischpreis()&lt;&lt;&quot; Euro&quot;&lt;&lt;endl;
    s&lt;&lt;&quot;Milchpreis: &quot;&lt;&lt;kuh::Getmilchpreis()&lt;&lt;&quot; Euro&quot;&lt;&lt;endl;
    s &lt;&lt; &quot;Wolle/Monat: &quot; &lt;&lt; wolle&lt;&lt;&quot; kg&quot; &lt;&lt; endl;
    s&lt;&lt;&quot;Wollpreis/kg: &quot; &lt;&lt; wollpreis&lt;&lt;&quot; Euro&quot;&lt;&lt;endl;
    s&lt;&lt; &quot;Aktueller Wert: &quot;&lt;&lt;wert()&lt;&lt;&quot; Euro&quot;&lt;&lt;endl;
    s&lt;&lt; &quot;Beinanzahl: &quot;&lt;&lt;vierbeiner::baz4%4+4&lt;&lt;endl&lt;&lt;endl;

}

ostream&amp; operator&lt;&lt;(ostream&amp; s, const schaf&amp; rhs)
{
    rhs.PrettyPrint(s);
    return s;
}
</code></pre>
<pre><code class="language-cpp">//pute.h
#ifndef PUTE_H
#define PUTE_H

#include &quot;zweibeiner.h&quot;

class pute : public zweibeiner
{
    public:
        static int turkey;
        /** Default constructor */
        pute(const string Name, const datum Geburtsdatum, float Gewicht, float Fleischpreis);
        /** Default destructor */
        virtual ~pute();
        void PrettyPrint(ostream&amp; s) const;
        float Getfleischpreis() const {return fleischpreis;}
        void Setfleischpreis(int val) { fleischpreis = val; }
        float wert()const {return fleischpreis*tier::Getkg();}
    protected:
    private:
    float fleischpreis;
};
ostream&amp; operator&lt;&lt;(ostream&amp; s, const pute&amp; rhs);

#endif // PUTE_H
</code></pre>
<pre><code class="language-cpp">//pute.cpp
#include &quot;pute.h&quot;
int pute::turkey(0);
pute::pute(const string Name, const datum Geburtsdatum, float Gewicht, float Fleischpreis)
:zweibeiner(Name, Geburtsdatum, Gewicht), fleischpreis(Fleischpreis)
{
    turkey++;
    //ctor
}

pute::~pute()
{
    turkey--;
    //dtor
}

void pute::PrettyPrint(ostream&amp; s) const
{
    s&lt;&lt; &quot;Pute: &quot;&lt;&lt;endl;
    tier::PrettyPrint(s);
    s&lt;&lt; &quot;Fleischpreis: &quot;&lt;&lt; pute::Getfleischpreis()&lt;&lt;&quot; Euro&quot;&lt;&lt;endl;
    s&lt;&lt; &quot;Aktueller Wert: &quot;&lt;&lt;wert()&lt;&lt;&quot; Euro&quot;&lt;&lt;endl;
    s&lt;&lt; &quot;Beinanzahl: &quot;&lt;&lt;zweibeiner::baz2%2+2&lt;&lt;endl&lt;&lt;endl;
}

ostream&amp; operator&lt;&lt;(ostream&amp; s, const pute&amp; rhs)
{
    rhs.PrettyPrint(s);
    return s;
}
</code></pre>
<pre><code class="language-cpp">//huhn.h
#ifndef HUHN_H
#define HUHN_H

#include &quot;pute.h&quot;

class huhn : public pute
{
    public:
        static int chicken;
        /** Default constructor */
        huhn(const string Name, const datum Geburtsdatum, float Gewicht, float Fleischpreis, int Eier, float Eierpreis);
        /** Default destructor */
        virtual ~huhn();

        int Geteier() const { return eier; }
        void Seteier(int val) { eier = val; }
        int Geteierpreis() const { return eierpreis; }
        void Seteierpreis(int val) { eierpreis = val; }

        void PrettyPrint(ostream&amp; s) const;

        float wert() const {return pute::wert()+eier*eierpreis;}
    protected:
    private:
        int eier; //!&lt; Member variable &quot;eier&quot;
        float eierpreis;
};
ostream&amp; operator&lt;&lt;(ostream&amp; s, const huhn&amp; rhs);

#endif // HUHN_H
</code></pre>
<pre><code class="language-cpp">//huhn.cpp
#include &quot;huhn.h&quot;
int huhn::chicken(0);
huhn::huhn(const string Name, const datum Geburtsdatum, float Gewicht, float Fleischpreis, int Eier, float Eierpreis)
:pute(Name, Geburtsdatum, Gewicht, Fleischpreis), eier(Eier), eierpreis(Eierpreis)
{
    pute::turkey--;
    chicken++;
    //ctor
}

huhn::~huhn()
{
    pute::turkey++;
    chicken--;
    //dtor
}

void huhn::PrettyPrint(ostream&amp; s) const
{
    s&lt;&lt; &quot;Huhn: &quot;&lt;&lt; endl;
    tier::PrettyPrint(s);
    s&lt;&lt; &quot;Fleischpreis: &quot;&lt;&lt;pute::Getfleischpreis()&lt;&lt;&quot; Euro&quot;&lt;&lt;endl;
    s&lt;&lt; &quot;Eier/Monat: &quot; &lt;&lt; eier&lt;&lt;&quot; Stueck&quot; &lt;&lt; endl;
    s&lt;&lt; &quot;Eierpreis: &quot; &lt;&lt; eierpreis&lt;&lt;&quot; Euro&quot; &lt;&lt; endl;
    s&lt;&lt; &quot;Aktueller Wert: &quot;&lt;&lt;wert()&lt;&lt;&quot; Euro&quot;&lt;&lt;endl;
    s&lt;&lt; &quot;Beinanzahl: &quot;&lt;&lt;zweibeiner::baz2%2+2&lt;&lt;endl&lt;&lt;endl;
}

ostream&amp; operator&lt;&lt;(ostream&amp; s, const huhn&amp; rhs)
{
    rhs.PrettyPrint(s);
    return s;
}
</code></pre>
<p>Es gibt noch mehrere Tierklassen. Aber das wäre zu viel zu posten. Wiederholt sich ja alles. Das Programm funktioniert so, aber wie schon in meinem vorherigen Post erwähnt funktioniert es so nur manchmal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2226473</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2226473</guid><dc:creator><![CDATA[priesn]]></dc:creator><pubDate>Sat, 23 Jun 2012 15:52:21 GMT</pubDate></item><item><title><![CDATA[Reply to Daten via operator&amp;lt;&amp;lt; in Textfile speichern on Sat, 23 Jun 2012 16:55:41 GMT]]></title><description><![CDATA[<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_down"
      title=":-1:"
      alt="👎"
    /></p>
<p>priesn schrieb:</p>
<blockquote>
<p>sorry wegen des langen codes, aber ich hab nicht so viel zeit ihn zu reduzieren, da ich für die uni auch andere sachen machen muss</p>
</blockquote>
<p>Glaubst du, jemand hat so viel Zeit, das alles zu lesen? Hier sind nur Freiwillige unterwegs. Meinst du, die nehmen sich für dich Zeit, wenn du keine Zeit/Lust für uns hast?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2226488</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2226488</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sat, 23 Jun 2012 16:55:41 GMT</pubDate></item></channel></rss>