Advertisement
lil_SV

TwoBigBlackDick

Sep 18th, 2022
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 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.     }
  51.  
  52.     void print()
  53.     {
  54.         cout<<"----------------\n";
  55.         cout<<"Class COne\n";
  56.         cout<<"f = "<<f<<endl;
  57.         printf("ps = %s\n", ps);
  58.     }
  59.  
  60.     ~COne(){      //деструктор
  61.         delete ps;
  62.     }
  63.  
  64. private:
  65.     float f;
  66.     char *ps;
  67. };
  68.  
  69. class CTwo{
  70. public:
  71.     CTwo()
  72.     :l(-2), obj(COne())
  73.     {
  74.     }
  75.  
  76.     CTwo(long _l, COne f)
  77.     :l(_l), obj(f)
  78.     {
  79.     }
  80.     CTwo(const CTwo & m)
  81.     :l(m.l), obj(m.obj)
  82.     {
  83.     }
  84.  
  85.     long getL() const {
  86.         return l;
  87.     }
  88.  
  89.     void setL(long l) {
  90.         CTwo::l = l;
  91.     }
  92.  
  93.     const COne &getObj() const {
  94.         return obj;
  95.     }
  96.  
  97.     void setObj(const COne &obj) {
  98.         CTwo::obj = obj;
  99.     }
  100.     CTwo & operator=(CTwo const & ctwo){
  101.         l=ctwo.l;
  102.         obj=ctwo.obj;
  103.     }
  104.     void print(){
  105.         cout<<"----------------\n";
  106.         cout<<"Class CTwo\n";
  107.         cout<<"l = "<<l<<endl;
  108.         obj.print();
  109.     }
  110.     ~CTwo(){}
  111.  
  112. private:
  113.     long l;
  114.     COne obj;
  115. };
  116.  
  117.  
  118.  
  119.  
  120. int main() {
  121.     char *a = "Pidorass";
  122.     COne s(89,a);
  123.     CTwo f(69, s);
  124.     f.print();
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement