From 50558803fa68b4fa4bf326f96a22caa6cff0cbf3 Mon Sep 17 00:00:00 2001 From: Amir965419 <133672881+Amir965419@users.noreply.github.com> Date: Mon, 15 May 2023 18:37:07 +0330 Subject: [PATCH 1/6] no bug --- 4.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/4.cpp b/4.cpp index a9a32f2..5a6ab7a 100644 --- a/4.cpp +++ b/4.cpp @@ -6,4 +6,5 @@ int main() float *ptr2 = ptr1 + 3; printf("%f", *ptr2 - *ptr1); return 0; -} \ No newline at end of file +} +//78.000 will print \ No newline at end of file From bcd6e57a394d4595713ba50e1a9d6313cda49b7e Mon Sep 17 00:00:00 2001 From: Amir965419 <133672881+Amir965419@users.noreply.github.com> Date: Mon, 15 May 2023 18:37:35 +0330 Subject: [PATCH 2/6] no bug --- 5.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/5.cpp b/5.cpp index e9a1737..60e58ee 100644 --- a/5.cpp +++ b/5.cpp @@ -7,4 +7,6 @@ int main() printf("%d\n", (*ptr2 - *ptr1)); printf("%c", (char)(*ptr2 - *ptr1)); return 0; -} \ No newline at end of file +} +//50 will print +//2 will print \ No newline at end of file From cbc674257c229e6ccf1acee87f4357da7a62361d Mon Sep 17 00:00:00 2001 From: Amir965419 <133672881+Amir965419@users.noreply.github.com> Date: Mon, 15 May 2023 18:37:52 +0330 Subject: [PATCH 3/6] no bug --- 6.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/6.cpp b/6.cpp index bb721c3..1c1f682 100644 --- a/6.cpp +++ b/6.cpp @@ -9,3 +9,4 @@ int main() printf("%d\n", a); return 0; } +//513 will print From 249d03e96a8aa1d2e6065d9d8f02040fee9e12a4 Mon Sep 17 00:00:00 2001 From: Amir965419 <133672881+Amir965419@users.noreply.github.com> Date: Mon, 15 May 2023 18:38:09 +0330 Subject: [PATCH 4/6] no bug --- 7.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/7.cpp b/7.cpp index 7b065a0..23eeabc 100644 --- a/7.cpp +++ b/7.cpp @@ -7,4 +7,5 @@ int main() p += 2; printf("%d", *p); return 0; -} \ No newline at end of file +} +//3 will print \ No newline at end of file From 3e8f93a07b08d723fa799896d33f0af4e9b32bf2 Mon Sep 17 00:00:00 2001 From: Amir965419 <133672881+Amir965419@users.noreply.github.com> Date: Mon, 15 May 2023 19:02:12 +0330 Subject: [PATCH 5/6] bug fixed --- 2.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/2.cpp b/2.cpp index 6a27746..624107a 100644 --- a/2.cpp +++ b/2.cpp @@ -5,11 +5,11 @@ using namespace std; // count all the specific char in the whole array of strings int countAllSpecificChars(string sArr[], int arrLength, char specificChar) { - int count; - for (int i = 0; i <= arrLength; ++i) - for (int j = 0; j <= sArr[i].size(); ++j) + int count = 0; + for (int i = 0; i < arrLength; i++)//i++ i < arrLength + for (int j = 0; j < sArr[i].size(); j++)//j++ j < sArr[i].size() // if the jth char of the string is the specific char - if (sArr[i][j] = specificChar) + if (sArr[i][j] == specificChar)//== count++; return count; } From 04435cb27fa8d1346a0f480c7d5898e68a5de2b7 Mon Sep 17 00:00:00 2001 From: Amir965419 <133672881+Amir965419@users.noreply.github.com> Date: Mon, 15 May 2023 19:02:45 +0330 Subject: [PATCH 6/6] bug fixed, one bug remains --- 1.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/1.cpp b/1.cpp index 190c209..fbbe4b6 100644 --- a/1.cpp +++ b/1.cpp @@ -2,12 +2,18 @@ using namespace std; class container { - +protected: int size; public: float* p; + container(){ + + } container(int s) :size(s){} const int& getsize() { return size;} + void set_size(int size){ + this->size = size; + } }; @@ -15,11 +21,14 @@ class vector :public container { int call_num; public: - explicit vector(int l) :len(l),size(1 * 100){ + vector(){ + + } + explicit vector(int l) :len(l),container(1 * 100){ p = new float(); } int len; - int& getlen() const { + int& getlen(){ call_num ++; return len; } @@ -29,12 +38,13 @@ class vector :public container { int main() { container c1(100); - vector v1 = c1; + vector v1 = (vector)c1; container& r1 = v1; container c2 = 100; - c2.getsize() = 20; + c2.set_size(20);//set function + c2.getsize(); cout << c2.getsize(); - vector v2 = 100; - v2.getlen = 40; + vector v2{100}; + v2.getlen() = 40; cout << v2.getlen(); } \ No newline at end of file