Monday, May 24, 2010

Program using C++?

how do i write a program for this:





a program that reads in the coordinates of three points on a two-dimensional surface (a plane). Each point has an x-coordinate and a y- coordinate. Each point is given on a line by itself.


Thus your program's input will be something like:


------------------------------------


5.0 5.0


6.0 6.0


7.0 7.0


------------------------------------


The program computes the total distance involved in traveling from the first point (in this case 5.0,5.0) to the second point (6.0,6.0)


to the third point (7.0,7.0 in this case). It displays this distance on a single line:


------------------------------------


2.82843


------------------------------------








I need this asap (C++ programming file.. like one that produces the letter G,





#include %26lt;iostream%26gt;


using namespace std;





int main() {


cout %26lt;%26lt; "G";


return 0;


}





thanks in advance)

Program using C++?
#include %26lt;iostream%26gt;


#include %26lt;math.h%26gt;


using namespace std;


int main() {float n[6];


for(int i=0;i%26lt;6;i++) cin%26gt;%26gt;n[i];


cout%26lt;%26lt;sqrt(pow(n[0]-n[2],2)+


pow(n[1]-n[3],2)) +


sqrt(pow(n[2]-n[4],2)+


pow(n[3]-n[5],2));}








happy? :-D
Reply:/** SAY HELLO TO YOUR TEACHER FROM MEEE :) , I HATE *THEM :)


*THIS PROGRAM IS A COMPLETE WORKING TESTED ONE.


*WRITTEN ON VC++ 6.0


*YOU BETTER CHOOSE ME AS THE BEST ANSWER :))


**/


#include%26lt;iostream%26gt;


#include "math.h"





using namespace std;


using std::endl;





int main()


{


/**


*Read 3 inputs from standard input


*(keyboard, you can make it read


*from a file)


**/





/**


*You can define floating point variables if you want


**/


double x1=0; double y1=0;


double x2=0; double y2=0;


double x3=0; double y3=0;


double result=0;





cout%26lt;%26lt;"Please input x1 y1 x2 y2 x3 y3:"%26lt;%26lt;endl;


cout%26lt;%26lt;"Example: 2 3 5 6 3 5"%26lt;%26lt;endl%26lt;%26lt;"Input: ";


cin%26gt;%26gt;x1%26gt;%26gt;y1%26gt;%26gt;x2%26gt;%26gt;y2%26gt;%26gt;x3%26gt;%26gt;y3;





/**Calculation goes here


*double fabs (double x ),Computes absolute value of x


**/


result += sqrt(fabs(pow((x2-x1),2) + pow((y2-y1),2)));


result += sqrt(fabs(pow((x3-x2),2) + pow((y3-y2),2)));





cout%26lt;%26lt;endl%26lt;%26lt;"The result is: "%26lt;%26lt;result%26lt;%26lt;endl;





return 0;


}





MY EDIT FOR YOUR LOGICAL ERROR: The error is about you lazy, it works on my computer very well, i'm giving you a screenshot, check the code and see if you could correctly copied and pasted it. Syntax is an important thing you know right? or you don't even know how to copy it?And i assumed that you saved the file as xxx.cpp not xxx.c! one last thing if you are using a platform other than MS Visual C++, try changing #include "math.h" into #include%26lt;math%26gt; or #include%26lt;math.h%26gt;


otherwise the program is totally working here is the proof:


http://img81.imageshack.us/img81/2656/un...





EDIT FOR SMART AS S ADVISORS AND FOR THE LOSER that calls me a jerk: If a person is old enough to surf the web and ask questions,then he is old enough to know what is good and not good for himself. Take care you very wise smart-a ss advisors.
Reply:It can easily be done in one function.





have the first and second numbers as part of the function, as well as a third for the solution.





easy
Reply:you should try doing your own homework and THEN ask for help
Reply:Great. So some jerk gave you the answer. Which you will probably hand in, rather that work on it yourself. So then you realize you can't pass the exams, so you cheat on those too, if you can.





Then you take a job someplace, and you're that useless guy that can never do anything for himself. Always bugging the other engineers, asking questions, trying to get them to do your work for you.





After a while they'll get tired of you. If they're too nice to fire you, you get shuffled around to different teams, never moving upward, only sideways. Then one day the company gets acquired, and they use the reorganization as an excuse to boot you out the door.





What a depressing life you're going to have.





Why not develop some self respect? Be good to yourself, and start developing the skills that you're supposed to have when you graduate. Stop faking it and actually become someone who can do things. You'll be happy you did.


No comments:

Post a Comment