Advertisement
VictoriaLodochkina

lab 3 z2

Nov 1st, 2020
1,073
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. #include "Strings.h"
  2. Stringg::Stringg() {};
  3. Stringg::Stringg(const char* ss)
  4. {
  5.     //*str = new char[MAX + 1];
  6.     int i;
  7.     for (i = 0; i < MAX && ss[i] != '\0'; i++)
  8.     {
  9.         str[i] = ss[i];
  10.     }
  11.     str[i] = '\0';
  12.     len = i - 1;
  13. }
  14.  
  15. Stringg::Stringg(const Stringg& ss)//////////////////////////////////
  16. {
  17.     int i;
  18.     for (i = 0; i < ss.len; i++)//<=
  19.     {
  20.         str[i] = ss.str[i];//
  21.     }
  22.     str[i] = '\0';
  23.     len = ss.len;
  24. }
  25.  
  26. int Stringg::Length()
  27. {
  28.     /*int i = 0;
  29.     len = 0;
  30.     while (ss.str[i] != '\0')
  31.     {
  32.         len++;
  33.         i++;
  34.     }
  35.     return len;*/
  36.     if (str == 0)
  37.     {
  38.         len = 0;
  39.     }
  40.     else
  41.     {
  42.         int i;
  43.         for (i = 0; str[i] != '\0'; i++);
  44.         len = i;
  45.     }
  46.     return len;
  47. }
  48.  
  49. void Stringg::clear()
  50. {
  51.     delete str;
  52.     len = 0;
  53.     str = new char[1];
  54.     str[0] = '\0';
  55. }
  56.  
  57. void Stringg::get_str()
  58. {
  59.     for (int i = 0; i < len; i++)
  60.     {
  61.         std::cout << str[i];
  62.     }
  63.     std::cout << std::endl;
  64. }
  65. Stringg& Stringg::operator=(Stringg ss)
  66. {
  67.     this->len = ss.len;
  68.     this->str = ss.str;
  69.     return *this;
  70. }
  71. char Stringg::operator[](int i)
  72. {
  73.     return str[i];
  74. }
  75.  
  76. Stringg::~Stringg() {};
  77.  
  78. String_ident::String_ident() {};
  79.  
  80. String_ident::String_ident(const char* ss)
  81. {
  82.     /*if (!(isalpha(ss[0])) || (ss[0] == '_'))//проходит в условие, даже если норм
  83.     {
  84.         len = 0;
  85.         //ss = new char[1];
  86.         ss = 0;
  87.     }
  88.     len = 0;
  89.     for (int i = 0; i < MAX && ss[i] != '\0'; i++)
  90.     {
  91.         len++;
  92.     }
  93.     //len -= 1;
  94.     strcpy(str, ss);*/
  95.     if (!(isalpha(ss[0])) || (ss[0] == '_'))//проходит в условие, даже если норм
  96.     {
  97.         len = 0;
  98.         //ss = new char[1];
  99.         ss = 0;
  100.         str = 0;
  101.         return;
  102.     }
  103.     else
  104.     {
  105.         len = 0;
  106.         for (int i = 0; i < MAX && ss[i] != '\0'; i++)
  107.         {
  108.             len++;
  109.         }
  110.     }
  111.     //len -= 1;
  112.     strcpy(str, ss);
  113. }
  114.  
  115. String_ident::String_ident(const String_ident& ss) :Stringg(ss) {};
  116.  
  117. void String_ident::to_upper()
  118. {
  119.     //char ch;
  120.     for (int i = 0; str[i] != '\0'; i++)
  121.     {
  122.         str[i] = toupper(str[i]);
  123.         //ch = str[i];
  124.         //str[i] = (char)toupper(ch);
  125.     }
  126. }
  127.  
  128. void String_ident::to_lower()
  129. {
  130.     for (int i = 0; str[i] != '\0'; i++)
  131.     {
  132.         str[i] = tolower(str[i]);
  133.     }
  134. }
  135.  
  136. /*char**/int String_ident::str_chr(char c)
  137. {
  138.     for (int i = 0; str[i] != '\0'; i++)
  139.     {
  140.         if (str[i] == c)
  141.             return i;
  142.     }
  143.     return -1;
  144. }
  145.  
  146. String_ident::~String_ident() {};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement