<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 4.7 &#8212; Structs</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/47-structs/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/47-structs/</link>
	<description></description>
	<lastBuildDate>Thu, 02 Feb 2012 21:20:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Structs &#171; Learn C++ Programming</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/comment-page-1/#comment-96839</link>
		<dc:creator>Structs &#171; Learn C++ Programming</dc:creator>
		<pubDate>Fri, 13 Jan 2012 09:40:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-96839</guid>
		<description>[...] 1) Hide Solution [...]</description>
		<content:encoded><![CDATA[<p>[...] 1) Hide Solution [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ayahsabbah</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/comment-page-1/#comment-96375</link>
		<dc:creator>ayahsabbah</dc:creator>
		<pubDate>Sat, 12 Nov 2011 23:18:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-96375</guid>
		<description>Hi, I have to write code to do the following task:
--define a simple structs to store common information. In particular, write definitions for a struct called Point to store the X, Y and Z coordinates of a point. 
I have this:
struct Point{
double xcoord;
double y coord;
};
Then Having defined a struct in the previous section, I need to write two simple functions to use this struct. First, write a function to prompt the user to enter the coordinates of a point, read the coordinates from the keyboard and store them a struct of type Point. The function prototype is as follows
Point ReadPoint();
Second, write a function to determine the Cartesian distance between two points. The function prototype is as follows
double DistanceBetweenPoints( const Point&amp; pt1, const Point&amp; pt2 );

I have:
Point ReadPoint(){
double x;
double y;
cout&lt;&lt;&quot;enter the x and y coordinate of the point: &quot;&lt;&gt;x&gt;&gt;y;
}
and 
double DistanceBetweenPoints( const Point&amp; pt1, const Point&amp; pt2 ){
double distance;
distance= sqrt (pow((x1-x2),2)+pow((y1-y2),2));//i dont know what variables I should add in here
return double;
}
..Please help and respond ASAP because I need to have this assignment done soon..thanks!</description>
		<content:encoded><![CDATA[<p>Hi, I have to write code to do the following task:<br />
&#8211;define a simple structs to store common information. In particular, write definitions for a struct called Point to store the X, Y and Z coordinates of a point.<br />
I have this:<br />
struct Point{<br />
double xcoord;<br />
double y coord;<br />
};<br />
Then Having defined a struct in the previous section, I need to write two simple functions to use this struct. First, write a function to prompt the user to enter the coordinates of a point, read the coordinates from the keyboard and store them a struct of type Point. The function prototype is as follows<br />
Point ReadPoint();<br />
Second, write a function to determine the Cartesian distance between two points. The function prototype is as follows<br />
double DistanceBetweenPoints( const Point&amp; pt1, const Point&amp; pt2 );</p>
<p>I have:<br />
Point ReadPoint(){<br />
double x;<br />
double y;<br />
cout&lt;&lt;&quot;enter the x and y coordinate of the point: &quot;&lt;&gt;x&gt;&gt;y;<br />
}<br />
and<br />
double DistanceBetweenPoints( const Point&amp; pt1, const Point&amp; pt2 ){<br />
double distance;<br />
distance= sqrt (pow((x1-x2),2)+pow((y1-y2),2));//i dont know what variables I should add in here<br />
return double;<br />
}<br />
..Please help and respond ASAP because I need to have this assignment done soon..thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ranjbar</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/comment-page-1/#comment-96366</link>
		<dc:creator>ranjbar</dc:creator>
		<pubDate>Sat, 12 Nov 2011 00:35:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-96366</guid>
		<description>hi
in quiz 2 i wrote the program :

#include 

struct Fraction
{
    float x;
    float y;
    float frac;

};

void Multiply(Fraction f1, Fraction f2)
{
    using namespace std;

    // Don&#039;t forget the static cast, otherwise the compiler will do integer division!
    cout &lt;&lt; f1.frac*f2.frac ;
}
int main()
{
    using namespace std;

    // Allocate our first fraction
    Fraction f1;
    cout &lt;&gt; f1.x;
    cout &lt;&gt; f1.y;

    // Allocate our second fraction
    Fraction f2;
    cout &lt;&gt; f2.x;
    cout &lt;&gt; f2.y;
    f1.frac = f1.x/f1.y;
    f2.frac =f2.x/f1.y;
    Multiply(f1,f2);

    return 0;
}

but my program has less accuracy than yours.
is this has a relation to this fact that i declare my variables first in float but u declare them first in int and then convert them to float?</description>
		<content:encoded><![CDATA[<p>hi<br />
in quiz 2 i wrote the program :</p>
<p>#include </p>
<p>struct Fraction<br />
{<br />
    float x;<br />
    float y;<br />
    float frac;</p>
<p>};</p>
<p>void Multiply(Fraction f1, Fraction f2)<br />
{<br />
    using namespace std;</p>
<p>    // Don&#8217;t forget the static cast, otherwise the compiler will do integer division!<br />
    cout &lt;&lt; f1.frac*f2.frac ;<br />
}<br />
int main()<br />
{<br />
    using namespace std;</p>
<p>    // Allocate our first fraction<br />
    Fraction f1;<br />
    cout &lt;&gt; f1.x;<br />
    cout &lt;&gt; f1.y;</p>
<p>    // Allocate our second fraction<br />
    Fraction f2;<br />
    cout &lt;&gt; f2.x;<br />
    cout &lt;&gt; f2.y;<br />
    f1.frac = f1.x/f1.y;<br />
    f2.frac =f2.x/f1.y;<br />
    Multiply(f1,f2);</p>
<p>    return 0;<br />
}</p>
<p>but my program has less accuracy than yours.<br />
is this has a relation to this fact that i declare my variables first in float but u declare them first in int and then convert them to float?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eddyboy18</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/comment-page-1/#comment-95847</link>
		<dc:creator>Eddyboy18</dc:creator>
		<pubDate>Thu, 11 Aug 2011 17:24:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-95847</guid>
		<description>@Jman try this
first ur struct is an integer,and the function double, does that make sense?
Try something like this:
struct fraction
{
int nNumerator;
int nDenominator;
};
void input(fraction obj,int nNum,int nDenom)
{
obj.nNumerator=nNum;
obj.nDenominator=nDenom;
cout&lt;&lt;&quot;the numerator &quot;&lt;&lt;obj.nNumerato&lt;&lt;endl;
cout&lt;&lt;&quot;the denominator&quot;&lt;&lt;obj.nDenominator&lt;&lt;endl;
}
int main()
{
fraction objm;
int nNum1,nDenom1;
cout&lt;&lt;&quot;enter the numerator&quot;&lt;&gt;nNum1;
cout&lt;&lt;&quot;enter the denominator&quot;&lt;&gt;nDenom1;
//call to the function
input(objm,nNum1,nDenom1);
return 0;
}</description>
		<content:encoded><![CDATA[<p>@Jman try this<br />
first ur struct is an integer,and the function double, does that make sense?<br />
Try something like this:<br />
struct fraction<br />
{<br />
int nNumerator;<br />
int nDenominator;<br />
};<br />
void input(fraction obj,int nNum,int nDenom)<br />
{<br />
obj.nNumerator=nNum;<br />
obj.nDenominator=nDenom;<br />
cout&lt;&lt;&quot;the numerator &quot;&lt;&lt;obj.nNumerato&lt;&lt;endl;<br />
cout&lt;&lt;&quot;the denominator&quot;&lt;&lt;obj.nDenominator&lt;&lt;endl;<br />
}<br />
int main()<br />
{<br />
fraction objm;<br />
int nNum1,nDenom1;<br />
cout&lt;&lt;&quot;enter the numerator&quot;&lt;&gt;nNum1;<br />
cout&lt;&lt;&quot;enter the denominator&quot;&lt;&gt;nDenom1;<br />
//call to the function<br />
input(objm,nNum1,nDenom1);<br />
return 0;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lynx1241</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/comment-page-1/#comment-95657</link>
		<dc:creator>lynx1241</dc:creator>
		<pubDate>Sun, 03 Jul 2011 19:14:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-95657</guid>
		<description>html screwed my last comment :/</description>
		<content:encoded><![CDATA[<p>html screwed my last comment :/</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lynx1241</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/comment-page-1/#comment-95656</link>
		<dc:creator>lynx1241</dc:creator>
		<pubDate>Sun, 03 Jul 2011 19:10:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-95656</guid>
		<description>Because you need to choose a type to cast, e.g. static_cast(expression) instead of static_cast(expression).</description>
		<content:encoded><![CDATA[<p>Because you need to choose a type to cast, e.g. static_cast(expression) instead of static_cast(expression).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JMan</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/comment-page-1/#comment-95356</link>
		<dc:creator>JMan</dc:creator>
		<pubDate>Fri, 22 Apr 2011 10:50:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-95356</guid>
		<description>why my code always produce interger output?Can anyone please help me?:(


// Enumeraor.cpp : Defines the entry point for the console application.
//

#include &quot;stdafx.h&quot;
#include 

struct Fraction
{
	int nNumerator;
	int nDenomintor;
};

double Input()
{
	using namespace std;
	Fraction sFrac;
	cout&lt;&lt;&quot;Enter the numerator of fraction :&quot;&lt;&gt;sFrac.nNumerator;
	cout&lt;&lt;&quot;Enter the denominator of fraction :&quot;&lt;&gt;sFrac.nDenomintor;
	return static_cast(sFrac.nNumerator/sFrac.nDenomintor);
}

int main()
{
	using namespace std;
	double dFracA=Input();
	double dFracB=Input();
	double dResult;
	static_cast(dResult=dFracA*dFracB);
	cout&lt;&lt;&quot;The result is :&quot;&lt;&lt;dResult&lt;&lt;endl;
	return 0;
}</description>
		<content:encoded><![CDATA[<p>why my code always produce interger output?Can anyone please help me?:(</p>
<p>// Enumeraor.cpp : Defines the entry point for the console application.<br />
//</p>
<p>#include &#8220;stdafx.h&#8221;<br />
#include </p>
<p>struct Fraction<br />
{<br />
	int nNumerator;<br />
	int nDenomintor;<br />
};</p>
<p>double Input()<br />
{<br />
	using namespace std;<br />
	Fraction sFrac;<br />
	cout&lt;&lt;&quot;Enter the numerator of fraction :&quot;&lt;&gt;sFrac.nNumerator;<br />
	cout&lt;&lt;&quot;Enter the denominator of fraction :&quot;&lt;&gt;sFrac.nDenomintor;<br />
	return static_cast(sFrac.nNumerator/sFrac.nDenomintor);<br />
}</p>
<p>int main()<br />
{<br />
	using namespace std;<br />
	double dFracA=Input();<br />
	double dFracB=Input();<br />
	double dResult;<br />
	static_cast(dResult=dFracA*dFracB);<br />
	cout&lt;&lt;&quot;The result is :&quot;&lt;&lt;dResult&lt;&lt;endl;<br />
	return 0;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Groovychicken</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/comment-page-1/#comment-95229</link>
		<dc:creator>Groovychicken</dc:creator>
		<pubDate>Sat, 05 Mar 2011 14:21:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-95229</guid>
		<description>cout &lt;&lt; &quot;Wage: &quot; &lt;&lt; sEmployee.fWage &lt;&lt; endl &lt;&lt; endl;

is there a reason for 2 endl&#039;s? or is it just a typo :)</description>
		<content:encoded><![CDATA[<p>cout &lt;&lt; &quot;Wage: &quot; &lt;&lt; sEmployee.fWage &lt;&lt; endl &lt;&lt; endl;</p>
<p>is there a reason for 2 endl&#039;s? or is it just a typo :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sm00th_0perat0r</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/comment-page-1/#comment-95225</link>
		<dc:creator>sm00th_0perat0r</dc:creator>
		<pubDate>Wed, 02 Mar 2011 02:51:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-95225</guid>
		<description>&lt;pre&gt;I&#039;ll bet one could be created!! C++ rocks!!!&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<pre>I&#039;ll bet one could be created!! C++ rocks!!!</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: anas.s</title>
		<link>http://www.learncpp.com/cpp-tutorial/47-structs/comment-page-1/#comment-95133</link>
		<dc:creator>anas.s</dc:creator>
		<pubDate>Tue, 25 Jan 2011 06:31:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/47-structs/#comment-95133</guid>
		<description>Alex,

You&#039;ve shown that we can pass struct to functions, but here is a question :

Can a function return result of type struct?</description>
		<content:encoded><![CDATA[<p>Alex,</p>
<p>You&#8217;ve shown that we can pass struct to functions, but here is a question :</p>
<p>Can a function return result of type struct?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

