Difference between revisions of "DPS915 Toad"

From CDOT Wiki
Jump to: navigation, search
(Code)
(Code)
Line 12: Line 12:
  
 
====Code====
 
====Code====
#include <cstdlib>
 
#include <iostream>
 
#include <iomanip>
 
#include <math.h>
 
  
using namespace std;
+
double xValue, yValue;
 
+
for(int i = 0; i < npoints; i++)
int main(int argc, char* argv[])
+
{
{
+
//Generate random numbers
if(argc < 2)
+
xValue = (double) rand()/RAND_MAX;
{
+
yValue = (double) rand()/RAND_MAX;
cout<<"Please input the number of circle points"<<endl;
+
}
+
if(sqrt((xValue*xValue)+(yValue*yValue)) <= 1)
 
+
{
int npoints = atoi(argv[1]);
+
circle_count++;
int circle_count = 0;
+
}
 
+
}
srand(time(NULL));
+
 
+
double pi, ds;
double xValue, yValue;
+
for(int i = 0; i < npoints; i++)
+
cout<<circle_count<<"/"<<npoints<<endl;
{
+
ds = (double)circle_count/npoints;
//Generate random numbers
+
cout<<ds<<endl;
xValue = (double) rand()/RAND_MAX;
+
pi = ((4.0)*ds);
yValue = (double) rand()/RAND_MAX;
+
 
+
cout<<"PI = "<< pi <<endl;
if(sqrt((xValue*xValue)+(yValue*yValue)) <= 1)
+
"
{
 
circle_count++;
 
}
 
}
 
 
 
double pi, ds;
 
 
 
cout<<circle_count<<"/"<<npoints<<endl;
 
ds = (double)circle_count/npoints;
 
cout<<ds<<endl;
 
pi = ((4.0)*ds);
 
 
 
cout<<"PI = "<< pi <<endl;
 
 
 
return 0;
 
 
 
}"
 
  
 
=== Assignment 2 ===
 
=== Assignment 2 ===
 
=== Assignment 3 ===
 
=== Assignment 3 ===

Revision as of 13:55, 14 October 2015

Project Name Goes here

Team Members

  1. Sandeep Saldanha
  2. Kris Vukasinovic
  3. ...

Email All

Progress

Assignment 1

PI Calculation

Code

double xValue, yValue;
for(int i = 0; i < npoints; i++)
{
//Generate random numbers
xValue = (double) rand()/RAND_MAX;
yValue = (double) rand()/RAND_MAX;

if(sqrt((xValue*xValue)+(yValue*yValue)) <= 1)
{
circle_count++;
}
}

double pi, ds;

cout<<circle_count<<"/"<<npoints<<endl;
ds = (double)circle_count/npoints;
cout<<ds<<endl;
pi = ((4.0)*ds);

cout<<"PI = "<< pi <<endl;

"

Assignment 2

Assignment 3