<?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[Suche Aufgaben&#x2F;Tutorials zum Objektlebenszyklus, Vererbung...]]></title><description><![CDATA[<p>Guten Morgen,</p>
<p>ich bin dabei meine C++ Kenntnisse wieder aufzufrischen und möchte das gerne weiter praktisch trainieren.</p>
<p>zum Objektlebenszyklus und der Vererbung hätte ich am liebsten Aufgaben die etwas komplizierter sind. So in der Art: 4-5 Klassen mit Vererbung (virtual, dynamischer Speicher usw.) an denen man den Ablauf des Programms feststellen soll.</p>
<p>Also wann der Konstruktor von Class A, B, C, D aufgerufen wird, was ausgeführt wird und wann der Destruktor folgt.<br />
Halt mehrere Verschachtelungen im main Programm.</p>
<p>Kann da jemand vielleicht mit ein paar Aufgaben bzw. Links weiterhelfen?</p>
<p>Ich danke schonmal!!</p>
<p>cu</p>
<p>Sven</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/152933/suche-aufgaben-tutorials-zum-objektlebenszyklus-vererbung</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 07:28:11 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/152933.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 11 Jul 2006 09:51:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Suche Aufgaben&#x2F;Tutorials zum Objektlebenszyklus, Vererbung... on Tue, 11 Jul 2006 09:51:28 GMT]]></title><description><![CDATA[<p>Guten Morgen,</p>
<p>ich bin dabei meine C++ Kenntnisse wieder aufzufrischen und möchte das gerne weiter praktisch trainieren.</p>
<p>zum Objektlebenszyklus und der Vererbung hätte ich am liebsten Aufgaben die etwas komplizierter sind. So in der Art: 4-5 Klassen mit Vererbung (virtual, dynamischer Speicher usw.) an denen man den Ablauf des Programms feststellen soll.</p>
<p>Also wann der Konstruktor von Class A, B, C, D aufgerufen wird, was ausgeführt wird und wann der Destruktor folgt.<br />
Halt mehrere Verschachtelungen im main Programm.</p>
<p>Kann da jemand vielleicht mit ein paar Aufgaben bzw. Links weiterhelfen?</p>
<p>Ich danke schonmal!!</p>
<p>cu</p>
<p>Sven</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1095654</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1095654</guid><dc:creator><![CDATA[sventhevan]]></dc:creator><pubDate>Tue, 11 Jul 2006 09:51:28 GMT</pubDate></item><item><title><![CDATA[Reply to Suche Aufgaben&#x2F;Tutorials zum Objektlebenszyklus, Vererbung... on Thu, 13 Jul 2006 19:26:52 GMT]]></title><description><![CDATA[<p>kann mir keiner was anbieten? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":-("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1097368</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097368</guid><dc:creator><![CDATA[sventhevan]]></dc:creator><pubDate>Thu, 13 Jul 2006 19:26:52 GMT</pubDate></item><item><title><![CDATA[Reply to Suche Aufgaben&#x2F;Tutorials zum Objektlebenszyklus, Vererbung... on Thu, 13 Jul 2006 21:10:04 GMT]]></title><description><![CDATA[<p>In Tutorials findet man solche komplexen Sachen selten. Aber wir können uns ja selbst hier etwas zusammenbauen. Dir geht es ja offensichtlich darum, zu sehen, wie OOP so läuft mit möglichst vielen Features.</p>
<p>Hier zunächst mal ein kleines Konstrukt zum Ausbauen:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;conio.h&gt;
using namespace std;

class C 
{
    public:
      C(){cout&lt;&lt;&quot;ctor C &quot;&lt;&lt;this&lt;&lt;endl;}
     ~C(){cout&lt;&lt;&quot;dtor C&quot;&lt;&lt;endl;}
};

class E
{
    public:
      E(){cout&lt;&lt;&quot;ctor E &quot;&lt;&lt;this&lt;&lt;endl;}
     ~E(){cout&lt;&lt;&quot;dtor E&quot;&lt;&lt;endl;}            
};

class D : public E
{
    public:
      D(){cout&lt;&lt;&quot;ctor D &quot;&lt;&lt;this&lt;&lt;endl;}
     ~D(){cout&lt;&lt;&quot;dtor D&quot;&lt;&lt;endl;}            
};

class A
{
    public:
      A(){cout&lt;&lt;&quot;ctor A &quot;&lt;&lt;this&lt;&lt;endl;}
     ~A(){cout&lt;&lt;&quot;dtor A&quot;&lt;&lt;endl;}            
};

class B : public A
{
    public:
      B()
      {
           cout&lt;&lt;&quot;ctor B &quot;&lt;&lt;this&lt;&lt;endl;
           pd_ = new D;
           cout&lt;&lt;pd_&lt;&lt;endl;
      }
     ~B()
     {
          cout&lt;&lt;&quot;dtor B&quot;&lt;&lt;endl;
          delete pd_;     
     }            

    private:
       C c_;
       D* pd_;       
};

int main()
{
 {
   B b;
   getch();
 }
 getch(); 
}
</code></pre>
<p>Ich gebe Dir aus einem meiner eigenen Beispiele hier mal eine Einstiegsversion, den Du ausbauen kannst:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;cctype&gt;
#include &lt;conio.h&gt;
using namespace std;

class Person
{
  public:
    Person( const string &amp; name = &quot;&quot;, const string &amp; info = &quot;&quot; ); //Konstruktor

    Person( const Person &amp; );        //Copy-Konstruktor
    Person &amp; operator=( const Person &amp; );                         //Zuweisung

    string getName() const;                                       //liefert Namen zurueck
    string getInfo() const;                                       //liefert Info zurueck
    void setName(string s);
    void setInfo(string s);

    int operator%( const Person &amp; a ) const;                      //Aehnlichkeit
    friend ostream &amp; operator&lt;&lt;( ostream &amp; s, const Person &amp; x ); //Ausgabe
  private:
    string name_;  // Name der Person
    string info_;  // Information
};

/***************** Implementierung ***************************************/

Person::Person( const string &amp; name, const string &amp; info ) : name_(name),
info_(info){}
Person::Person( const Person &amp; p ) : name_(p.name_), info_(p.info_){}

string Person::getName() const { return name_; }
string Person::getInfo() const { return info_; }
void Person::setName(string s) { name_ = s; }
void Person::setInfo(string s) { info_ = s; }

Person &amp; Person::operator=( const Person &amp; p )
{
  name_  = p.name_;
  info_  = p.info_;
  return *this;
}

int Person::operator%( const Person &amp; p ) const // Aehnlichkeit
{
    int gleicheZeichen = 0; // Anzahl gleicher Zeichen
    int min, max;           // kleinste, groesste Laenge
    if( name_.length() &gt; p.name_.length() )
    {
      max = name_.length();
      min = p.name_.length();
    }
    else
    {
      min = name_.length();
      max = p.name_.length();
    }
    for( int i=0; i &lt; min; ++i )
    {
      if ( toupper( name_[i] ) == toupper( p.name_[i] ) )
          ++gleicheZeichen;
    }
    return gleicheZeichen;
}

ostream &amp; operator&lt;&lt;( ostream &amp; out, const Person &amp; p )
{
    return ( out &lt;&lt; p.name_ &lt;&lt; '\t' &lt;&lt; p.info_ );
}

/*************************************************************************/

class Notizbuch
{
  public:
    Notizbuch();

    // Die großen Drei: dtor, copycon, op= // wichtig wegen Zeigervariable
    ~Notizbuch();
    Notizbuch( const Notizbuch &amp; );
    Notizbuch &amp; operator=( const Notizbuch &amp; );

    void neuerEintrag( const Person &amp; p );         // traegt die Person p ein
    string getInfo( const string &amp; Name ) const;   // liefert Name und Info
    int getAnzahl() const;
    friend ostream &amp; operator&lt;&lt;( ostream &amp;, const Notizbuch &amp; );
  private:
    int anzahl_;           // Anzahl Eintraege
    int maxanzahl_;        // maximale Anzahl Eintraege
    Person * pPerson_;     // Personen
};

/***************** Implementierung ***************************************/

Notizbuch::Notizbuch () : anzahl_(0), maxanzahl_(100)
{
    pPerson_ = new Person[maxanzahl_];
    if( !pPerson_ )
        maxanzahl_ = 0;
}

Notizbuch::~Notizbuch() { delete[] pPerson_; };

void Notizbuch::neuerEintrag( const Person &amp; person )
{
    if( anzahl_ &lt; maxanzahl_ )
    {
      pPerson_[anzahl_] = person;
      ++anzahl_;
    }
}

string Notizbuch::getInfo( const string &amp; Name ) const
{
    if( anzahl_ &gt; 0 )
    {
        Person p = Name;
        int maxmatch = p % pPerson_[0];      // max. Aehnlichkeit
        int similarindex = 0;                // Index des aehnlichsten

        for( int i=anzahl_-1; i&gt;0; --i )
        {
            int match = ( p % pPerson_[i] ); // aktuelle Aehnlichkeit
            if( match &gt;= maxmatch )          // der neueste wird bevorzugt
            {
              maxmatch = match;
              similarindex = i;
            }
        }
        if( maxmatch &gt; 0 )
        {
            return pPerson_[similarindex].getName() + &quot;, &quot; +
pPerson_[similarindex].getInfo();
        }
    }
    else
    {
        cout &lt;&lt; &quot;Noch keine Eintraege in diesem Notizbuch vorhanden.&quot; &lt;&lt;
endl;
    }
    return (&quot;&quot;);
}

int Notizbuch::getAnzahl() const { return anzahl_; }

ostream &amp; operator &lt;&lt; ( ostream &amp; out, const Notizbuch &amp; nb )
{
    out &lt;&lt; &quot;Gesamtzahl der Eintraege im Notizbuch: &quot; &lt;&lt; nb.getAnzahl() &lt;&lt;
endl &lt;&lt; endl;
    return out;
}

/*******************************************/

unsigned countData(const string FN)
{
    ifstream in( FN.c_str() );
    if(!in)
    {
        cerr &lt;&lt; &quot;Datei kann nicht geoeffnet werden.&quot; &lt;&lt; endl;
        return 0;
    }
    else
    {
        // Zahl der Eintraege ermitteln
        int count = 0;
        for( string s; getline(in, s); ++count ){}
        return count;
    }
}

void loadData( Person * pPerson, const string FN, unsigned count )
{
    struct data
    {
        string name;
        string info;
    };

    ifstream in( FN.c_str() );
    if(!in)
    {
        cerr &lt;&lt; &quot;Datei kann nicht geoeffnet werden.&quot; &lt;&lt; endl;
    }
    else
    {
        data * pData = new data[count];

        in.clear();  // EOF-Status loeschen
        in.seekg(0); // Lesezeiger auf Dateianfang setzen
        count = 0;
        for( string s; getline(in, s); ++count )
        {
            int dest = s.find(&quot;#&quot;,0);
            pData[count].name = s.substr(0,dest);
            pData[count].info = s.substr(dest+1);
        }
        in.close();

        for( int i=0; i&lt;count; ++i )
        {
            pPerson[i].setName(pData[i].name);
            pPerson[i].setInfo(pData[i].info);
        }

        // dynamisches Array auf dem heap freigeben
        delete[] pData;
        pData = 0;
     }
}

int main()
{
    const string FN = &quot;notizbuch.txt&quot;;
    unsigned zahl = countData(FN);
    Person * pP = new Person[zahl];
    Notizbuch cpp_teilnehmer;
    loadData( pP, FN, zahl );

    for( int i=0; i&lt;zahl; ++i )
        cpp_teilnehmer.neuerEintrag( pP[i] );

    cout &lt;&lt; cpp_teilnehmer;

    string suchbegriff;
    cout &lt;&lt; &quot;Bitte Suchbegriff eingeben: &quot; &lt;&lt; endl;
    while( cin &gt;&gt; suchbegriff )
    {
        if( suchbegriff == &quot;#&quot; ) // Programmabbruch durch '#'
            break;
        cout &lt;&lt; cpp_teilnehmer.getInfo( suchbegriff ) &lt;&lt; endl;
    }

    delete[] pP;
}
</code></pre>
<p>Dateiaufbau notizbuch.txt im gleichen Verzeichnis wie exe:</p>
<pre><code>Moser Hans#001-464-7373773
Mueller Peter#001-464-3849787
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1097385</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097385</guid><dc:creator><![CDATA[Erhard Henkes]]></dc:creator><pubDate>Thu, 13 Jul 2006 21:10:04 GMT</pubDate></item><item><title><![CDATA[Reply to Suche Aufgaben&#x2F;Tutorials zum Objektlebenszyklus, Vererbung... on Thu, 13 Jul 2006 20:15:23 GMT]]></title><description><![CDATA[<p>Zur Übung der STL:</p>
<p><a href="http://forum.finalfantasy.de/archive/28993/thread.html" rel="nofollow">http://forum.finalfantasy.de/archive/28993/thread.html</a><br />
<a href="http://www.matheboard.de/archiv/thread,1577,gruene-augen-geloest-.htm" rel="nofollow">http://www.matheboard.de/archiv/thread,1577,gruene-augen-geloest-.htm</a><br />
<a href="http://www.melchisedech.net/Logikratsel/Monche/Losung/losung.html" rel="nofollow">http://www.melchisedech.net/Logikratsel/Monche/Losung/losung.html</a></p>
<pre><code class="language-cpp">#include &lt;set&gt; 
#include &lt;iostream&gt; 
#include &lt;conio.h&gt; 
using namespace std; 

class moench;  
set&lt;moench*&gt; alleMoenche;  
set&lt;moench*&gt;::iterator pos; 
set&lt;moench*&gt;::iterator pos1; 

class moench 
{ 
  private: 
    bool gesund_; 
    bool lebendig_; 
    bool kill_; 
    unsigned anzahl_kranke_Moenche_gesehen_; 
    unsigned anzahl_tage_noch_abwarten_; 

  public: 
    moench(){alleMoenche.insert(this); kill_ = false; lebendig_= true; gesund_ = true; anzahl_kranke_Moenche_gesehen_=0; anzahl_tage_noch_abwarten_=0; } 
    ~moench(){alleMoenche.erase(this);} 
    bool is_lebendig() const {return lebendig_;} 
    bool is_gesund() const {return gesund_;} 
    unsigned wieviele_andere_Moenche_krank() const; // Funktion nachstehend 
    void set_gesund(bool val) {gesund_=val;} 
    void set_anzahl_Tage_noch_abwarten(unsigned val) {anzahl_tage_noch_abwarten_= val;} 
    unsigned get_anzahl_Tage_noch_abwarten() const {return anzahl_tage_noch_abwarten_;} 
    void set_selfkill() {kill_= true;} 
    bool get_selfkill() const {return kill_;} 
    void sich_umbringen() {lebendig_= false;} 
}; 

unsigned moench::wieviele_andere_Moenche_krank() const 
{ 
    unsigned count = 0; 
    for( pos1 = alleMoenche.begin(); pos1 != alleMoenche.end(); ++pos1) 
    { 
      if( ( (*pos1)-&gt;is_lebendig() == true ) &amp;&amp; ( (*pos1) != this ) ) 
      { 
        if( (*pos1)-&gt;is_gesund() != true ) count++;   
      } 
    }  
    return count; 
} 

int main() 
{ 
  // Moenche /////////////// 
  moench M[10]; 
  M[6].set_gesund(false); 
  M[7].set_gesund(false); 
  M[8].set_gesund(false); 
  M[9].set_gesund(false); 
  ////////////////////////// 

  bool krankheit_besiegt = false; 
  unsigned tag = 0; 

  while( krankheit_besiegt == false ) 
  { 
       // Tag anzeigen 
       tag++; 
       cout &lt;&lt; &quot;\nTag: &quot; &lt;&lt; tag &lt;&lt; endl; 

       for( pos = alleMoenche.begin(); pos != alleMoenche.end(); ++pos) 
       { 
         cout &lt;&lt; *pos &lt;&lt; &quot; sieht Kranke: &quot; &lt;&lt; (*pos)-&gt;wieviele_andere_Moenche_krank() &lt;&lt; endl; 
         if ( tag == 1 ) 
         { 
            if( (*pos)-&gt;wieviele_andere_Moenche_krank() == 0 ) (*pos)-&gt;set_selfkill(); 
            else (*pos)-&gt;set_anzahl_Tage_noch_abwarten( (*pos)-&gt;wieviele_andere_Moenche_krank() ); 
         } 
         else 
         { 
           (*pos)-&gt;set_anzahl_Tage_noch_abwarten( (*pos)-&gt;get_anzahl_Tage_noch_abwarten() - 1 ); 
           if( (*pos)-&gt;get_anzahl_Tage_noch_abwarten() == 0 ) 
               if ( (*pos)-&gt;wieviele_andere_Moenche_krank() != 0 ) (*pos)-&gt;set_selfkill(); 
         } 
       }   

       // Die Nacht der Entscheidung 
       for( pos = alleMoenche.begin(); pos != alleMoenche.end(); ++pos) 
       { 
         if( (*pos)-&gt;get_selfkill() ) (*pos)-&gt;sich_umbringen(); 
       } 

       // Test, ob Krankheit besiegt 
       krankheit_besiegt = true; 
       for( pos = alleMoenche.begin(); pos != alleMoenche.end(); ++pos)        
       { 
         if( !(*pos)-&gt;is_gesund() &amp;&amp; (*pos)-&gt;is_lebendig() ) krankheit_besiegt = false; 
       } 

       // Report             
       for( pos = alleMoenche.begin(); pos != alleMoenche.end(); ++pos) 
       { 
            cout &lt;&lt; *pos &lt;&lt; &quot;: &quot; &lt;&lt; &quot;gesund = &quot; &lt;&lt; (*pos)-&gt;is_gesund() &lt;&lt; &quot; lebendig = &quot; &lt;&lt; 
            (*pos)-&gt;is_lebendig() &lt;&lt; &quot; Tage warten: &quot; &lt;&lt; (*pos)-&gt;get_anzahl_Tage_noch_abwarten() &lt;&lt; endl; 
       } 
       getch(); 
  } 

  cout &lt;&lt; &quot;\nKrankheit besiegt!&quot; &lt;&lt; endl; 
  getch(); 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1097393</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097393</guid><dc:creator><![CDATA[Erhard Henkes]]></dc:creator><pubDate>Thu, 13 Jul 2006 20:15:23 GMT</pubDate></item><item><title><![CDATA[Reply to Suche Aufgaben&#x2F;Tutorials zum Objektlebenszyklus, Vererbung... on Thu, 13 Jul 2006 20:25:12 GMT]]></title><description><![CDATA[<p>Jetzt noch was mit Templates zum Ausbauen:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;conio.h&gt;
using namespace std;

template &lt;typename T&gt; 
void eingabe( T&amp; x )
{
   cout &lt;&lt; &quot;Input:  &quot;;
   cin &gt;&gt; x;
}

template &lt;typename T&gt; 
void ausgabe ( const T x )
{
   cout &lt;&lt; &quot;Output: &quot;;
   cout &lt;&lt; x;
}

int isSchaltjahr( int jahr ) 
{
  return !(jahr%4) &amp;&amp; jahr%100 || !(jahr%400);
}

int main()
{
    int jahr;
    eingabe( jahr );
    ausgabe( isSchaltjahr(jahr) ? &quot;ja&quot; : &quot;nein&quot;  );

    getch();
}
</code></pre>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;conio.h&gt;

template&lt;class T&gt; 
class Wert 
{ 
  private: 
    T wert_; 
  public: 
    Wert( const T&amp; w ) : wert_(w){}; 
    operator T&amp;(){ return wert_; } 
};

int main()
{
    Wert&lt;float&gt;  f(9.81f); 
    Wert&lt;double&gt; d(19.5); 
    std::cout &lt;&lt; d*f;
    getch();
}
</code></pre>
<pre><code class="language-cpp">#include &lt;iostream&gt; 
#include &lt;iomanip&gt;  
#include &lt;cstdlib&gt; 
#include &lt;ctime&gt;  
#include &lt;conio.h&gt;  

class Random_aus_Stdlib_geklaut 
{ 
private: 
   unsigned seed_; 
   int random() 
   { 
     // so funktioniert rand():
     return ((( seed_ = seed_ * 214013L + 2531011L ) &gt;&gt; 16 ) &amp; 0x7fff ); 
   } 
public: 
   Random_aus_Stdlib_geklaut(){ seed_ = static_cast&lt;unsigned&gt;(time(NULL)); } 
   Random_aus_Stdlib_geklaut( unsigned seed ) { seed_ = seed; } 

   int getNum(){ return random(); } 
};

class RandomStdlib // verwendet rand()
{ 
private: 
   const unsigned int seed_;
public: 
   RandomStdlib():seed_( static_cast&lt;unsigned&gt;(time(NULL)) ){}

   int getNum() const
   { 
     static bool seed_flag = 0;
     if( !seed_flag )
     { 
       srand( seed_ );  
       seed_flag = true; 
     } 
     return rand();
   } 
};

class RandomTestEqual // Test auf Gleichverteilung
{ 
private: 
   int num_; 
public: 
   RandomTestEqual() : num_(RAND_MAX - 1){}; 
   int getNum()  
   { 
      ++num_; 
      if( num_ &gt;= RAND_MAX ) 
          num_ = 0; 
      return num_; 
   } 
};

template&lt; class T_Generator &gt; // Template-Klasse !!!
class Wuerfel  
{  
private:
  const unsigned maxzahl_; 
  const unsigned maxrandom_; 
  T_Generator zahlengenerator_; // Template-Typ als Attribut

public:  
  Wuerfel( unsigned maxzahl ) : 
  maxzahl_(maxzahl), maxrandom_(RAND_MAX-(RAND_MAX%maxzahl)) {}  

  unsigned wuerfelt() 
  { 
    unsigned r; 
    do{ r = zahlengenerator_.getNum(); }  
        while ( r &gt;= maxrandom_ ); 
    return ( r % maxzahl_ + 1 );  
  }      
};  

int main()  
{  
  const unsigned long long Serie     = 3;  
  const unsigned long long Versuche  = 30000000;  
  const unsigned limit               = 200;  
  const unsigned moeglichkeiten      = 6;  

  Wuerfel&lt;RandomTestEqual&gt;            w0a( moeglichkeiten );  
  Wuerfel&lt;RandomTestEqual&gt;            w0b( 2 );  
  Wuerfel&lt;RandomStdlib&gt;               w1a( moeglichkeiten );  
  Wuerfel&lt;RandomStdlib&gt;               w1b( 2 );
  Wuerfel&lt;Random_aus_Stdlib_geklaut&gt;  w2a( moeglichkeiten );  
  Wuerfel&lt;Random_aus_Stdlib_geklaut&gt;  w2b( 2 );

  unsigned long long H[moeglichkeiten+1];  

  for( unsigned long long i=1; i&lt;Serie+1; ++i )  
  {  
    for( unsigned j=0; j&lt;moeglichkeiten+1; ++j ) 
        H[j] = 0;  
    for( unsigned long long k=1; k&lt;Versuche+1; ++k )  
    {  
      unsigned wurf = w1a.wuerfelt(); // hier wird gewürfelt !!!!

      if( Versuche&lt;limit ) 
          std::cout &lt;&lt; wurf &lt;&lt; &quot; &quot;;  
      ++H[wurf];  
    }  

    for( unsigned c=1; c&lt;moeglichkeiten+1; ++c )  
    {  
      std::cout &lt;&lt; std::endl &lt;&lt; c &lt;&lt; &quot;: &quot; &lt;&lt; H[c] &lt;&lt; &quot; &quot; &lt;&lt; std::setprecision(7)   
                &lt;&lt; 100 * static_cast&lt;float&gt;(H[c]) / Versuche &lt;&lt; &quot; %&quot;;  
      H[0] += H[c];  
    }  
    std::cout &lt;&lt; std::endl &lt;&lt; &quot;Wuerfe insgesamt: &quot; &lt;&lt; H[0] &lt;&lt; std::endl &lt;&lt; std::endl;  
  }  
  getch();  
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1097397</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097397</guid><dc:creator><![CDATA[Erhard Henkes]]></dc:creator><pubDate>Thu, 13 Jul 2006 20:25:12 GMT</pubDate></item><item><title><![CDATA[Reply to Suche Aufgaben&#x2F;Tutorials zum Objektlebenszyklus, Vererbung... on Thu, 13 Jul 2006 20:33:09 GMT]]></title><description><![CDATA[<p>Noch was Virtuelles:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;conio.h&gt;
using namespace std;

class Teilnehmer
{ 
  private:
    string name_;
    char sex_;
  public:
    string getName() const { return name_; }
    char   getSex()  const { return sex_;  }
    Teilnehmer(){}
    Teilnehmer(string name, char sex) : name_(name), sex_(sex) {}

    virtual //kommentiere dies mal aus
    void take_the_Floor() 
    { cout &lt;&lt; &quot;Teilnehmer &quot; &lt;&lt; getName() &lt;&lt; &quot; erhaelt Floor&quot; &lt;&lt; endl; }

};

class Dozent : public Teilnehmer
{
  public:
    Dozent(string name, char sex) : Teilnehmer(name,sex){};
    void take_the_Floor() 
    { 
      string s;
      if( getSex() == 'm' ) 
          s = &quot;Dozent &quot;;
      else
          s = &quot;Dozentin &quot;;    

      cout &lt;&lt; s &lt;&lt; getName() &lt;&lt; &quot; erhaelt Floor &quot; 
           &lt;&lt; &quot;und erlaeutert Details des Stoffes.&quot; &lt;&lt; endl; 
    }
};

class Schueler : public Teilnehmer
{
  public:
    Schueler(string name, char sex) : Teilnehmer(name,sex){};    
    void take_the_Floor() 
    { 
      string s;
      if( getSex() == 'm' ) 
          s = &quot;Schueler &quot;;
      else
          s = &quot;Schuelerin &quot;;    

      cout &lt;&lt; s &lt;&lt; getName() &lt;&lt; &quot; erhaelt Floor &quot; 
           &lt;&lt; &quot;und stellt Fragen zum Unterrichtsstoff.&quot; &lt;&lt; endl; 
    }
};

void trauDich(Teilnehmer * tn)
{
    tn-&gt;take_the_Floor();
}

int main()
{
    Schueler   t1(&quot;Hagen&quot;, 'm');
    Schueler   t2(&quot;Ilonka&quot;,'w');
    Dozent     t3(&quot;Peter&quot;,'m');
    Dozent     t4(&quot;Ms X&quot;,  'w'); 

    Teilnehmer * pT[3];
    pT[0] = &amp;t1;
    pT[1] = &amp;t2;
    pT[2] = &amp;t3;
    pT[3] = &amp;t4;

    for( int i=0; i&lt;4; ++i )
        trauDich( pT[i] );

    /*
    Bedingt durch frühe Bindung legt der Compiler die Verbindung 
    zur Elementfunktion beim Übersetzen fest. 
    Es wäre aber wünschenswert, dass ein übergebenes Objekt selbst prüft, 
    welche Member-Funktion zu ihm gehört. Es kann jedoch erst zur Laufzeit des 
    Programms getestet werden, welches Objekt sich hinter dem Zeiger befindet.
    */

    getch();
}
</code></pre>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;conio.h&gt;
using namespace std;

class Person
{
  public:
    virtual // versuchsweise auskommentieren
    void geldueberweisung(float geld){ cout &lt;&lt; geld &lt;&lt; &quot; an Person &quot; &lt;&lt; endl; };
};

class Mitarbeiter : public Person
{
  public:
    void geldueberweisung(float geld){ cout &lt;&lt; geld &lt;&lt; &quot; an Mitarbeiter &quot; &lt;&lt; endl; };
};

class Kunde : public Person
{
  public:
    void geldueberweisung(float geld){ cout &lt;&lt; geld &lt;&lt; &quot; an Kunde &quot; &lt;&lt; endl; };
};

class Lieferant : public Person
{
  public:
    void geldueberweisung(float geld){ cout &lt;&lt; geld &lt;&lt; &quot; an Lieferant &quot; &lt;&lt; endl;};
};

void zahlung(Person * x, float Summe)
{
    x-&gt;geldueberweisung(Summe);
}

int main()
{
    Lieferant a;
    Kunde b;
    Mitarbeiter c,d;

    zahlung( &amp;a, 500 );
    zahlung( &amp;b, 300 );
    zahlung( &amp;c, 250 );
    zahlung( &amp;d, 170 );

    getch();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1097404</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097404</guid><dc:creator><![CDATA[Erhard Henkes]]></dc:creator><pubDate>Thu, 13 Jul 2006 20:33:09 GMT</pubDate></item><item><title><![CDATA[Reply to Suche Aufgaben&#x2F;Tutorials zum Objektlebenszyklus, Vererbung... on Thu, 13 Jul 2006 21:30:44 GMT]]></title><description><![CDATA[<p>Fehlt Dir noch etwas?</p>
<p>Exceptions sollte man auch verstehen/üben:</p>
<pre><code class="language-cpp">#include &lt;conio.h&gt;
#include &lt;iostream&gt;

int main()
{
  class irgendwas
  {
    public:
      void print() { std::cerr &lt;&lt; &quot;catch as catch can.&quot; &lt;&lt; std::endl; }
  }; 

  try 
  { 
    throw irgendwas(); 
  } 
  catch(irgendwas&amp; e) 
  { 
    e.print();
  }
  getch();
}
</code></pre>
<p>... und hier noch eine Testklasse zum Container testen:</p>
<pre><code class="language-cpp">//////////////////////////////////////
//Xint_Sonde.h
//////////////////////////////////////

#define _TEST_
#include &lt;windows.h&gt;
#include &lt;conio.h&gt;
#include &lt;iostream&gt;

/*
 0    BLACK,
 1    BLUE,
 2    GREEN,
 3    CYAN,
 4    RED,
 5    MAGENTA,
 6    BROWN,
 7    LIGHTGRAY,
 8    DARKGRAY,
 9    LIGHTBLUE,
10    LIGHTGREEN,
11    LIGHTCYAN,
12    LIGHTRED,
13    LIGHTMAGENTA,
14    YELLOW,
15    WHITE
*/

void textcolor(WORD color) 
{ 
    SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), color); 
} 

const int farbe1 =  3;
const int farbe2 = 15;

class Xint
{
private:
  int num;  
  static int countCtor;
  static int countDtor;  
  static int countCopycon;  
  static int countOpAssign;  
public:
  Xint()
  {
      #ifdef _TEST_  
      textcolor(farbe1); 
      std::cout &lt;&lt; this &lt;&lt; &quot;: &quot; &lt;&lt; &quot;ctor&quot; &lt;&lt; std::endl;  
      textcolor(farbe2); 
      #endif
      ++countCtor;
  }

 ~Xint()
  {
      #ifdef _TEST_ 
      textcolor(farbe1);  
      std::cout &lt;&lt; this &lt;&lt; &quot;: &quot; &lt;&lt; &quot;dtor&quot; &lt;&lt; std::endl;
      textcolor(farbe2);
      #endif      
      ++countDtor;
  }

  Xint(const Xint&amp; x)
  {
      #ifdef _TEST_
      textcolor(farbe1);  
      std::cout &lt;&lt; this &lt;&lt; &quot;: &quot; &lt;&lt; &quot;copycon von &quot; &lt;&lt; std::dec &lt;&lt; &amp;x &lt;&lt; std::endl;
      textcolor(farbe2);
      #endif  
      num = x.getNum();
      ++countCopycon;
  }

  Xint&amp; operator=(const Xint&amp; x)
  {
      if (&amp;x == this)
      {
          #ifdef _TEST_
          textcolor(farbe1);            
          std::cout &lt;&lt; &quot;Selbstzuweisung mit op=&quot; &lt;&lt; std::endl;
          textcolor(farbe2);
          #endif
      }
      #ifdef _TEST_
      textcolor(farbe1);
      std::cout &lt;&lt; this &lt;&lt; &quot;: &quot; &lt;&lt; &quot;op= von &quot; &lt;&lt; std::dec &lt;&lt; &amp;x &lt;&lt; std::endl; 
      textcolor(farbe2);
      #endif
      num = x.getNum();
      ++countOpAssign;
      return *this;
  }
  int getNum() const {return num;}
  void setNum(int val) {num = val;}
  static void statistik(std::ostream&amp;);
  static void reset();
};

int Xint::countCtor     = 0;
int Xint::countDtor     = 0;  
int Xint::countCopycon  = 0;  
int Xint::countOpAssign = 0;  

void Xint::statistik(std::ostream&amp; os)
{
  textcolor(farbe1);  
  os   &lt;&lt; &quot;Ctor:    &quot; &lt;&lt; countCtor    &lt;&lt; std::endl 
       &lt;&lt; &quot;Dtor:    &quot; &lt;&lt; countDtor    &lt;&lt; std::endl
       &lt;&lt; &quot;Copycon: &quot; &lt;&lt; countCopycon &lt;&lt; std::endl
       &lt;&lt; &quot;op=:     &quot; &lt;&lt; countOpAssign;   
  textcolor(farbe2);     
}    

void Xint::reset()
{
    countCtor     = 0;
    countDtor     = 0;  
    countCopycon  = 0;  
    countOpAssign = 0;  
} 

std::ostream&amp; operator&lt;&lt; (std::ostream&amp; os, const Xint&amp; x) 
{
  os &lt;&lt; x.getNum();
  return os;
}

bool operator&lt; (const Xint&amp; a, const Xint&amp; b) 
{
    return a.getNum() &lt; b.getNum(); 
}

bool operator&gt; (const Xint&amp; a, const Xint&amp; b) 
{
    return a.getNum() &gt; b.getNum(); 
}

bool operator== (const Xint&amp; a, const Xint&amp; b) 
{
    return a.getNum() == b.getNum(); 
}

bool operator!= (const Xint&amp; a, const Xint&amp; b) 
{
    return a.getNum() != b.getNum(); 
}

//////////////////////////////////////
//Xint_Sonde.cpp
//////////////////////////////////////

#include &lt;deque&gt;       
#include &lt;vector&gt;
#include &lt;list&gt;
#include &lt;algorithm&gt;    
#include &lt;iostream&gt;
#include &lt;conio.h&gt;
#include &quot;Xint_Sonde.h&quot;

using namespace std;

int main () 
{
    cout &lt;&lt; &quot;Container-Typ: &quot; &lt;&lt; &quot;vector&quot; &lt;&lt; endl;
    vector&lt;Xint&gt; ct; // Hier Containertyp tauschen
    vector&lt;Xint&gt;::iterator it; // ... und hier den Iterator anpassen

    const int N = 3;
    Xint x;

    cout &lt;&lt; endl &lt;&lt; N &lt;&lt; &quot; mal push_back (hinten anhaengen).&quot; &lt;&lt; endl;
    for(size_t i=0; i&lt;N; ++i)
    {
        x.setNum(i); 
        ct.push_back(x); 
    }
    cout &lt;&lt; endl;

    for(it=ct.begin();it!=ct.end();++it)
    {
        cout &lt;&lt; *it &lt;&lt; endl;
    } 
    cout &lt;&lt; endl;

    Xint::statistik(cout);   
    Xint::reset();
    cout &lt;&lt; endl &lt;&lt; endl;    

    cout &lt;&lt; &quot;Zahl 42 am Anfang einschieben.&quot; &lt;&lt; endl;
    x.setNum(42);
    it = ct.begin(); 
    ct.insert(it,x);
    cout &lt;&lt; endl;

    for(it=ct.begin();it!=ct.end();++it)
    {
        cout &lt;&lt; *it &lt;&lt; endl;
    } 
    cout &lt;&lt; endl;

    Xint::statistik(cout);   
    Xint::reset();
    cout &lt;&lt; endl &lt;&lt; endl;    

    cout &lt;&lt; &quot;Sortieren.&quot; &lt;&lt; endl;
    sort(ct.begin(),ct.end());
    //ct.sort();
    cout &lt;&lt; endl;

    for(it=ct.begin();it!=ct.end();++it)
    {
        cout &lt;&lt; *it &lt;&lt; endl;
    } 
    cout &lt;&lt; endl;

    Xint::statistik(cout);   
    Xint::reset();
    cout &lt;&lt; endl &lt;&lt; endl;    

    getch();
}
</code></pre>
<p>Wenn Du in OOP richtig fit werden willst, solltest Du bei Herb Sutters Guru of the Week vorbei schauen:<br />
<a href="http://www.gotw.ca/gotw/" rel="nofollow">http://www.gotw.ca/gotw/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1097414</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097414</guid><dc:creator><![CDATA[Erhard Henkes]]></dc:creator><pubDate>Thu, 13 Jul 2006 21:30:44 GMT</pubDate></item><item><title><![CDATA[Reply to Suche Aufgaben&#x2F;Tutorials zum Objektlebenszyklus, Vererbung... on Fri, 14 Jul 2006 09:54:25 GMT]]></title><description><![CDATA[<p>Vielen Dank Erhard für die ganzen Beispiele und Infos!!!</p>
<p>da weiß ich schon was ich das ganze Wochenende über zu tun habe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
ich meld mich dann wieder mit meinen vielen Fragen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>cu<br />
sven</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1097569</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1097569</guid><dc:creator><![CDATA[sventhevan]]></dc:creator><pubDate>Fri, 14 Jul 2006 09:54:25 GMT</pubDate></item></channel></rss>