<?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[HILFE bei if else :(]]></title><description><![CDATA[<p>Hallo, ich habe ein kleinen Programm in Visual Studio erstellt, wo ich zwei Objekte erzeugen kann.</p>
<p>Ausgabe im Compiler:</p>
<p>ID 1000<br />
Hersteller Mercedes<br />
Baujahr 2015<br />
Leistung 320 PS<br />
Art Cabrio<br />
Gewicht 1 Tonne</p>
<p>ID 1001<br />
Hersteller Ferari<br />
Baujahr 2015<br />
Leistung 420 PS<br />
Art Cabrio<br />
Gewicht 2 Tonnen</p>
<p>Ich möchte jett das Gewicht der beiden erstellten Objekte vergleichen und derjenige Hersteller, der weniger wiegt, bekommt einen Bonus. Was dann auch in der Konsole ausgegeben sollte. Wie mache ich das, bin am verzweifeln. <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>
<p>Zu meinem Programm, habe 3 cpp und 2 Header Dateien. Das Gewicht ist in der Klasse &quot;Pkw&quot; und der Hersteller ist in der Klasse &quot;Fahrzeuge&quot;.</p>
<p>Fahrzeuge.h</p>
<pre><code>#ifndef FAHRZEUGE_H
#define FAHRZEUGE_H

class Fahrzeuge
{
private:
	static int serial;
	unsigned int m_id;
	char* m_hersteller;
	unsigned int m_baujahr;
	unsigned int m_mleistung;

public:
	Fahrzeuge(char* hersteller, unsigned int baujahr, unsigned int mleistung);
	~Fahrzeuge();
	Fahrzeuge(Fahrzeuge &amp;otherFahrzeuge);
	Fahrzeuge &amp;operator=(Fahrzeuge &amp;otherFahrzeuge);

	//Set Methode
	void setHersteller(char* hersteller);
	void setBaujahr(unsigned int baujahr);
	void setMleistung(unsigned int mleistung);

	//Get Methode
	char* getHersteller() { return m_hersteller; }
	unsigned int getBaujahr() { return m_baujahr; }
	unsigned int getMleistung() { return m_mleistung; }

	void destroy();
	void print();

};

#endif

Fahrzeuge.cpp

#include&quot;Fahrzeuge.h&quot;
#include&lt;iostream&gt;

using namespace std;

int Fahrzeuge::serial = 1000;

Fahrzeuge::Fahrzeuge(char* hersteller, unsigned int baujahr, unsigned int mleistung) :m_id(serial++)
{
	this-&gt;m_hersteller = new char[strlen(hersteller) + 1];
	strcpy(this-&gt;m_hersteller, hersteller);
	this-&gt;m_baujahr = baujahr;
	this-&gt;m_mleistung = mleistung;
}

Fahrzeuge::~Fahrzeuge() 
{
	destroy();
}

Fahrzeuge::Fahrzeuge(Fahrzeuge &amp;otherFahrzeuge) :m_id(serial++)
{
	this-&gt;m_hersteller = new char[strlen(otherFahrzeuge.m_hersteller) + 1];
	strcpy(this-&gt;m_hersteller, otherFahrzeuge.m_hersteller);
	this-&gt;m_baujahr = otherFahrzeuge.m_baujahr;
	this-&gt;m_mleistung = otherFahrzeuge.m_mleistung;
}

Fahrzeuge &amp;Fahrzeuge::operator=(Fahrzeuge &amp;otherFahrzeuge) 
{
	if (this != &amp;otherFahrzeuge)
	{
		void destroy();
		this-&gt;m_hersteller = new char[strlen(otherFahrzeuge.m_hersteller) + 1];
		strcpy(this-&gt;m_hersteller, otherFahrzeuge.m_hersteller);
		this-&gt;m_baujahr = otherFahrzeuge.m_baujahr;
		this-&gt;m_mleistung = otherFahrzeuge.m_mleistung;
	}
	return *this;
}

void Fahrzeuge::destroy() 
{
	delete[] m_hersteller;
}

void Fahrzeuge::print() 
{
	cout &lt;&lt; &quot;ID\t\t\t: &quot; &lt;&lt; m_id &lt;&lt; endl;
	cout &lt;&lt; &quot;Hersteller\t\t: &quot; &lt;&lt; m_hersteller &lt;&lt; endl;
	cout &lt;&lt; &quot;Baujahr\t\t\t: &quot; &lt;&lt; m_baujahr &lt;&lt; endl;
	cout &lt;&lt; &quot;Motorenleistung\t\t: &quot; &lt;&lt; m_mleistung &lt;&lt; &quot; PS&quot; &lt;&lt; endl;
}

Pkw.h

#ifndef PKW_H
#define PKW_H
#include&quot;Fahrzeuge.h&quot;

class Pkw:public Fahrzeuge
{
private:
	char* m_art;
	double m_gewicht;

public:
	Pkw(char* art, double gewicht, char* hersteller, unsigned int baujahr, unsigned int mleistung);
	~Pkw();

	//Set Methode
	void setArt(char* art);
	void setGewicht(double gewicht);

	//Get Methode
	char* getArt() { return m_art; }
	double getGewicht() { return m_gewicht; }

	void printPkw();

};
#endif /* PKW_H */

Pkw.cpp

#include&quot;Pkw.h&quot;
#include&lt;iostream&gt;

using namespace std;

Pkw::Pkw(char* art, double gewicht, char* hersteller, unsigned int baujahr, unsigned int mleistung) :Fahrzeuge(hersteller, baujahr, mleistung)
{
	this-&gt;m_art = new char[strlen(art) + 1];
	strcpy(this-&gt;m_art, art);
	this-&gt;m_gewicht = gewicht;
}

Pkw::~Pkw() 
{
	delete[]m_art;
}

void Pkw::printPkw() 
{
	print();
	cout &lt;&lt; &quot;Art\t\t\t: &quot; &lt;&lt; m_art &lt;&lt; endl;
	cout &lt;&lt; &quot;Gewicht\t\t\t: &quot; &lt;&lt; m_gewicht &lt;&lt; &quot;\n&quot; &lt;&lt; endl;
}

main.cpp

#include&lt;iostream&gt;
#include&quot;Fahrzeuge.h&quot;
#include&quot;Pkw.h&quot;

using namespace std;

int main() 
{
	Pkw p1(&quot;Cabrio&quot;, 1, &quot;Mercedes&quot;, 2015, 320);
	p1.printPkw();

	Pkw p2(&quot;Limousine&quot;, 3, &quot;Bentley&quot;, 2015, 400);
	p2.printPkw();

	system(&quot;pause&quot;);
}
</code></pre>
<p>Edit durch Arcoth: Code-Tags</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/335471/hilfe-bei-if-else</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Apr 2026 18:18:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/335471.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 22 Nov 2015 15:51:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to HILFE bei if else :( on Sun, 22 Nov 2015 16:47:08 GMT]]></title><description><![CDATA[<p>Hallo, ich habe ein kleinen Programm in Visual Studio erstellt, wo ich zwei Objekte erzeugen kann.</p>
<p>Ausgabe im Compiler:</p>
<p>ID 1000<br />
Hersteller Mercedes<br />
Baujahr 2015<br />
Leistung 320 PS<br />
Art Cabrio<br />
Gewicht 1 Tonne</p>
<p>ID 1001<br />
Hersteller Ferari<br />
Baujahr 2015<br />
Leistung 420 PS<br />
Art Cabrio<br />
Gewicht 2 Tonnen</p>
<p>Ich möchte jett das Gewicht der beiden erstellten Objekte vergleichen und derjenige Hersteller, der weniger wiegt, bekommt einen Bonus. Was dann auch in der Konsole ausgegeben sollte. Wie mache ich das, bin am verzweifeln. <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>
<p>Zu meinem Programm, habe 3 cpp und 2 Header Dateien. Das Gewicht ist in der Klasse &quot;Pkw&quot; und der Hersteller ist in der Klasse &quot;Fahrzeuge&quot;.</p>
<p>Fahrzeuge.h</p>
<pre><code>#ifndef FAHRZEUGE_H
#define FAHRZEUGE_H

class Fahrzeuge
{
private:
	static int serial;
	unsigned int m_id;
	char* m_hersteller;
	unsigned int m_baujahr;
	unsigned int m_mleistung;

public:
	Fahrzeuge(char* hersteller, unsigned int baujahr, unsigned int mleistung);
	~Fahrzeuge();
	Fahrzeuge(Fahrzeuge &amp;otherFahrzeuge);
	Fahrzeuge &amp;operator=(Fahrzeuge &amp;otherFahrzeuge);

	//Set Methode
	void setHersteller(char* hersteller);
	void setBaujahr(unsigned int baujahr);
	void setMleistung(unsigned int mleistung);

	//Get Methode
	char* getHersteller() { return m_hersteller; }
	unsigned int getBaujahr() { return m_baujahr; }
	unsigned int getMleistung() { return m_mleistung; }

	void destroy();
	void print();

};

#endif

Fahrzeuge.cpp

#include&quot;Fahrzeuge.h&quot;
#include&lt;iostream&gt;

using namespace std;

int Fahrzeuge::serial = 1000;

Fahrzeuge::Fahrzeuge(char* hersteller, unsigned int baujahr, unsigned int mleistung) :m_id(serial++)
{
	this-&gt;m_hersteller = new char[strlen(hersteller) + 1];
	strcpy(this-&gt;m_hersteller, hersteller);
	this-&gt;m_baujahr = baujahr;
	this-&gt;m_mleistung = mleistung;
}

Fahrzeuge::~Fahrzeuge() 
{
	destroy();
}

Fahrzeuge::Fahrzeuge(Fahrzeuge &amp;otherFahrzeuge) :m_id(serial++)
{
	this-&gt;m_hersteller = new char[strlen(otherFahrzeuge.m_hersteller) + 1];
	strcpy(this-&gt;m_hersteller, otherFahrzeuge.m_hersteller);
	this-&gt;m_baujahr = otherFahrzeuge.m_baujahr;
	this-&gt;m_mleistung = otherFahrzeuge.m_mleistung;
}

Fahrzeuge &amp;Fahrzeuge::operator=(Fahrzeuge &amp;otherFahrzeuge) 
{
	if (this != &amp;otherFahrzeuge)
	{
		void destroy();
		this-&gt;m_hersteller = new char[strlen(otherFahrzeuge.m_hersteller) + 1];
		strcpy(this-&gt;m_hersteller, otherFahrzeuge.m_hersteller);
		this-&gt;m_baujahr = otherFahrzeuge.m_baujahr;
		this-&gt;m_mleistung = otherFahrzeuge.m_mleistung;
	}
	return *this;
}

void Fahrzeuge::destroy() 
{
	delete[] m_hersteller;
}

void Fahrzeuge::print() 
{
	cout &lt;&lt; &quot;ID\t\t\t: &quot; &lt;&lt; m_id &lt;&lt; endl;
	cout &lt;&lt; &quot;Hersteller\t\t: &quot; &lt;&lt; m_hersteller &lt;&lt; endl;
	cout &lt;&lt; &quot;Baujahr\t\t\t: &quot; &lt;&lt; m_baujahr &lt;&lt; endl;
	cout &lt;&lt; &quot;Motorenleistung\t\t: &quot; &lt;&lt; m_mleistung &lt;&lt; &quot; PS&quot; &lt;&lt; endl;
}

Pkw.h

#ifndef PKW_H
#define PKW_H
#include&quot;Fahrzeuge.h&quot;

class Pkw:public Fahrzeuge
{
private:
	char* m_art;
	double m_gewicht;

public:
	Pkw(char* art, double gewicht, char* hersteller, unsigned int baujahr, unsigned int mleistung);
	~Pkw();

	//Set Methode
	void setArt(char* art);
	void setGewicht(double gewicht);

	//Get Methode
	char* getArt() { return m_art; }
	double getGewicht() { return m_gewicht; }

	void printPkw();

};
#endif /* PKW_H */

Pkw.cpp

#include&quot;Pkw.h&quot;
#include&lt;iostream&gt;

using namespace std;

Pkw::Pkw(char* art, double gewicht, char* hersteller, unsigned int baujahr, unsigned int mleistung) :Fahrzeuge(hersteller, baujahr, mleistung)
{
	this-&gt;m_art = new char[strlen(art) + 1];
	strcpy(this-&gt;m_art, art);
	this-&gt;m_gewicht = gewicht;
}

Pkw::~Pkw() 
{
	delete[]m_art;
}

void Pkw::printPkw() 
{
	print();
	cout &lt;&lt; &quot;Art\t\t\t: &quot; &lt;&lt; m_art &lt;&lt; endl;
	cout &lt;&lt; &quot;Gewicht\t\t\t: &quot; &lt;&lt; m_gewicht &lt;&lt; &quot;\n&quot; &lt;&lt; endl;
}

main.cpp

#include&lt;iostream&gt;
#include&quot;Fahrzeuge.h&quot;
#include&quot;Pkw.h&quot;

using namespace std;

int main() 
{
	Pkw p1(&quot;Cabrio&quot;, 1, &quot;Mercedes&quot;, 2015, 320);
	p1.printPkw();

	Pkw p2(&quot;Limousine&quot;, 3, &quot;Bentley&quot;, 2015, 400);
	p2.printPkw();

	system(&quot;pause&quot;);
}
</code></pre>
<p>Edit durch Arcoth: Code-Tags</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2476559</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2476559</guid><dc:creator><![CDATA[Caroline Acosta]]></dc:creator><pubDate>Sun, 22 Nov 2015 16:47:08 GMT</pubDate></item><item><title><![CDATA[Reply to HILFE bei if else :( on Sun, 22 Nov 2015 15:55:12 GMT]]></title><description><![CDATA[<blockquote>
<p>Wie mache ich das, bin am verzweifeln. <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>
</blockquote>
<p>Wir auch, bei deinem Post.<br />
Einfach 170 Zeilen reinpasten und darauf zu hoffen, dass wir die entsprechenden Änderungen vornehmen, ist verdammt optimistisch.</p>
<p><a href="https://www.c-plusplus.net/forum/200753">Du brauchst Hilfe?</a><br />
<a href="https://www.c-plusplus.net/forum/p2454960#2454960">Wie man seinen Beitrag lesbar formatiert</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2476560</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2476560</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 22 Nov 2015 15:55:12 GMT</pubDate></item><item><title><![CDATA[Reply to HILFE bei if else :( on Sun, 22 Nov 2015 16:45:51 GMT]]></title><description><![CDATA[<p>Nutzlose und gefährliche Funktionen sind op== und copyconst in der Basisklasse. Wie man sieht, auch für wenigstens einen Datenfehler verantwortlich, nähmlich im Pkw vergessen worden, Daten an den Basisklassenkonstruktor weiterzuleiten.<br />
Außerdem std::string nehmen oder selbergebaute Stringklasse und dafür in den Klassen der Geschäftslogik die &quot;Großen Drei&quot; loswerden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2476573</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2476573</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 22 Nov 2015 16:45:51 GMT</pubDate></item></channel></rss>