<?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 mit der berechnung in Valarry + funktion]]></title><description><![CDATA[<p>Hallo habe ein Programm geschrieben das eine Fläche berechnen soll.<br />
Dies geht so weit aber ich möchte gerne die berechnung von delta X und das Result (res) in einer Funktion schreiben.<br />
Könnt ihr mir vieleicht helfen.<br />
Danke und gruss Turbohawk</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;valarray&gt;
#include &lt;cmath&gt;
typedef double Tv;

using namespace std;

//##################----fnc ermitteln der Feldweite----############################
template&lt;class T&gt; inline T&amp; fnc_fw(T&amp; fw){ 
	char *ch=0; //wird für Typecast benötigt
	char s; 
	char str[2]; 
	fw=0;  //Feldweite auf null setzen
	ifstream fin(&quot;test.dat&quot;);
	if (!fin){cout &lt;&lt; &quot;Eingabedatei nicht gefunden!&quot;;exit(1);}
	for(int e=0;!fin.eof();e++)
	{ 
		str[0]=s; 
        str[1]=0; 
        ch=&amp;str[0]; 
		fin &gt;&gt; ch;
		fw++;//Stream an ch
	};
fin.close();
cout &lt;&lt; &quot;Feldweite von x,y in fnc_fw: &quot;&lt;&lt; fw/2 &lt;&lt; endl;
	fw=fw/2; // Dividiert durch 2 (Koordinatenpaare)
	return(fw);
}
 //##################----fnc Werte von Datei einlesen----############################
template&lt;class T&gt; inline T&amp; fnc_fread(T&amp; x, T&amp; y){ 
	char *ch=0; //wird für Typecast benötigt
	char s; 
	char str[2]; 

	ifstream in(&quot;test.dat&quot;);
	if (!in){cout &lt;&lt; &quot;Eingabedatei nicht gefunden!&quot;;exit(1);}
	for(int i=0;!in.eof();i++)
	{
	    str[0]=s; 
        str[1]=0; 
        ch=&amp;str[0]; 
		in &gt;&gt; ch;		//Stream an ch
		x[i]= atof(ch); //Typ char in double;
		in &gt;&gt; ch;		//Stream an ch
		y[i] = atof(ch);//Typ char in double;  
		//cout &lt;&lt; ch;
	};//end for
	in.close();//schliessen der Datei
	return(x,y);
}

//#######################------MAIN-----------###############################################
void main() {

  int fw=0,i=0;
  fnc_fw(fw);//fnc ermittelt Feldweite

  size_t fw1=fw;// !!!!! fw GIBT PROBLEM wenn nicht initialisiert.
  valarray &lt;Tv&gt; x(0.0,fw),y(x);
  Tv dx;  //Datentyp: double dx
  Tv res;

  fnc_fread(x,y);//fnc Werte von Datei einlesen 

  cout &lt;&lt; &quot;Feldweite in main: &quot; &lt;&lt; fw &lt;&lt; endl;
  cout &lt;&lt; endl &lt;&lt;&quot;x.Feldweite: &quot; &lt;&lt; x.size() &lt;&lt; endl;

  for (i=0;i&lt;x.size();++i) cout &lt;&lt; &quot;x[&quot;  &lt;&lt;i&lt;&lt;   &quot;]: &quot; &lt;&lt; x[i] &lt;&lt; &quot; #### y[&quot;  &lt;&lt;i&lt;&lt;   &quot;]: &quot; &lt;&lt; y[i]&lt;&lt; endl;

//fnc_dx(x,x.size());//fnc zur berechnung von Delta X
//fnc_res(dx,y,x.size());//fnc zur berechnung von Delta X

//----------Berechnung dx noch in Funktionen schreiben!!!!!  ---------------------
  dx=((x[x.size()-1]-x[0]) / (x.size()-1)); 
  res = dx *(y.sum()-(y[0]-y[y.size()-1])/2.0);

	cout &lt;&lt; endl &lt;&lt;&quot;Feldweite: &quot; &lt;&lt; x.size() &lt;&lt; endl;
	cout &lt;&lt; endl &lt;&lt;&quot;Delta-X: &quot; &lt;&lt; dx &lt;&lt; endl;
	cout &lt;&lt; endl &lt;&lt;&quot;Gesamtflaeche: &quot; &lt;&lt; res &lt;&lt; endl;
} //end Main#############################################################################################
</code></pre>
<p>p.s: die Datei Test.dat hat folgendes aussehen:</p>
<pre><code>0.0
1.0 2.0
1.1 2.124
1.2 3.3
1.3 3.51
</code></pre>
<p>u.s.w<br />
nur werte die einlesen werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/75932/probleme-mit-der-berechnung-in-valarry-funktion</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Apr 2026 02:45:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/75932.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 06 Jun 2004 11:22:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Probleme mit der berechnung in Valarry + funktion on Sun, 06 Jun 2004 11:22:08 GMT]]></title><description><![CDATA[<p>Hallo habe ein Programm geschrieben das eine Fläche berechnen soll.<br />
Dies geht so weit aber ich möchte gerne die berechnung von delta X und das Result (res) in einer Funktion schreiben.<br />
Könnt ihr mir vieleicht helfen.<br />
Danke und gruss Turbohawk</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;valarray&gt;
#include &lt;cmath&gt;
typedef double Tv;

using namespace std;

//##################----fnc ermitteln der Feldweite----############################
template&lt;class T&gt; inline T&amp; fnc_fw(T&amp; fw){ 
	char *ch=0; //wird für Typecast benötigt
	char s; 
	char str[2]; 
	fw=0;  //Feldweite auf null setzen
	ifstream fin(&quot;test.dat&quot;);
	if (!fin){cout &lt;&lt; &quot;Eingabedatei nicht gefunden!&quot;;exit(1);}
	for(int e=0;!fin.eof();e++)
	{ 
		str[0]=s; 
        str[1]=0; 
        ch=&amp;str[0]; 
		fin &gt;&gt; ch;
		fw++;//Stream an ch
	};
fin.close();
cout &lt;&lt; &quot;Feldweite von x,y in fnc_fw: &quot;&lt;&lt; fw/2 &lt;&lt; endl;
	fw=fw/2; // Dividiert durch 2 (Koordinatenpaare)
	return(fw);
}
 //##################----fnc Werte von Datei einlesen----############################
template&lt;class T&gt; inline T&amp; fnc_fread(T&amp; x, T&amp; y){ 
	char *ch=0; //wird für Typecast benötigt
	char s; 
	char str[2]; 

	ifstream in(&quot;test.dat&quot;);
	if (!in){cout &lt;&lt; &quot;Eingabedatei nicht gefunden!&quot;;exit(1);}
	for(int i=0;!in.eof();i++)
	{
	    str[0]=s; 
        str[1]=0; 
        ch=&amp;str[0]; 
		in &gt;&gt; ch;		//Stream an ch
		x[i]= atof(ch); //Typ char in double;
		in &gt;&gt; ch;		//Stream an ch
		y[i] = atof(ch);//Typ char in double;  
		//cout &lt;&lt; ch;
	};//end for
	in.close();//schliessen der Datei
	return(x,y);
}

//#######################------MAIN-----------###############################################
void main() {

  int fw=0,i=0;
  fnc_fw(fw);//fnc ermittelt Feldweite

  size_t fw1=fw;// !!!!! fw GIBT PROBLEM wenn nicht initialisiert.
  valarray &lt;Tv&gt; x(0.0,fw),y(x);
  Tv dx;  //Datentyp: double dx
  Tv res;

  fnc_fread(x,y);//fnc Werte von Datei einlesen 

  cout &lt;&lt; &quot;Feldweite in main: &quot; &lt;&lt; fw &lt;&lt; endl;
  cout &lt;&lt; endl &lt;&lt;&quot;x.Feldweite: &quot; &lt;&lt; x.size() &lt;&lt; endl;

  for (i=0;i&lt;x.size();++i) cout &lt;&lt; &quot;x[&quot;  &lt;&lt;i&lt;&lt;   &quot;]: &quot; &lt;&lt; x[i] &lt;&lt; &quot; #### y[&quot;  &lt;&lt;i&lt;&lt;   &quot;]: &quot; &lt;&lt; y[i]&lt;&lt; endl;

//fnc_dx(x,x.size());//fnc zur berechnung von Delta X
//fnc_res(dx,y,x.size());//fnc zur berechnung von Delta X

//----------Berechnung dx noch in Funktionen schreiben!!!!!  ---------------------
  dx=((x[x.size()-1]-x[0]) / (x.size()-1)); 
  res = dx *(y.sum()-(y[0]-y[y.size()-1])/2.0);

	cout &lt;&lt; endl &lt;&lt;&quot;Feldweite: &quot; &lt;&lt; x.size() &lt;&lt; endl;
	cout &lt;&lt; endl &lt;&lt;&quot;Delta-X: &quot; &lt;&lt; dx &lt;&lt; endl;
	cout &lt;&lt; endl &lt;&lt;&quot;Gesamtflaeche: &quot; &lt;&lt; res &lt;&lt; endl;
} //end Main#############################################################################################
</code></pre>
<p>p.s: die Datei Test.dat hat folgendes aussehen:</p>
<pre><code>0.0
1.0 2.0
1.1 2.124
1.2 3.3
1.3 3.51
</code></pre>
<p>u.s.w<br />
nur werte die einlesen werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/534157</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/534157</guid><dc:creator><![CDATA[turbohawk]]></dc:creator><pubDate>Sun, 06 Jun 2004 11:22:08 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit der berechnung in Valarry + funktion on Mon, 07 Jun 2004 05:52:53 GMT]]></title><description><![CDATA[<p>und was hat das mit der MFC zu tun ?????</p>
]]></description><link>https://www.c-plusplus.net/forum/post/534736</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/534736</guid><dc:creator><![CDATA[-----------------------]]></dc:creator><pubDate>Mon, 07 Jun 2004 05:52:53 GMT</pubDate></item></channel></rss>