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
15 changes: 9 additions & 6 deletions 1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ class vector :public container {

int call_num;
public:
explicit vector(int l) :len(l),size(1 * 100){
explicit vector(int l) :len(l),container(100){
p = new float();
}

explicit vector(const container c): container{c}
{}
int len;
int& getlen() const {
int& getlen(){
call_num ++;
return len;
}
Expand All @@ -29,12 +32,12 @@ class vector :public container {
int main() {

container c1(100);
vector v1 = c1;
vector v1{c1};
container& r1 = v1;
container c2 = 100;
c2.getsize() = 20;
c2.getsize();
cout << c2.getsize();
vector v2 = 100;
v2.getlen = 40;
vector v2(100);
v2.getlen();
cout << v2.getlen();
}
19 changes: 8 additions & 11 deletions 2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,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)
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;
}

int main() {
string sArr[4] = {
"I am",
"in",
"ap",
"class"
};
string sArr[4] = {"I am","in","ap","class"};
char findIt;
cin >> findIt;
cout << countAllSpecificChars(sArr, 4, findIt);
}
}

// return the number of occurence of char findIt in the sArr
43 changes: 33 additions & 10 deletions 3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,25 @@ struct alfa {
long long x;
alfaptr next;
};

alfaptr rear = NULL, front = NULL;


void push(int x)
{
alfaptr node;
node = (alfaptr)malloc(sizeof(struct alfa));
node->x = x;
if (!front)
{
front = node;
else {
front->next = NULL;
}
else
{
rear->next = node;
rear = node;
rear->next = NULL;
}
}

Expand All @@ -31,6 +39,7 @@ void pop()
else
{
node = front->next;
delete front;
front = node;
}
}
Expand All @@ -39,18 +48,24 @@ void search(int x)
alfaptr node = front;
int counter = 0;
while (node)
{
if (node->x == x)
{
printf("%d", counter);
else {
printf("ERROR2");
break;
}
return;
}
node = node->next;
}

printf("ERROR2");


}

void rpop() {//pop last element

alfaptr node = front;
while (node)
while (node->next->next)
node = node->next;
free(rear);
rear = node;
Expand All @@ -66,9 +81,13 @@ 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,16 +107,20 @@ 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;
}

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

// print 90.5 - 12.5 which is 78.000000
5 changes: 3 additions & 2 deletions 5.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include<stdio.h>
int main()
{
int arr[] = { 10, 20, 30, 40, 50, 60 };
int arr[] = { 10, 20, 30, 40, 50, 60 }; // 5
int *ptr1 = arr;
int *ptr2 = arr + 5;
printf("%d\n", (*ptr2 - *ptr1));
printf("%c", (char)(*ptr2 - *ptr1));
return 0;
}
}
// print (60 - 10) and character ('2')
2 changes: 2 additions & 0 deletions 6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ int main()
printf("%d\n", a);
return 0;
}

// print 513
6 changes: 3 additions & 3 deletions 7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ int main()
{
int arr[] = { 1, 2, 3, 4, 5 };
int *p = arr;
++*p;
p += 2;
printf("%d", *p);
++*p; // 1++ -> 2 (first arr element)
p += 2; // go to index 2
printf("%d", *p); // print 3
return 0;
}
2 changes: 2 additions & 0 deletions 8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ int main() {


}

// print "Be WooW"