Skip to content
Open

fddf #21

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
30 changes: 22 additions & 8 deletions 1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,53 @@
using namespace std;

class container {

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

};

class vector :public container {

int call_num;
public:
explicit vector(int l) :len(l),size(1 * 100){
explicit vector(int l) :len(l),container(1 * 100){
p = new float();
}
int len;
int& getlen() const {
int& getlen() {
call_num ++;
return len;
}
~vector() = default;
vector (vector& vec):container(vec.len)
{
call_num=vec.call_num;
p=new float[size];
len=vec.len;
for(int i=0;i<size;i++)
{
p[i]=vec.p[i];
}

}

};

int main() {

container c1(100);
vector v1 = c1;
vector v1(100);
container& r1 = v1;
container c2 = 100;
container c2(100);
c2.getsize() = 20;
cout << c2.getsize();
vector v2 = 100;
v2.getlen = 40;
vector v2(100);
v2.getlen()= 40;
cout << v2.getlen();
// result = 2040
//Output = 2040
}
31 changes: 26 additions & 5 deletions 2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ 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)
// if the jth char of the string is the specific char
if (sArr[i][j] = specificChar)
count++;
for (int i = 0; i < arrLength; ++i)
{
for (int j = 0; j < sArr[i].length(); ++j)
{// if the jth char of the string is the specific char
if (sArr[i][j] == specificChar)
{
count++;
}
}
}
return count;
}


int main() {
string sArr[4] = {
"I am",
Expand All @@ -24,4 +30,19 @@ int main() {
char findIt;
cin >> findIt;
cout << countAllSpecificChars(sArr, 4, findIt);
//result for(a)=3;
//result for(I)=1;
//result for(m)=1;
//result for(i)=1;
//result for(p)=1;
//result for(c)=1;
//result for(s)=2;
//result for(l)=1;






return 0;
}
14 changes: 8 additions & 6 deletions 3.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include<stdio.h>
#include<stdlib.h>
#pragma warning(disable:4996)
#define MAX_SIZE 200
int arr[MAX_SIZE];

typedef struct alfa * alfaptr;
typedef struct alfa* alfaptr;

struct alfa {
long long x;
Expand Down Expand Up @@ -45,7 +46,7 @@ void search(int x)
printf("ERROR2");
break;
}
node = node->next;
node = node->next;
}

void rpop() {//pop last element
Expand All @@ -66,9 +67,9 @@ void set()
int size()
{
alfaptr node = front;
int count;
int count = 0;
while (node)
count++;node = node->next;
count++; node = node->next;
return count;
}

Expand All @@ -88,7 +89,7 @@ int average()
{

alfaptr node = front;
int sum = 0, count;
int sum = 0, count = 0;
while (node) {
sum += node->x;
count++;
Expand All @@ -97,7 +98,7 @@ int average()
return sum / count;
}

void main()
int main()
{
int cmd;
long long int x;
Expand All @@ -109,6 +110,7 @@ void main()
case 1://push
scanf("%lld", &x);
push(x);
// از دفعه دوم به چون front دیگر null نیست به مشکل میخورد
break;
case 2://pop
pop();
Expand Down
3 changes: 2 additions & 1 deletion 4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ int main()
float arr[5] = { 12.5, 10.0, 13.5, 90.5, 0.5 };
float *ptr1 = &arr[0];
float *ptr2 = ptr1 + 3;
printf("%f", *ptr2 - *ptr1);
printf("%f", (*ptr2 - *ptr1));
//Output = 78.000000
return 0;
}
3 changes: 3 additions & 0 deletions 5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ int main()
{
int arr[] = { 10, 20, 30, 40, 50, 60 };
int *ptr1 = arr;
// printf("%d\n",*ptr1);
int *ptr2 = arr + 5;
printf("%d\n", (*ptr2 - *ptr1));
printf("%c", (char)(*ptr2 - *ptr1));
// Output = 50
//Output = 2
return 0;
}
1 change: 1 addition & 0 deletions 6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ int main()
a = 512;
x[0] = 1;
printf("%d\n", a);
//Output = 512
return 0;
}
1 change: 1 addition & 0 deletions 7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ int main()
++*p;
p += 2;
printf("%d", *p);
//Output = 3
return 0;
}
2 changes: 1 addition & 1 deletion 8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ int main() {
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));


//Output = Be WooW

}