Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
55 changes: 26 additions & 29 deletions 1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,36 @@
using namespace std;

class container {

int size;
int size;
float* p;
public:
float* p;
container(int s) :size(s){}
const int& getsize() { return size;}

container(int s) : size(s), p(new float[s]) {}
int& getsize() { return size; }
~container() { delete[] p; }
};

class vector :public container {

int call_num;
class vector : public container {
mutable int call_num;
public:
explicit vector(int l) :len(l),size(1 * 100){
p = new float();
}
int len;
int& getlen() const {
call_num ++;
return len;
}
~vector() = default;
int len;
explicit vector(int l) : container(100), len(l), call_num(0) {}
int& getlen() {
call_num++;
return len;
}
~vector() = default;
};

int main() {

container c1(100);
vector v1 = c1;
container& r1 = v1;
container c2 = 100;
c2.getsize() = 20;
cout << c2.getsize();
vector v2 = 100;
v2.getlen = 40;
cout << v2.getlen();
}
container c1(100);
vector v1(100);
container& r1 = v1;
container c2(100);
c2.getsize() = 20;
cout << c2.getsize();
vector v2(100);
v2.getlen() = 40;
cout << v2.getlen();
return 0;
}
8 changes: 4 additions & 4 deletions 2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
33 changes: 27 additions & 6 deletions 3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,33 @@ void search(int x)
printf("ERROR2");
break;
}
counter ++;
node = node->next;
}

void rpop() {//pop last element
if(!front)
{
return ;
}
alfaptr node = front;
while (node)
alfaptr prev_node = NULL;
while (node->next)
{
prev_node = node;
node = node->next;
free(rear);
rear = node;
}
if(prev_node)
{
prev_node->next = NULL;
}
else
{
front = NULL;
free(node);
rear = prev_node;
}

}

void set()
Expand All @@ -66,7 +84,7 @@ void set()
int size()
{
alfaptr node = front;
int count;
int count = 0;
while (node)
count++;node = node->next;
return count;
Expand All @@ -86,14 +104,17 @@ void show()

int average()
{

alfaptr node = front;
int sum = 0, count;
int sum = 0, count = 0;
while (node) {
sum += node->x;
count++;
node = node->next;
}
if(count == 0)
{
return 0;
}
return sum / count;
}

Expand Down
5 changes: 4 additions & 1 deletion 4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ int main()
float *ptr2 = ptr1 + 3;
printf("%f", *ptr2 - *ptr1);
return 0;
}
}


// 78
Binary file added 4.exe
Binary file not shown.
13 changes: 12 additions & 1 deletion 5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,15 @@ int main()
printf("%d\n", (*ptr2 - *ptr1));
printf("%c", (char)(*ptr2 - *ptr1));
return 0;
}
}

//کد مشکلی نداره ولی اگر بخوایم خط اخر کاراکتر چاپ کنه باید اینجوری بنویسیم
//علت اینکه در نسخه اصلی عدد چاپ می شود این است که ما کد اسکی را با کست کردن به کاراکتر خواهیم داشت و نه خود حرف را

// printf("%c", (*ptr2 - *ptr1) + 'a');

// خروجی حالت اصلی
// 50 - 2

// خروجی حالت فرعی
// 50 - p
Binary file added 5.exe
Binary file not shown.
6 changes: 4 additions & 2 deletions 6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
int main()
{
int a;
char *x;
x = (char *)&a;
unsigned char *x;
x = (unsigned char *)&a;
a = 512;
x[0] = 1;
printf("%d\n", a);
return 0;
}

//513
Binary file added 6.exe
Binary file not shown.
4 changes: 3 additions & 1 deletion 7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ int main()
p += 2;
printf("%d", *p);
return 0;
}
}

//3
6 changes: 2 additions & 4 deletions 8.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#include<stdio.h>
const char * f(const char **p) {
auto q = (p + sizeof(char))[1];
auto q = *(p + 1);
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%c%c\n", *str[0], *(str[1] + 1) , *((str + 2) + 1), **(str - 1 + 4));

}