Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "CalculatePI.hpp"
- CalculatePI::CalculatePI() {
- }
- CalculatePI::CalculatePI(int squareSize) {
- this->squareSize = squareSize;
- }
- CalculatePI::~CalculatePI() {
- }
- int CalculatePI::throwX() {
- return 1 + rand() % this->squareSize;
- }
- int CalculatePI::throwY() {
- return 1 + rand() % this->squareSize;
- }
- int CalculatePI::GetCountInSide() {
- return this->countInSide;
- }
- int CalculatePI::GetCountOutSide() {
- return this->countOutSide;
- }
- int CalculatePI::GetSquareSize() {
- return this->squareSize;
- }
- double CalculatePI::getPi() {
- return (4 * (this->countInSide / this->countOutSide));
- }
- double CalculatePI::pythagoras(int x, int y) {
- return (sqrt(pow(x, 2) + pow(y, 2)));
- }
- void CalculatePI::calculatePoints() {
- int x = this->throwX();
- int y = this->throwY();
- if (pythagoras(x, y)<this->squareSize / 2) {
- this->countInSide++;
- }
- this->countOutSide++;
- cout << "Valor de PI: " << this->getPi() << endl;
- }
- void CalculatePI::launchThread() {
- pthread_t thread;
- pthread_create(&thread, NULL, calculatePoints, NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement