Using the programs written for the previous assignments, create a simular program which randomly generates 3 sets of x and y coordinates and one randomly generated Real. Two of the sets of coordinates will (as in program 2) represent the end points of a line. The other set of coordinates and the Real will represent the midpoint of a circle and the circle's radius.

The coordinates should be randomly generated numbers from -99.9 to 99.9. The radius should be a randomly generated number from 0.1 to 99.9. Determine if the line is wholly within the circle. The program should display all of the generated data and one of the messages regarding the location of the line as shown below in Output Layout section. Make sure the decimal places line up.

Special Calculations:
Length of a Line Segment Equation:
√((p0x – p1x)2 + (p0y – p1y)2) (This requires use of the math library)

Output Layout:
Line Segment's 1st x coordinate: -##.#
Line Segment's 1st y coordinate: -##.#
Line Segment's 2nd x coordinate: -##.#
Line Segment's 2nd y coordinate: -##.#

Circle's Midpoint x coordinate: -##.#
Circle's Midpoint y coordinate: -##.#
Circle's Radius: ##.#

The line is in the circle!
The line is not in the circle!

Data, function names and conditions:

p0x // a float from -99.9 to 99.9
p0y // a float from -99.9 to 99.9
p1x // a float from -99.9 to 99.9
p1y // a float from -99.9 to 99.9
mpx // a float from -99.9 to 99.9
mpy // a float from -99.9 to 99.9
radius // a float from 0.1 to 99.9

double lineSegLen(const float& p0x, const float& p0y, const float& p1x, const float& p1y);
bool lineInCircle(const float& lp0x, const float& lp0y, const float& lp1x, const float& lp1y, const float& cmpx, const float& cmpy, const float& radius);
Please note, that it is not a homework site. We won't do your homework for you. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attemts to solve this youself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again. As it is impossible to find deriviative of function without knowledge in ariphmetics, you cannot do more complex tasks in programming without clear understanding of basics

And that:
Using the programs written for the previous assignments
Would you mind post it here so we could use it as a base as assignment reqire.
Last edited on
please I miss something this problem is about writing function with arguments,function prototype but I keep trying and it doesn't want to debug.could you help me with that?

// ConsoleApplication31.cpp : Defines the entry point for the console application.

#include <iostream>
#include <cmath>
#include <ctime>
using namespace std;

double lineSegLen(const float & p0x, const float & p0y, const float & p1x, const float & p1y);
bool lineLnCircle(const float & lp0x, const float & lp0y, const float & lp1x, const float & lp1y, const float & cmpx, const float & cmpy, const float & radius);

int main()
float p0x;
float p1x;
float p0y;
float p1y;
float mpx;
float mpy;
float radius;
float deltaX;
float deltaY;
double lenght;

p0x = (rand()% (999+999+1)-999) / 10.0;
p0y =(rand()% (999+999+1)-999) / 10.0;
p1x = (rand()% (999+999+1)-999 / 10.0;
p1y = (rand()% (999+999+1)-999 / 10.0;
mpx = (rand()% (999+999+1)-999 / 10.0;
mpy = (rand()% (999+999+1)-999 / 10.0;
radius = (rand()% (999-1+1)+1) / 10.0;

cout <<"Line Segment\'s 1st x coordinate:"
cout <<"Line Segment\'s 1st y coordinate:"
cout <<"Line Segment\'s 2nd x coordinate:"
cout <<"Line Segment\'s 2nd y coordinate:"
cout <<"Circle\'s Midpoint x coordinate:"
cout <<"Circle\'s Midpoint y coordinate:"
cout <<"Circle\'s Radius:"

deltaX = p0x-p1x;
deltaY = p0x-p1y;

lenght = sqrt(pow(deltaX,2) + (deltaY,2));


and thanks for the last one,you really help me a lot.
Topic archived. No new replies allowed.