I need help :(

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 43
Reputation: UKmason is an unknown quantity at this point 
Solved Threads: 1
UKmason UKmason is offline Offline
Light Poster

I need help :(

 
0
  #1
Oct 25th, 2009
I am very new to computer programming and am struggling with my Computer Science class...

I have been working on this program all week long...

My assignment is to ;

Write a float function that will have four float parameters. The four parameters represent two Cartesian points, 2 x's and 2 y's. Return the distance between the two points. It involves a square root.
Write a main function which will ask the user for 2 points (4 numbers), decide whether the distance between them is within 25 units ("hit"), exactly 25 units ("on the rim"), or more than 25 units away ("missed"). You must call the function written previously. Use the fewest possible number of if statements and comparisons to do this efficiently. Output this message on the console window (use "cout").

Then add in some code to use the first point entered as the center of a circle, and draw a circle that is 25 units in radius. Draw a small circle at the location of the other point. Output the classification of the distance on the graphics screen (look up the function "outtextxy".). The use of the word "units" does not imply any conversions needed, they are just 'spaces on the plane' or pixels in the graphics sense.

This is what I have gotten so far... I honestly have no idea how close I am to finishing up

  1. #include <iostream>
  2. #include <cmath>
  3. #include "graphics.h"
  4.  
  5. using namespace std;
  6.  
  7. float point (float x1, float x2, float y1, float y2);
  8. float point (float x1, float x2, float y1, float y2)
  9. {
  10. if (distance < 25.0)
  11. return "hit";
  12. else if (distance == 25.0,)
  13. return "on the rim";
  14. else if (distance > 25.0)
  15. return "miss";
  16. }
  17.  
  18. int main ()
  19. {
  20. float x1;
  21. float x2;
  22. float y1;
  23. float y2;
  24. float distance;
  25. float squareroot;
  26.  
  27. cout << "Please enter the cordinates for the first point.";
  28. cin >> x1 >> y1;
  29. cout << "Now enter the cordinates for the second point.";
  30. cin >> x2 >> y2;
  31.  
  32. squareroot = pow (float(x2-x1),2) + pow (float(y2-y1),2);
  33. distance = squareroot/squareroot;
  34.  
  35. cout<< point <<endl;
  36.  
  37. return 0;
  38.  
  39. }

Any ideas of what I should do?

Thanks -
~mason
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 29
Reputation: Shinedevil is an unknown quantity at this point 
Solved Threads: 0
Shinedevil Shinedevil is offline Offline
Light Poster
 
0
  #2
Oct 25th, 2009
http://www.daniweb.com/code/snippet216430.html

this might help you with your circle
Last edited by Shinedevil; Oct 26th, 2009 at 12:01 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 43
Reputation: UKmason is an unknown quantity at this point 
Solved Threads: 1
UKmason UKmason is offline Offline
Light Poster
 
0
  #3
Oct 26th, 2009
Thanks a bunch, now I just need to find out how to get it to draw a circle
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 480
Reputation: Clinton Portis is on a distinguished road 
Solved Threads: 56
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Pro in Training
 
0
  #4
Oct 26th, 2009
Your professor gave you a function free of charge called outtextxy( ). Worst case scenario, why not just call outtextxy() individually for every ascii character that you will to output on the dos console to draw your circle?

This may seem inefficient, but here is a way to at least make your code look 'better':
  1. struct coord{
  2.  
  3. int x;
  4. int y;
  5. };
  6.  
  7. void draw_circle();
  8.  
  9. coord point[80];
  10.  
  11.  
  12. //This is where it sucks.. it's up to you to come up with this list of coordinates
  13. //through trial-and-error.
  14. point[0].x = 10; point[0].y = 15;
  15. point[1].x = 11; point[1].y = 14;
  16. point[2].x = 12; point[2].y = 14;
  17. point[3].x = 13; point[3].y = 13;
  18. point[4].x = 14; point[4].y = 13;
  19. ...
  20. ...
  21. ...
  22. point[79].x = 9; point[79].y = 16;
  23.  
  24.  
  25. void draw_circle()
  26. {
  27. for(int i=0; i<80; i++)
  28. {
  29. outtextxy(point[i].x, point[i].y);
  30. }
  31. }

Although this looks brutally painful, I believe this is an appropriate technique for your level of academics. This will involve a lot of trial-and-error (having to recompile and run your program after every 'guess' of where to plot the next point for your circle) but after you've done the hard part of getting all those coordinate positions, the rest is easy.

One thing that will ease the pain: buy some graph paper. Once you get your circle started, it will be quite easy to forecast the majority of the remainder of coordinates for your ascii circle. This will help you ensure that all points are roughly at a 25 unit radius.

Other alternatives would be to look online for information on how to draw an ascii circle... your professor would undoubtedly ask where you got this information as some of these functions are quite complex... specifically the Bresenham Circle.
Last edited by Clinton Portis; Oct 26th, 2009 at 1:07 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 480
Reputation: Clinton Portis is on a distinguished road 
Solved Threads: 56
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Pro in Training
 
0
  #5
Oct 26th, 2009
  1. void draw_circle()
  2. {
  3. for(int i=0; i<80; i++)
  4. {
  5. outtextxy(point[i].x, point[i].y);
  6. cout << '*';
  7. }
  8. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,432
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 186
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Nearly a Posting Virtuoso
 
0
  #6
Oct 26th, 2009
Not exactly sure if this will help but the equation to a circle is :
  1. //Cartesian coordinate
  2. X^2 + Y^2 = R^2
  3. //polar coordinate
  4. //R = radius
  5. sin^2(x)* R + cos^2(X) * R = 1
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle.
2) Problem 2[b]solved by : jonsca
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC