<?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[P.roblem s.olved :)]]></title><description><![CDATA[<p>done</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/250060/p-roblem-s-olved</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 02:22:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/250060.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 15 Sep 2009 20:41:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to P.roblem s.olved :) on Sun, 07 Feb 2010 14:41:22 GMT]]></title><description><![CDATA[<p>done</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779070</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779070</guid><dc:creator><![CDATA[c.groupe]]></dc:creator><pubDate>Sun, 07 Feb 2010 14:41:22 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 20:43:57 GMT]]></title><description><![CDATA[<p>Dann zeig mal deinen Lösungsansatz, hier macht keiner Hausaufgaben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779073</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779073</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Tue, 15 Sep 2009 20:43:57 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 20:44:50 GMT]]></title><description><![CDATA[<p>c.groupe schrieb:</p>
<blockquote>
<p>Ich bekomme die aufgabe einfach nicht hin..</p>
</blockquote>
<p>Wenn du nicht sagst, woran genau es scheitert, wird das wohl auch so bleiben. Und wenn du denkst, dass du hier einfach eine komplette Lösung vorgekaut bekommst, bist du an der falschen Adresse. Eigeninitiative ist das Zauberwort. Bei Detailfragen kannst du dich dann natürlich ans Forum wenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779075</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779075</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Tue, 15 Sep 2009 20:44:50 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 20:47:11 GMT]]></title><description><![CDATA[<p>Ja nur immer mit der ruhe,<br />
hab mich erst grad eben registriert, und wusste nicht wie schnell ihr seid <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /><br />
bin gerade am stöbern ..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779079</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779079</guid><dc:creator><![CDATA[c.groupe]]></dc:creator><pubDate>Tue, 15 Sep 2009 20:47:11 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 20:51:55 GMT]]></title><description><![CDATA[<p>Also..</p>
<pre><code class="language-cpp">/*
 * Interval.h
 *
 *  Created on: 15.09.2009
 *      Author: benn1
 */

#ifndef INTERVAL_H_
#define INTERVAL_H_

class Intervall
{
	double a,e;

	public:
		Intervall (double a, double e);
		int isEmpty();
		int contains(double wert);
		Intervall Operator_plus(intervall i);
		Intervall Operator_minus();

};

#endif /* INTERVAL_H_ */
</code></pre>
<p>und</p>
<pre><code class="language-cpp">/*
 * Intervall.cpp
 *
 *  Created on: 15.09.2009
 *      Author: benn1
 */

#include &quot;Intervall.h&quot;
#include &lt;iostream.h&gt;
using namespace std;

Intervall::Intervall(double a, double e)
{
	if (isEmpty != 0)
	{
		this -&gt;a = a;
		this -&gt;e = e;

	}
	else
	{
		cerr &lt;&lt; &quot;Leeres Intervall&quot;;
		this -&gt;a = 0;
		this -&gt;e = 0;
	}

}

int Intervall::isEmpty()
{
	if (a &gt; e)
	{
		cout &lt;&lt; &quot;Intervall enthält keine Werte: -&gt; leeres Intervall&quot;;
		return 1;
	}
	else
	{
		return 0;
	}
}

int Intervall::contains(double wert)
{
	if ((wert &gt;= a) &amp;&amp; (wert &lt; e))
	{
		return 1;
		cout &lt;&lt; &quot;Wert liegt innerhalb des Intervalls&quot;;
	}
	else
	{
		return 0;
		cout &lt;&lt; &quot;Wert liegt außerhalb des Intervalls&quot;;
	}
}
</code></pre>
<p>gut in der main ist noch nicht viel ..</p>
<pre><code class="language-cpp">/*
 * main.cpp
 *
 *  Created on: 15.09.2009
 *      Author: benn1
 */

#include &quot;Intervall.h&quot;
#include &lt;iostream.h&gt;
using namespace std;

int main()
{
	Intervall v1(0,5), v2(6,20), v3(3,10);

	wert = 2;
	contains(wert);
}
</code></pre>
<p>soweit so gut..<br />
kann man das überhaupt so machen ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779088</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779088</guid><dc:creator><![CDATA[c.groupe]]></dc:creator><pubDate>Tue, 15 Sep 2009 20:51:55 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 21:02:15 GMT]]></title><description><![CDATA[<p>Sorry, aber noch immer fehlt eine konkrete Fragestellung.</p>
<p>Beim Überfliegen ist mir schonmal Folgendes aufgefallen:</p>
<pre><code class="language-cpp">return 1;
        cout &lt;&lt; &quot;Wert liegt innerhalb des Intervalls&quot;;
</code></pre>
<p>Du springst hier mit return aus der Funktion raus. Das folgende Statement wird also nie ausgeführt. Sicher nicht in deinem Sinne.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779105</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779105</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Tue, 15 Sep 2009 21:02:15 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 21:07:39 GMT]]></title><description><![CDATA[<p>stimmt.. gut ist gefixt, aber das ist auch nicht grad mein problem <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="🙂"
    /></p>
<p>wir haben einfach keinen plan wie man die operator richtig aufruft und benutzt..</p>
<pre><code class="language-cpp">class Name
{
   ....

   Datentyp operator+(argumentliste);
}
</code></pre>
<p>bekomms irgendwie nicht gebacken .. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":/"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779109</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779109</guid><dc:creator><![CDATA[c.groupe]]></dc:creator><pubDate>Tue, 15 Sep 2009 21:07:39 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 21:10:44 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">/*
 * Interval.h
 *
 *  Created on: 15.09.2009
 *      Author: c.groupe
 */

#ifndef INTERVAL_H_
#define INTERVAL_H_

class Intervall
{
	double a,e;
	int wert[5];

	public:
		Intervall (double a, double e);
		int isEmpty();
		int contains(double wert);
		Intervall operator+();
		Intervall operator-();

};

#endif /* INTERVAL_H_ */
</code></pre>
<p>so soweit sogut ..<br />
ich weiß dennoch nicht wie ich damit umgehen soll,<br />
ich mein, ich hab ja keine felder, ich soll doch nur mit den grenzen arbeiten..<br />
wie mach ich das dann mit dem zweiten feld ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779115</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779115</guid><dc:creator><![CDATA[c.groupe]]></dc:creator><pubDate>Tue, 15 Sep 2009 21:10:44 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 21:13:58 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">Intervall operator+(const Intervall&amp; other);

... So wird das dann verwendet:
Intervall i1, i2;
Intervall i3 = i1 + i2;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1779117</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779117</guid><dc:creator><![CDATA[lalilo]]></dc:creator><pubDate>Tue, 15 Sep 2009 21:13:58 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 21:14:48 GMT]]></title><description><![CDATA[<p>Auf dieser Seite gibts einen <a href="http://magazin.c-plusplus.net/artikel/%DCberladung%20von%20Operatoren%20in%20CPlusPlus%20%28Teil%201%29" rel="nofollow">Artikel zur Operatorüberladung</a>, der eine gute Einführung in die Thematik liefert und sowohl syntaktische als auch stilistische Aspekte anspricht. Zum Beispiel steht dort, dass man den binären <code>operator+</code> im Allgemeinen global deklarieren sollte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779118</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779118</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 15 Sep 2009 21:14:48 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 21:14:47 GMT]]></title><description><![CDATA[<p>Aha, deine Frage ist also, wie man Operatoren überlädt? Also das mit dem Fragenstellen musst du echt noch üben... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Lies dir das hier mal durch: <a href="http://magazin.c-plusplus.net/artikel/%DCberladung%20von%20Operatoren%20in%20CPlusPlus%20%28Teil%201%29" rel="nofollow">http://magazin.c-plusplus.net/artikel/�berladung von Operatoren in CPlusPlus (Teil 1)</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779120</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779120</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Tue, 15 Sep 2009 21:14:47 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 21:19:40 GMT]]></title><description><![CDATA[<p>tu mir ma pls den gefallen und schreib die aufgabenstellung hier hin - aus *.jpg`s kann ich nich ganz so gut copy&amp;pasten^^<br />
und dann beschreib ma pls, was für dich ein leeres intervall ist und dann noch mal, was du im konstruktor machen willst - da fehlt mindestens noch ein paar Klammern hinter isEmpty - was btw den rückgabewert bool haben sollte, wenn ichs richtig gelesen habe.<br />
dein ctor hat so und so undefiniertes verhalten zur folge...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779126</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779126</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Tue, 15 Sep 2009 21:19:40 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 21:25:32 GMT]]></title><description><![CDATA[<p>gut das hab ich grad auch rausgekommen, danke für die hilfe.<br />
aber ich muss doch zwei intervalle damit verarbeiten oder ist das nun ein denkfehler meinerseits ?</p>
<pre><code class="language-cpp">Intervall operator+(const Intervall&amp; i1);
</code></pre>
<p>geht</p>
<p>und</p>
<pre><code class="language-cpp">Intervall operator+(const Intervall&amp; i1, const Intervall&amp; i2);
</code></pre>
<p>will er nicht..<br />
oder brauch ich das garnicht und nehme gleich i3 ?<br />
und definiere i3 = i1 + i2 ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779132</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779132</guid><dc:creator><![CDATA[c.groupe]]></dc:creator><pubDate>Tue, 15 Sep 2009 21:25:32 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 21:31:02 GMT]]></title><description><![CDATA[<p>Lies bitte den Artikel, das sind wirklich Grundlagen. Bist du auch sicher, dass es klug ist, für Intervallvereinigung das Plus zu verwenden? Implementierst du das kommutativ? Denke einfach an den verwirrten Anwender, der sich mit der Bedeutung zurechtfinden muss (und wenn das nur du selbst bist).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779137</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779137</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 15 Sep 2009 21:31:02 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 21:29:16 GMT]]></title><description><![CDATA[<p>c.groupe schrieb:</p>
<blockquote>
<pre><code class="language-cpp">Intervall operator+(const Intervall&amp; i1);
</code></pre>
<p>geht</p>
<p>und</p>
<pre><code class="language-cpp">Intervall operator+(const Intervall&amp; i1, const Intervall&amp; i2);
</code></pre>
<p>will er nicht..</p>
</blockquote>
<p>Das kommt darauf an, wo du das hinschreibst...<br />
Entweder ist operator+ ein Klassenmember, dann</p>
<pre><code class="language-cpp">class Intervall {
  public:
  Intervall operator+(const Intervall&amp; other);
};
</code></pre>
<p>Oder eben global:</p>
<pre><code class="language-cpp">class Intervall
{
  // Methoden
};

Intervall operator+( const Intervall&amp; i1, const Intervall&amp; i2);
</code></pre>
<p>Aber lies dir doch endlich den Artikel durch...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779139</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779139</guid><dc:creator><![CDATA[lodiladi]]></dc:creator><pubDate>Tue, 15 Sep 2009 21:29:16 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 21:38:07 GMT]]></title><description><![CDATA[<p>okay der artikel ist echt nicht schlecht ..</p>
<p>also das ist schonmal meine header datei:</p>
<pre><code class="language-cpp">/*
 * Interval.h
 *
 *  Created on: 15.09.2009
 *      Author: c.groupe
 */

#ifndef INTERVAL_H_
#define INTERVAL_H_

class Intervall
{
	double a,e;
	int wert[5];

	public:
		Intervall (double a, double e);
		int isEmpty();
		int contains(double wert);
		const Intervall Intervall::plus(Intervall const&amp; i2) const;
		const Intervall Intervall::minus(Intervall const&amp; i2) const;

};

#endif /* INTERVAL_H_ */
</code></pre>
<p>in der Intervall.cpp<br />
hab ichs nun so eingebunden..</p>
<pre><code class="language-cpp">const Intervall operator+(Intervall const&amp; i1, Intervall const&amp; i2)
{
	return i1.plus(i2);
}

const Intervall operator-(Intervall const&amp; i1, Interval const&amp; i2)
{
	return i2.minus(i2);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1779148</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779148</guid><dc:creator><![CDATA[c.groupe]]></dc:creator><pubDate>Tue, 15 Sep 2009 21:38:07 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 21:41:43 GMT]]></title><description><![CDATA[<p>Hast ein paar Fehler, sieht aber prinzipiell nach einem guten Ansatz aus.</p>
<p>Erstmal Kritik:</p>
<pre><code class="language-cpp">#include &quot;Intervall.h&quot;
#include &lt;iostream.h&gt;  // iostream.h ist kein Standardheader
using namespace std;

Intervall::Intervall(double a, double e)
{
/* Zwei Fehler: 
   1) Programmiertechnisch: isEmpty benutzt this-&gt;a und this-&gt;e, diese werden aber erst hier gesetzt
   2) Progrmmlopgik: Das Intervall [0,0] ist nicht leer, sondern enthält die 0
*/
    if (isEmpty != 0)
    {
        this -&gt;a = a;
        this -&gt;e = e;

    }
    else
    {
        cerr &lt;&lt; &quot;Leeres Intervall&quot;;
        this -&gt;a = 0;
        this -&gt;e = 0;
    }

}

int Intervall::isEmpty()  // const correctness nicht beachtet
{
    if (a &gt; e)
    {
/* Hier überschreitet die Methode ihre vorgesehenen Kompetenzen. Sie soll 
nichts ausgeben, sondern nur wahr oder falsch zurückgeben. Ansonsten richtig, 
wenn auch ziemlich lang ausgeschrieben.
*/
        cout &lt;&lt; &quot;Intervall enthält keine Werte: -&gt; leeres Intervall&quot;;
        return 1;
    }
    else
    {
        return 0;
    }
}

int Intervall::contains(double wert)  // const correctness nicht beachtet
{
/* gleiche Kritik wie bei isEmpty */

    if ((wert &gt;= a) &amp;&amp; (wert &lt; e))
    {
        return 1;
        cout &lt;&lt; &quot;Wert liegt innerhalb des Intervalls&quot;;
    }
    else
    {
        return 0;
        cout &lt;&lt; &quot;Wert liegt außerhalb des Intervalls&quot;;
    }
}
</code></pre>
<p>Ein Verbesserungvorschlag:</p>
<pre><code class="language-cpp">#include &quot;Intervall.h&quot;

Intervall::Intervall(const double &amp;a, const double &amp;e): a(a), e(e)
{
/* Initialisierungslisten sind hier die bessere Lösung. Es interessiert in den 
anderen Programmteilen ja gar nicht, ob a oder e größer ist. Falls trotzdem 
eine Prüfung stattfinden soll, kann man nun auch this-&gt;a und this-&gt;e verwenden,
da sie schon initialisiert wurden. Sinnvoll wäre es zum Beispiel für das leere 
Intervall a sehr groß und e sehr klein zu setzen. */
}

bool Intervall::isEmpty() const   // bool ist hier angemessener als int.
{
return (a &gt;= e);
/* So kurz kann man sich fassen. Kleine verbesserung: a darf nun auch gleich e sein (Intervall enthält nur 1 Element)
*/
}

bool Intervall::contains(const double &amp; wert) const
{
return ((wert &gt;= a) &amp;&amp; (wert &lt; e));
/* Siehe oben */
}
</code></pre>
<p>Was die Operatorüberladung angeht: Deiner Deklaration im Header nach zu schließen, weißt du nicht, was es mit Operatorüberladung auf sich hat. Das musst du dir angucken, um das weitere zu verstehen. Da in der Aufgabenstellung nur die Implementierung von Operator + verlangt wird, gebe ich dir als Beispiel mal den Operator minus. Ich werde aber hier nicht Operatorüberladung vollständig diskutieren, da musst du dir mal eine gute Beschreibung suchen (zum Beispiel den Artikel im Thread &quot;Neue Artikel zu C++ im Magazin&quot;)</p>
<pre><code class="language-cpp">const Intervall Intervall::operator-(const Intervall &amp;i, const Intervall &amp;j){
/* Nun ist es doch wichtig, ob die Intervalle eventuell leer sind. Das hätte 
wohl doch besser im Konstruktor abgefangen werden müssen. Da ich das nicht 
gemacht habe, habe ich nun mehr Mühe. Du kannst das süäter sicherlich besser :-)
*/
if (i.isEmpty()) return Intervall(j.a,j.e);
if (j.isEmpty()) return Intervall(i.a,i.e);
/* Ok, alle Sonderfälle erledigt, jetzt geht es richtig los: */
double max_a = (i.a &gt; j.a) ? i.a : j.a;
double min_e = (i.e &lt; j.e) ? i.e : j.e;
return Intervall(max_a,min_e);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1779152</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779152</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 15 Sep 2009 21:41:43 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 21:44:53 GMT]]></title><description><![CDATA[<p>sry, dass ich jz wieder HAs mach, aber die lange Weile... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";D"
      alt="😉"
    /></p>
<p>ungetestet (und unvollständig):</p>
<p>Intervall -&gt; 2 Werte. Kommawerte -&gt; double oder float</p>
<pre><code class="language-cpp">struct interval
{
private:
   float lower_bound;
   float upper_bound;
};
</code></pre>
<p>beim Instanzieren (-&gt; Konstruktor) werden 2 Parameter angegeben (-&gt; interval(float left, float right)). wenn der rechte kleiner ist, als der linke soll ein leeres interval angelegt werden:</p>
<pre><code class="language-cpp">struct interval
{
private:
  float lower_bound;
  float upper_bound;
public:
  interval(float lower, float upper)
  :  lower_bound(lower),
     upper_bound(upper)
  {
    if(lower_bound &gt; upper_bound)
      upper_bound = lower_bound;
  }
};
</code></pre>
<p>Die Methode isEmpty gibt zurück, ob ein Intervall keine Werte beinhalten kann(ob es ein leeres Intervall ist):</p>
<pre><code class="language-cpp">struct interval
{
private:
  float lower_bound;
  float upper_bound;
public:
  interval(float lower, float upper)
  :  lower_bound(lower),
     upper_bound(upper)
  {
    if(lower_bound &gt; upper_bound)
      upper_bound = lower_bound;
  }

  bool isEmpty() const //verändert nichts am objekt
  {
    return lower_bound &gt; upper_bound;
  }
};
</code></pre>
<p>oh - das haben wir im konstruktor schon mal verwendet:</p>
<pre><code class="language-cpp">struct interval
{
private:
  float lower_bound;
  float upper_bound;
public:
  interval(float lower, float upper)
  :  lower_bound(lower),
     upper_bound(upper)
  {
    if(isEmpty())
      upper_bound = lower_bound;
  }

  bool isEmpty() const //verändert nichts am objekt
  {
    return lower_bound &gt; upper_bound;
  }
};
</code></pre>
<p>Die Methode contains kontrolliert, ob ein gegebener Wert (-&gt;contains(float value)). rückgabewert ist true oder false -&gt; bool contains(float value)<br />
auch contains verändert wieder nichts an unserem objekt:</p>
<pre><code class="language-cpp">struct interval
{
private:
  float lower_bound;
  float upper_bound;
public:
  interval(float lower, float upper)
  :  lower_bound(lower),
     upper_bound(upper)
  {
    if(isEmpty())
      upper_bound = lower_bound;
  }

  bool isEmpty() const //verändert nichts am objekt
  {
    return lower_bound &gt; upper_bound;
  }

  bool contains(float value) const
  {
    return (lower_bound &lt;= value) &amp;&amp; (value &lt;= upper_bound);
  }
};
</code></pre>
<p>etc...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779156</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779156</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Tue, 15 Sep 2009 21:44:53 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Wed, 16 Sep 2009 09:18:52 GMT]]></title><description><![CDATA[<p>unskilled schrieb:</p>
<blockquote>
<p>tu mir ma pls den gefallen und schreib die aufgabenstellung hier hin - aus *.jpg`s kann ich nich ganz so gut copy&amp;pasten^^<br />
und dann beschreib ma pls, was für dich ein leeres intervall ist und dann noch mal, was du im konstruktor machen willst - da fehlt mindestens noch ein paar Klammern hinter isEmpty - was btw den rückgabewert bool haben sollte, wenn ichs richtig gelesen habe.<br />
dein ctor hat so und so undefiniertes verhalten zur folge...</p>
<p>bb</p>
</blockquote>
<p>habs selbst nur als jpg daher wirds wohl nicht, aber wenns nicht geht ist auch nicht schlimm.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779157</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779157</guid><dc:creator><![CDATA[c.groupe]]></dc:creator><pubDate>Wed, 16 Sep 2009 09:18:52 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 21:54:21 GMT]]></title><description><![CDATA[<p>wow ihr seit ja echt spitze, ich muss mir das aber nun weiter mal in ruhe anschauen, kann es echt nicht so schnell nachvollziehen, also nicht sauer sein, wenn ich nicht gleich antworte. dennoch vielen dank schonmal an alle..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779164</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779164</guid><dc:creator><![CDATA[c.groupe]]></dc:creator><pubDate>Tue, 15 Sep 2009 21:54:21 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 22:35:57 GMT]]></title><description><![CDATA[<p>nun hab ich noch ne frage beim inizialisieren..</p>
<p>warum kann ich die operatoren nur so initialisieren, dass 0 oder 1 argument übergeben wird ?</p>
<p>also so</p>
<pre><code class="language-cpp">const Intervall Intervall::minus(Intervall const &amp;j) const;
</code></pre>
<p>und nicht so</p>
<pre><code class="language-cpp">const Intervall Intervall::operator-(const Intervall &amp;i, const Intervall &amp;j);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1779199</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779199</guid><dc:creator><![CDATA[c.groupe]]></dc:creator><pubDate>Tue, 15 Sep 2009 22:35:57 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 22:59:15 GMT]]></title><description><![CDATA[<blockquote>
<p>operatoren nur so initialisieren, dass 0 oder 1 argument</p>
</blockquote>
<p>1. definieren<br />
2. lies den ******* artikel! aber tip: es gibt nur 2 seiten und *this ist die eine...</p>
<p>bb</p>
<p>edit:<br />
hier, fertiglösung:</p>
<pre><code class="language-cpp">#include &lt;algorithm&gt;

template&lt;typename T&gt;
struct interval
{
private:
	T lower_bound;
	T upper_bound;
public:
	interval(const T &amp;lower, const T &amp;upper)
	:	lower_bound(lower),
		upper_bound(upper)
	{
		if(isEmpty())
			upper_bound = lower_bound;
	}

	bool isEmpty() const //&quot;Die Methode isEmpty gibt an, ob ein Intervall keine Werte enthalten kann&quot;
	{	//[x, x] kann nicht keine Werte enthalten, da x dazu gehört
		return lower_bound &gt; upper_bound;
	}

	bool contains(const T &amp;value) const
	{
		return (value &lt;= lower_bound) &amp;&amp; (value &lt;= upper_bound);
	}

	interval operator+ (const interval &amp;other) const
	{
		T lower = std::min(lower_bound, other.lower_bound);
		T upper = std::max(upper_bound, other.upper_bound);
		return interval(lower, upper);
	}

	interval opertor- (const interval &amp;other) const
	{
		T lower = std::max(lower_bound, other.lower_bound);
		T upper = std::min(upper_bound, other.upper_bound);
		return interval(lower, upper);
	}
};
</code></pre>
<p>allein für die Formulierung des Verhaltens der isEmpty()-Fkt gehört der Aufgabensteller verprügelt - hat mich mehr Zeit gekostet, darüber nachzudenken, was ein leeres abgeschlossenes Intervall sein sollte als den Rest zu tippen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779208</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779208</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Tue, 15 Sep 2009 22:59:15 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 22:55:19 GMT]]></title><description><![CDATA[<p>c.groupe schrieb:</p>
<blockquote>
<p>nun hab ich noch ne frage beim inizialisieren..</p>
<p>warum kann ich die operatoren nur so initialisieren, dass 0 oder 1 argument übergeben wird ?</p>
<p>also so</p>
<pre><code class="language-cpp">const Intervall Intervall::minus(Intervall const &amp;j) const;
</code></pre>
<p>und nicht so</p>
<pre><code class="language-cpp">const Intervall Intervall::operator-(const Intervall &amp;i, const Intervall &amp;j);
</code></pre>
</blockquote>
<p>Ups, da hatte ich einen kleinen Schreibfehler bei meinem Beispiel. Wenn man einen binären Operator als Klassenmethode implementiert, kann er nur ein Argument nehmen, die linke Seite ist dann &quot;this&quot;. Will man die Variante mit zwei Argumenten verwenden, muss man den Operator als freie Funktion überladen. Die Pros und Contras beider Methoden kannst du in guten Texten zum Thema nachlesen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779216</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779216</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 15 Sep 2009 22:55:19 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Tue, 15 Sep 2009 22:55:34 GMT]]></title><description><![CDATA[<p>ist ja gut <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> ..</p>
<p>gut werde ich dann machen, wird also meine bett lektüre!<br />
wünsche allen eine gute nacht, und bis nacher <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779217</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779217</guid><dc:creator><![CDATA[c.groupe]]></dc:creator><pubDate>Tue, 15 Sep 2009 22:55:34 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Wed, 16 Sep 2009 06:47:12 GMT]]></title><description><![CDATA[<p>Kurze anmerkung:</p>
<p>unskilled  schrieb:</p>
<blockquote>
<pre><code class="language-cpp">bool contains(const T &amp;value) const
    {
        return (value &lt;= lower_bound) &amp;&amp; (value &lt;= upper_bound);
    }
</code></pre>
</blockquote>
<p>müsste es da nicht eher</p>
<pre><code class="language-cpp">return (value   &gt;=   lower_bound) &amp;&amp; (value &lt;= upper_bound);
</code></pre>
<p>heißen, da ja geprüft werden soll, ob der Wert im Intervall ist ....</p>
<p>Gruß Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779557</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779557</guid><dc:creator><![CDATA[varginator]]></dc:creator><pubDate>Wed, 16 Sep 2009 06:47:12 GMT</pubDate></item><item><title><![CDATA[Reply to P.roblem s.olved :) on Wed, 16 Sep 2009 09:42:31 GMT]]></title><description><![CDATA[<p>Und die Zeilen 14-15 müssen in unskilled code auch noch weg <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Nexus schrieb:</p>
<blockquote>
<p>Bist du auch sicher, dass es klug ist, für Intervallvereinigung das Plus zu verwenden? Implementierst du das kommutativ?</p>
</blockquote>
<p>Vereinigung ist kommutativ. Trotzdem ist es natürlich etwas merkwürdig dafür operator+ verwenden zu wollen..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1779666</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1779666</guid><dc:creator><![CDATA[life]]></dc:creator><pubDate>Wed, 16 Sep 2009 09:42:31 GMT</pubDate></item></channel></rss>