3. Pi In this problem, you are asked to write a C++ program which displays the value of Pi (1) using three different ways, as described in the three parts below, respectively. (a) Define a constant variable Pi and set it equal to 3.1416, which is a rounded value of n. You should use the proper data type and the variable should be a constant (i.e. its value cannot be changed in the program). (b) Approximate the value of t using the Gregory-Leibniz series shown below (instead of infinity as the upper limit, use a sufficiently large limit, e.g. 200). You can use the pow function from the library. 00 (-1)k 1 1 IT = 4 2k + 1 k=0 = 4 +--- +.. 7 (c) See problem 2 and its solution to be able to understand and solve this part Approximate the value of t using the Monte Carlo method with M (choose a sufficiently large M, e.g. M=1000000) random points. The idea is to generate M random points inside a square with side = 2 centered at the origin of the coordinate system. Then you need to count the number of points that fall within the unit circle (i.e. radius 1) centered at the origin (and so the circle is fully inside the square). Finally, you can approximate n by considering the following relation: Area of Square Area of Circle side? 22 4 TT x radius² Tn x 12 (d) Print the three values of pi obtained in parts a, b, and c above. You should get close results if M and the summation limit of part b are sufficiently large. Submit your solution in Pi.cpp.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
C++
3. Pi
In this problem, you are asked to write a C++ program which displays the value of Pi (n) using
three different ways, as described in the three parts below, respectively.
(a) Define a constant variable Pi and set it equal to 3.1416, which is a rounded value of t.
You should use the proper data type and the variable should be a constant (i.e. its value
cannot be changed in the program).
(b) Approximate the value of a using the Gregory-Leibniz series shown below (instead of
infinity as the upper limit, use a sufficiently large limit, e.g. 200). You can use the pow
function from the <math.h> library.
(-1)*
1
1
TT = 4
= 4
+ --
+..
7.
|
2k + 1
k=0
(c) See problem 2 and its solution to be able to understand and solve this part
Approximate the value of t using the Monte Carlo method with M (choose a sufficiently
large M, e.g. M=1000000) random points. The idea is to generate M random points inside
a square with side = 2 centered at the origin of the coordinate system. Then you need to
count the number of points that fall within the unit circle (i.e. radius 1) centered at the
origin (and so the circle is fully inside the square). Finally, you can approximate n by
considering the following relation:
Area of Square
side?
22
4
Area of Circle
n x radius²
Tn × 12
(d) Print the three values of pi obtained in parts a, b, and c above. You should get close results
if M and the summation limit of part b are sufficiently large.
Submit your solution in Pi.cpp.
Transcribed Image Text:3. Pi In this problem, you are asked to write a C++ program which displays the value of Pi (n) using three different ways, as described in the three parts below, respectively. (a) Define a constant variable Pi and set it equal to 3.1416, which is a rounded value of t. You should use the proper data type and the variable should be a constant (i.e. its value cannot be changed in the program). (b) Approximate the value of a using the Gregory-Leibniz series shown below (instead of infinity as the upper limit, use a sufficiently large limit, e.g. 200). You can use the pow function from the <math.h> library. (-1)* 1 1 TT = 4 = 4 + -- +.. 7. | 2k + 1 k=0 (c) See problem 2 and its solution to be able to understand and solve this part Approximate the value of t using the Monte Carlo method with M (choose a sufficiently large M, e.g. M=1000000) random points. The idea is to generate M random points inside a square with side = 2 centered at the origin of the coordinate system. Then you need to count the number of points that fall within the unit circle (i.e. radius 1) centered at the origin (and so the circle is fully inside the square). Finally, you can approximate n by considering the following relation: Area of Square side? 22 4 Area of Circle n x radius² Tn × 12 (d) Print the three values of pi obtained in parts a, b, and c above. You should get close results if M and the summation limit of part b are sufficiently large. Submit your solution in Pi.cpp.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education