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;
- static int count;
- const int id;
- public:
- void set();
- MyString();
- ~MyString();
- void update();
- void print();
- static int getcount();
- int getid() const;
- };
- MyString::MyString() :id(count + 1)
- {
- cout << "Вызвался конструктор" << endl;
- m_s = new char[length];
- count++;
- }
- MyString::~MyString()
- {
- cout << "Вызвался деструктор. id "<< id << endl;
- count--;
- cout << "Объектов класса " << count << endl;
- delete[] m_s;
- }
- int MyString::getcount()
- {
- cout << "Объектов класса " << count << endl;
- return count;
- }
- int MyString::getid() const
- {
- cout << endl;
- return id;
- }
- 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 MyString::count = 0;
- int main()
- {
- setlocale(0, "RUS");
- MyString string1;
- string1.getcount();
- string1.set();
- cout << "Введенная строка : ";
- string1.print();
- string1.update();
- cout << "Измененная строка : ";
- string1.print();
- string1.getid();
- MyString string2;
- string2.getcount();
- string2.set();
- cout << "Введенная строка : ";
- string2.print();
- string2.update();
- cout << "Измененная строка : ";
- string2.print();
- string2.getid();
- MyString string3;
- string3.getcount();
- string3.set();
- cout << "Введенная строка : ";
- string3.print();
- string3.update();
- cout << "Измененная строка : ";
- string3.print();
- string3.getid();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement