//The solution of the above problem is attached below:
//CPP CODE-
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
const double PI = 3.141592653589793;
static double x_cor = 0;
static double y_cor = 0;
static double x_sum = 0;
static double y_sum = 0;
double x_y_total = 0;
long int num_darts = 0;
long int num_hits = 0;
long int num_misses = 0;
long double pi_approx = 0;
srand(time(0));
while ( num_darts != 0 ) // Start of while loop
{
cout << " How many times do you want to throw the
darts: ";
cin >> num_darts;
cout << endl;
if ( num_darts != 0 )
{
for ( int i = 0; i < num_darts; i++) // Start of for
loopa inside the while loop
{
x_cor =
static_cast<double>(rand())/RAND_MAX;
y_cor =
static_cast<double>(rand())/RAND_MAX;
x_sum = (x_cor * x_cor);
y_sum = (y_cor * y_cor);
x_y_total = x_sum + y_sum;
if (x_y_total < 1)
{
num_hits++;
}
else
{
num_misses++;
}
}
} // end of if loop
pi_approx = (num_hits / num_darts);
} // end of while loop
cout << " The value is " << pi_approx <<
endl;
return 0;
}
1. Consider a dartboard consisting of a circle of radius r inscribed in a square of...
CS0007
Good day, I am in an entry-level Java class and need assistance
completing an assignment. Below is the assignment criteria and the
source code from the previous assignment to build
from. Any help would be appreciated, thank you in
advance.
Source Code from the previous assignment to build from shown
below:
Here we go! Let's start with me giving you some startup code: import java.io.*; import java.util.*; public class Project1 { // Random number generator. We will be using this...
1) Consider the following Java program: 1 public class HelloWorld { 2 // My first program! 3 public static void main(String[] args) { 4 System.out.println("Hello, World!"); 5 } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...