fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // pair<int, int> koordinat;
  5.  
  6. struct point {
  7. double x, y;
  8. // constructor
  9. point() {
  10. // cout << "Constructor kosong" << endl;
  11. }
  12. point(double _x, double _y) {
  13. // cout << "Constructor dgn 2 double" << endl;
  14. x = _x;
  15. y = _y;
  16. }
  17. double euclidean(point other) {
  18. return sqrt((x-other.x)*(x-other.x) + (y-other.y)*(y-other.y));
  19. }
  20. double manhattan(point other) {
  21. return abs(x-other.x) + abs(y-other.y);
  22. }
  23. };
  24.  
  25. struct line {
  26. double A, B, C;
  27.  
  28. line() {}
  29. line(double _A, double _B, double _C) {
  30. A = _A;
  31. B = _B;
  32. C = _C;
  33. }
  34. bool isVertical() {
  35. return B == 0;
  36. }
  37. double gradient() {
  38. if(isVertical())
  39. return 0;
  40. return -A/B;
  41. }
  42. double constant() {
  43. if(isVertical())
  44. return 0;
  45. return C/B;
  46. }
  47. double distanceFromPoint(point other) {
  48. return fabs((A*other.x+B*other.y-C)/sqrt(A*A+B*B));
  49. }
  50. };
  51.  
  52. struct segment {
  53. point A, B;
  54. };
  55.  
  56. const double PI = acos(-1);
  57. // arccos = cos^-1
  58. // cos(x) = y --> acos(y) = x
  59. // trigonometri menggunakan radian
  60. // 180 derajat = PI radian
  61.  
  62. struct circle {
  63. point center;
  64. double radius;
  65. circle() {}
  66. circle(point _center, double _radius) {
  67. center = _center;
  68. radius = _radius;
  69. }
  70. double area() {
  71. return PI*radius*radius;
  72. }
  73. };
  74.  
  75. int main() {
  76. /*
  77. Materi Pembinaan Intensif 2 Mei 2024
  78. - Struct(ure)
  79. - Dasar2 Geometri
  80. - Titik
  81. - Garis
  82. - Lingkaran
  83. */
  84. point koordinat(-2, -3);
  85. cout << koordinat.x << " " << koordinat.y << endl;
  86. cout << koordinat.euclidean(point(6, 3)) << endl;
  87. cout << koordinat.manhattan(point(6, 3)) << endl;
  88.  
  89. line ver(1, 0, 3);
  90. cout << ver.distanceFromPoint(koordinat) << endl;
  91.  
  92. circle lingkaran(koordinat, 10);
  93. cout << setprecision(8);
  94. cout << lingkaran.area() << endl;
  95. return 0;
  96. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
-2 -3
10
14
5
314.15927