Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program tests the concepts of: Function with Arguments Conditional Statemen

ID: 3910229 • Letter: T

Question

This program tests the concepts of:

Function with Arguments

Conditional Statement if

cmath Library

Random Number Generation


Program Objective:

Create a program which randomly generates 3 sets of x and y Integer coordinates and one randomly generated Integer. Two of the sets of coordinates will represent the end points of a line segment. The other set of coordinates and the Integer will represent the midpoint of a circle and its radius.

The coordinates should be randomly generated using a user defined function that returns an Integer value based on from and to parameters; see the function declaration in the Other section below. Your coordinates should be randomly selected from -99 to 99. The radius should be a randomly generated number (using the same function) from 1 to 200.

Two other functions should be created to determine if a line is wholly within a circle. One of the functions should return the length of a line segment and the other will return a Boolean indicating if the passed line is in the passed circle; again, see the function declarations below.

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. Try to make everything line up correctly.

Don't forget the SDM.

Record Layouts:
None.

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

Specific Processing:
None.

Output Layout:

Coordinates of a Random Line Segment
  1st Point's x coordinate: -##
  1st Point's y coordinate: -##
  2nd Point's x coordinate: -##
  2nd Point's y coordinate: -##

Coordinates of a Random Circle
  x coordinate: -##
  y coordinate: -##
  Radius: ###

The line segment is within the circle.
OR
The line segment is outside of the circle.
OR
The line segment is a secant of the circle.
OR
The line segment is tangent to the circle.
OR
The line segment bisects the circle.

Other:
Data, function names and conditions:

p0x // an int from -99 to 99
p0y // an int from -99 to 99
p1x // an int from -99 to 99
p1y // an int from -99 to 99
mpx // an int from -99 to 99
mpy // an int from -99 to 99
radius // an int from 1 to 200

int randomInteger(const int from, const int to);
int lineSegLength(const int p0x, const int p0y, const int p1x, const int p1y);
bool lineInCircle(const int p0x, const int p0y, const int p1x, const int p1y, const int mpx, const int mpy, const int radius);
bool lineOutsideCircle(const int p0x, const int p0y, const int p1x, const int p1y, const int mpx, const int mpy, const int radius);
bool lineIntersectsCircle(const int p0x, const int p0y, const int p1x, const int p1y, const int mpx, const int mpy, const int radius);
bool lineSecantCircle(const int p0x, const int p0y, const int p1x, const int p1y, const int mpx, const int mpy, const int radius);
bool lineBisectsCircle(const int p0x, const int p0y, const int p1x, const int p1y, const int mpx, const int mpy, const int radius);

How do you do this.

File Format Example Description Program 1 Program#v#.cpp Program1v0.cpp Main source file.

Explanation / Answer

#include<iostream>

#include<cmath>

#include<ctime>

const int to = 99;

const int from = -99;

int randomInterger(const int from, const int to);

int lineSegLength(const int p0x, const int p0y, const int p1x, const int p1y);

bool lineInCircle (const int p0x, const int p0y, const int p1x, const int p1y, const int mpx, const int mpy, const int radius);

int main(void)

{

srand(time(0));

randomInterger(from, to);

lineInCircle (p0x, p0y, p1x, p1y, mpx, mpy, radius);

return EXIT_SUCCESS;

}

int randomInterger(const int from, const int to)

{

int p0x = rand() % (to-from+1)+from;

int p0y = rand() % (to-from+1)+from;

int p1x = rand() % (to-from+1)+from;

int p1y = rand() % (to-from+1)+from;

int mpx = rand() % (to-from+1)+from;

int mpy = rand() % (to-from+1)+from;

int radius = rand() % (200-1+1)+1;

cout << "the Coordinates of Random Line " << endl;

cout << "1st Point x : " << p0x << endl;

cout << "1st Point y : " << p0y << endl;

cout << "2nd Point x : " << p1x << endl;

cout << "2nd Point y : " << p1y << endl;

cout << "the Coordinates of Random Circle" << endl;

cout << "X: " << mpx << endl;

cout << "Y: " << mpy << endl;

cout << "the radius: " << radius << endl;

cout << "Length of line: " << lineSegLength(p0x, p0y, p1x, p1y) << endl;

}

int lineSegLength(const int p0x, const int p0y, const int p1x, const int p1y)

{

int delx;

int dely;

delx = p0x - p1x;

dely = p0y - p1y;

double lineSegmentLength = sqrt(pow(delx,2) + (dely,2));

return (lineSegmentLength);

}

bool lineInCircle (const int p0x, const int p0y, const int p1x, const int p1y, const mpx, const int mpy, const int radius)

{

int dia = 2 * radius;

if(lineSegLength(p0x, p0y, p1x, p1y) <= dia)

lineInCircle == true;

cout << "The line is in the circle!" << endl;

else

lineInCircle == false;

cout << "line is not inside circle!" << endl;

return (lineInCircle);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote