Monday, April 8, 2013

Implementing One Function Into A Second Function - C And C++ ...


Example
#{example}
"); ipb.editor_values.get('templates')['togglesource'] = new Template("
??? Cancel Source Edit
"); ipb.editor_values.get('templates')['toolbar'] = new Template(""); ipb.editor_values.get('templates')['button'] = new Template("
  • Icon
  • "); ipb.editor_values.get('templates')['menu_item'] = new Template("
  • #{title}
  • "); ipb.editor_values.get('templates')['togglesource'] = new Template("
    ??? Cancel Source Edit
    "); ipb.editor_values.get('templates')['emoticons_showall'] = new Template(""); ipb.editor_values.get('templates')['emoticon_wrapper'] = new Template("

    Emoticons

    "); // Add smilies into the mix ipb.editor_values.set( 'show_emoticon_link', false ); ipb.editor_values.set( 'bbcodes', $H({"snapback":{"id":"1","title":"Post Snap Back","desc":"This tag displays a little linked image which links back to a post - used when quoting posts from the board. Opens in same window by default.","tag":"snapback","useoption":"0","example":"[snapback]100[/snapback]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"topic":{"id":"5","title":"Topic Link","desc":"This tag provides an easy way to link to a topic","tag":"topic","useoption":"1","example":"[topic=1]Click me![/topic]","switch_option":"0","menu_option_text":"Enter the topic ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"post":{"id":"6","title":"Post Link","desc":"This tag provides an easy way to link to a post.","tag":"post","useoption":"1","example":"[post=1]Click me![/post]","switch_option":"0","menu_option_text":"Enter the Post ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"spoiler":{"id":"7","title":"Spoiler","desc":"Spoiler tag","tag":"spoiler","useoption":"0","example":"[spoiler]Some hidden text[/spoiler]","switch_option":"0","menu_option_text":"","menu_content_text":"Enter the text to be masked","single_tag":"0","optional_option":"0","image":""},"acronym":{"id":"8","title":"Acronym","desc":"Allows you to make an acronym that will display a description when moused over","tag":"acronym","useoption":"1","example":"[acronym='Laugh Out Loud']lol[/acronym]","switch_option":"0","menu_option_text":"Enter the description for this acronym (EG: Laugh Out Loud)","menu_content_text":"Enter the acronym (EG: lol)","single_tag":"0","optional_option":"0","image":""},"hr":{"id":"12","title":"Horizontal Rule","desc":"Adds a horizontal rule to separate text","tag":"hr","useoption":"0","example":"[hr]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"php":{"id":"14","title":"PHP Code","desc":"Allows you to enter PHP code into a formatted/highlighted syntax box","tag":"php","useoption":"0","example":"[php]$variable = true;\n\nprint_r($variable);[/php]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"html":{"id":"15","title":"HTML Code","desc":"Allows you to enter formatted/syntax-highlighted HTML code","tag":"html","useoption":"0","example":"[html]\n \n[/html]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"sql":{"id":"16","title":"SQL Code","desc":"Allows you to enter formatted/syntax-highlighted SQL code","tag":"sql","useoption":"0","example":"[sql]SELECT p.*, t.* FROM posts p LEFT JOIN topics t ON t.tid=p.topic_id WHERE t.tid=7[/sql]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"xml":{"id":"17","title":"XML Code","desc":"Allows you to enter formatted/syntax-highlighted XML code","tag":"xml","useoption":"0","example":"[xml]\n \n Test\n \n[/xml]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"member":{"id":"31","title":"Member","desc":"Given a member name, a link is automatically generated to the member's profile","tag":"member","useoption":"1","example":"[member=skyhawk133] runs this site.","switch_option":"0","menu_option_text":"Input Username of Member","menu_content_text":"","single_tag":"1","optional_option":"0","image":"memberbbcode.png"},"extract":{"id":"33","title":"Extract Blog Entry","desc":"This will allow users to define an extract for an entry. Only this piece of the entry will be displayed on the main blog page and will show up in the RSS feed.","tag":"extract","useoption":"0","example":"[extract]This is an example![/extract]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"blog":{"id":"34","title":"Blog Link","desc":"This tag provides an easy way to link to a blog.","tag":"blog","useoption":"1","example":"[blog=100]Click me![/blog]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"entry":{"id":"35","title":"Blog Entry Link","desc":"This tag provides an easy way to link to a blog entry.","tag":"entry","useoption":"1","example":"[entry=100]Click me![/entry]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"twitter":{"id":"36","title":"Twitter","desc":"A tag to link to a user's twitter account","tag":"twitter","useoption":"0","example":"[twitter]userName[/twitter]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":"twitter.png"},"inline":{"id":"37","title":"Inline Code","desc":"Formats code inline instead of in a seperate code box. ","tag":"inline","useoption":"0","example":"[inline]style=\"font-size: 12px;\"[/inline]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"il":{"id":"38","title":"Abbreviated Inline (IL)","desc":"Abbreviated version of the [inline] tag. ","tag":"il","useoption":"0","example":"[il]Code Here[/il]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":"il2.png"},"code":{"id":"41","title":"Code","desc":"Allows you to enter general code","tag":"code","useoption":"1","example":"[code]$text = 'Some long code here';[/code]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"1","image":""}}) ); ipb.vars['emoticon_url'] = "http://cdn.dreamincode.net/forums/public/style_emoticons/default"; //Search Setup ipb.vars['search_type'] = 'forum'; ipb.vars['search_type_id'] = 15; ipb.vars['search_type_2'] = 'topic'; ipb.vars['search_type_id_2'] = 317810; //]]>

    4 Replies - 59 Views - Last Post: Today, 11:51 AM Rate Topic: -----

    #1 breezett93 ?Icon User is offline

    Reputation: 0

    • Posts: 32
    • Joined: 10-March 13

    Posted Today, 09:29 AM

    Hi everyone,

    I have been searching around, but could not find any good examples, so I am bringing my question here. My program gathers 2 longitude/latitude coordinates and calculates the distance between them. So I have one function that converts the user-entered coordinates into radian form:

    
  double radianCoord( double coord, string d) { 	double answer = 0; 	long double rad = .0174532925;  	if (d == "W" || d == "S")          //if statement accounts for west and south coordinates being negative 	{ 		answer = coord * rad * -1; 		return answer; 	} 		 	answer = coord * rad;  	return answer; } 

    And then with those new radian values, I have a second function that takes those values, and applies the distance formula to them:

    
 double coordDistance(double x, double x2, double y, double y2) { 	double coordx = 0; 	double coordy = 0; 	double coordx2 = 0; 	double coordy2 = 0; 	string dx; 	string dx2; 	string dy; 	string dy2; 	double distance; 	double distFormula; 	const double WI = 3956.575;   	radianCoord(coordx, dx); 	radianCoord(coordx2, dx2); 	radianCoord(coordy, dy); 	radianCoord(coordy2, dy2);  	distFormula = sqrt(((x2-x) * (x2-x)) + ((y2-y) * (y2-y))); 	distance = distFormula * WI;  	return distance;	 } 

    I am getting a very large number (over 9,000 mi), and for the test coordinates I am using, I should only get a distance of 170 mi. I understand functions moderately well, as I have used them in other languages; however, having two functions work together seems to be the issue I am having. Clarification would be most appreciated!

    Is This A Good Question/Topic? 0

    Replies To: Implementing one function into a second function

    #2 sepp2k ?Icon User is offline

    Reputation: 1635

    • Posts: 2,455
    • Joined: 21-June 11

    Re: Implementing one function into a second function

    Posted Today, 09:40 AM

    All the variables that you pass to radianCoord are either 0 or empty strings. You also don't do anything with the return values of either of your calls to radianCoord.

    The reason you're getting wrong results is that you don't convert your arguments to radians before use them in your formula. You should be calling radianCoord on your arguments (not on unrelated variables that are always 0) and then you should store the results of those calls and use those in your formula.


    #3 breezett93 ?Icon User is offline

    Reputation: 0

    • Posts: 32
    • Joined: 10-March 13

    Re: Implementing one function into a second function

    Posted Today, 11:11 AM

    I built radianCoord first, and it works perfectly fine. No variables being 0 or empty strings. For example, if I use
    (44.232 N 88.416 W) and (41.879 N 87.636 W), I get answers of (.771994, -1.54315) and (.730926, -1.52954). These are both correct.
    coordDistance should be taking those two new radian coordinates and finding the distance between them, but it doesn't.
    This is the whole program if you are confused.
    
  #include<iostream> #include<string> #include<cmath> #include<sstream> #include<iomanip>  using namespace std; using std::getline;  double radianCoord( double coord, string d); double coordDistance(double x, double x2, double y, double y2);  int main() { 	//Declare variables 	double coordx = 0;    //first coordinate N_S degree 	double coordx2 = 0;   //first coordinate E_W degree 	double coordy = 0;    //second coordinate N_S degree 	double coordy2 = 0;   //second coordinate E_W degree 	string dx;            //first coordinate N_S direction 	string dx2;           //first coordinate E_W direction 	string dy;            //second coordinate N_S direction 	string dy2;           //second coordinate E_W direction 	double coord = 0;     //radianCoord degree variable 	string d;             //radianCoord string variable 	 	//Get input 	cout << "This program firsts asks for a coordinate in degrees, followed by a second question asking the direction." << endl; 	cout << "Enter the first location's N/S coordinates: "; 	cin >> coordx; 	cout << "and its direction: "; 	cin >> dx; 	cout << "Enter the first location's E/W coordinates: "; 	cin >> coordx2; 	cout << "and its direction: "; 	cin >> dx2; 	//cout << endl; 	cout << "Enter the second location's N/S coordinates: "; 	cin >> coordy; 	cout << "and its direction: "; 	cin >> dy; 	cout << "Enter the second location's E/W coordinates: "; 	cin >> coordy2; 	cout << "and its direction: "; 	cin >> dy2;  	cout << radianCoord(coordx, dx) << endl;     //these four lines correctly display the radian values 	cout << radianCoord(coordx2, dx2) << endl; 	cout << radianCoord(coordy, dy) << endl; 	cout << radianCoord(coordy2, dy2) << endl;  	cout << coordDistance(coordx, coordy, coordx2, coordy2);   //displays a very incorrect distance  	cin.get(); 	cin.get(); 	 	//Exit program 	return 0; }  double radianCoord( double coord, string d) { 	double answer = 0; 	long double rad = .0174532925;  	if (d == "W" || d == "S")          //west and south values carry a negative with them 	{ 		answer = coord * rad * -1; 		return answer; 	} 		 	answer = coord * rad;  	return answer; }  double coordDistance(double x, double x2, double y, double y2) { 	double coordx = 0; 	double coordy = 0; 	double coordx2 = 0; 	double coordy2 = 0; 	string dx; 	string dx2; 	string dy; 	string dy2; 	double distance; 	double distFormula; 	const double WI = 3956.575;   	radianCoord(coordx, dx); 	radianCoord(coordx2, dx2); 	radianCoord(coordy, dy); 	radianCoord(coordy2, dy2);  	distFormula = sqrt(((x2-x) * (x2-x)) + ((y2-y) * (y2-y))); 	distance = distFormula * WI;  	return distance;	 } 


    #4 CTphpnwb ?Icon User is offline

    Reputation: 2458

    • Posts: 8,416
    • Joined: 08-August 08

    Re: Implementing one function into a second function

    Posted Today, 11:19 AM

    Pay attention to what Sepp2k is telling you. Look at lines 92 - 93 of your code in post 3. They do nothing. Sure, they call the function, but they don't do anything with its results. Read up on functions.

    #5 sepp2k ?Icon User is offline

    Reputation: 1635

    • Posts: 2,455
    • Joined: 21-June 11

    Re: Implementing one function into a second function

    Posted Today, 11:51 AM

    View Postbreezett93, on 06 April 2013 - 08:11 PM, said:

    I built radianCoord first, and it works perfectly fine.

    I didn't claim anything to the contrary.

    Quote

    No variables being 0 or empty strings. For example, if I use
    (44.232 N 88.416 W) and (41.879 N 87.636 W), I get answers of (.771994, -1.54315) and (.730926, -1.52954).

    But if you use 0 and empty strings, you have 0 and empty strings. And that's exactly what you're doing on lines 92-95. You're calling radianCoord with 0 and empty strings as arguments.


    Page 1 of 1


    Source: http://www.dreamincode.net/forums/topic/317810-implementing-one-function-into-a-second-function/

    brian mcknight sbux nfldraft asante samuel salton sea arizona immigration law aubrey huff

    No comments:

    Post a Comment

    Note: Only a member of this blog may post a comment.