Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <fstream>
- #define SIZE 256
- class String {
- public:
- String() {
- s1 = new char[SIZE];
- }
- ~String() {
- delete[] s1;
- }
- void Set();
- void Print();
- void Task();
- String& operator= (const String &temp);
- char* s1;
- };
- void String::Set() {
- std::cin.getline(s1, SIZE);
- }
- void String::Print() {
- std::cout << s1 << std::endl;
- }
- void String::Task() { //если длина L кратна 2, то удаляются все числа, которые делятся на 2
- std::ofstream output;
- output.open("out.txt");
- if(strlen(s1) % 2 == 0) {
- char* temp = new char[strlen(s1)];
- int j = 0;
- for (int i = 0; i < strlen(s1); ++i) {
- if((int)s1[i] >= 48 && (int)s1[i] <= 57 && (int)s1[i] % 2 == 0)
- continue;
- else {
- temp[j] = s1[i];
- ++j;
- }
- }
- output << s1 << std::endl;
- s1 = temp;
- output << s1 << std::endl;
- }
- }
- String& String::operator= (const String &temp) {
- if (this == &temp)
- return *this;
- s1 = temp.s1;
- return *this;
- }
- int main() {
- String s;
- String *s2 = new String;
- s.Set(); //Вбить строку
- s.Print(); //Вывод
- s.Task(); //Выполняем задание
- s.Print(); //Вывод
- s.Print(); //Вывод
- s = s2; //Показываем работу перегруженного =
- s.Print(); //Вывод
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement