Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<string>
- using namespace std;
- class MyString
- {
- private:
- char* m_s;
- int L;
- const int length = 50;
- public:
- void set();
- MyString();
- ~MyString();
- void update();
- void print();
- };
- MyString::MyString()
- {
- cout << "Вызвался конструктор" << endl;
- m_s = new char[length];
- }
- MyString::~MyString()
- {
- cout << "Вызвался деструктор" << endl;
- delete[] m_s;
- }
- void MyString::set()
- {
- cout << "Введите элементы строки " << endl;
- cin >> m_s;
- L = strlen(m_s);
- }
- void MyString::update()
- {
- if (L > 10)
- {
- char* m_s1 = new char[length];
- int k = 0;
- bool match = false;
- const char numbers[11] = "1234567890";
- for (int i = 0; i < L; i++)
- {
- for (int j = 0; j < 11; j++)
- if (m_s[i] == numbers[j])
- {
- match = true;
- break;
- }
- if (match != true)
- {
- m_s1[k] = m_s[i];
- k++;
- }
- match = false;
- }
- m_s = m_s1;
- L = k;
- }
- }
- void MyString::print()
- {
- for (int i = 0; i < L; i++)
- {
- cout << m_s[i] << " ";
- }
- cout << endl;
- }
- int main()
- {
- setlocale(0, "RUS");
- MyString string;
- string.set();
- cout << "Введенная строка : ";
- string.print();
- string.update();
- cout << "Измененная строка : ";
- string.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement