Advertisement
dizzy94

Untitled

Jun 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Segment {
  6. double A, B;
  7. public:
  8. Segment(double A, double B) : A(A), B(B) { }
  9.  
  10. friend ostream & operator<< (ostream &wyjscie, const Segment &s);
  11.  
  12. friend const Segment operator*(const int
  13. &arg_lewy, const Segment &arg_prawy);
  14.  
  15. friend const Segment operator+(const int
  16. &arg_lewy, const Segment &arg_prawy);
  17.  
  18. friend const Segment operator*(const Segment
  19. &arg_lewy, const int &arg_prawy);
  20.  
  21. friend const Segment operator/(const Segment
  22. &arg_lewy, const int &arg_prawy);
  23.  
  24. friend const Segment operator+(const Segment
  25. &arg_lewy, const int &arg_prawy);
  26.  
  27. friend const Segment operator+(const Segment
  28. &arg_lewy, const Segment &arg_prawy);
  29.  
  30. friend const Segment operator-(const Segment
  31. &arg_lewy, const int &arg_prawy);
  32.  
  33. const Segment operator-(Segment &s) {
  34. return Segment(A + s.A, B + s.B);
  35. };
  36.  
  37. const bool operator()(double &d) {
  38. if (d == A || d == B)
  39. return true;
  40. else { false; }
  41. };
  42.  
  43. };
  44.  
  45. ostream & operator<< (ostream &wyjscie, const Segment &s) {
  46. return wyjscie << s.A << " " << s.B << endl;
  47. }
  48.  
  49. const Segment operator*(const Segment & arg_lewy, const int & arg_prawy)
  50. {
  51. return Segment(arg_lewy.A * arg_prawy,
  52. arg_lewy.B * arg_prawy);
  53. }
  54.  
  55. const Segment operator*(const int & arg_lewy, const Segment & arg_prawy)
  56. {
  57. return Segment(arg_lewy * arg_prawy.A,
  58. arg_lewy * arg_prawy.B);
  59. }
  60.  
  61. const Segment operator+(const int & arg_lewy, const Segment & arg_prawy)
  62. {
  63. return Segment(arg_lewy + arg_prawy.A,
  64. arg_lewy + arg_prawy.B);
  65. }
  66.  
  67. const Segment operator/(const Segment & arg_lewy, const int & arg_prawy)
  68. {
  69. return Segment(arg_lewy.A / arg_prawy,
  70. arg_lewy.B / arg_prawy);
  71. }
  72.  
  73. const Segment operator+(const Segment & arg_lewy, const int & arg_prawy)
  74. {
  75. return Segment(arg_lewy.A + arg_prawy,
  76. arg_lewy.B + arg_prawy);
  77. }
  78.  
  79. const Segment operator+(const Segment & arg_lewy, const Segment & arg_prawy)
  80. {
  81. return Segment(arg_lewy.A + arg_prawy.A,
  82. arg_lewy.B + arg_prawy.B);
  83. }
  84.  
  85. const Segment operator-(const Segment & arg_lewy, const int & arg_prawy)
  86. {
  87. return Segment(arg_lewy.A - arg_prawy,
  88. arg_lewy.B - arg_prawy);
  89. }
  90.  
  91. int main() {
  92. using std::cout; using std::endl;
  93. Segment seg{ 2,3 }, s = 1 + 2 * ((seg - 2) / 2 + seg) / 3;
  94. cout << s << endl << std::boolalpha;
  95. for (double x = 0.5; x < 4; x += 1)
  96. cout << "x=" << x << ": " << s(x) << endl;
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement