Wiki source code of ROS Crash Course
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | = C++ Crash Crash Course = | ||
| 2 | |||
| 3 | == Day 1 == | ||
| 4 | |||
| 5 | main function | ||
| 6 | |||
| 7 | g++ source1.cpp -o program1 | ||
| 8 | |||
| 9 | Paths, . and .. in navigating directories | ||
| 10 | |||
| 11 | data type - memory, binary | ||
| 12 | |||
| 13 | declare variables (int, char, string as series of chars) | ||
| 14 | |||
| 15 | statements end with semicolon | ||
| 16 | |||
| 17 | cstdio library include | ||
| 18 | |||
| 19 | calling a function - printf | ||
| 20 | |||
| 21 | if condition block else block (example: do something different based on argc) | ||
| 22 | |||
| 23 | for loop - 3 statements (initialiser, condition, post-loop advancement) and a code block | ||
| 24 | |||
| 25 | Homework: study "while" loop and "switch" statement | ||
| 26 | |||
| 27 | == Day 2 == | ||
| 28 | |||
| 29 | While loop - condition and 1 code block. | ||
| 30 | |||
| 31 | Do while loop - code block then condition. | ||
| 32 | |||
| 33 | While loop = for loop with empty initialiser/advancement statements | ||
| 34 | |||
| 35 | Switch - match expression's result to case label | ||
| 36 | |||
| 37 | Switch vs if-else differences. | ||
| 38 | |||
| 39 | your own function | ||
| 40 | |||
| 41 | calling with parameters copied as separate set of var values in function | ||
| 42 | |||
| 43 | classes as blueprints. | ||
| 44 | |||
| 45 | complex var data type - instances of a class all have the same set of fields | ||
| 46 | |||
| 47 | the "." field accessor (var1.func1() etc) | ||
| 48 | |||
| 49 | each instance have it's own separate memory for storing data. | ||
| 50 | |||
| 51 | Example code - fibonacci sequence. | ||
| 52 | |||
| 53 | Value overflow because not enough number of bits to represent large numbers. | ||
| 54 | |||
| 55 | Homework: implement factorial (1 to 20) calculator | ||
| 56 | |||
| 57 | == Day 3 == | ||
| 58 | |||
| 59 | factorial printer - 2 approaches: | ||
| 60 | |||
| 61 | 1. for-loop that goes 1 to 20 and each loop calls fact(n ) function and prints return. | ||
| 62 | 1. for-loop that goes 1 to 20 and multiplies once each time and print. | ||
| 63 | |||
| 64 | set initial values of vars when declaring otherwise initial values are unpredictable | ||
| 65 | |||
| 66 | |||
| 67 | |||
| 68 | |||
| 69 |