From bef7255737972a07b19dca88796c908b9d97ff70 Mon Sep 17 00:00:00 2001 From: vania Date: Wed, 17 May 2023 18:31:13 +0330 Subject: [PATCH 1/8] file 1 is edited and succcessfully compiled. --- 1.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/1.cpp b/1.cpp index 190c209..1877a58 100644 --- a/1.cpp +++ b/1.cpp @@ -8,33 +8,47 @@ class container { float* p; container(int s) :size(s){} const int& getsize() { return size;} + void setsize(int s){ + size=s; + } }; - class vector :public container { int call_num; public: - explicit vector(int l) :len(l),size(1 * 100){ + vector():len(0),container(0){ + p=NULL; + } + vector(int l) :len(l),container(1 * 100){ p = new float(); } int len; - int& getlen() const { + int& getlen() { call_num ++; return len; } + void setlen(int l){ + len=l; + } ~vector() = default; + vector& operator=(container& c){ + setsize(c.getsize()); + len=0; + return *this; + } }; int main() { container c1(100); - vector v1 = c1; + vector v1; + v1=c1; container& r1 = v1; container c2 = 100; - c2.getsize() = 20; + c2.setsize(20); cout << c2.getsize(); vector v2 = 100; - v2.getlen = 40; + v2.setlen(40); cout << v2.getlen(); } \ No newline at end of file From e87348008f85de296424ffd2ba4843c376b17f85 Mon Sep 17 00:00:00 2001 From: vania Date: Wed, 17 May 2023 18:37:30 +0330 Subject: [PATCH 2/8] file2 is edited and compiled successfuly. --- 2.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/2.cpp b/2.cpp index 6a27746..58e302a 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) + for (int j = 0; j < sArr[i].size(); ++j) // 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 87581c9b9fd8c27c775076c7228f11deadd09d11 Mon Sep 17 00:00:00 2001 From: vania Date: Wed, 17 May 2023 20:58:55 +0330 Subject: [PATCH 3/8] file3 is edited and compiled successfuly --- 3.cpp | 153 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 82 insertions(+), 71 deletions(-) diff --git a/3.cpp b/3.cpp index c8732ef..48cc66e 100644 --- a/3.cpp +++ b/3.cpp @@ -1,41 +1,45 @@ #include #include #define MAX_SIZE 200 -int arr[MAX_SIZE]; - +int arr[MAX_SIZE]= {0}; +//we want to create a linklist typedef struct alfa * alfaptr; -struct alfa { - long long x; +struct alfa {//we have a struct(alfa) have one data of long long int and one pointer + long long int x; alfaptr next; }; -alfaptr rear = NULL, front = NULL; -void push(int x) -{ - alfaptr node; - node = (alfaptr)malloc(sizeof(struct alfa)); +alfaptr rear = NULL, front = NULL;//add new node +void push(int x) { //this function push new node to our linklist + alfaptr node;//we have a pointer that save the address of new node in it + node = (alfaptr)malloc(sizeof(struct alfa));//get memory for new node node->x = x; - if (!front) + if (!front) { //if the new node is the first node of linklist front = node; - else { + rear=node; + } else { rear->next = node; - rear = node; + rear = node;//the rear pointer should point to the new node + rear->next=NULL; } } -void pop() -{ - alfaptr node; - if (!front) +void pop() { //remove the first node + alfaptr node,ptr=front; + if (!front)//the linklist is empty printf("ERROR1"); - else - { + if(front->next==NULL) { + free(front); + front=NULL; + rear=NULL; + return; + } else { node = front->next; front = node; + free(ptr); } } -void search(int x) -{ +void search(int x) { //search one data in our list while find one data that not equal to this data alfaptr node = front; int counter = 0; while (node) @@ -45,50 +49,57 @@ void search(int x) printf("ERROR2"); break; } - node = node->next; + node = node->next; } -void rpop() {//pop last element +void rpop() {//pop last element(remove the node from the last of the linklist) alfaptr node = front; - while (node) + if(front->next==NULL) { + free(front); + front=NULL; + rear=NULL; + return; + } + while (node->next->next!=NULL) node = node->next; free(rear); rear = node; + node->next=NULL; } -void set() -{ +void set() { alfaptr node = front; for (int i = 0; i < MAX_SIZE && node; i++, node = node->next) arr[i] = node->x; } -int size() -{ +int size() { //this function count the nodes and return the number of nodes alfaptr node = front; - int count; - while (node) - count++;node = node->next; + int count=0; + if(front==NULL) + return count; + while (node!=NULL) { + count++; + node = node->next; + } return count; } -void show() -{ - if (!front) { +void show() {//show the all member of arr if the linklist is not empty + if (!front) + printf("ERROR3"); + else { for (int i = 0; i < MAX_SIZE; i++) printf("%d ", arr[i]); } - else - { - printf("ERROR3"); - } } -int average() -{ +int average() {//this function measure the average number and return it alfaptr node = front; - int sum = 0, count; + int sum = 0, count=0; + if(front==NULL)//default average + return 0; while (node) { sum += node->x; count++; @@ -97,40 +108,40 @@ int average() return sum / count; } -void main() -{ +int main() { int cmd; long long int x; - while (true) - { + while (true) { scanf("%d", &cmd); - switch (cmd) - { - case 1://push - scanf("%lld", &x); - push(x); - break; - case 2://pop - pop(); - break; - case 3://rpop - rpop(); - break; - case 4://search - scanf("%lld", &x); - search(x); - break; - case 5://set - set(); - break; - case 6://show - show(); - break; - case 7://size - printf("%d", size()); - break; - case 10: - exit(0); + switch (cmd) { + case 1://push + scanf("%lld", &x); + push(x); + break; + case 2://pop + pop(); + break; + case 3://rpop + rpop(); + break; + case 4://search + scanf("%lld", &x); + search(x); + break; + case 5://set + set(); + break; + case 6://show + show(); + break; + case 7://size + printf("%d", size()); + break; + case 9: + printf("%d", average()); + case 10: + exit(0); } } + return 0; } \ No newline at end of file From 6012a28dbe1302a11eb312d4b31538c5232c4c68 Mon Sep 17 00:00:00 2001 From: vania Date: Wed, 17 May 2023 21:09:11 +0330 Subject: [PATCH 4/8] file4 is edited and compiled successfuly. --- 4.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/4.cpp b/4.cpp index a9a32f2..e8f7905 100644 --- a/4.cpp +++ b/4.cpp @@ -6,4 +6,8 @@ int main() float *ptr2 = ptr1 + 3; printf("%f", *ptr2 - *ptr1); return 0; -} \ No newline at end of file +}/*this program first build a float_array contain of +5 memberes and then we have pointer1 that have the address +of the first house of array and the second pointer that have the +address of the fourth house of array and then we print the defference +between the tow number that these these two pointers point to and the output is 78*/ \ No newline at end of file From 8837d7096e88251735091b7bd380e8b40cd960f2 Mon Sep 17 00:00:00 2001 From: vania Date: Wed, 17 May 2023 21:20:29 +0330 Subject: [PATCH 5/8] the file 5 is edited --- 5.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/5.cpp b/5.cpp index e9a1737..13eaaea 100644 --- a/5.cpp +++ b/5.cpp @@ -4,7 +4,12 @@ int main() int arr[] = { 10, 20, 30, 40, 50, 60 }; int *ptr1 = arr; int *ptr2 = arr + 5; - printf("%d\n", (*ptr2 - *ptr1)); - printf("%c", (char)(*ptr2 - *ptr1)); + printf("%d\n", (*ptr2 - *ptr1));//the output is 50 + printf("%c", (char)(*ptr2 - *ptr1));//the output is 2 return 0; -} \ No newline at end of file +}/*we have a array of 6 number,we have the first + pointer that point to the first house of array and +the second pointer that point the sixth house of array +then we print the deference between the number that pointer +2 point and the number that pointer 1 point,then we print the +fifth char of askii table*/ \ No newline at end of file From b161e4ef2c0cce0d1940aa775df1bdaf67a00b92 Mon Sep 17 00:00:00 2001 From: vania Date: Wed, 17 May 2023 21:27:26 +0330 Subject: [PATCH 6/8] file 6 --- 6.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/6.cpp b/6.cpp index bb721c3..90b394d 100644 --- a/6.cpp +++ b/6.cpp @@ -6,6 +6,7 @@ int main() x = (char *)&a; a = 512; x[0] = 1; - printf("%d\n", a); + printf("%d\n", a);//print 513 return 0; -} +}/*we have a int named a +than we ++a and then print it*/ From fe8ab23ad3abdbae30daf77c6c40b3f923f2cb37 Mon Sep 17 00:00:00 2001 From: vania Date: Wed, 17 May 2023 21:30:09 +0330 Subject: [PATCH 7/8] file 7 --- 7.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/7.cpp b/7.cpp index 7b065a0..8ba96f0 100644 --- a/7.cpp +++ b/7.cpp @@ -3,8 +3,8 @@ int main() { int arr[] = { 1, 2, 3, 4, 5 }; int *p = arr; - ++*p; - p += 2; - printf("%d", *p); + ++*p;//first ++p and then *p + p += 2;//arr[0]+2 + printf("%d", *p);//the output is 3 return 0; } \ No newline at end of file From cba6fcd058bf870c9612db709e8ea18e00d2cb7d Mon Sep 17 00:00:00 2001 From: vania Date: Wed, 17 May 2023 21:47:32 +0330 Subject: [PATCH 8/8] file 8 --- 8.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/8.cpp b/8.cpp index 76b870c..9a479e9 100644 --- a/8.cpp +++ b/8.cpp @@ -1,12 +1,13 @@ #include -const char * f(const char **p) { - auto q = (p + sizeof(char))[1]; +const char * f(const char **p) {//this fuction get char ** + auto q = (p + sizeof(char))[1];//move the pointer forward one house and then again move it forward one house return q; } int main() { const char * str[] = { "Wish","You","Best",":D" }; - printf("%c%c ", *f(str), *(f(str) + 1)); - printf("%c%c%c%c\n", **str, *(*(str + 1) + 1), *((str + 2)[-1] + 1), **&*(&str[-1] + 1)); + printf("%c%c ", *f(str), *(f(str) + 1));//the *f(str)==B , the f(str)+1 the address of the house B and *(f(str)+1)==e the result is Be + printf("%c%c%c%c\n", **str, *(*(str + 1) + 1), *((str + 2)[-1] + 1), **&*(&str[-1] + 1));/***str==w ,*(str + 1)=the address of the house of "you" + *(*(str + 1) + 1)==O ,*((str + 2)[-1] + 1)==o , **&*(&str[-1] + 1)==w the result is woow*/