<?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[Verbesserungsvorschläge]]></title><description><![CDATA[<p>Sehr geehrte Community,</p>
<p>die Aufgabe die ich zu bearbeiten habe lautet wie folgt:</p>
<p>Ich soll eine Klasse namens Rectangle erstellen.<br />
Der Output eines Objektes dieser Klasse soll length, width, area und scope sein.</p>
<p>Zu beachten soll sein :</p>
<p>Welche Funktionen können versteckt sein (Which functions can be hidden?)<br />
- Ist damit die Datenkapselung gemeint ?<br />
Welche Funktionen müssen sichtbar sein (Which functions need to be visible?)<br />
- S.o.</p>
<p>Verstehe diese zwei Punkte nicht ganz. Ich habe das jetzt mal wie folgt gemacht und würde gerne wissen ob es so richtig ist.</p>
<pre><code>class Rectangle {
private:
    float length;
    float width;
public:
    void setLength(float l);
    void setWidth(float w);
    float getLength() {return length;}
    float getWidth() {return width;}
    float calculateArea(float a, float b);
    float calculateScope(float c,float d);
};
</code></pre>
<pre><code>void Rectangle::setLength(float l){
    length=l;
}

void Rectangle::setWidth(float w){
    width=w;
}

float Rectangle::calculateArea(float a,float b){
    return a*b;
}

float Rectangle::calculateScope(float c,float d){
    return 2*c+2*d;
}

int main(){

Rectangle eins;

eins.setLength(12);
eins.setWidth(3);

eins.calculateArea(eins.getLength(),eins.getWidth());
eins.calculateScope(eins.getLength(),eins.getWidth());

cout &lt;&lt; &quot;Lenght: &quot; &lt;&lt; eins.getLength() &lt;&lt; endl;
cout &lt;&lt; &quot;Width: &quot; &lt;&lt; eins.getWidth() &lt;&lt; endl;
cout &lt;&lt; &quot;Area: &quot; &lt;&lt; eins.calculateArea(eins.getLength(),eins.getWidth()) &lt;&lt; endl;
cout &lt;&lt; &quot;Scope: &quot; &lt;&lt; eins.calculateScope(eins.getLength(),eins.getWidth()) &lt;&lt; endl;

return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/326878/verbesserungsvorschläge</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Jul 2026 02:46:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/326878.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 11 Jul 2014 11:56:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Verbesserungsvorschläge on Fri, 11 Jul 2014 11:56:12 GMT]]></title><description><![CDATA[<p>Sehr geehrte Community,</p>
<p>die Aufgabe die ich zu bearbeiten habe lautet wie folgt:</p>
<p>Ich soll eine Klasse namens Rectangle erstellen.<br />
Der Output eines Objektes dieser Klasse soll length, width, area und scope sein.</p>
<p>Zu beachten soll sein :</p>
<p>Welche Funktionen können versteckt sein (Which functions can be hidden?)<br />
- Ist damit die Datenkapselung gemeint ?<br />
Welche Funktionen müssen sichtbar sein (Which functions need to be visible?)<br />
- S.o.</p>
<p>Verstehe diese zwei Punkte nicht ganz. Ich habe das jetzt mal wie folgt gemacht und würde gerne wissen ob es so richtig ist.</p>
<pre><code>class Rectangle {
private:
    float length;
    float width;
public:
    void setLength(float l);
    void setWidth(float w);
    float getLength() {return length;}
    float getWidth() {return width;}
    float calculateArea(float a, float b);
    float calculateScope(float c,float d);
};
</code></pre>
<pre><code>void Rectangle::setLength(float l){
    length=l;
}

void Rectangle::setWidth(float w){
    width=w;
}

float Rectangle::calculateArea(float a,float b){
    return a*b;
}

float Rectangle::calculateScope(float c,float d){
    return 2*c+2*d;
}

int main(){

Rectangle eins;

eins.setLength(12);
eins.setWidth(3);

eins.calculateArea(eins.getLength(),eins.getWidth());
eins.calculateScope(eins.getLength(),eins.getWidth());

cout &lt;&lt; &quot;Lenght: &quot; &lt;&lt; eins.getLength() &lt;&lt; endl;
cout &lt;&lt; &quot;Width: &quot; &lt;&lt; eins.getWidth() &lt;&lt; endl;
cout &lt;&lt; &quot;Area: &quot; &lt;&lt; eins.calculateArea(eins.getLength(),eins.getWidth()) &lt;&lt; endl;
cout &lt;&lt; &quot;Scope: &quot; &lt;&lt; eins.calculateScope(eins.getLength(),eins.getWidth()) &lt;&lt; endl;

return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2408177</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408177</guid><dc:creator><![CDATA[Serdar262]]></dc:creator><pubDate>Fri, 11 Jul 2014 11:56:12 GMT</pubDate></item><item><title><![CDATA[Reply to Verbesserungsvorschläge on Fri, 11 Jul 2014 12:03:11 GMT]]></title><description><![CDATA[<p>Es sollen natürlich Fläche und Umfang DIESES Rechtecks berechnet werden. Also benutze auch die Attribute (oder Getter) innerhalb.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408178</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408178</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Fri, 11 Jul 2014 12:03:11 GMT</pubDate></item><item><title><![CDATA[Reply to Verbesserungsvorschläge on Fri, 11 Jul 2014 12:09:15 GMT]]></title><description><![CDATA[<p>Erstmal vielen Dank für deine Antwort.</p>
<p>Habe jedoch leider nicht verstanden was du mit &quot;DIESES Rechteck&quot; und mit &quot;innerhalb&quot; meinst. Könntest du mir das erläutern ?</p>
<p>Vielen herzlichen Dank.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408179</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408179</guid><dc:creator><![CDATA[Serdar262]]></dc:creator><pubDate>Fri, 11 Jul 2014 12:09:15 GMT</pubDate></item><item><title><![CDATA[Reply to Verbesserungsvorschläge on Fri, 11 Jul 2014 12:10:52 GMT]]></title><description><![CDATA[<pre><code>float Rectangle::calculateArea(){
    return length*width;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2408180</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408180</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Fri, 11 Jul 2014 12:10:52 GMT</pubDate></item><item><title><![CDATA[Reply to Verbesserungsvorschläge on Fri, 11 Jul 2014 12:13:55 GMT]]></title><description><![CDATA[<p>Zuerst kommen mir folgende Fragen in den Sinn:</p>
<p>Sollte ein Rechteck, dass einmal erzeugt wurde veraendert werden koennen? Das kann je nach Anwendungsfall mal mit ja oder nein beantwortet werden. Annahme: Nein.</p>
<p>Wie oft werden die einzelnen Attribute eines Rechtecks abgerufen (Laenge a, Laenge b, Umfang, Flaeche)? Das, was oft gefragt wird, sollte aus Performancegruenden schon vorberechnet sein. Annahme: Flaeche und Umfang.</p>
<p>Welche Funktionen koennen versteckt sein? Alle die, die der Anwender nicht direkt aufrufen muss.</p>
<pre><code>class Rectangle
{
public:
    Rectange(const float a, const float b) : a_(a), b_(b)
    {
        if (a&lt;0.0 || b&lt;0.0)
        {
            throw ranger_error(&quot;negative&quot;);
        }
        // pre-calculate area and circumfence as they are often used
        // (performance-critical)
        area_ = a_*b_;
        circumfence =2*(a+b);
    }

    float area()
    {
        return area_;
    }

    float circumfence()
    {
        return circumfence_;
    }

    float aLength()
    {
        return a_;
    }

    float bLength()
    {
        return b_;
    }

private:
    float a_;
    float b_;
    float area_;
    float circumfence_;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2408182</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408182</guid><dc:creator><![CDATA[archiMed]]></dc:creator><pubDate>Fri, 11 Jul 2014 12:13:55 GMT</pubDate></item><item><title><![CDATA[Reply to Verbesserungsvorschläge on Fri, 11 Jul 2014 12:19:39 GMT]]></title><description><![CDATA[<p>Vielen Dank volkard, habe jetzt verstanden was du meinst.</p>
<p>ArchiMed vielen Dank für deine hilfreiche Antwort.<br />
Das mit den Vorberechnen von Werten ist ein guter Ratschlag.</p>
<p>Ich stecke aber immernoch bei dem Wort &quot;versteckt&quot; in Bezug auf Funktionen fest, da nicht verstehe wo eine Funktion versteckt sein soll.</p>
<p>In deinem Quellcode sagt mir das Wort &quot;throw&quot; derzeit leide rnichts. Das kommt aber sicher noch <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2408184</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408184</guid><dc:creator><![CDATA[Serdar262]]></dc:creator><pubDate>Fri, 11 Jul 2014 12:19:39 GMT</pubDate></item><item><title><![CDATA[Reply to Verbesserungsvorschläge on Fri, 11 Jul 2014 12:27:42 GMT]]></title><description><![CDATA[<p>Die Aufgabe ist merkwürdig. Mir fällt im Moment keine Methode ein, die man sinnvoll <code>private</code> machen kann. Ebenso ist mir nicht ganz klar, was ein Output einer Klasse sein soll. Das Interface? Oder doch der <code>operator&lt;&lt;</code> ? Von einem Konstruktor ist auch nirgends die Rede obwohl dieser ziemlich praktisch ist. Ausserdem <code>const</code> -correctness beachten! Methoden, die nichts verändern, sollten <code>const</code> hinten dran haben, sonst wird man manchmal Mühe haben sie aufzurufen!</p>
<p>Ps.: Ist der geometrische Umfang auf Englisch nicht Perimeter? Scope ist ja allgemein der Umfang / Rahmen (nicht geometrisch) und Circumference ist afaik der Kreisumfang (sagt ja das Wort ja schon).</p>
<p>Edit: <a href="http://english.stackexchange.com/questions/87605/whats-the-difference-between-perimeter-and-circumference" rel="nofollow">Für Interessierte.</a></p>
<p>Edit 2: @TE: Hast du einen Link oder so zu der Aufgabenstellung?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408186</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408186</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Fri, 11 Jul 2014 12:27:42 GMT</pubDate></item><item><title><![CDATA[Reply to Verbesserungsvorschläge on Fri, 11 Jul 2014 12:30:35 GMT]]></title><description><![CDATA[<p>asfdlol  schrieb:</p>
<blockquote>
<p>Ps.: Ist der geometrische Umfang auf Englisch nicht Perimeter? Scope ist ja allgemein der Umfang / Rahmen (nicht geometrisch) und Circumference ist afaik der Kreisumfang (sagt ja das Wort ja schon).</p>
<p>Edit: Für Interessierte.</p>
</blockquote>
<p>Danke fuer den Hinweis!</p>
<p>asfdlol  schrieb:</p>
<blockquote>
<p>Mir fällt im Moment keine Methode ein, die man sinnvoll private machen kann</p>
</blockquote>
<p>Ist mir auch nicht eingefallen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408190</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408190</guid><dc:creator><![CDATA[ArchiMed]]></dc:creator><pubDate>Fri, 11 Jul 2014 12:30:35 GMT</pubDate></item><item><title><![CDATA[Reply to Verbesserungsvorschläge on Fri, 18 Jul 2014 16:39:07 GMT]]></title><description><![CDATA[<p>also da sich das wie eine typische Professoren aufgabe anhört würde ich die Klasse einfach etwas anders aufbauen.</p>
<pre><code>class Rectangle {
private:
    float length;
    float width;
    float area;
    flaot scope;
    void calculateArea(float a, float b);
    void calculateScope(float c,float d);
public:
    //angabe der parameter des Rechteckes über den konstruktor
    void Rectangle(float lenght, float width)    
    float getLength() {return length;}
    float getWidth() {return width;}
    float get scope() {return scope;};
    float getwidth() {return area;};    
};
</code></pre>
<p>So kanst du nun im Konstruktor alle wichtigen Elemente des rechtecks ausrechnen(lassen). Bei diesem ansatz können die beiden calculate funktionen private sein und die getFkt's müssen eh public sein.</p>
<p>mfg BabCom</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2409269</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409269</guid><dc:creator><![CDATA[BabCom]]></dc:creator><pubDate>Fri, 18 Jul 2014 16:39:07 GMT</pubDate></item><item><title><![CDATA[Reply to Verbesserungsvorschläge on Fri, 18 Jul 2014 16:46:50 GMT]]></title><description><![CDATA[<p>Bitte auf const-correctness achten.</p>
<pre><code class="language-cpp">class ...
{
...
//  ReturnType getXxx();
// =&gt;
    ReturnType getXxx() const; // Wir ändern ja nix
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2409272</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409272</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Fri, 18 Jul 2014 16:46:50 GMT</pubDate></item></channel></rss>