Advertisement
Pug_coder

lab9

May 12th, 2021
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. template<typename T>
  3. class Curve
  4. {
  5. private:
  6.     T x, y, y1;
  7. public:
  8.     Curve(T x) {
  9.         y = x*x+2;
  10.         y1 = x - 2;
  11.     }
  12.     const T operator+(const Curve& a) const {
  13.         return y + a.y1;
  14.     }
  15.     const T operator-(const Curve& a) const {
  16.         return y- a.y1;
  17.     }
  18.     const T operator*(const T& a) const {
  19.         return (y*a);
  20.     }
  21.  
  22.     T operator()(T x) {
  23.         return y;
  24.     }
  25.     T getY(){
  26.         return y;
  27.     }
  28.  
  29. };
  30. int main()
  31. {
  32.     Curve<double> c1(6.0);
  33.     Curve<double> c2(4.0);
  34.     std::cout <<c1.getY() <<std::endl;
  35.     std::cout <<c2.getY() << std::endl;
  36.     std::cout <<(c2 - c1) <<std::endl;
  37.     std::cout <<(c1*4.0) << std::endl;
  38.     std::cout << c1(4.0) << std::endl;
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement