Advertisement
nastiia_firefly

Untitled

Nov 14th, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.36 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.     return (this->str[0]==s.str[0]) ? true : false;
  94. }
  95. bool TString::operator!=(const TString &s)const
  96. {
  97.     return (this->str[0]!=s.str[0]) ? true : false;
  98. }
  99. bool TString::operator<(const TString &s)const
  100. {
  101.     return (this->str[0]<s.str[0]) ? true : false;
  102. }
  103. bool TString::operator>(const TString &s)const
  104. {
  105.     return (this->str[0]>s.str[0]) ? true : false;
  106. }
  107. bool TString::operator<=(const TString &s)const
  108. {
  109.     return (this->str[0]<=s.str[0]) ? true : false;
  110. }
  111. bool TString::operator>=(const TString &s)const
  112. {
  113.     return (this->str[0]>=s.str[0]) ? true : false;
  114. }
  115. void TString::input()
  116. {
  117.    char buffer[100];
  118.  
  119.    cout<<"Input string\n";
  120.    cin.getline(buffer,100);
  121.  
  122.    delete[]str;
  123.  
  124.    str[0]=strlen(buffer)-1;
  125.    str=new char[str[0]+1];
  126.  
  127.    str=strdup(buffer);
  128.    SetStr(str);
  129. }
  130. void TString::output()
  131. {
  132.    cout<<endl<<"You have inputed : "<<endl;
  133.    for (int i=1;i<strlen(str);i++)
  134.    {
  135.        cout<<str[i];
  136.    }
  137.    cout<<endl;
  138.    cout<<"Size = "<<(int)str[0]<<endl<<endl;
  139. }
  140. int GetLength(const TString &s)
  141. {
  142.     return s.str[0];
  143. }
  144. TString ClearPoz(TString &s)
  145. {
  146.     TString sop,temp;
  147.  
  148.     sop.str=new char[strlen(s.str)+1];
  149.     sop.str[0]=strlen(s.str)-1;
  150.     strcpy(sop.str+1,s.str+1);
  151.  
  152.     temp.str= new char[sop.str[0]+1];
  153.     temp.str[0]=strlen(temp.str)-1;
  154.     //strcpy(temp.str+1,temp.str);
  155.  
  156.     int n=0,poz=0,i=0,j=0;
  157.     //cout<<"Input poz and n\n";
  158.     //cin>>poz>>n ;
  159. }
  160. TString TString::s1_in_s2(const TString &s)
  161. {
  162.     int poz;
  163.     //poz=strlen(this->str)+strlen(s.str)-2;
  164.  
  165.    str=new char[str[0]+1];
  166.    str[0]=strlen(str)-1;
  167.  
  168.     poz=2;
  169.     for(int i=0;i<strlen(sz);i++)
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement