daily pastebin goal
48%
SHARE
TWEET

layla

rex897 Jan 18th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. #include <fstream>
  5. #include <clocale>
  6. #include <curses.h>
  7. #include <cstdlib>
  8. #include <cstdio>
  9.  
  10. using namespace std;
  11.  
  12. class dvect2 {
  13. protected:
  14.     double x;
  15.     double *py;
  16.  
  17. public:
  18.     dvect2() // конструктор без параметров
  19.     {
  20.         py = new double(0);
  21.     }
  22.  
  23.     ~dvect2() {
  24.         if (py != NULL)
  25.             delete py;
  26.     }
  27.  
  28.     dvect2(dvect2 &z) //конструктор копирования
  29.     {
  30.         x = z.x;
  31.         py = new double(*z.py);
  32.     }
  33.  
  34.     dvect2(double x0, double y0) //конструктор с параметрами
  35.     {
  36.         x = x0;
  37.         py = new double(y0);
  38.     }
  39.  
  40.     friend istream &operator>>(istream &in, dvect2 &z);
  41.  
  42.     void raz(dvect2 v1, dvect2 v2);
  43.  
  44.     dvect2 &operator=(dvect2 &z) //перегрузка присваивания
  45.     {
  46.         if (this == &z)
  47.             return z;
  48.         x = z.x;
  49.         *py = *z.py;
  50.         return *this;
  51.     }
  52. };
  53.  
  54.  
  55. istream &operator>>(istream &in, dvect2 &z) {
  56.     cout << "x = ";
  57.     in >> z.x;
  58.     cout << "y = ";
  59.     in >> *z.py;
  60.     return in;
  61. }
  62.  
  63. void dvect2::raz(dvect2 v1, dvect2 v2) {
  64.     x = v1.x - v2.x;
  65.     *py = *v1.py - *v2.py;
  66. }
  67.  
  68. class vect3 : public dvect2 {
  69. private:
  70.     double z;
  71. public:
  72.     vect3() : dvect2() {}
  73.  
  74.     vect3(double x0, double y0, double z0) : dvect2(x0, y0), z(z0) {}
  75.  
  76.     ~vect3() {
  77.         dvect2::~dvect2();
  78.     }
  79.  
  80.     vect3(vect3 &z1) : dvect2(z1) {
  81.         z = z1.z;
  82.     }
  83.  
  84.     vect3 &operator=(vect3 &z1) {
  85.         if (this == &z1)
  86.             return z1;
  87.         dvect2::operator=(z1);
  88.         z = z1.z;
  89.     }
  90.  
  91.     friend istream &operator>>(istream &in, vect3 &z1);
  92.  
  93.     void razn(vect3 v1, vect3 v2);
  94.  
  95. };
  96.  
  97. istream &operator>>(istream &in, vect3 &z1) {
  98.     cout << "x = ";
  99.     in >> z1.x;
  100.     cout << "y = ";
  101.     in >> *z1.py;
  102.     cout << "z = ";
  103.     in >> z1.z;
  104.     return in;
  105. }
  106.  
  107. void vect3::razn(vect3 v1, vect3 v2) {
  108.     x = v1.x - v2.x;
  109.     *py = *v1.py - *v2.py;
  110.     z = v1.z - v2.z;
  111. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top