Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <fstream>
  4.  
  5. #define SIZE 256
  6.  
  7. class String {
  8. public:
  9.     String() {
  10.         s1 = new char[SIZE];
  11.     }
  12.    
  13.     ~String() {
  14.         delete[] s1;
  15.     }
  16.    
  17.     void Set();
  18.     void Print();
  19.     void Task();
  20.    
  21.     String& operator= (const String &temp);
  22.    
  23.     char* s1;
  24. };
  25.  
  26. void String::Set() {
  27.     std::cin.getline(s1, SIZE);
  28. }
  29.  
  30. void String::Print() {
  31.     std::cout << s1 << std::endl;
  32. }
  33.  
  34. void String::Task() { //если длина L кратна 2, то удаляются все числа, которые делятся на 2
  35.     std::ofstream output;
  36.     output.open("out.txt");
  37.     if(strlen(s1) % 2 == 0) {
  38.         char* temp = new char[strlen(s1)];
  39.         int j = 0;
  40.         for (int i = 0; i < strlen(s1); ++i) {
  41.             if((int)s1[i] >= 48 && (int)s1[i] <= 57 && (int)s1[i] % 2 == 0)
  42.                 continue;
  43.             else {
  44.                 temp[j] = s1[i];
  45.                 ++j;
  46.             }
  47.         }
  48.        
  49.         output << s1 << std::endl;
  50.         s1 = temp;
  51.         output << s1 << std::endl;
  52.     }
  53. }
  54.  
  55. String& String::operator= (const String &temp) {
  56.     if (this == &temp)
  57.         return *this;
  58.        
  59.     s1 = temp.s1;
  60.    
  61.     return *this;
  62. }
  63.  
  64. int main() {
  65.    
  66.     String s;
  67.     String *s2 = new String;
  68.    
  69.     s.Set();  //Вбить строку
  70.     s.Print(); //Вывод
  71.  
  72.     s.Task(); //Выполняем задание
  73.     s.Print(); //Вывод
  74.  
  75.     s.Print(); //Вывод
  76.     s  = s2; //Показываем работу перегруженного =
  77.     s.Print(); //Вывод
  78.    
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement