From 281a8b53f66e9e5783e369b5ff9081ece9135cd5 Mon Sep 17 00:00:00 2001 From: milana Date: Sun, 30 Apr 2023 21:18:27 +0500 Subject: [PATCH 1/4] 1 --- .idea/.gitignore | 8 +++ .idea/CPP.iml | 2 + .idea/misc.xml | 6 ++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 6 ++ classString/CMakeLists.txt | 7 ++ classString/main.cpp | 16 +++++ classString/string.cpp | 72 +++++++++++++++++++ classString/string.h | 18 +++++ .../CMakeFiles/clion-Debug-log.txt | 1 + 10 files changed, 144 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/CPP.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 classString/CMakeLists.txt create mode 100644 classString/main.cpp create mode 100644 classString/string.cpp create mode 100644 classString/string.h create mode 100644 cmake-build-debug/CMakeFiles/clion-Debug-log.txt diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/CPP.iml b/.idea/CPP.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/CPP.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5a853d8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..095bf1d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/classString/CMakeLists.txt b/classString/CMakeLists.txt new file mode 100644 index 0000000..c011521 --- /dev/null +++ b/classString/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.23) +project(CPP) + +set(CMAKE_CXX_STANDARD 14) + +add_executable(CPP + string.cpp string.h main.cpp) \ No newline at end of file diff --git a/classString/main.cpp b/classString/main.cpp new file mode 100644 index 0000000..02c31a8 --- /dev/null +++ b/classString/main.cpp @@ -0,0 +1,16 @@ +#include +#include "string.h" + +using namespace std; + +int main(){ + String firstString("Milana"); + String secondString("Zinovieva"); + String emptyString; + String cloneString(firstString); + cout << cloneString; + String result = firstString + secondString; + cout << result; + bool check = firstString == result; + cout << check << endl; +} \ No newline at end of file diff --git a/classString/string.cpp b/classString/string.cpp new file mode 100644 index 0000000..f35dd53 --- /dev/null +++ b/classString/string.cpp @@ -0,0 +1,72 @@ +#include +#include "string.h" + +using namespace std; + +String::String(){ + lengthString = 0; + dataString = new char[1]; + dataString[0] = '\0'; +} + +String::String(const char *string) { + lengthString = 0; + while(string[lengthString] != '\0'){ + lengthString++; + } + dataString = new char[lengthString + 1]; + for(int i = 0;i < lengthString;i++) + dataString[i] = string[i]; + dataString[lengthString + 1] = '\0'; +} + +String::String(const String &otherString) { + lengthString = otherString.lengthString; + dataString = new char[lengthString + 1]; + for (int i = 0;i < lengthString;i++) + dataString[i] = otherString.dataString[i]; + dataString[lengthString + 1] = '\0'; +} + +String::~String() { + delete[] dataString; +} + +const char* String::c_str() const { + return dataString; +} + +ostream& operator<< (ostream &out, const String &string) +{ + out << string.c_str() << endl; + return out; +} + +String String::operator+(String secondString) { + String result; + result.lengthString = secondString.lengthString + lengthString; + result.dataString = new char[result.lengthString + 1]; + for (int i = 0;i < lengthString;i++) + result.dataString[i] = dataString[i]; + for (int u = lengthString, t = 0;u < result.lengthString;u++, t++) { + result.dataString[u] = secondString.dataString[t]; + } + result.dataString[result.lengthString + 1] = '\0'; + return result; +} + +bool String::operator==(String other) { + int count = 0; + if (other.lengthString != lengthString){ + return false; + }else{ + for(int i = 0;i < lengthString;i++){ + if (other.dataString[i] == dataString[i]) + count++; + } + } + if (count == lengthString) + return true; + else + return false; +} diff --git a/classString/string.h b/classString/string.h new file mode 100644 index 0000000..d027ecb --- /dev/null +++ b/classString/string.h @@ -0,0 +1,18 @@ +#include + +using namespace std; + +class String{ +private: + char* dataString; + int lengthString; + const char* c_str() const; +public: + String(); + String(const char* string); + String(const String& otherString); + ~String(); + friend ostream& operator<< (ostream &out, const String &string); + String operator +(String secondString); + bool operator ==(String other); +}; \ No newline at end of file diff --git a/cmake-build-debug/CMakeFiles/clion-Debug-log.txt b/cmake-build-debug/CMakeFiles/clion-Debug-log.txt new file mode 100644 index 0000000..726dd27 --- /dev/null +++ b/cmake-build-debug/CMakeFiles/clion-Debug-log.txt @@ -0,0 +1 @@ +CMakeLists.txt not found in /Users/milana/CLionProjects/CPP Select CMakeLists.txt From fc70c0c8262c3cf5d366f6d34dd78b29e1cadc51 Mon Sep 17 00:00:00 2001 From: milana Date: Tue, 2 May 2023 22:19:38 +0500 Subject: [PATCH 2/4] =?UTF-8?q?=D0=92=D1=81=D0=B5,=20=D0=BA=D1=80=D0=BE?= =?UTF-8?q?=D0=BC=D0=B5=20replace.=20=D0=9D=D0=B5=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D0=B5=D0=BD=D0=B0=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classString/main.cpp | 5 +-- classString/string.cpp | 94 +++++++++++++++++++++++++++++++++++++++++- classString/string.h | 17 +++++++- 3 files changed, 108 insertions(+), 8 deletions(-) diff --git a/classString/main.cpp b/classString/main.cpp index 02c31a8..c1f66e9 100644 --- a/classString/main.cpp +++ b/classString/main.cpp @@ -8,9 +8,6 @@ int main(){ String secondString("Zinovieva"); String emptyString; String cloneString(firstString); - cout << cloneString; String result = firstString + secondString; - cout << result; - bool check = firstString == result; - cout << check << endl; + cout << result[4]; } \ No newline at end of file diff --git a/classString/string.cpp b/classString/string.cpp index f35dd53..6cff054 100644 --- a/classString/string.cpp +++ b/classString/string.cpp @@ -42,7 +42,7 @@ ostream& operator<< (ostream &out, const String &string) return out; } -String String::operator+(String secondString) { +String String::operator+(const String& secondString) { String result; result.lengthString = secondString.lengthString + lengthString; result.dataString = new char[result.lengthString + 1]; @@ -55,7 +55,7 @@ String String::operator+(String secondString) { return result; } -bool String::operator==(String other) { +bool String::operator==(const String& other) { int count = 0; if (other.lengthString != lengthString){ return false; @@ -70,3 +70,93 @@ bool String::operator==(String other) { else return false; } + +char String::operator[](int number) { + return dataString[number]; +} + +char String::front() { + if (lengthString == 0) + return ' '; + else + return dataString[0]; +} + +char String::back() { + if (lengthString == 0) + return ' '; + else + return dataString[lengthString]; +} + +int String::size() const { + return lengthString; +} + +void String::clear() { + for(int i = 0;i < lengthString;i++) + dataString[i] = '\0'; + lengthString = 0; +} + +bool String::empty() const { + if (lengthString == 0) + return true; + else + return false; +} + +String String::insert(const String& need, int position) { + int tempLength = lengthString; + lengthString = lengthString + need.lengthString; + for(int j = tempLength;j < lengthString;j++) + dataString[j] = dataString[j - position]; + for(int i = position, b = 0;b < need.lengthString;i++, b++) + dataString[i] = need.dataString[b]; + return dataString; +} + +String String::push_back(char symbol) { + dataString[lengthString - 1] = symbol; + lengthString++; + return dataString; +} + +String String::pop_back() { + dataString[lengthString - 1] = '\0'; + lengthString--; + return dataString; +} + +int String::find_first_of(String subString) { + for(int i = 0;i < lengthString;i++){ + int count = 0; + for(int j = 0;j < subString.lengthString;j++){ + if (dataString[i] == subString[j]) + count++; + } + if (count == subString.lengthString) + return i; + } + return -1; +} + +String String::substr(int startPosition, int endPosition) { + String newString; + for(int i = startPosition, j = 0;i < endPosition;i++, j++) + newString.dataString[j] = dataString[i]; + return newString; +} + +String String::replace(int position, int count, String newString) { + return String(); +} + +String String::append(const String& secondString) { + int tempLength = lengthString; + lengthString = lengthString + secondString.lengthString; + for (int i = tempLength, j = 0;i < lengthString;i++, j++){ + dataString[i] = secondString.dataString[j]; + } + return dataString; +} diff --git a/classString/string.h b/classString/string.h index d027ecb..1fcd0c7 100644 --- a/classString/string.h +++ b/classString/string.h @@ -13,6 +13,19 @@ class String{ String(const String& otherString); ~String(); friend ostream& operator<< (ostream &out, const String &string); - String operator +(String secondString); - bool operator ==(String other); + String operator +(const String& secondString); + bool operator ==(const String& other); + char operator [](int number); + char front(); + char back(); + int size() const; + void clear(); + bool empty() const; + String insert(const String& need, int position); + String push_back(char symbol); + String pop_back(); + String append(const String& secondString); + String replace(int position, int count, String newString); + String substr(int startPosition, int endPosition); + int find_first_of(String subString); }; \ No newline at end of file From 788e1875caad78dd1cf4915e00220cee73e78302 Mon Sep 17 00:00:00 2001 From: milana Date: Thu, 4 May 2023 21:38:59 +0500 Subject: [PATCH 3/4] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D1=8E?= =?UTF-8?q?=D1=82=20front,=20back,=20size,=20clear,=20empty,=20push=5Fback?= =?UTF-8?q?=20Insert,=20pop=5Fback=20-=20=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=D1=8E=D1=82=20=D0=9E=D1=81=D1=82=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=BD=D0=B5=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=8F=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classString/main.cpp | 16 +++++++++++++++- classString/string.cpp | 34 ++++++++++++++++++++++------------ classString/string.h | 4 ++-- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/classString/main.cpp b/classString/main.cpp index c1f66e9..7d93295 100644 --- a/classString/main.cpp +++ b/classString/main.cpp @@ -9,5 +9,19 @@ int main(){ String emptyString; String cloneString(firstString); String result = firstString + secondString; - cout << result[4]; + cout << result; + cout << result.front() << endl; + cout << result.back() << endl; + cout << result.size() << endl; + bool check = result.empty(); + bool check1 = emptyString.empty(); + cout << check << check1 << endl; + firstString.clear(); + cout << firstString.size() << endl; + secondString.push_back('r'); + cout << secondString; + secondString.pop_back(); + cout << secondString; + int h = secondString.find_first_of("no"); + cout << h; } \ No newline at end of file diff --git a/classString/string.cpp b/classString/string.cpp index 6cff054..bcb8ead 100644 --- a/classString/string.cpp +++ b/classString/string.cpp @@ -86,7 +86,7 @@ char String::back() { if (lengthString == 0) return ' '; else - return dataString[lengthString]; + return dataString[lengthString - 1]; } int String::size() const { @@ -106,19 +106,23 @@ bool String::empty() const { return false; } -String String::insert(const String& need, int position) { - int tempLength = lengthString; - lengthString = lengthString + need.lengthString; - for(int j = tempLength;j < lengthString;j++) - dataString[j] = dataString[j - position]; - for(int i = position, b = 0;b < need.lengthString;i++, b++) - dataString[i] = need.dataString[b]; - return dataString; +String String::insert(String need, int position) { + String tempString; + tempString.lengthString = lengthString - position; + for(int i = 0, b = position;i < tempString.lengthString;i++, b++) + tempString.dataString[i] = dataString[b]; + for(int j = position, a = 0;a < need.lengthString;j++, a++) + dataString[j] = need.dataString[a]; + String result; + result.lengthString = position + need.lengthString; + for(int y = 0; y < result.lengthString;y++) + result.dataString[y] = dataString[y]; + return result; } String String::push_back(char symbol) { - dataString[lengthString - 1] = symbol; lengthString++; + dataString[lengthString - 1] = symbol; return dataString; } @@ -148,8 +152,14 @@ String String::substr(int startPosition, int endPosition) { return newString; } -String String::replace(int position, int count, String newString) { - return String(); +String String::replace(int position, int count, const String& newString) { + for(int i = position;i < position + count;i++) + dataString[i] = '\0'; + lengthString = lengthString - count + newString.lengthString; + for(int j = position;j < lengthString;j++){ + dataString[j] = newString.dataString[j]; + } + return dataString; } String String::append(const String& secondString) { diff --git a/classString/string.h b/classString/string.h index 1fcd0c7..d02c033 100644 --- a/classString/string.h +++ b/classString/string.h @@ -21,11 +21,11 @@ class String{ int size() const; void clear(); bool empty() const; - String insert(const String& need, int position); + String insert(String need, int position); String push_back(char symbol); String pop_back(); String append(const String& secondString); - String replace(int position, int count, String newString); + String replace(int position, int count, const String& newString); String substr(int startPosition, int endPosition); int find_first_of(String subString); }; \ No newline at end of file From faef6f8ba9b63f647e7790bb6dee41b51245308f Mon Sep 17 00:00:00 2001 From: milana Date: Mon, 15 May 2023 21:11:17 +0500 Subject: [PATCH 4/4] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20replace=20=D0=B8=20append?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classString/main.cpp | 10 +++++++-- classString/string.cpp | 48 ++++++++++++++++++++++-------------------- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/classString/main.cpp b/classString/main.cpp index 7d93295..6afc01b 100644 --- a/classString/main.cpp +++ b/classString/main.cpp @@ -22,6 +22,12 @@ int main(){ cout << secondString; secondString.pop_back(); cout << secondString; - int h = secondString.find_first_of("no"); - cout << h; + secondString.insert("jj", 3); + cout << secondString; + String checkString("milashkakakashka"); + int m = checkString.find_first_of("sa"); + cout << m << endl; + String haha = checkString.substr(4, 8); + cout << haha << endl; + } \ No newline at end of file diff --git a/classString/string.cpp b/classString/string.cpp index bcb8ead..1a11505 100644 --- a/classString/string.cpp +++ b/classString/string.cpp @@ -75,77 +75,79 @@ char String::operator[](int number) { return dataString[number]; } -char String::front() { +char String::front() { //ready if (lengthString == 0) return ' '; else return dataString[0]; } -char String::back() { +char String::back() { //ready if (lengthString == 0) return ' '; else return dataString[lengthString - 1]; } -int String::size() const { +int String::size() const { //ready return lengthString; } -void String::clear() { +void String::clear() { //ready for(int i = 0;i < lengthString;i++) dataString[i] = '\0'; lengthString = 0; } -bool String::empty() const { +bool String::empty() const { //ready if (lengthString == 0) return true; else return false; } -String String::insert(String need, int position) { +String String::insert(String need, int position) { //ready String tempString; - tempString.lengthString = lengthString - position; - for(int i = 0, b = position;i < tempString.lengthString;i++, b++) - tempString.dataString[i] = dataString[b]; - for(int j = position, a = 0;a < need.lengthString;j++, a++) - dataString[j] = need.dataString[a]; - String result; - result.lengthString = position + need.lengthString; - for(int y = 0; y < result.lengthString;y++) - result.dataString[y] = dataString[y]; - return result; + for(int i = position, j = 0;i < lengthString;i++, j++) + tempString.dataString[j] = dataString[i]; + lengthString += need.lengthString; + for(int x = position, y = 0;x < position + need.lengthString;x++, y++) + dataString[x] = need.dataString[y]; + for(int h = position + need.lengthString, n = 0;h < lengthString;h++, n++) + dataString[h] = tempString.dataString[n]; + return dataString; } -String String::push_back(char symbol) { +String String::push_back(char symbol) { //ready lengthString++; dataString[lengthString - 1] = symbol; return dataString; } -String String::pop_back() { +String String::pop_back() { //ready dataString[lengthString - 1] = '\0'; lengthString--; return dataString; } -int String::find_first_of(String subString) { - for(int i = 0;i < lengthString;i++){ +int String::find_first_of(String subString) { //ready + int i = 0; + while(i < lengthString){ int count = 0; - for(int j = 0;j < subString.lengthString;j++){ - if (dataString[i] == subString[j]) + int j = 0; + while (j < subString.lengthString){ + if (dataString[i + j] == subString[j]) count++; + j++; } if (count == subString.lengthString) return i; + i++; } return -1; } -String String::substr(int startPosition, int endPosition) { +String String::substr(int startPosition, int endPosition) { // ready String newString; for(int i = startPosition, j = 0;i < endPosition;i++, j++) newString.dataString[j] = dataString[i];