Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Segment {
- double A, B;
- public:
- Segment(double A, double B) : A(A), B(B) { }
- friend ostream & operator<< (ostream &wyjscie, const Segment &s);
- const Segment operator*(int &d) {
- return Segment(A*d, B*d);
- };
- const Segment operator/(int &d) {
- return Segment(A/d, B/d);
- };
- const Segment operator+(int &d) {
- return Segment(A + d, B + d);
- };
- const Segment operator-(int &d) {
- return Segment(A-d, B-d);
- };
- const Segment operator-(Segment &s) {
- return Segment(A + s.A, B + s.B);
- };
- const bool operator()(double &d) {
- if (d == A || d == B)
- return true;
- else { false; }
- };
- };
- ostream & operator<< (ostream &wyjscie, const Segment &s) {
- return wyjscie << " " << s.A << endl << "Srednia ocen: " << s.B << endl;
- }
- int main() {
- using std::cout; using std::endl;
- Segment seg{ 2,3 }, s = 1 + 2 * ((seg - 2) / 2 + seg) / 3;
- cout << s << endl << std::boolalpha;
- for (double x = 0.5; x < 4; x += 1)
- cout << "x=" << x << ": " << s(x) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement