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
40 changes: 40 additions & 0 deletions github_git bug/AP_Git_Practice/1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
using namespace std;

class container {
protected:
int size;
public:
float* p;
container(int s) :size(s), p(nullptr) {}
const int& getsize() { return size; }
void Setsize(int x) { size = x; }
};

class vector :public container {

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

int main() {

container c1(100);
vector v1 = static_cast<vector&>(c1);
container& r1 = v1;
container c2 = 100; //emplicitly call container(100)
c2.Setsize(20);
cout << c2.getsize() << endl;
vector v2(100);
v2.len = 40;
cout << v2.getlen() << endl;
}
27 changes: 27 additions & 0 deletions github_git bug/AP_Git_Practice/2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
#include <string>

using namespace std;

// count all the specific char in the whole array of strings
int countAllSpecificChars(string sArr[], int arrLength, char specificChar) {
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)
count++;
return count;
}

int main() {
string sArr[4] = {
"I am",
"in",
"ap",
"class"
};
char findIt;
cin >> findIt;
cout << countAllSpecificChars(sArr, 4, findIt);
}
167 changes: 167 additions & 0 deletions github_git bug/AP_Git_Practice/3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#include<stdio.h>
#include<stdlib.h>
#define MAX_SIZE 200
int arr[MAX_SIZE];

typedef struct alfa* alfaptr;

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;
node->next = NULL;
if (!front) {
front = node;
rear = node;
}
else {
rear->next = node;
rear = node;
}
}

void pop()
{
alfaptr node;
if (!front)
printf("ERROR1");
else
{
node = front->next;
free(front);
front = node;
}
}
void search(int x)
{
alfaptr node = front;
int counter = 0;
while (node) {
if (node->x == x) {
printf("%d", counter);
return;
}
node = node->next;
++counter;
}

printf("ERROR2");
}

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

void set()
{
alfaptr node = front;
for (int i = 0; i < MAX_SIZE && node; i++, node = node->next)
arr[i] = node->x;
}

int size()
{
alfaptr node = front;
int count = 0;
while (node) {
count++;
node = node->next;
}
return count;
}

void show()
{
if (front) {
for (int i = 0; i < MAX_SIZE; i++)
printf("%d ", arr[i]);
}
else
{
printf("ERROR3");
}
}

int average()
{

alfaptr node = front;
int sum = 0, count = 0;

while (node) {
sum += node->x;
count++;
node = node->next;
}
if (!count)
throw 1;
return sum / count;
}

void main()
{
int cmd;
long long int x;
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 8://average
try {
int n;
n = average();
printf("%d", n);
}
catch (int) {
printf("Empty!\n");
}
break;
case 10:
exit(0);
}
}
}
10 changes: 10 additions & 0 deletions github_git bug/AP_Git_Practice/4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include<stdio.h>
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);
return 0;
}
// output: 78.000000
13 changes: 13 additions & 0 deletions github_git bug/AP_Git_Practice/5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include<stdio.h>
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));
return 0;
}
// output:
// 50 (integer)
// 2 (character)
12 changes: 12 additions & 0 deletions github_git bug/AP_Git_Practice/6.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include<stdio.h>
int main()
{
int a;
char *x;
x = (char *)&a;
a = 512;
x[0] = 1;
printf("%d\n", a);
return 0;
}
// output: 513
11 changes: 11 additions & 0 deletions github_git bug/AP_Git_Practice/7.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include<stdio.h>
int main()
{
int arr[] = { 1, 2, 3, 4, 5 };
int *p = arr;
++*p;
p += 2;
printf("%d", *p);
return 0;
}
// output: 3
11 changes: 11 additions & 0 deletions github_git bug/AP_Git_Practice/8.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include<stdio.h>
const char * f(const char **p) {
auto q = (p + sizeof(char))[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));
}
// output: Be WooW
2 changes: 2 additions & 0 deletions github_git bug/AP_Git_Practice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# APLabGitPractice
باید که کد های این مخزن رو بررسی و دیباگ کنید و کد اصلاح شده رو اینجا ارسال کنید