| | |
I need help :(
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2009
Posts: 43
Reputation:
Solved Threads: 1
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
Any ideas of what I should do?
Thanks -
~mason
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
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cmath> #include "graphics.h" using namespace std; float point (float x1, float x2, float y1, float y2); float point (float x1, float x2, float y1, float y2) { if (distance < 25.0) return "hit"; else if (distance == 25.0,) return "on the rim"; else if (distance > 25.0) return "miss"; } int main () { float x1; float x2; float y1; float y2; float distance; float squareroot; cout << "Please enter the cordinates for the first point."; cin >> x1 >> y1; cout << "Now enter the cordinates for the second point."; cin >> x2 >> y2; squareroot = pow (float(x2-x1),2) + pow (float(y2-y1),2); distance = squareroot/squareroot; cout<< point <<endl; return 0; }
Any ideas of what I should do?
Thanks -
~mason
•
•
Join Date: Nov 2008
Posts: 29
Reputation:
Solved Threads: 0
0
#2 Oct 25th, 2009
Last edited by Shinedevil; Oct 26th, 2009 at 12:01 am.
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':
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.
This may seem inefficient, but here is a way to at least make your code look 'better':
C++ Syntax (Toggle Plain Text)
struct coord{ int x; int y; }; void draw_circle(); coord point[80]; //This is where it sucks.. it's up to you to come up with this list of coordinates //through trial-and-error. point[0].x = 10; point[0].y = 15; point[1].x = 11; point[1].y = 14; point[2].x = 12; point[2].y = 14; point[3].x = 13; point[3].y = 13; point[4].x = 14; point[4].y = 13; ... ... ... point[79].x = 9; point[79].y = 16; void draw_circle() { for(int i=0; i<80; i++) { outtextxy(point[i].x, point[i].y); } }
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.
0
#5 Oct 26th, 2009
C++ Syntax (Toggle Plain Text)
void draw_circle() { for(int i=0; i<80; i++) { outtextxy(point[i].x, point[i].y); cout << '*'; } }
0
#6 Oct 26th, 2009
Not exactly sure if this will help but the equation to a circle is :
C++ Syntax (Toggle Plain Text)
//Cartesian coordinate X^2 + Y^2 = R^2 //polar coordinate //R = radius sin^2(x)* R + cos^2(X) * R = 1
1) What word becomes shorter if you add a letter to it?
[ Solved by : niek_e, Paul Thompson, SgtMe, murtan, xavier666, jonsca]
2) What does this sequence equal to : (.5u - .5a)(.5u-.5b)(.5u-.5c) ...
[*solved by : murtan, xavier666]
3) What is the 123456789th prime numer?![]() |
Other Threads in the C++ Forum
- Previous Thread: adding arrays
- Next Thread: validate float number
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library linker list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






