Advertisement
dizzy94

Untitled

Jun 27th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4.  
  5. using namespace std;
  6.  
  7. class Segment {
  8.     double A, B;
  9. public:
  10.     Segment(double A, double B) : A(A), B(B) { }
  11.  
  12.     friend ostream & operator<< (ostream &wyjscie, const Segment &s);
  13.    
  14.     const Segment operator*(int &d) {
  15.         return Segment(A*d, B*d);
  16.     };
  17.  
  18.     const Segment operator/(int &d) {
  19.         return Segment(A/d, B/d);
  20.     };
  21.  
  22.     const Segment operator+(int &d) {
  23.         return Segment(A + d, B + d);
  24.     };
  25.  
  26.     const Segment operator-(int &d) {
  27.         return Segment(A-d, B-d);
  28.     };
  29.  
  30.     const Segment operator-(Segment &s) {
  31.         return Segment(A + s.A, B + s.B);
  32.     };
  33.  
  34.     const bool operator()(double &d) {
  35.         if (d == A || d == B)
  36.             return true;
  37.         else { false; }
  38.     };
  39.  
  40. };
  41.  
  42. ostream & operator<< (ostream &wyjscie, const Segment &s) {
  43.     return wyjscie << " " << s.A << endl << "Srednia ocen: " << s.B << endl;
  44. }
  45.  
  46. int main() {
  47.     using std::cout; using std::endl;
  48.     Segment seg{ 2,3 }, s = 1 + 2 * ((seg - 2) / 2 + seg) / 3;
  49.     cout << s << endl << std::boolalpha;
  50.     for (double x = 0.5; x < 4; x += 1)
  51.         cout << "x=" << x << ": " << s(x) << endl;
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement