<?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[Probleme bei Programm mit pointer, array und struct]]></title><description><![CDATA[<p>Hallo Forum,<br />
ich bin neu hier, meine C++-Kenntnisse sind sehr beschränkt und ich habe auch gleich eine Frage (deswegen habe ich mich angemeldet):<br />
Ich schreibe zur Zeit ein Programm, das Bauteile 'Verwalten' soll. Jedes Bauteil wird durch die Eigenschaften Name, Lieferant, Preis und Anzahl charakarisiert.<br />
Folgenden Code habe ich bis jetzt zusammengewurschtelt:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;conio.h&gt; 
#include &lt;string&gt;
#include &lt;iomanip&gt;

using namespace std;

#define ANZAHL 2

struct Bauteil{
    string name;
	string lieferant;
	double preis, anzahl;
};

Bauteil *pMyStruct = new Bauteil[ANZAHL];

void eingabe(){
	cout&lt;&lt;&quot;Wieviele Bauteile moechten Sie hinzufuegen? &quot;;
	int hin;
	cin&lt;&lt;hin;
	cout&lt;&lt;endl;
	for(unsigned int index = 1; index &lt;= hin; index++){
		cout&lt;&lt;&quot;Das &quot;&lt;&lt;index&lt;&lt;&quot;. Bauteil: Name, Lieferant, Preis, Anzahl? &quot;;
		string na, li;
		double pr, an;
		cin&gt;&gt;na&gt;&gt;li&gt;&gt;pr&gt;&gt;an;
		pMyStruct[index-1].name = na;
		pMyStruct[index-1].lieferant = li;
		pMyStruct[index-1].preis = pr;
		pMyStruct[index-1].anzahl = an;
    }
}

void ausgabe(){
	cout&lt;&lt;endl&lt;&lt;left&lt;&lt;setw(12)&lt;&lt;&quot;Bauteilname&quot;&lt;&lt;setw(12)&lt;&lt;&quot;Lieferant&quot;&lt;&lt;setw(12)&lt;&lt;&quot;Preis&quot;&lt;&lt;setw(12)&lt;&lt;&quot;Anzahl&quot;&lt;&lt;endl;
	for(unsigned int index = 1; index &lt;= ANZAHL; index++){
		cout&lt;&lt;left&lt;&lt;setw(12)&lt;&lt;pMyStruct[index-1].name&lt;&lt;setw(12)&lt;&lt;pMyStruct[index-1].lieferant&lt;&lt;fixed&lt;&lt;setprecision(2)&lt;&lt;setw(12)&lt;&lt;pMyStruct[index-1].preis&lt;&lt;
        setw(12)&lt;&lt;pMyStruct[index-1].anzahl&lt;&lt;endl;  
	}
}

int main(){
	delete [] pMyStruct;	
	char wahl;
	int i=1;
	do{
		cout&lt;&lt;endl&lt;&lt;endl&lt;&lt;&quot;* * * * Programm zur Verwaltung von Bauteilen * * * *&quot;&lt;&lt;endl&lt;&lt;endl;
		cout&lt;&lt;&quot;Was moechten Sie machen?&quot;&lt;&lt;endl;
		cout&lt;&lt;&quot;1. Bauteil (h)inzufuegen!&quot;&lt;&lt;endl;
		cout&lt;&lt;&quot;2. Bauteilliste (a)nzeigen!&quot;&lt;&lt;endl; 
		cout&lt;&lt;&quot;3. Programm (b)eenden! HA!&quot;&lt;&lt;endl;
		cout&lt;&lt;&quot;h, a oder b? &quot;;
		cin&gt;&gt;wahl;
		cout&lt;&lt;endl;
		getchar();
		switch(wahl){
			case 'h': 
				eingabe();
				break;
			case 'a': 
				ausgabe();
				break;
			case 'b': 
				i=0;
				break;
			default:
				cout&lt;&lt;&quot;Falsche Eingabe&quot;;
				break;
		}
	}while (i!=0); 

	//eingabe();
	//ausgabe();
	getch(); 
	return 0;
}
</code></pre>
<p>Wie ihr sehen könnt, bestimme ich gleich am Anfang mit</p>
<pre><code class="language-cpp">#define ANZAHL 2
</code></pre>
<p>wieviele Bauteile man hinzufügen soll/muss/darf.</p>
<p>Genau da liegt mein Problem, das möchte ich ändern.<br />
Man soll beliebig viele Bauteile der Liste hinzufügen können. Also man wird im 'Hauptmenu' gefragt, was man möchte. Gibt man 'Bauteil hinzufuegen' an, kommt man zu einer Eingabemaske und fügt eins hinzu. Danach springt man wieder ins 'Hauptmenu'. Nun kann man erneut 'Bauteil hinzufuegen' anwaehlen. Dieses Bauteil wird dann der vorhandenen Liste angefuegt. Das soll 'beliebig oft' funktionieren.</p>
<p>Wie muss ich da ran gehen?</p>
<p>Das wars erst mal von meiner Seite. Ich hoffe ihr versteht (einigermaßen) mein Problem und könnt mir helfen. Bei Fragen: fragen!</p>
<p>Gruß von mir!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/175267/probleme-bei-programm-mit-pointer-array-und-struct</link><generator>RSS for Node</generator><lastBuildDate>Sat, 19 Sep 2026 01:31:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/175267.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 08 Mar 2007 16:53:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Probleme bei Programm mit pointer, array und struct on Thu, 08 Mar 2007 16:53:18 GMT]]></title><description><![CDATA[<p>Hallo Forum,<br />
ich bin neu hier, meine C++-Kenntnisse sind sehr beschränkt und ich habe auch gleich eine Frage (deswegen habe ich mich angemeldet):<br />
Ich schreibe zur Zeit ein Programm, das Bauteile 'Verwalten' soll. Jedes Bauteil wird durch die Eigenschaften Name, Lieferant, Preis und Anzahl charakarisiert.<br />
Folgenden Code habe ich bis jetzt zusammengewurschtelt:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;conio.h&gt; 
#include &lt;string&gt;
#include &lt;iomanip&gt;

using namespace std;

#define ANZAHL 2

struct Bauteil{
    string name;
	string lieferant;
	double preis, anzahl;
};

Bauteil *pMyStruct = new Bauteil[ANZAHL];

void eingabe(){
	cout&lt;&lt;&quot;Wieviele Bauteile moechten Sie hinzufuegen? &quot;;
	int hin;
	cin&lt;&lt;hin;
	cout&lt;&lt;endl;
	for(unsigned int index = 1; index &lt;= hin; index++){
		cout&lt;&lt;&quot;Das &quot;&lt;&lt;index&lt;&lt;&quot;. Bauteil: Name, Lieferant, Preis, Anzahl? &quot;;
		string na, li;
		double pr, an;
		cin&gt;&gt;na&gt;&gt;li&gt;&gt;pr&gt;&gt;an;
		pMyStruct[index-1].name = na;
		pMyStruct[index-1].lieferant = li;
		pMyStruct[index-1].preis = pr;
		pMyStruct[index-1].anzahl = an;
    }
}

void ausgabe(){
	cout&lt;&lt;endl&lt;&lt;left&lt;&lt;setw(12)&lt;&lt;&quot;Bauteilname&quot;&lt;&lt;setw(12)&lt;&lt;&quot;Lieferant&quot;&lt;&lt;setw(12)&lt;&lt;&quot;Preis&quot;&lt;&lt;setw(12)&lt;&lt;&quot;Anzahl&quot;&lt;&lt;endl;
	for(unsigned int index = 1; index &lt;= ANZAHL; index++){
		cout&lt;&lt;left&lt;&lt;setw(12)&lt;&lt;pMyStruct[index-1].name&lt;&lt;setw(12)&lt;&lt;pMyStruct[index-1].lieferant&lt;&lt;fixed&lt;&lt;setprecision(2)&lt;&lt;setw(12)&lt;&lt;pMyStruct[index-1].preis&lt;&lt;
        setw(12)&lt;&lt;pMyStruct[index-1].anzahl&lt;&lt;endl;  
	}
}

int main(){
	delete [] pMyStruct;	
	char wahl;
	int i=1;
	do{
		cout&lt;&lt;endl&lt;&lt;endl&lt;&lt;&quot;* * * * Programm zur Verwaltung von Bauteilen * * * *&quot;&lt;&lt;endl&lt;&lt;endl;
		cout&lt;&lt;&quot;Was moechten Sie machen?&quot;&lt;&lt;endl;
		cout&lt;&lt;&quot;1. Bauteil (h)inzufuegen!&quot;&lt;&lt;endl;
		cout&lt;&lt;&quot;2. Bauteilliste (a)nzeigen!&quot;&lt;&lt;endl; 
		cout&lt;&lt;&quot;3. Programm (b)eenden! HA!&quot;&lt;&lt;endl;
		cout&lt;&lt;&quot;h, a oder b? &quot;;
		cin&gt;&gt;wahl;
		cout&lt;&lt;endl;
		getchar();
		switch(wahl){
			case 'h': 
				eingabe();
				break;
			case 'a': 
				ausgabe();
				break;
			case 'b': 
				i=0;
				break;
			default:
				cout&lt;&lt;&quot;Falsche Eingabe&quot;;
				break;
		}
	}while (i!=0); 

	//eingabe();
	//ausgabe();
	getch(); 
	return 0;
}
</code></pre>
<p>Wie ihr sehen könnt, bestimme ich gleich am Anfang mit</p>
<pre><code class="language-cpp">#define ANZAHL 2
</code></pre>
<p>wieviele Bauteile man hinzufügen soll/muss/darf.</p>
<p>Genau da liegt mein Problem, das möchte ich ändern.<br />
Man soll beliebig viele Bauteile der Liste hinzufügen können. Also man wird im 'Hauptmenu' gefragt, was man möchte. Gibt man 'Bauteil hinzufuegen' an, kommt man zu einer Eingabemaske und fügt eins hinzu. Danach springt man wieder ins 'Hauptmenu'. Nun kann man erneut 'Bauteil hinzufuegen' anwaehlen. Dieses Bauteil wird dann der vorhandenen Liste angefuegt. Das soll 'beliebig oft' funktionieren.</p>
<p>Wie muss ich da ran gehen?</p>
<p>Das wars erst mal von meiner Seite. Ich hoffe ihr versteht (einigermaßen) mein Problem und könnt mir helfen. Bei Fragen: fragen!</p>
<p>Gruß von mir!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1241790</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1241790</guid><dc:creator><![CDATA[das_bin_ich]]></dc:creator><pubDate>Thu, 08 Mar 2007 16:53:18 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Programm mit pointer, array und struct on Thu, 08 Mar 2007 17:02:37 GMT]]></title><description><![CDATA[<p>Dann brauchst du am besten einen vector aus der STL. Den kannst du beliebig erweitern.<br />
Schau dich mal um, du findest sicher was.<br />
Hier ist auch ein eBuch, das ganz ok ist: <a href="http://www.informatik.hs-bremen.de/~brey/stlb.html" rel="nofollow">http://www.informatik.hs-bremen.de/~brey/stlb.html</a></p>
<p>Ach ja, guter Start ist wohl das Magazin hier: <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-143816.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-143816.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1241793</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1241793</guid><dc:creator><![CDATA[THX 1138]]></dc:creator><pubDate>Thu, 08 Mar 2007 17:02:37 GMT</pubDate></item></channel></rss>