Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include "CalculatePI.hpp"
  2. CalculatePI::CalculatePI() {
  3. }
  4. CalculatePI::CalculatePI(int squareSize) {
  5. this->squareSize = squareSize;
  6. }
  7. CalculatePI::~CalculatePI() {
  8. }
  9. int CalculatePI::throwX() {
  10. return 1 + rand() % this->squareSize;
  11. }
  12. int CalculatePI::throwY() {
  13. return 1 + rand() % this->squareSize;
  14. }
  15. int CalculatePI::GetCountInSide() {
  16. return this->countInSide;
  17. }
  18. int CalculatePI::GetCountOutSide() {
  19. return this->countOutSide;
  20. }
  21. int CalculatePI::GetSquareSize() {
  22. return this->squareSize;
  23. }
  24. double CalculatePI::getPi() {
  25. return (4 * (this->countInSide / this->countOutSide));
  26. }
  27. double CalculatePI::pythagoras(int x, int y) {
  28. return (sqrt(pow(x, 2) + pow(y, 2)));
  29. }
  30. void CalculatePI::calculatePoints() {
  31. int x = this->throwX();
  32. int y = this->throwY();
  33. if (pythagoras(x, y)<this->squareSize / 2) {
  34. this->countInSide++;
  35. }
  36. this->countOutSide++;
  37.  
  38. cout << "Valor de PI: " << this->getPi() << endl;
  39. }
  40. void CalculatePI::launchThread() {
  41. pthread_t thread;
  42. pthread_create(&thread, NULL, calculatePoints, NULL);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement