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

C++ computer programming Write a program that generates three random points on a

ID: 3557415 • Letter: C

Question

C++ computer programming

Write a program that generates three random points on a circle centered at (0,0) with radius 40 and display three angels in a triangle formed by these three points, as show in Figure 4.5a. (Hint: Generate a random angle alpha in radians between 0 and 2 pi , as shown in Figure 4.5b and the point determined by this angle is A triangle is formed from three random points on the circle. A random point on the circle can be generated using a random angle A pentagon is centered at (0, 0) with one point at the 0 o'clock position.

Explanation / Answer


#include <iostream.h>
#include<stdlib.h>
#include<math.h>
#include <time.h>

int main()
{
float rad,x1,y1,x2,y2,x3,y3,a,b,c,A,B,C;
int i;

srand (time(NULL));
rad = 2*3.1416*rand()/RAND_MAX;
x1 = 40*cos(rad);
y1 = 40*sin(rad);

rad = 2*3.1416*rand()/RAND_MAX;
x2 = 40*cos(rad);
y2 = 40*sin(rad);

rad = 2*3.1416*rand()/RAND_MAX;
x3 = 40*cos(rad);
y3 = 40*sin(rad);

a = sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
b = sqrt( (x3-x2)*(x3-x2) + (y3-y2)*(y3-y2));
c = sqrt( (x1-x3)*(x1-x3) + (y1-y3)*(y1-y3));

A = acos( (b*b + c*c - a*a) / (2*b*c) );
B = acos( (c*c + a*a - b*b) / (2*a*c) );
C = acos( (a*a + b*b - c*c) / (2*a*b) );

cout<<" Angles are (in radians) : "<<A<<" "<<B<<" "<<C;

return 1;
}

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