<?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[Brauche Hilfe]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>habe folgende Programmteile geschrieben.</p>
<pre><code>// lottoziehung.cpp

#include &quot;lotto.hpp&quot;
#include &lt;iostream&gt;
#include &lt;ctime&gt;
#include &lt;cstdlib&gt;

using namespace std;

int main() {
	Ziehungsverwaltung z1(3), z2(2);

	cout &lt;&lt; &quot;Ziehungsverwaltung z1:&quot; &lt;&lt; endl &lt;&lt; z1;
	cout &lt;&lt; &quot;Ziehungsverwaltung z2:&quot; &lt;&lt; endl &lt;&lt; z2;

	cout &lt;&lt; &quot;Setze z1=z2&quot; &lt;&lt; endl &lt;&lt; endl;
	z1 = z2;

	cout &lt;&lt; &quot;Ziehungsverwaltung z1:&quot; &lt;&lt; endl;
	cout &lt;&lt; z1;

	cout &lt;&lt; &quot;Erstelle Ziehungsverwaltung z3 aus z1 mit Copy-Konstruktor&quot; &lt;&lt; endl &lt;&lt; endl;
	Ziehungsverwaltung z3(z1);
	cout &lt;&lt; &quot;Ziehungsverwaltung z3:&quot; &lt;&lt; endl &lt;&lt; z3;

	Ziehungsverwaltung z4(2);
	cout &lt;&lt; &quot;Ziehungsverwaltung z4:&quot; &lt;&lt; endl &lt;&lt; z4;
	cout &lt;&lt; &quot;Setze z1+=z4&quot; &lt;&lt; endl &lt;&lt; endl;
	z1 += z4;
	cout &lt;&lt; &quot;Ziehungsverwaltung z1:&quot; &lt;&lt; endl &lt;&lt; z1 &lt;&lt; endl;

	cout &lt;&lt; endl;

	Ziehungsverwaltung z5(1000000);
	unsigned int tipp[] = {4,8,15,16,23,42};
	z5.gewinn(tipp,0);

/*
Erweitern Sie das Programm so, dass am Ende solange Ziehungen wiederholt werden, bis die Zahlenkombination 1, 2, 3, 5, 8, 13 mit Superzahl 0 gezogen wird. Geben
Sie die Anzahl der dafur noetigen Ziehungen aus. */

	return 0;
}
</code></pre>
<pre><code>// lotto.cpp

#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;cmath&gt;
#include &quot;lotto.hpp&quot;

using namespace std;

Ziehung::Ziehung()
{
	for(int i=0; i&lt;6; i++)
	{
		zahlen[i] = rand() % 49 + 1;
	}
}

std::ostream&amp; operator&lt;&lt;(ostream&amp; os, const Ziehung&amp; z)
{
	for(int j=0; j&lt;9; j++)
	{
		os &lt;&lt; z.zahlen[j] &lt;&lt; endl;
	}

	os &lt;&lt; &quot;Superzahl &quot; &lt;&lt; z.sz &lt;&lt; endl;

	return os;
}

Ziehungsverwaltung::Ziehungsverwaltung(unsigned int k) : n(k)
{
	p = new Ziehung[n];
	for(int i=0; i&lt;n; i++)
		p[i] = Ziehung();
}

Ziehungsverwaltung::Ziehungsverwaltung(const Ziehungsverwaltung&amp; zv)
{
	n = zv.n;
	p = new Ziehung[n];
	for(int i=0; i&lt;n; i++)
		p[i] = zv.p[i];
}

Ziehungsverwaltung::~Ziehungsverwaltung()
{
	delete[] p;
}

Ziehungsverwaltung&amp; Ziehungsverwaltung::operator=(const Ziehungsverwaltung&amp; zv)
{
	if(this != &amp;zv)
	{
		delete[] p;
		n = zv.n;
		p = new Ziehung[n];
		for(int i=0; i&lt;n; i++)
			p[i] = zv.p[i];
	}

	return (*this);
}

Ziehungsverwaltung&amp; Ziehungsverwaltung::operator+=(const Ziehungsverwaltung&amp; zv)
{
	Ziehung *tmp;
	tmp = new Ziehung[n];
	for(int i=0; i&lt;n; i++)
		tmp[i] = p[i];
	unsigned int ntmp = n;
	delete[] p;
	n += zv.n;
	p = new Ziehung[n];
	for(int j=0; j&lt;(n-zv.n); j++)
		p[j] tmp[j];
	for(int k=(n-zv.n); k&lt;n; k++)
		p[k] = zv.p[k-ntmp];
	return(*this);
}

std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const Ziehungsverwaltung&amp; zv)
{
	for(int i=0; i&lt;zv.n; i++)
		os &lt;&lt; zv.p[i] &lt;&lt; &quot; &quot;;
	return os;
}
/* Gewinnfunktion, welche einen Tipp in Form eines entsprechenden Arrays
und einer Superzahl ubergeben bekommt und fur alle durchgefuehrten Ziehungen
die Gewinnklasse fuer diesen Tipp bestimmt. Dabei soll festgehalten werden, wie oft
die jeweilige Gewinnklasse erreicht wurde und es soll eine entsprechende Uebersicht
auf cout ausgegeben werden. */

int gewinn(unsigned int tipp[6], unsigned int sz)
{
	int gewinn = 9;
	for(int i=0; i&lt;6; i++)
	{
		for(int j=0; j&lt;9; j++)
		{
			if(zahlen[i] == tipp[j])
			gew--;
		}
	}

	if((gew == 2) &amp;&amp;(sz == sz1))
	gew--;

	return gew;
}
/* Eine Methode gewinnklasse_bestimmen, welche ein Array mit den sechs Zahlen
eines Tipps sowie die Superzahl ubergeben bekommt und die Gewinnklasse fuer
diesen Tipp bei der jeweiligen Ziehung bestimmt und zurueckgibt. */

int Ziehung::gewinnklasse_bestimmen(unsigned int tipp[6], unsigned int sz1)
{
	int gew = 9;
	for(int i=0; i&lt;6; i++)
	{
		for(int j=0; j&lt;9; j++)
		{
			if(zahlen[i] == tipp[j])
			gew--;
		}
	}

	if((gew == 2) &amp;&amp; (sz == sz1))
	gew--;

	return gew;
}
</code></pre>
<p>und</p>
<pre><code>// lotto.hpp

#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;cmath&gt;

#ifndef LOTTO_HPP
#define LOTTO_HPP

class Ziehung
{
	private:
		unsigned int* zahlen;
		unsigned int sz;

	public:
		Ziehung();
		friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, const Ziehung&amp;);
		int gewinnklasse_bestimmen(unsigned int tipp[6], unsigned int sz);
};

class Ziehungsverwaltung
{
	private:
		unsigned int anzahl;
		Ziehung *ziehungen;

	public:
		Ziehungsverwaltung(unsigned int);
		Ziehungsverwaltung(const Ziehungsverwaltung&amp;);
		~Ziehungsverwaltung();

		Ziehungsverwaltung&amp; operator=(const Ziehungsverwaltung&amp;);
		Ziehungsverwaltung&amp; operator+=(const Ziehungsverwaltung&amp;);

		friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, const Ziehungsverwaltung&amp;);

		int gewinn(unsigned int tipp[6], unsigned int sz);
};
#endif
</code></pre>
<p>Mein Problem ist dass bei Dev C++ viele Fehlermeldungen rauskommen.</p>
<p>Gruß<br />
Jay</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/329525/brauche-hilfe</link><generator>RSS for Node</generator><lastBuildDate>Sun, 31 May 2026 11:05:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/329525.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 26 Nov 2014 15:10:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Brauche Hilfe on Wed, 26 Nov 2014 15:10:49 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>habe folgende Programmteile geschrieben.</p>
<pre><code>// lottoziehung.cpp

#include &quot;lotto.hpp&quot;
#include &lt;iostream&gt;
#include &lt;ctime&gt;
#include &lt;cstdlib&gt;

using namespace std;

int main() {
	Ziehungsverwaltung z1(3), z2(2);

	cout &lt;&lt; &quot;Ziehungsverwaltung z1:&quot; &lt;&lt; endl &lt;&lt; z1;
	cout &lt;&lt; &quot;Ziehungsverwaltung z2:&quot; &lt;&lt; endl &lt;&lt; z2;

	cout &lt;&lt; &quot;Setze z1=z2&quot; &lt;&lt; endl &lt;&lt; endl;
	z1 = z2;

	cout &lt;&lt; &quot;Ziehungsverwaltung z1:&quot; &lt;&lt; endl;
	cout &lt;&lt; z1;

	cout &lt;&lt; &quot;Erstelle Ziehungsverwaltung z3 aus z1 mit Copy-Konstruktor&quot; &lt;&lt; endl &lt;&lt; endl;
	Ziehungsverwaltung z3(z1);
	cout &lt;&lt; &quot;Ziehungsverwaltung z3:&quot; &lt;&lt; endl &lt;&lt; z3;

	Ziehungsverwaltung z4(2);
	cout &lt;&lt; &quot;Ziehungsverwaltung z4:&quot; &lt;&lt; endl &lt;&lt; z4;
	cout &lt;&lt; &quot;Setze z1+=z4&quot; &lt;&lt; endl &lt;&lt; endl;
	z1 += z4;
	cout &lt;&lt; &quot;Ziehungsverwaltung z1:&quot; &lt;&lt; endl &lt;&lt; z1 &lt;&lt; endl;

	cout &lt;&lt; endl;

	Ziehungsverwaltung z5(1000000);
	unsigned int tipp[] = {4,8,15,16,23,42};
	z5.gewinn(tipp,0);

/*
Erweitern Sie das Programm so, dass am Ende solange Ziehungen wiederholt werden, bis die Zahlenkombination 1, 2, 3, 5, 8, 13 mit Superzahl 0 gezogen wird. Geben
Sie die Anzahl der dafur noetigen Ziehungen aus. */

	return 0;
}
</code></pre>
<pre><code>// lotto.cpp

#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;cmath&gt;
#include &quot;lotto.hpp&quot;

using namespace std;

Ziehung::Ziehung()
{
	for(int i=0; i&lt;6; i++)
	{
		zahlen[i] = rand() % 49 + 1;
	}
}

std::ostream&amp; operator&lt;&lt;(ostream&amp; os, const Ziehung&amp; z)
{
	for(int j=0; j&lt;9; j++)
	{
		os &lt;&lt; z.zahlen[j] &lt;&lt; endl;
	}

	os &lt;&lt; &quot;Superzahl &quot; &lt;&lt; z.sz &lt;&lt; endl;

	return os;
}

Ziehungsverwaltung::Ziehungsverwaltung(unsigned int k) : n(k)
{
	p = new Ziehung[n];
	for(int i=0; i&lt;n; i++)
		p[i] = Ziehung();
}

Ziehungsverwaltung::Ziehungsverwaltung(const Ziehungsverwaltung&amp; zv)
{
	n = zv.n;
	p = new Ziehung[n];
	for(int i=0; i&lt;n; i++)
		p[i] = zv.p[i];
}

Ziehungsverwaltung::~Ziehungsverwaltung()
{
	delete[] p;
}

Ziehungsverwaltung&amp; Ziehungsverwaltung::operator=(const Ziehungsverwaltung&amp; zv)
{
	if(this != &amp;zv)
	{
		delete[] p;
		n = zv.n;
		p = new Ziehung[n];
		for(int i=0; i&lt;n; i++)
			p[i] = zv.p[i];
	}

	return (*this);
}

Ziehungsverwaltung&amp; Ziehungsverwaltung::operator+=(const Ziehungsverwaltung&amp; zv)
{
	Ziehung *tmp;
	tmp = new Ziehung[n];
	for(int i=0; i&lt;n; i++)
		tmp[i] = p[i];
	unsigned int ntmp = n;
	delete[] p;
	n += zv.n;
	p = new Ziehung[n];
	for(int j=0; j&lt;(n-zv.n); j++)
		p[j] tmp[j];
	for(int k=(n-zv.n); k&lt;n; k++)
		p[k] = zv.p[k-ntmp];
	return(*this);
}

std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const Ziehungsverwaltung&amp; zv)
{
	for(int i=0; i&lt;zv.n; i++)
		os &lt;&lt; zv.p[i] &lt;&lt; &quot; &quot;;
	return os;
}
/* Gewinnfunktion, welche einen Tipp in Form eines entsprechenden Arrays
und einer Superzahl ubergeben bekommt und fur alle durchgefuehrten Ziehungen
die Gewinnklasse fuer diesen Tipp bestimmt. Dabei soll festgehalten werden, wie oft
die jeweilige Gewinnklasse erreicht wurde und es soll eine entsprechende Uebersicht
auf cout ausgegeben werden. */

int gewinn(unsigned int tipp[6], unsigned int sz)
{
	int gewinn = 9;
	for(int i=0; i&lt;6; i++)
	{
		for(int j=0; j&lt;9; j++)
		{
			if(zahlen[i] == tipp[j])
			gew--;
		}
	}

	if((gew == 2) &amp;&amp;(sz == sz1))
	gew--;

	return gew;
}
/* Eine Methode gewinnklasse_bestimmen, welche ein Array mit den sechs Zahlen
eines Tipps sowie die Superzahl ubergeben bekommt und die Gewinnklasse fuer
diesen Tipp bei der jeweiligen Ziehung bestimmt und zurueckgibt. */

int Ziehung::gewinnklasse_bestimmen(unsigned int tipp[6], unsigned int sz1)
{
	int gew = 9;
	for(int i=0; i&lt;6; i++)
	{
		for(int j=0; j&lt;9; j++)
		{
			if(zahlen[i] == tipp[j])
			gew--;
		}
	}

	if((gew == 2) &amp;&amp; (sz == sz1))
	gew--;

	return gew;
}
</code></pre>
<p>und</p>
<pre><code>// lotto.hpp

#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;cmath&gt;

#ifndef LOTTO_HPP
#define LOTTO_HPP

class Ziehung
{
	private:
		unsigned int* zahlen;
		unsigned int sz;

	public:
		Ziehung();
		friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, const Ziehung&amp;);
		int gewinnklasse_bestimmen(unsigned int tipp[6], unsigned int sz);
};

class Ziehungsverwaltung
{
	private:
		unsigned int anzahl;
		Ziehung *ziehungen;

	public:
		Ziehungsverwaltung(unsigned int);
		Ziehungsverwaltung(const Ziehungsverwaltung&amp;);
		~Ziehungsverwaltung();

		Ziehungsverwaltung&amp; operator=(const Ziehungsverwaltung&amp;);
		Ziehungsverwaltung&amp; operator+=(const Ziehungsverwaltung&amp;);

		friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, const Ziehungsverwaltung&amp;);

		int gewinn(unsigned int tipp[6], unsigned int sz);
};
#endif
</code></pre>
<p>Mein Problem ist dass bei Dev C++ viele Fehlermeldungen rauskommen.</p>
<p>Gruß<br />
Jay</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2429702</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2429702</guid><dc:creator><![CDATA[jay82z]]></dc:creator><pubDate>Wed, 26 Nov 2014 15:10:49 GMT</pubDate></item><item><title><![CDATA[Reply to Brauche Hilfe on Wed, 26 Nov 2014 15:42:07 GMT]]></title><description><![CDATA[<p>jay82z schrieb:</p>
<blockquote>
<p>Mein Problem ist dass bei Dev C++ viele Fehlermeldungen rauskommen.</p>
</blockquote>
<p>Dein Problem ist, dass Header und die Implementierung kaum zusammenpassen. So hat z.B. Ziehungsverwaltung kein <code>n</code> und kein <code>p</code> , aber <code>ziehungen</code> und <code>anzahl</code> .</p>
<p>Die Fehlermeldungen Deines Compilers sind vielmehr die Lösung. Musst sie halt lesen.<br />
Das kann erstmal erschlagen, aber wenn Du oben anfängst und eine nach der anderen behebst, stellen sich viele auch als Folgefehler heraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2429709</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2429709</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Wed, 26 Nov 2014 15:42:07 GMT</pubDate></item></channel></rss>