Advertisement
Imran1107048

Basic OOP

Jun 8th, 2021
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6. class Point
  7. {
  8. private:
  9. double x;
  10. double y;
  11.  
  12. public:
  13. Point();
  14. Point(double first, double second);
  15.  
  16. double getX();
  17. double getY();
  18. void display();
  19. ~Point();
  20. };
  21.  
  22. Point::Point(void)
  23. {
  24. x = 0.0;
  25. y = 0.0;
  26. }
  27.  
  28. Point::Point(double first, double second)
  29. {
  30. x = first;
  31. y = second;
  32. }
  33. Point::~Point(void)
  34. {
  35.  
  36. }
  37.  
  38. double Point::getX(void)
  39. {
  40. return x;
  41. }
  42.  
  43. double Point::getY(void)
  44. {
  45. return y;
  46. }
  47.  
  48. void Point::display()
  49. {
  50. cout << "(" << x << ", " << y << ")" << endl;
  51. }
  52.  
  53. class Line
  54. {
  55. private:
  56. double offset, slope;
  57.  
  58. public:
  59. Line();
  60. Line(Point P1, Point P2);
  61.  
  62. bool isPerpendicularTo(Line l);
  63. void display();
  64. ~Line();
  65. };
  66.  
  67. Line::Line(void)
  68. {
  69. offset = 0.0;
  70. slope = 1.0;
  71. }
  72.  
  73. Line::Line(Point p1, Point p2)
  74. {
  75.  
  76. }
  77.  
  78. void Line::display()
  79. {
  80. cout << "y = " << slope << "x + " << offset << endl;
  81. }
  82.  
  83. ///If multiplication of 2slope of 2line equal to -1
  84. bool isPerpendicularTo(Line l)
  85. {
  86.  
  87. }
  88.  
  89. int main()
  90. {
  91. Point P1(1.0, 2.0), P2(3.0, -3.0), P3(0.0,1.0), P4(10.0, 5.0);
  92.  
  93. Line L1(P1, P2);
  94. L1.display();
  95. cout << endl;
  96.  
  97. Line L2(P3, P4);
  98. L2.display();
  99. cout << endl;
  100.  
  101. if(L1.isPerpendicularTo(L2)){
  102. cout << "Line ";
  103. L1.display();
  104. cout << " is perpendicular to Line ";
  105. L2.display();
  106. cout << "." << endl;
  107. }
  108. else{
  109. cout << "Line ";
  110. L1.display();
  111. cout << " is NOT perpendicular to Line ";
  112. L2.display();
  113. cout << "." << endl;
  114. }
  115.  
  116. return 0;
  117. }
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement