Okay, so I worked on it some, tried to do what I could. I must say I'm embarrassed at how little I can do thus far. I really got screwed with this course because my curriculum calls for us to start on java (which i did) then it switches us to c (what I'm in now). Long story short I chose a professor who I knew was reputable, but the changed my professor dude to an influx of computer science students this year, so they had to add and shuffle around professors. Well I get stuck with a young woman who is not very good at teaching. The problem is, the head of the department is very strict and tells her what to teach, but she never gets to everything, so when I get a project (The project is made by the head of the department) it's vey challenging, because now I have to go back and teach myself everything that she failed to even bring up. Anyways, here's what I have to far, I'm going to keep chiseling away at it.
Code:
#include <stdio.h>
#define PI 3.14159
#define RADIUS 10
int main (void)
{
//stuff
}
tester() /* tester function */
{
double cirArea = PI * RADIUS * RADIUS;
double distance = sqrt(x*x + y*y); /* This is the Pythagorean that i'm suppose to use, where does the x and y come from?*/
/* The circle is suppose to be centered at (0,0) so if I've chosen my radius to be 10, i can calculat x and y? */
//Here I'm suppose to draw grid with triangle, to show how hypotenuse is distance.. How do I draw it?
if (distance <= RADIUS)
return 1;
else
return 0;
// call the function int DartHits(double x, double y); here
// This functions is how we know the estimated area of circle
//Now we compare actual area vs. estmated area. I think the mean print out statement?
//like this:
printf("The actual area is %f, and the estimated area is %d /n", cirAreal, DartHits);
}
ThrowDarts() /* ThrowDarts function */
{
int n;
int i;
printf("How many darts would you like to throw?");
scanf("%d", &n); /* Prompts user for how many darts to throw, and saves it n */
/* completely lost on the next step: I'm suppose to call the function void
GetBorders(double *xmin, double *xmax, double *ymin, double *ymax); and it says that
all four of these values are supplied by the tester function. So is Getborders
seperate function, or is it inside the tester function? Very confused here. */
int rectArea = (xmax - xmin) * (ymax - ymin);
for (i = 1; i <= n, i++)
// The following should go under this for loop:
/* a. Generate random # between [xmin,xmax]; call this xdart (xcoord of dart)
-> call xdart = RandNumInRange(xmin, xmax);
b. Generate random # between [ymin,ymax]; call this ydart (ycoord of dart)
-> call ydart = RandNumInRange(ymin, ymax);
c. hit = DartHits(xdart, ydart);
e. if hit != 0, add one to # of hits */
// One thing that confuses me is, in part a and b above
// It says to take a variable like xdart and ydart, then
// make them = to functions? How does that work?
// also those instructions say get a random number between xmin and xmax
// and call that number x dart
// then on the next like it says make xdart = a function???
double estRectArea = rectArea * (nhits/n); //nhits is number of hits, generated by for loop above
/* and the last part of this function is suppose to be how they want us to calculate rand
/* ** How do we get a number between xmin, xmax (more generally between w & z)
-> man -a rand brings up manpage
-> set seed using srand
-> rand(void) returns a number between [0, RAND_MAX]
-> Can change integer between [0,RAND_MAX] to real between [0,1]:
- interpret rand() and RAND_MAX as doubles, and simply divide them:
* rn = ((double)rand())/((double)RAND_MAX); real between [0,1]
* make span any distance by multiplying by distance
- Distance is z-w (z known to be >= to w)
* Make start at particular value by adding starting value in
(will change ending value by same amount, so be prepared for that)
==> Can write func:
double RandNumInRange(double W, double Z) */
}
return 0;
}