Advertisement
awsmpshk

Untitled

Mar 11th, 2020
179
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //№1 на семинар по информатике и программированию. Написать перегрузку функции distance()
  2. #include <iostream>
  3. #include <cmath>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. struct Point_flat {
  9. double x, y;
  10. Point_flat(double x, double y) {
  11. this->x = x;
  12. this->y = y;
  13. }
  14. void print_flat() {
  15. cout << "x = " << x << "; y = " << y << endl;
  16. }
  17. };
  18.  
  19. struct Point_izohor {
  20. double x, y, z;
  21. Point_izohor(double x, double y, double z) {
  22. this->x = x;
  23. this->y = y;
  24. this->z = z;
  25. }
  26. void print_izohor() {
  27. cout << "x = " << x << "; y = " << y << "; z = " << z << endl;
  28. }
  29. };
  30.  
  31. double distance(double x, double y) {
  32. return sqrt(x * x + y * y);
  33. }
  34.  
  35. double distance(double x, double y, double z) {
  36. return sqrt(x * x + y * y + z * z);
  37. }
  38.  
  39. double distance(double x1, double y1, double x2, double y2) {
  40. return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
  41. }
  42.  
  43. double distance(double x1, double y1, double z1, double x2, double y2, double z2) {
  44. return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2) + pow(z1 - z2, 2));
  45. }
  46.  
  47. double distance(Point_flat p) {
  48. return sqrt(p.x * p.x + p.y * p.y);
  49. }
  50.  
  51. double distance(Point_izohor p) {
  52. return sqrt(p.x * p.x + p.y * p.y + p.z * p.z);
  53. }
  54.  
  55. int main() {
  56. double x, y, z;
  57.  
  58. cout << "Enter coordinates for the point from struct Point_flat: ";
  59. cin >> x >> y;
  60. Point_flat p1(x, y);
  61.  
  62. cout << "Enter coordinates for the point from struct Point_izohor: ";
  63. cin >> x >> y >> z;
  64. Point_izohor p2(x, y, z);
  65.  
  66. cout << "Enter coordinates for distance(x, y): ";
  67. cin >> x >> y;
  68. cout << "Current distance is " << distance(x, y) << endl;
  69.  
  70. cout << "Enter coordinates for distance(x, y, z): ";
  71. cin >> x >> y >> z;
  72. cout << "Current distance is " << distance(x, y, z) << endl;
  73.  
  74. double x2, y2, z2;
  75.  
  76. cout << "Enter coordinates for distance(x1, y1, x2, y2): ";
  77. cin >> x >> y >> x2 >> y2;
  78. cout << "Current distance is " << distance(x, y, x2, y2) << endl;
  79.  
  80. cout << "Enter coordinates for distance(x1, y1, z1, x2, y2, z2): ";
  81. cin >> x >> y >> z >> x2 >> y2 >> z2;
  82. cout << "Current distance is " << distance(x, y, z, x2, y2, z2) << endl;
  83.  
  84. cout << "Coordinates of the point from struct Point_flat: ";
  85. p1.print_flat();
  86. cout << "Current distance is " << distance(p1) << endl;
  87.  
  88. cout << "Coordinates of the point from struct Point_izohor: ";
  89. p2.print_izohor();
  90. cout << "Current distance is " << distance(p2) << endl;
  91.  
  92. return 0;
  93. }
Advertisement
RAW Paste Data Copied
Advertisement