lil_SV

BigWhiteTits

Sep 18th, 2022
749
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. class COne {
  7. public:
  8.     COne()
  9.             : f(0), ps(0) {
  10.     }
  11.  
  12.     COne(float _f, char * _ps)
  13.     :f(_f)
  14.     {
  15.         ps =new char [strlen(_ps)];
  16.         strcpy(ps, _ps);
  17.     }
  18.  
  19.     COne(const COne & Q)
  20.     :f(Q.f)
  21.     {
  22.         ps =new char [strlen(   Q.ps)];
  23.         strcpy(ps, Q.ps);
  24.     }
  25.  
  26.     float getF() const { //getter setter
  27.         return f;
  28.     }
  29.  
  30.     void setF(float f) {
  31.         COne::f = f;
  32.     }
  33.  
  34.     char *getPs() const {
  35.         return ps;
  36.     }
  37.  
  38.     void setPs(char *_ps) {
  39.         ps =new char [strlen(_ps)];
  40.         strcpy(ps, _ps);
  41.     }
  42.  
  43.     // возвращает ссылку на СОne
  44.     // принимает константную ссылку на Q
  45.     COne& operator=(COne const & Q){    //перегрузка
  46.         delete ps;
  47.         ps =new char [strlen(   Q.ps)];
  48.         strcpy(ps, Q.ps);
  49.         f=Q.f;
  50.         return *this;
  51.  
  52.     }
  53.  
  54.     void print()
  55.     {
  56.         cout<<"----------------\n";
  57.         cout<<"Class COne\n";
  58.         cout<<"f = "<<f<<endl;
  59.         printf("ps = %s\n", ps);
  60.     }
  61.  
  62.     ~COne(){      //деструктор
  63.         delete ps;
  64.     }
  65.  
  66. private:
  67.     float f;
  68.     char *ps;
  69. };
  70.  
  71. class CTwo{
  72. public:
  73.     CTwo()
  74.     :l(-2), obj(COne())
  75.     {
  76.     }
  77.  
  78.     CTwo(long _l, COne f)
  79.     :l(_l), obj(f)
  80.     {
  81.     }
  82.     CTwo(const CTwo & m)
  83.     :l(m.l), obj(m.obj)
  84.     {
  85.     }
  86.  
  87.     long getL() const {
  88.         return l;
  89.     }
  90.  
  91.     void setL(long l) {
  92.         CTwo::l = l;
  93.     }
  94.  
  95.     const COne &getObj() const {
  96.         return obj;
  97.     }
  98.  
  99.     void setObj(const COne &obj) {
  100.         CTwo::obj = obj;
  101.     }
  102.     CTwo & operator=(CTwo const & ctwo){
  103.         l=ctwo.l;
  104.         obj=ctwo.obj;
  105.         return *this;
  106.     }
  107.     void print(){
  108.         cout<<"----------------\n";
  109.         cout<<"Class CTwo\n";
  110.         cout<<"l = "<<l<<endl;
  111.         obj.print();
  112.     }
  113.     ~CTwo(){}
  114.  
  115. private:
  116.     long l;
  117.     COne obj;
  118. };
  119.  
  120.  
  121.  
  122.  
  123. int main() {
  124.     char a[] = "Pidorass";
  125.     COne s(89,a);
  126.     CTwo f(69, s);
  127.     f.print();
  128. }
Advertisement
Add Comment
Please, Sign In to add comment