<?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[Klasse]]></title><description><![CDATA[<p>Hallo Ihr,<br />
ich habe ein für mich großes Problem..<br />
Ich möchte gerne eine Klasse erstellen...in dieser Klasse soll es möglich sein den Kontostand zu erfahren und auch etwas einzuzahlen bzw. auszugeben...<br />
Jetzt habe ich mir da schon einiges zusammengereimt, aber irgendwie passt alles nicht...</p>
<p>Bräuchte ein paar nützliche Tips...<br />
Vielen Dank für eure Hilfe!</p>
<p>:xmas1:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

class Konto
{
	double kontostand;

public: 
	Konto() : kontostand(2000) {}

	void einzahlen(void);
	double auszahlen(void);
	double getKontostand(void) { return kontostand;}
};

void Konto::einzahlen(void)
{
	double einzahlwert;
	cout &lt;&lt; &quot; Geben Sie ein, wieviel Sie einzahlen wollen: &quot;;
	kontostand = kontostand + einzahlwert;

}

double Konto::auszahlen(void)
{
	double auszahlwert;
	cout &lt;&lt; &quot; Geben Sie ein, wieviel Sie abheben wollen: &quot;;
	kontostand = kontostand - auszahlwert;
	return kontostand;

}

int main()
{

	double eingabe;
	cout &lt;&lt; &quot; **** Herzlich willkommen auf Ihrem Konto ***\n\n\n&quot;;
	cout &lt;&lt; &quot; \n Moechten Sie Ihren Kontostand sehen? (j/n)&quot;;
	cin &gt;&gt; eingabe;

	Konto konto1;
	konto1.getKontostand();

	if (eingabe == 'j')
	{

		cout &lt;&lt; &quot; Ihr aktueller Kontostand betraegt: \n&quot; &lt;&lt; konto1.getKontostand() &lt;&lt; &quot;Euro&quot; &lt;&lt; endl;

	}
	if (eingabe == 'n')
	{

		cout &lt;&lt; &quot; Moechten Sie Geld ein oder auszahlen? (e/a)&quot;;
		cout &lt;&lt; &quot; Wenn Sie das Programm verlassen moechten geben \nSie bitte v ein!\n&quot;;
		cin &gt;&gt; eingabe;
	}
	 if (eingabe == 'e')
	{
		cout &lt;&lt; konto1.einzahlen();

	}
	 if (eingabe == 'a')
	{
		cout &lt;&lt; konto1.auszahlen();
	}
	 if (eingabe == 'v')
	{
		cin &gt;&gt; eingabe;
		cout &lt;&lt; &quot; *** Herzlichen Dank für Ihren Besuch *** &quot; &lt;&lt; endl;

	}
	cin.get();

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/168319/klasse</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 09:10:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/168319.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 20 Dec 2006 19:45:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Klasse on Wed, 20 Dec 2006 19:45:17 GMT]]></title><description><![CDATA[<p>Hallo Ihr,<br />
ich habe ein für mich großes Problem..<br />
Ich möchte gerne eine Klasse erstellen...in dieser Klasse soll es möglich sein den Kontostand zu erfahren und auch etwas einzuzahlen bzw. auszugeben...<br />
Jetzt habe ich mir da schon einiges zusammengereimt, aber irgendwie passt alles nicht...</p>
<p>Bräuchte ein paar nützliche Tips...<br />
Vielen Dank für eure Hilfe!</p>
<p>:xmas1:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

class Konto
{
	double kontostand;

public: 
	Konto() : kontostand(2000) {}

	void einzahlen(void);
	double auszahlen(void);
	double getKontostand(void) { return kontostand;}
};

void Konto::einzahlen(void)
{
	double einzahlwert;
	cout &lt;&lt; &quot; Geben Sie ein, wieviel Sie einzahlen wollen: &quot;;
	kontostand = kontostand + einzahlwert;

}

double Konto::auszahlen(void)
{
	double auszahlwert;
	cout &lt;&lt; &quot; Geben Sie ein, wieviel Sie abheben wollen: &quot;;
	kontostand = kontostand - auszahlwert;
	return kontostand;

}

int main()
{

	double eingabe;
	cout &lt;&lt; &quot; **** Herzlich willkommen auf Ihrem Konto ***\n\n\n&quot;;
	cout &lt;&lt; &quot; \n Moechten Sie Ihren Kontostand sehen? (j/n)&quot;;
	cin &gt;&gt; eingabe;

	Konto konto1;
	konto1.getKontostand();

	if (eingabe == 'j')
	{

		cout &lt;&lt; &quot; Ihr aktueller Kontostand betraegt: \n&quot; &lt;&lt; konto1.getKontostand() &lt;&lt; &quot;Euro&quot; &lt;&lt; endl;

	}
	if (eingabe == 'n')
	{

		cout &lt;&lt; &quot; Moechten Sie Geld ein oder auszahlen? (e/a)&quot;;
		cout &lt;&lt; &quot; Wenn Sie das Programm verlassen moechten geben \nSie bitte v ein!\n&quot;;
		cin &gt;&gt; eingabe;
	}
	 if (eingabe == 'e')
	{
		cout &lt;&lt; konto1.einzahlen();

	}
	 if (eingabe == 'a')
	{
		cout &lt;&lt; konto1.auszahlen();
	}
	 if (eingabe == 'v')
	{
		cin &gt;&gt; eingabe;
		cout &lt;&lt; &quot; *** Herzlichen Dank für Ihren Besuch *** &quot; &lt;&lt; endl;

	}
	cin.get();

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1195627</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195627</guid><dc:creator><![CDATA[Visual Newbie]]></dc:creator><pubDate>Wed, 20 Dec 2006 19:45:17 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse on Wed, 20 Dec 2006 19:49:07 GMT]]></title><description><![CDATA[<p>Fehlt doch nur noch das einlesen:</p>
<pre><code class="language-cpp">void Konto::einzahlen(void)
{
    double einzahlwert;
    cout &lt;&lt; &quot; Geben Sie ein, wieviel Sie einzahlen wollen: &quot;;
    cin &gt;&gt; einzahlwert;
    kontostand = kontostand + einzahlwert;
}
</code></pre>
<p>und</p>
<pre><code class="language-cpp">double Konto::auszahlen(void)
{
    double auszahlwert;
    cout &lt;&lt; &quot; Geben Sie ein, wieviel Sie abheben wollen: &quot;;
    cin &gt;&gt; auszahlwert;
    kontostand = kontostand - auszahlwert;
    return kontostand;
}
</code></pre>
<p>Ich frage mich nur, wie du den ganzen Rest hingekriegt hast, wenn du unten in main() weißt, wie man cin benutzt, aber oben bei den Methodendefinitionen nicht...</p>
<p>Felix :xmas2:</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1195629</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195629</guid><dc:creator><![CDATA[Phoemuex]]></dc:creator><pubDate>Wed, 20 Dec 2006 19:49:07 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse on Wed, 20 Dec 2006 20:01:47 GMT]]></title><description><![CDATA[<p>War mir nicht sicher...</p>
<p>sobald ich 'j' eingebe und enter drücker schliesst das Fenster ohne eine aktion...</p>
<p>viele warnings...z.b. das auszahlwert ohne initialisierung verwendet wurde, was heisst das genau?</p>
<p>irgendwo muss noch ein Fehler sein... :xmas1:</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1195636</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195636</guid><dc:creator><![CDATA[Visual Newbie]]></dc:creator><pubDate>Wed, 20 Dec 2006 20:01:47 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse on Wed, 20 Dec 2006 20:08:55 GMT]]></title><description><![CDATA[<p>Hmm probier mal statt cin.get() am Ende cin &gt;&gt; eingabe;</p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1195644</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195644</guid><dc:creator><![CDATA[ceplusplus]]></dc:creator><pubDate>Wed, 20 Dec 2006 20:08:55 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse on Wed, 20 Dec 2006 20:10:55 GMT]]></title><description><![CDATA[<p>das mit dem schließen, guck mal hier in die faq, bei dem problem das ein programm ncihts macht oder nur ganz kurz auftaucht. Weiterhin:</p>
<p>in main musst du char eingabe und nicht double eingabe nehmen. DOuble speichert zahlen, du willst aber buchstaben eingeben, also nimmst du char.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1195647</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195647</guid><dc:creator><![CDATA[Maxi]]></dc:creator><pubDate>Wed, 20 Dec 2006 20:10:55 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse on Wed, 20 Dec 2006 20:19:48 GMT]]></title><description><![CDATA[<p>Die Tipps waren ja schon mal hilfreich...<br />
jetzt gibt er wenigstens schon den Kontostand aus...danach is allerdings schluß...<br />
kann ich das ganze auch umschreiben?</p>
<p>Stimmt das wirklich? Oder habe ich was vergessen?</p>
<pre><code class="language-cpp">if (eingabe == 'e')
	{
		konto1.einzahlen();

	}
</code></pre>
<p>VIelen Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1195663</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195663</guid><dc:creator><![CDATA[Visual Newbie]]></dc:creator><pubDate>Wed, 20 Dec 2006 20:19:48 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse on Wed, 20 Dec 2006 20:39:57 GMT]]></title><description><![CDATA[<p>Aus Code lernt man</p>
<pre><code class="language-cpp">#include &lt;iostream&gt; 

class Konto 
{ 
    double kontostand; 

public: 
    Konto() : kontostand(2000) { }
	~Konto() { }

    void Einzahlen(); 
    void Auszahlen(); 
    double getKontostand() { return kontostand; } 
}; 

void Konto::Einzahlen() 
{ 
    double einzahlwert; 

    std::cout &lt;&lt; &quot;Geben Sie ein, wieviel Sie einzahlen wollen: &quot;;
    std::cin &gt;&gt; einzahlwert;

    kontostand += einzahlwert;
} 

void Konto::Auszahlen() 
{ 
    double auszahlwert; 

    std::cout &lt;&lt; &quot;Geben Sie ein, wieviel Sie abheben wollen: &quot;;
    std::cin &gt;&gt; auszahlwert;

    kontostand -= auszahlwert; 
} 

int main() 
{ 
	std::cout &lt;&lt; &quot; **** Herzlich willkommen auf Ihrem Konto *** &quot; &lt;&lt; std::endl &lt;&lt; std::endl; 

	char eingabe = ' ';

	Konto konto1;

    while('v' != eingabe)
	{
		std::cout &lt;&lt; std::endl &lt;&lt; &quot;&lt;s&gt; Kontostand einsehen&quot; &lt;&lt; std::endl;
		std::cout &lt;&lt; &quot;&lt;e&gt; Einzahlen&quot; &lt;&lt; std::endl;
		std::cout &lt;&lt; &quot;&lt;a&gt; Auszahlen&quot; &lt;&lt; std::endl;
		std::cout &lt;&lt; &quot;&lt;v&gt; Beenden&quot; &lt;&lt; std::endl &lt;&lt; std::endl;

		std::cin &gt;&gt; eingabe;

		switch(eingabe)
		{
		case 's':
			std::cout &lt;&lt; konto1.getKontostand() &lt;&lt; std::endl;
			break;
		case 'e':
			konto1.Einzahlen();
			break;
		case 'a':
			konto1.Auszahlen();
			break;
		case 'v':
			std::cout &lt;&lt; &quot; *** Herzlichen Dank für Ihren Besuch *** &quot; &lt;&lt; std::endl;
		default:
			break;
		}
	}

    return 0; 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1195689</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195689</guid><dc:creator><![CDATA[ceplusplus]]></dc:creator><pubDate>Wed, 20 Dec 2006 20:39:57 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse on Wed, 20 Dec 2006 20:45:17 GMT]]></title><description><![CDATA[<p>Problem erledigt...vielen Dank für eure Hilfe.. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1195698</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195698</guid><dc:creator><![CDATA[Visual Newbie]]></dc:creator><pubDate>Wed, 20 Dec 2006 20:45:17 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse on Wed, 20 Dec 2006 20:47:15 GMT]]></title><description><![CDATA[<p>Visual Newbie schrieb:</p>
<blockquote>
<pre><code class="language-cpp">double kontostand;
</code></pre>
</blockquote>
<p>Fataler Fehler. Nimm hier auf JEDEN FALL int!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1195701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195701</guid><dc:creator><![CDATA[nununun]]></dc:creator><pubDate>Wed, 20 Dec 2006 20:47:15 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse on Wed, 20 Dec 2006 21:36:18 GMT]]></title><description><![CDATA[<p>Nimm halt float.</p>
<p>Musst dann aber auch</p>
<p>Konto() : kontostand(2000.0f) {}</p>
<p>schreiben</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1195730</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195730</guid><dc:creator><![CDATA[ceplusplus]]></dc:creator><pubDate>Wed, 20 Dec 2006 21:36:18 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse on Wed, 20 Dec 2006 22:01:40 GMT]]></title><description><![CDATA[<p>Es geht hier eher darum, dass bei größeren Zahlen bei double Rundungsfehler auftreten und man deswegen (jedenfalls bei kritischen Programmen, wie bei Banken) int oder irgend einen anderen Datentyp verwendet, bei dem keine Rundungsfehler auftreten. Aber bei dem simplen Beispiel denke ich nicht, dass es wirklich viel ausmacht. Man sollte es vielleicht nur wissen, falls man später mal &quot;richtige&quot; Anwendungen schreibt...</p>
<p>Felix :xmas1: :xmas2:</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1195761</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195761</guid><dc:creator><![CDATA[Phoemuex]]></dc:creator><pubDate>Wed, 20 Dec 2006 22:01:40 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse on Wed, 20 Dec 2006 22:45:49 GMT]]></title><description><![CDATA[<p>Hallo Visual Newbie,</p>
<p>mal eine kleine Anmerkung zum Design. Es ist in der Regel von Vorteil, das Frontend und das Modell zu trennen. Das Frontend ist der Teil des Programmes, in dem Du Benuzer Eingaben erhältst und die Ausgabe machst. In obigem Fall die Konsole. Dein Model ist die Konto-Klasse.</p>
<p>Du kannst nach diesem Ansatz z. B. die Buchungs-Daten in der Main abfragen und dann erst an die Konto-Klasse übergeben. Der Code währe dann Folgender.</p>
<pre><code class="language-cpp">class Konto 
{
private:
    double kontostand; 

public: 
    Konto(void) : kontostand(2000.0L) { }
    ~Konto(void) { }

    void Einzahlen(double einzahlwert) { kontostand += einzahlwert; } 
    void Auszahlen(double auszahlwert) { kontostand -= auszahlwert; }
    double getKontostand() const { return kontostand; } 
}; 

int main() 
{ 
	std::cout &lt;&lt; &quot; **** Herzlich willkommen auf Ihrem Konto *** &quot; &lt;&lt; std::endl &lt;&lt; std::endl; 

	char eingabe = ' ';

	Konto konto1;

    while('v' != eingabe)
	{
		std::cout &lt;&lt; std::endl &lt;&lt; &quot;&lt;s&gt; Kontostand einsehen&quot; &lt;&lt; std::endl;
		std::cout &lt;&lt; &quot;&lt;e&gt; Einzahlen&quot; &lt;&lt; std::endl;
		std::cout &lt;&lt; &quot;&lt;a&gt; Auszahlen&quot; &lt;&lt; std::endl;
		std::cout &lt;&lt; &quot;&lt;v&gt; Beenden&quot; &lt;&lt; std::endl &lt;&lt; std::endl;

		std::cin &gt;&gt; eingabe;

		switch(eingabe)
		{
		case 's':
			std::cout &lt;&lt; konto1.getKontostand() &lt;&lt; std::endl;
			break;
		case 'e':
			{
			double betrag;
			std::cout &lt;&lt; &quot;Einzahlungsbetrag: &quot;;
			std::cin &gt;&gt; betrag;
			konto1.Einzahlen(betrag);
			}
			break;
		case 'a':
			{
			double betrag;
			std::cout &lt;&lt; &quot;Auszahlungsbetrag: &quot;;
			std::cin &gt;&gt; betrag;
			konto1.Auszahlen(betrag);
			break;
			}
		case 'v':
			std::cout &lt;&lt; &quot; *** Herzlichen Dank für Ihren Besuch *** &quot; &lt;&lt; std::endl;
		default:
			break;
		}
	}
}
</code></pre>
<p>Ich hoffe das hilft Dir weiter</p>
<p>Viele Grüße<br />
Knecht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1195775</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195775</guid><dc:creator><![CDATA[Knecht]]></dc:creator><pubDate>Wed, 20 Dec 2006 22:45:49 GMT</pubDate></item></channel></rss>