-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
168 changed files
with
21,444 additions
and
493 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
doc/c++ tutorial/1. new grammer/1. input and output/main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <stdio.h> | ||
|
||
int main() { | ||
char name[80]; | ||
unsigned int number; | ||
|
||
printf("Input name: "); | ||
scanf("%s", name); | ||
printf("Input school number: "); | ||
scanf("%u", &number); | ||
|
||
printf("Greetings from %s(%u).\n", name, number); | ||
|
||
return 0; | ||
} |
15 changes: 15 additions & 0 deletions
15
doc/c++ tutorial/1. new grammer/1. input and output/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
int main() { | ||
std::string name; | ||
unsigned int number; | ||
|
||
std::cout << "Input name: "; | ||
std::cin >> name; | ||
std::cout << "Input school number: "; | ||
std::cin >> number; | ||
std::cout << "Greetings from " << name << "(" << number << ")." << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <stdio.h> | ||
|
||
void update(int* p, int value) { | ||
*p = value; | ||
} | ||
|
||
void example1() { | ||
int i = 0; | ||
int* iPtr = &i; | ||
|
||
printf("Example1: refence as aliasing\n"); | ||
|
||
printf("1. Initial state\n"); | ||
printf("i: %d\n", i); | ||
printf("*iPtr: %d\n\n", *iPtr); | ||
|
||
printf("2. Change i value\n"); | ||
i = 100; | ||
printf("i: %d\n", i); | ||
printf("*iPtr: %d\n\n", *iPtr); | ||
|
||
printf("3. Change the value iPtr pointing to\n"); | ||
*iPtr = 200; | ||
printf("i: %d\n", i); | ||
printf("*iPtr: %d\n\n", *iPtr); | ||
} | ||
|
||
void example2() { | ||
int i = 0; | ||
int* iPtr = &i; | ||
|
||
printf("Example2: refence as function parameters\n"); | ||
printf("1. Initial state\n"); | ||
printf("i: %d\n", i); | ||
printf("*iPtr: %d\n\n", *iPtr); | ||
|
||
printf("2. Pass the address of i to update\n"); | ||
update(&i, 100); | ||
printf("i: %d\n", i); | ||
printf("*iPtr: %d\n\n", *iPtr); | ||
|
||
printf("3. Pass iPtr to update\n"); | ||
update(iPtr, 200); | ||
printf("i: %d\n", i); | ||
printf("*iPtr: %d\n\n", *iPtr); | ||
} | ||
|
||
int main() { | ||
example1(); | ||
example2(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <iostream> | ||
|
||
void update(int& ref, int value) { | ||
ref = value; | ||
} | ||
|
||
void example1() { | ||
int i = 0; | ||
int& iRef = i; | ||
|
||
std::cout << "Example1: refence as aliasing" << std::endl; | ||
|
||
std::cout << "1. Initial state" << std::endl; | ||
std::cout << "i: " << i << std::endl; | ||
std::cout << "iRef: " << iRef << '\n' << std::endl; | ||
|
||
std::cout << "2. Change i value" << std::endl; | ||
i = 100; | ||
std::cout << "i: " << i << std::endl; | ||
std::cout << "iRef: " << iRef << '\n' << std::endl; | ||
|
||
std::cout << "3. Change iRef value" << std::endl; | ||
iRef = 200; | ||
std::cout << "i: " << i << std::endl; | ||
std::cout << "iRef: " << iRef << '\n' << std::endl; | ||
} | ||
|
||
void example2() { | ||
int i = 0; | ||
int& iRef = i; | ||
|
||
std::cout << "Example2: refence as function parameters" << std::endl; | ||
std::cout << "1. Initial state" << std::endl; | ||
std::cout << "i: " << i << std::endl; | ||
std::cout << "iRef: " << iRef << '\n' << std::endl; | ||
|
||
std::cout << "2. Pass i to update" << std::endl; | ||
update(i, 100); | ||
std::cout << "i: " << i << std::endl; | ||
std::cout << "iRef: " << iRef << '\n' << std::endl; | ||
|
||
std::cout << "3. Pass iRef to update" << std::endl; | ||
update(iRef, 200); | ||
std::cout << "i: " << i << std::endl; | ||
std::cout << "iRef: " << iRef << '\n' << std::endl; | ||
} | ||
|
||
int main() { | ||
example1(); | ||
example2(); | ||
|
||
return 0; | ||
} |
43 changes: 43 additions & 0 deletions
43
doc/c++ tutorial/1. new grammer/3. dynamic memory issue/main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#define N 10 | ||
|
||
typedef struct Student { | ||
char name[80]; | ||
int age; | ||
} Student; | ||
|
||
void example1() { | ||
printf("Example1: dynamic object\n"); | ||
int* i = (int*)malloc(sizeof(int)); | ||
|
||
*i = 100; | ||
printf("i = %d\n\n", *i); | ||
|
||
free(i); | ||
} | ||
|
||
void example2() { | ||
printf("Example2: dynamic array\n"); | ||
Student* students = (Student*)malloc(sizeof(Student) * N); | ||
|
||
for (int i = 0; i < N; ++i) { | ||
students[i].name[0] = (char)('A' + i); | ||
students[i].name[1] = '\0'; | ||
students[i].age = 20 + i; | ||
} | ||
|
||
for (int i = 0; i < N; ++i) { | ||
printf("students[%d] = { %s, %d }\n", i, students[i].name, students[i].age); | ||
} | ||
|
||
free(students); | ||
} | ||
|
||
int main() { | ||
example1(); | ||
example2(); | ||
|
||
return 0; | ||
} |
43 changes: 43 additions & 0 deletions
43
doc/c++ tutorial/1. new grammer/3. dynamic memory issue/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
constexpr int N = 10; | ||
|
||
struct Student { | ||
std::string name; | ||
int age; | ||
}; | ||
|
||
void example1() { | ||
printf("Example1: dynamic object\n"); | ||
int* i = new int; | ||
|
||
*i = 100; | ||
std::cout << "i = " << *i << '\n' << std::endl; | ||
|
||
delete i; | ||
} | ||
|
||
void example2() { | ||
printf("Example2: dynamic array\n"); | ||
Student* students = new Student[N]; | ||
|
||
for (int i = 0; i < N; ++i) { | ||
students[i].name = std::string(1, (char)('A' + i)); | ||
students[i].age = 20 + i; | ||
} | ||
|
||
for (int i = 0; i < N; ++i) { | ||
std::cout << "students[" << i << "] = { " | ||
<< students[i].name << ", " << students[i].age << " }" << std::endl; | ||
} | ||
|
||
delete[] students; | ||
} | ||
|
||
int main() { | ||
example1(); | ||
example2(); | ||
|
||
return 0; | ||
} |
34 changes: 34 additions & 0 deletions
34
doc/c++ tutorial/1. new grammer/4. operator overloading/main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <stdio.h> | ||
|
||
typedef struct Vector3f { | ||
float x, y, z; | ||
} Vector3f; | ||
|
||
Vector3f add(const Vector3f* lhs, const Vector3f* rhs) { | ||
Vector3f result; | ||
result.x = lhs->x + rhs->x; | ||
result.y = lhs->y + rhs->y; | ||
result.z = lhs->z + rhs->z; | ||
|
||
return result; | ||
} | ||
|
||
void print(const Vector3f* v) { | ||
printf("(%.3f, %.3f, %.3f)", v->x, v->y, v->z); | ||
} | ||
|
||
int main() { | ||
Vector3f v1 = { 1.0f, 0.0f, 0.0f }; | ||
Vector3f v2 = { 0.0f, 1.0f, 0.0f }; | ||
|
||
Vector3f v = add(&v1, &v2); | ||
|
||
print(&v1); | ||
printf(" + "); | ||
print(&v2); | ||
printf(" = "); | ||
print(&v); | ||
printf("\n"); | ||
|
||
return 0; | ||
} |
30 changes: 30 additions & 0 deletions
30
doc/c++ tutorial/1. new grammer/4. operator overloading/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <iostream> | ||
|
||
struct Vector3f { | ||
float x, y, z; | ||
}; | ||
|
||
Vector3f operator+(const Vector3f& lhs, const Vector3f& rhs) { | ||
Vector3f result; | ||
result.x = lhs.x + rhs.x; | ||
result.y = lhs.y + rhs.y; | ||
result.z = lhs.z + rhs.z; | ||
|
||
return result; | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, const Vector3f& v) { | ||
os << "(" << v.x << ", " << v.y << ", " << v.z << ")"; | ||
return os; | ||
} | ||
|
||
int main() { | ||
Vector3f v1 = { 1.0f, 0.0f, 0.0f }; | ||
Vector3f v2 = { 0.0f, 1.0f, 0.0f }; | ||
|
||
Vector3f v = v1 + v2; | ||
|
||
std::cout << v1 << " + " << v2 << " = " << v << std::endl; | ||
|
||
return 0; | ||
} |
61 changes: 61 additions & 0 deletions
61
doc/c++ tutorial/2. object oriented programming/1. class/c version/main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <stdio.h> | ||
#include "person.h" | ||
|
||
int main() { | ||
/* default constructor */ { | ||
printf("Init person\n"); | ||
Person p; | ||
initPersonDefault(&p); | ||
|
||
printPersonInfo(&p); | ||
} | ||
|
||
/* constructor with name and age */ { | ||
printf("\nInit person with name and age\n"); | ||
Person p; | ||
initPerson(&p, "Ben", 27); | ||
|
||
printPersonInfo(&p); | ||
} | ||
|
||
/* copy constructor */ { | ||
printf("\nInit person with another person\n"); | ||
Person q; | ||
initPerson(&q, "Sarah", 23); | ||
|
||
Person p; | ||
initPersonCopy(&p, &q); | ||
|
||
printPersonInfo(&p); | ||
} | ||
|
||
/* assign operator */ { | ||
printf("\nAssign person with another person\n"); | ||
Person p, q; | ||
initPerson(&p, "Ben", 27); | ||
initPerson(&q, "Sarah", 23); | ||
|
||
assignPerson(&p, &q); | ||
|
||
printPersonInfo(&p); | ||
} | ||
|
||
/* get info */ { | ||
printf("\nGet test\n"); | ||
Person p; | ||
initPerson(&p, "Ben", 27); | ||
printf("name: %s\n", getPersonName(&p)); | ||
printf("age: %d\n", getPersonAge(&p)); | ||
} | ||
|
||
/* set info */ { | ||
printf("\nSet test\n"); | ||
Person p; | ||
initPerson(&p, "Ben", 27); | ||
setPersonName(&p, "NEW NAME"); | ||
setPersonAge(&p, 100); | ||
printPersonInfo(&p); | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.