Skip to content

Commit 4c4f8b6

Browse files
committed
cpp training
1 parent df005bf commit 4c4f8b6

File tree

106 files changed

+8208
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+8208
-1
lines changed

01_Cpp_Tutorials/.DS_Store

8 KB
Binary file not shown.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Learning C++ eBook - Compiled from StackOverflow Documentation (PDF)
2+
3+
https://riptutorial.com/Download/cplusplus.pdf
4+
5+
# Cpp : Bjarne Stroustrup
6+
7+
- C++ Core Guidelines - edt.: Bjarne Stroustrup, Herb Sutter
8+
9+
- https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md
10+
11+
- Joint Strike Fighter, C++ Coding Standards - Bjarne Stroustrup (PDF)
12+
13+
- https://www.stroustrup.com/JSF-AV-rules.pdf
14+
15+
<br>
16+
17+
<hr>
18+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Result
2+
3+
```
4+
$ ./build.sh
5+
6+
$ ls
7+
a.out build.sh delete.sh main.cpp main.o
8+
9+
$ ./a.out
10+
4
11+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
g++ -g -std=c++11 -Wall -Wextra -ggdb -c *.cpp
4+
5+
g++ *.o
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
rm -rf a.out.dSYM *.gch *.o a.out
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <iostream>
2+
3+
int add2(int i) {
4+
int j = i + 2;
5+
return j;
6+
}
7+
8+
int main() {
9+
10+
std::cout << add2(2) << "\n";
11+
12+
return 0;
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Result
2+
3+
```
4+
$ ./build.sh
5+
6+
$ ./a.out
7+
8+
No argument passed: ***
9+
First argument passed: ###
10+
11+
Both arguments passed: $$$$$
12+
13+
```
14+
15+
# Source
16+
17+
https://www.programiz.com/cpp-programming/default-argument
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
g++ -g -std=c++11 -Wall -Wextra -ggdb -c *.cpp
4+
5+
g++ *.o
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
rm -rf a.out.dSYM *.gch *.o a.out
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <iostream>
2+
3+
// defining the default arguments
4+
void display(char = '*', int = 3);
5+
6+
int main() {
7+
int count = 5;
8+
9+
std::cout << "No argument passed: ";
10+
// *, 3 will be parameters
11+
display();
12+
13+
std::cout << "First argument passed: ";
14+
// #, 3 will be parameters
15+
display('#');
16+
17+
std::cout << "Both arguments passed: ";
18+
// $, 5 will be parameters
19+
display('$', count);
20+
21+
return 0;
22+
}
23+
24+
void display(char c, int count) {
25+
for (int i = 1; i <= count; ++i) {
26+
std::cout << c;
27+
}
28+
std::cout << std::endl;
29+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Result
2+
3+
```
4+
$ ./build.sh
5+
6+
$ ./a.out
7+
8+
4
9+
6
10+
14
11+
11
12+
13+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
g++ -g -std=c++11 -Wall -Wextra -ggdb -c *.cpp
4+
5+
g++ *.o
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
rm -rf a.out.dSYM *.gch *.o a.out
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <iostream>
2+
3+
int add2(int i) {
4+
int j = i + 2;
5+
return j;
6+
}
7+
8+
int add2(int i, int j) {
9+
int k = i + j + 2;
10+
return k;
11+
}
12+
13+
int main() {
14+
15+
std::cout << add2(2) << "\n";
16+
std::cout << add2(1, 3) << "\n";
17+
std::cout << add2(5, 7) << "\n";
18+
std::cout << add2(9) << "\n";
19+
20+
return 0;
21+
}
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Result
2+
3+
```
4+
$ ./build.sh
5+
6+
$ ls
7+
a.out build.sh delete.sh main.cpp main.o
8+
9+
$ ./a.out
10+
4
11+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
g++ -g -std=c++11 -Wall -Wextra -ggdb -c *.cpp
4+
5+
g++ *.o
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
rm -rf a.out.dSYM *.gch *.o a.out
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <iostream>
2+
3+
int main() {
4+
int a, b;
5+
6+
int result;
7+
8+
a = 5;
9+
b = 2;
10+
a = a + 1;
11+
result = a - b;
12+
std::cout << result << std::endl;
13+
14+
return 0;
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# C++ doc tutorial
2+
3+
https://cplusplus.com/doc/tutorial/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Result
2+
3+
```
4+
$ ./build.sh
5+
6+
$ ./a.out
7+
8+
Element found in myints: 30
9+
Element found in myvector: 30
10+
11+
```
12+
13+
# Source
14+
15+
https://cplusplus.com/reference/algorithm/find/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
g++ -g -std=c++11 -Wall -Wextra -ggdb -c *.cpp
4+
5+
g++ *.o
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
rm -rf a.out.dSYM *.gch *.o a.out
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <algorithm>
2+
#include <iostream>
3+
#include <vector>
4+
5+
int main() {
6+
int myints[] = {10, 20, 30, 40};
7+
int *p;
8+
9+
p = std::find(myints, myints + 4, 30);
10+
if (p != myints + 4)
11+
std::cout << "Element found in myints: " << *p << '\n';
12+
else
13+
std::cout << "Element not found in myints \n";
14+
15+
std::vector<int> myvector(myints, myints + 4);
16+
std::vector<int>::iterator it;
17+
18+
it = find(myvector.begin(), myvector.end(), 30);
19+
if (it != myvector.end())
20+
std::cout << "Element found in myvector: " << *it << '\n';
21+
else
22+
std::cout << "Element not found in myvector \n";
23+
24+
return 0;
25+
}
6 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Result
2+
3+
```
4+
❯ ./build.sh
5+
❯ ./main
6+
255.000000
7+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
clang -Wall -Wextra -ggdb -o main main.c -lm
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
rm -rf a.out.dSYM main.dSYM main
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
int p, n;
5+
float r, si;
6+
7+
p = 1000;
8+
n = 3;
9+
r = 8.5;
10+
11+
si = p * n * r / 100;
12+
printf("%f\n", si);
13+
return 0;
14+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# CodeAhoy
2+
3+
https://codeahoy.com/learn/cprogramming/ch4/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Source
2+
3+
https://codeahoy.com/learn/cprogramming/ch46/
4+
5+
# Result
6+
7+
```
8+
9+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CC=gcc
2+
CFLAGS=-g3 -Wall
3+
4+
all:
5+
6+
test: test-stack
7+
./test-stack
8+
@echo OK!
9+
10+
test-stack: test-stack.o tester.o stack.o
11+
$(CC) $(CFLAGS) -o $@ $^
12+
13+
test-stack.o: stack.h tester.h
14+
stack.o: stack.h
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Source
2+
3+
https://codeahoy.com/learn/cprogramming/ch46/
4+
5+
# Result
6+
7+
```
8+
9+
```

0 commit comments

Comments
 (0)