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
24 changes: 14 additions & 10 deletions 1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ class container {
int size;
public:
float* p;
container(int s) :size(s){}
const int& getsize() { return size;}

container(int s) :size(s) {}
const int& getsize() { return size; }
const int& getsize() const { 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();
}
vector(const container& m) :len(10), container(m.getsize()) {
p = new float();
}
int len;
int& getlen() const {
call_num ++;
int& getlen() {
call_num++;
return len;
}
~vector() = default;
Expand All @@ -32,9 +35,10 @@ int main() {
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 = (vector)100;
v2.getlen() = 40;
cout << v2.getlen();
}
}
//output after debug:10040
6 changes: 3 additions & 3 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)
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
50 changes: 35 additions & 15 deletions 3.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include<stdio.h>
#pragma warning(disable : 4996)

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#define MAX_SIZE 200
int arr[MAX_SIZE];

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

struct alfa {
long long x;
Expand All @@ -15,8 +18,12 @@ 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;
Expand All @@ -31,6 +38,7 @@ void pop()
else
{
node = front->next;
free(front);
front = node;
}
}
Expand All @@ -39,21 +47,31 @@ void search(int x)
alfaptr node = front;
int counter = 0;
while (node)
{
if (node->x == x)
printf("%d", counter);
{
counter++;
printf("%d\n", counter);
}
else {
printf("ERROR2");
break;
printf("ERROR4");
}
node = node->next;
}
}

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

void set()
Expand All @@ -66,15 +84,17 @@ void set()
int size()
{
alfaptr node = front;
int count;
while (node)
count++;node = node->next;
int count=0;
while (node!=rear->next)
{
++count; node = node->next;
}
return count;
}

void show()
{
if (!front) {
if (front) {
for (int i = 0; i < MAX_SIZE; i++)
printf("%d ", arr[i]);
}
Expand All @@ -88,7 +108,7 @@ int average()
{

alfaptr node = front;
int sum = 0, count;
int sum = 0, count=0;
while (node) {
sum += node->x;
count++;
Expand Down
3 changes: 2 additions & 1 deletion 4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ int main()
float *ptr2 = ptr1 + 3;
printf("%f", *ptr2 - *ptr1);
return 0;
}
}
//no bug output 78.000000
7 changes: 6 additions & 1 deletion 5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ int main()
printf("%d\n", (*ptr2 - *ptr1));
printf("%c", (char)(*ptr2 - *ptr1));
return 0;
}
}

//no bug
//output
//50
//2
4 changes: 4 additions & 0 deletions 6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ int main()
printf("%d\n", a);
return 0;
}
//no bug
//output
//513
//
5 changes: 4 additions & 1 deletion 7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ int main()
p += 2;
printf("%d", *p);
return 0;
}
}
//no bug
//output
//3
4 changes: 4 additions & 0 deletions 8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ int main() {


}
//no bug
//output
//Be WooW