Difference between revisions of "DPS915 Toad"

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

Revision as of 13:52, 14 October 2015

Project Name Goes here

Team Members

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

Email All

Progress

Assignment 1

PI Calculation

Code

  1. include <cstdlib>
  2. include <iostream>
  3. include <iomanip>
  4. include <math.h>

using namespace std;


int main(int argc, char* argv[]) {

       if(argc < 2)
       {
               cout<<"Please input the number of circle points"<<endl;
       }
       int npoints = atoi(argv[1]);
       int circle_count = 0;
       srand(time(NULL));
       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;
       return 0;

}

Assignment 2

Assignment 3