Advertisement
nastiia_firefly

(oop_4.1.)!=work

Nov 13th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "Person.h"
  5.  
  6.  
  7. TString::TString()
  8. {
  9.  
  10.     char buf[100];
  11.  
  12.     sprintf(buf,"Wet under foot");
  13.     str = new char[strlen(buf)+1];
  14.     strcpy(str+1, buf);
  15.     str[0]=strlen(str)-1;
  16. }
  17. TString::TString(char* Str)
  18. {
  19.  
  20.     this->str=new char [strlen(Str)+1];
  21.     this->str[0]=strlen(Str);
  22.     strcpy(this->str+1,Str);
  23. }
  24. TString::TString(const TString &ob)
  25. {
  26.  
  27.     this->str=new char[strlen(ob.str)+1];
  28.     strcpy(this->str+1,ob.str+1);
  29.     str[0]=strlen(ob.str)-1;
  30.  
  31. }
  32. TString::~TString()
  33. {
  34.     delete[]str;
  35. }
  36. void TString::operator=(const TString &s)
  37. {
  38.         TString sop(s);
  39.         delete[]str;
  40.         str=new char[strlen(s.str)+1];
  41.         strcpy(str,s.str);
  42. }
  43. TString TString::operator+(const TString &s2)const
  44. {
  45.     TString sop;
  46.  
  47.     int sz=strlen(str)+strlen(s2.str)-2;
  48.  
  49.     sop.str=new char[sz+1];
  50.     sop.str[0]=sz;
  51.  
  52.     strcpy(sop.str+1,str+1);
  53.     strcat(sop.str,s2.str+1);
  54.     return sop;
  55. }
  56. TString TString::operator%(TString &s2)//--------------------(!!!!!)
  57. {
  58.     TString sop;
  59.     int sz;
  60.  
  61.     sz=strlen(str)+strlen(s2.str)-2;
  62.     sop.str=new char[sz+1];
  63.     sop.str[0]=sz;
  64.  
  65.     strcpy(sop.str+1,this->str+1);
  66.  
  67. bool flag;
  68.  
  69.     for(int i=1,k=strlen(sop.str)-1; i<strlen(sop.str); i++)
  70.     {
  71.         flag=true;
  72.  
  73.         for(int j=1;j<strlen(s2.str);j++)
  74.         {
  75.             if(sop.str[i]==s2.str[j])
  76.             {
  77.                     flag=false;
  78.                     break;
  79.             }
  80.         }
  81.         if(flag)
  82.         {
  83.  
  84.             sop.str[k]=s2.str[i];
  85.             sop.output();
  86.             k++;
  87.         }
  88.     }
  89.  
  90. }
  91. bool TString::operator==(const TString &s)const// length compare º [==;>=]
  92. {
  93.    TString sop;
  94.  
  95.    sop=new char[strlen(str)+1];
  96.    sop.str[0]=strlen(str)-1;
  97.    strcpy(sop.str+1,s.str+1);
  98.  
  99.     return (sop.str[0]==s.str[0]) ? true : false;
  100. }
  101. bool TString::operator!=(const TString &s)const
  102. {
  103.    TString sop;
  104.  
  105.    sop=new char[strlen(str)+1];
  106.    sop.str[0]=strlen(str)-1;
  107.    strcpy(sop.str+1,s.str+1);
  108.  
  109.   return (sop.str[0]!=s.str[0]) ? true : false;
  110. }
  111. bool TString::operator<(const TString &s)const
  112. {
  113.   TString sop;
  114.  
  115.    sop=new char[strlen(str)+1];
  116.    sop.str[0]=strlen(str)-1;
  117.    strcpy(sop.str+1,s.str+1);
  118.  
  119.    return (sop.str[0]<s.str[0]) ? true : false;
  120. }
  121. bool TString::operator>(const TString &s)const
  122. {
  123.     TString sop;
  124.     bool flag=0;
  125.  
  126.    sop=new char[strlen(str)+1];
  127.    sop.str[0]=strlen(str)-1;
  128.    strcpy(sop.str+1,s.str+1);
  129.  
  130.  
  131.     return (sop.str[0]>s.str[0]) ? true : false;
  132.  
  133. }
  134. bool TString::operator<=(const TString &s)const
  135. {
  136.     TString sop;
  137.  
  138.    sop=new char[strlen(str)+1];
  139.    sop.str[0]=strlen(str)-1;
  140.    strcpy(sop.str+1,s.str+1);
  141.  
  142.  return (sop.str[0]<=s.str[0]) ? true : false;
  143. }
  144. bool TString::operator>=(const TString &s)const
  145. {
  146.       TString sop;
  147.  
  148.    sop=new char[strlen(str)+1];
  149.    sop.str[0]=strlen(str)-1;
  150.    strcpy(sop.str+1,s.str+1);
  151.  
  152.     return (sop.str[0]>=s.str[0]) ? true : false;
  153. }
  154. void TString::input()
  155. {
  156.    char buffer[100];
  157.  
  158.    cout<<"Input string\n";
  159.    cin.getline(buffer,100);
  160.  
  161.    delete[]str;
  162.  
  163.     str[0]=strlen(buffer)-1;
  164.    str=new char[str[0]+1];
  165.  
  166.  
  167.    str=strdup(buffer);
  168.  
  169.    SetStr(str);
  170.  
  171. }
  172. void TString::output()
  173. {
  174.    cout<<endl<<"You have inputed : "<<endl;
  175.  
  176.    for (int i=1;i<strlen(str);i++)
  177.    {
  178.        cout<<str[i];
  179.    }
  180.    cout<<endl;
  181.    cout<<"Size = "<<(int)str[0]<<endl<<endl;
  182. }
  183. TString GetLength(const TString &s)
  184. {
  185.     TString sop;
  186.     sop=new char[strlen(sop.str)+1];
  187.     sop.str[0]=strlen(sop.str)-1;
  188.     cout<<(int)s.str[0];
  189. }
  190. TString NClearPoz(const TString&s)
  191. {
  192.  
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement