├── 2-foundations ├── 8-course-outro.md ├── 4-writing-larger-programs.md ├── 6-a-star-with-openstreeetmap-data.md ├── 5-extending-the-openstreetmap-data-model.md ├── 7-project-build-an-openstreetmap-route-planner.md ├── 1-welcome.md ├── 3-a-star-search.md └── 2-introduction-to-the-c++-language.md ├── 1-welcome ├── 0-important-notes.md ├── 2-get-help-with-your-account.md ├── 3-workspaces.md └── 1-welcome-to-the-c++-developer-nanodegree-program.md ├── links.md └── README.md /2-foundations/8-course-outro.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /2-foundations/4-writing-larger-programs.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /2-foundations/6-a-star-with-openstreeetmap-data.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /2-foundations/5-extending-the-openstreetmap-data-model.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /2-foundations/7-project-build-an-openstreetmap-route-planner.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /1-welcome/0-important-notes.md: -------------------------------------------------------------------------------- 1 | When you're ready to compile and run your program: 2 | 3 | `g++ ` 4 | `./a.out` 5 | -------------------------------------------------------------------------------- /links.md: -------------------------------------------------------------------------------- 1 | [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines) 2 | [istringstream docs](http://www.cplusplus.com/reference/sstream/istringstream/) 3 | -------------------------------------------------------------------------------- /1-welcome/2-get-help-with-your-account.md: -------------------------------------------------------------------------------- 1 | # 1 - FAQ 2 | Read the FAQ before asking for help on an account problem 3 | 4 | # 2 - Support 5 | After reviewing FAQ, reach out to support 6 | 7 | # 3 - Bugcrowd 8 | Platform that has Udacity's BugBounty program. 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Udacity C++ Nanodegree 2 | 3 | This is the home for my notes and coursework. 4 | 5 | The projects will live in other repos. 6 | 7 | The program has 6 parts which are broken into multiple lessons that are further broken down into multiple concepts. 8 | 9 | Part > Lesson > Concept 10 | 11 | The program also includes 4 projects and one capstone project. 12 | -------------------------------------------------------------------------------- /1-welcome/3-workspaces.md: -------------------------------------------------------------------------------- 1 | # 1 - Introduction to Workspaces 2 | You saw these in the last one. 3 | 4 | # 2 - Notebook Workspaces 5 | Jupyter notebooks with embedded terminals 6 | 7 | # 3 - Terminal Workspaces 8 | In browser IDE 9 | 10 | # 4 - Desktop Workspaces 11 | Has GPU mode 12 | 13 | # 5 - Submitting Projects 14 | Work through the notebook and either submit there or on GitHub. 15 | 16 | # 6 - Resetting and Refreshing Workspaces 17 | It's under "menu" 18 | -------------------------------------------------------------------------------- /2-foundations/1-welcome.md: -------------------------------------------------------------------------------- 1 | # 1 - Welcome 2 | Intro to some basic programming syntax 3 | A* find shortest path between 2 points on a map 4 | 5 | # 2 - Bjarne Talks About the C++ Language 6 | Between higher level software and the hardware 7 | - much bigger part of the world than most people think 8 | Started out in the telecommunications industry 9 | Other languages are implemented in C++ (java, javascript, etc) 10 | Has many features so you can learn various types of programming 11 | Works directly on the hardware very efficiently 12 | Provides strong abstraction mechanisms (so you don't always have to deal with low level stuffs) 13 | 14 | # 3 - Bjarne on How to Learn C++ 15 | Get overview of the language 16 | C++ is a modern language (treat it as such) 17 | Stick to fundamentals then use some libraries 18 | 19 | # 4 - The Core Guidelines 20 | The core guidelines exist and tell you how to use C++ 21 | -------------------------------------------------------------------------------- /1-welcome/1-welcome-to-the-c++-developer-nanodegree-program.md: -------------------------------------------------------------------------------- 1 | # 1 - Intro 2 | Good for self-driving cars, robotics, etc 3 | Will hear from creator of c++ 4 | Will emd w/job-ready portfolio 5 | 6 | # 2 - Prerequisites 7 | Know a programming language 8 | 9 | # 3 - Courses 10 | 4 course projects 11 | 1 capstone project 12 | 13 | # 4 - Projects 14 | Route Planner: OpenStreetMap data and IO2d vis library to build route planner 15 | Process Monitor: system monitor to show you what's happening on your computer 16 | Smart Pointers: build your own smart pointer to make sure you understand what it's doing 17 | Concurrent Traffic Simulation: multithreaded traffic sim using real map 18 | Capstone Project: Come up with a project of your own 19 | 20 | # 5 - David Silver 21 | Curriculum Team at Udacity 22 | 23 | # 6 - Stephen Welch 24 | Foundations Course in C++ for Udacity 25 | 26 | # 7 - Ermin Kreponic 27 | OO Programming Course and Memory Management Course 28 | 29 | # 8 - Andreas Haja 30 | Concurrency Course teacher 31 | 32 | # 9 - Bjarne Stroustrup 33 | Designer/Original implementor of C++ 34 | 35 | # 10 - What It Takes 36 | Pass every project 37 | When stuck, reach out to classmates and instructors 38 | 39 | # 11 - Reviews 40 | Submit projects and get reviews from mentors 41 | 42 | # 12 - Knowledge 43 | QA platform 44 | - try ask a question 45 | - maybe see some answers 46 | 47 | # 13 - Student Hub 48 | Real time collaboration platform 49 | -------------------------------------------------------------------------------- /2-foundations/3-a-star-search.md: -------------------------------------------------------------------------------- 1 | # 1 - Intro 2 | Going to use output from previous lesson as input for this lesson 3 | - output previously was a maze 4 | - output now will be maze + path from start to end of maze 5 | A* is algorithm professional mapping apps use to find path from one point in city to another 6 | 7 | # 2 - Motion Planning 8 | Have to devise a plan on getting from point A to point B 9 | 10 | # 3 - Quiz: Maze 11 | 7 steps to get from a to b in shortest path 12 | 13 | # 4 - Quiz: Maze 2 14 | 11 steps to get from a to b in shortest path 15 | 16 | # 5 - Coding the Shortest Path Algorithm 17 | Give grid cell names 18 | 19 | 20 | 0 1 2 3 21 | 22 | 0 23 | 24 | 1 25 | 26 | 2 27 | 28 | 3 29 | 30 | Keep a list of nodes that you'd like to investigate further 31 | - Open [0,0] (your starting state) 32 | - make sure to mark it as checked so you don't recheck it later 33 | - check if it's your final goal state 34 | Check spaces around you and see if they're open 35 | - Store the state that needs to be checked and how many expansions it took to get there (that's your g-value) 36 | [1,0] (1), [0,1] (1) 37 | Now you continue expanding 38 | - always expand the one with the smallest possible g-value first 39 | [1,0] has 3 neighbors 40 | - [0,0] (already checked) 41 | - [2,1](2) 42 | - [1,1](2) 43 | - now go back and check the next lowest 44 | - [0,1] has three neighbors but they've already been expanded so we don't do any checks 45 | You'll probably need to recurse to keep checking 46 | When you get to the end, you'll have the path with the shortest g-value because you always expanded the lowest g-value node first 47 | 48 | # 6 - A* Search 49 | Variant of the general search algorithm that's more efficient than expanding every node 50 | - does minimum amount of work necessary to make progress to the goal 51 | 52 | Uses a heuristic function 53 | h(x,y) <= distance to goal from x,y 54 | 55 | Now, f-value is g-value + heuristic value 56 | - start point is g-value 0, but heuristic value of 9 (because you're really far from the goal) so f-value is 9 57 | - always expand space with lowest f-value 58 | 59 | Pseudocode for A*: 60 | ``` 61 | Search( grid, initial_point, goal_point ) : 62 | 63 | Initialize an empty list of open nodes. 64 | 65 | Initialize a starting node with the following: 66 | 67 | x and y values given by initial_point. 68 | g = 0, where g is the cost for each move. 69 | h given by the heuristic function (a function of the current coordinates and the goal). 70 | Add the new node to the list of open nodes. 71 | 72 | while the list of open nodes is nonempty: 73 | 74 | Sort the open list by f-value 75 | Pop the optimal cell (called the current cell). 76 | Mark the cell's coordinates in the grid as part of the path. 77 | if the current cell is the goal cell: 78 | 79 | return the grid. 80 | else, expand the search to the current node's neighbors. This includes the following steps: 81 | 82 | Check each neighbor cell in the grid to ensure that the cell is empty: it hasn't been closed and is not an obstacle. 83 | If the cell is empty, compute the cost (g value) and the heuristic, and add to the list of open nodes. 84 | Mark the cell as closed. 85 | If you exit the while loop because the list of open nodes is empty, you have run out of new nodes to explore and haven't found a path. 86 | ``` 87 | 88 | # 7 - CODE: Starting A* Search 89 | 90 | 91 | # 8 - CODE: Writing the A* Heuristic 92 | 93 | 94 | # 9 - Pass by Reference in C++ 95 | 96 | 97 | # 10 - CODE: Adding Nodes to the Open Vector 98 | 99 | 100 | # 11 - CODE: Initialize the Open Vector 101 | 102 | 103 | # 12 - CODE: Create a Comparison Function 104 | 105 | 106 | # 13 - CODE: Write a While Loop for the A* Algorithm 107 | 108 | 109 | # 14 - CODE: Check fro Valid Neighbors 110 | 111 | 112 | # 15 - Constants 113 | 114 | 115 | # 16 - CODE: Expand the A* Search to Neighbors 116 | 117 | 118 | # 17 - Arrays 119 | 120 | 121 | # 18 - CODE: Adding a Start and End to the Board 122 | 123 | 124 | # 19 - Congratulations!! 125 | 126 | 127 | # 20 - How to Become More Proficient at C++ 128 | -------------------------------------------------------------------------------- /2-foundations/2-introduction-to-the-c++-language.md: -------------------------------------------------------------------------------- 1 | # 1 - Intro 2 | Gonna learn the basic syntax of C++ 3 | 4 | # 2 - Code: Write Your First C++ Program 5 | Every program has a `main` function which executes when the program runs 6 | - everything else is run directly or indirectly from `main` 7 | - should always return an integer which indicates if the program exited successfully 8 | 9 | Smalles c++ program: 10 | ``` 11 | int main() { 12 | } 13 | ``` 14 | Compile with `g++ your_file.cpp` 15 | Run with `./a.out` 16 | 17 | # 3 - Compiled Languages vs Scripted Languages 18 | This is a compiled language 19 | 20 | # 4 - C++ Output and Language Basics 21 | ``` 22 | #include 23 | using std::cout; 24 | 25 | int main() { 26 | cout << "Hello!" << "\n"; 27 | } 28 | ``` 29 | 30 | include is preprocessor command to get header files 31 | using is a way to namespace commands (in this case adds it to global namespace) 32 | 33 | 34 | # 5 - Code: Sending Output to the Console 35 | 36 | Behold, the first real c++ I ever wrote 37 | - save this for future when people want to know how my robots took over the universe. 38 | ``` 39 | #include 40 | using std::cout; 41 | 42 | int main() { 43 | cout << "Hello!" << "\n"; 44 | } 45 | ``` 46 | 47 | # 6 - How to Store Data 48 | Gonna learn to store some data. 49 | 50 | # 7 - Bjarne Discusses C++ Types 51 | c++ is mostly strongly typed 52 | - sometimes weaken types to deal with the hardware 53 | 54 | # 8 - Storing Primitive Types 55 | Things like `int`s, `string`s, `float`s 56 | If you try to dealre a var twice in same function you'll see an error 57 | 58 | ``` 59 | // Declaring and initializing an int variable. 60 | int a = 9; 61 | 62 | // Declaring a string variable without initializing right away. 63 | std::string b; 64 | 65 | // Initializing the string b. 66 | b = "Here is a string"; 67 | ``` 68 | 69 | # 9 - What is a Vector? 70 | Linear sequence of contiguously allocated memory 71 | - most useful of all the structures 72 | Linked lists == overused 73 | Hash table, maps have fast lookups 74 | 75 | # 10 - Storing Vectors 76 | ``` 77 | // Three ways of declaring and initializing vectors. 78 | vector v_1{0, 1, 2}; 79 | vector v_2 = {3, 4, 5}; 80 | vector v_3; 81 | v_3 = {6}; 82 | ``` 83 | 84 | Vectors can be 2-dimensional 85 | ``` 86 | vector> v {{1,2}, {3,4}}; 87 | ``` 88 | 89 | # 11 - C++ Comments 90 | Two forward slashes for single line comments 91 | // like this! 92 | 93 | /* 94 | for longer comments 95 | that need multiple lines 96 | */ 97 | 98 | 99 | # 12 - Using Auto 100 | c++ can do automatic type inference if you use the keyword `auto` 101 | 102 | ``` 103 | auto i = 5; 104 | auto v_6 = {1, 2, 3}; 105 | ``` 106 | 107 | This works and the types are correctly inferred 108 | 109 | # 13 - Code: Store a Grid in Your Program 110 | 111 | ``` 112 | #include 113 | #include 114 | using std::cout; 115 | using std::vector; 116 | 117 | 118 | int main() { 119 | vector> board = {{0, 1, 0, 0, 0, 0}, 120 | {0, 1, 0, 0, 0, 0}, 121 | {0, 1, 0, 0, 0, 0}, 122 | {0, 1, 0, 0, 0, 0}, 123 | {0, 0, 0, 0, 1, 0}}; 124 | 125 | cout << "It compiled!" << "\n"; 126 | } 127 | ``` 128 | 129 | # 14 - Getting Ready for Printing 130 | Gonna write a function to print out the board you just stored 131 | 132 | # 15 - Working with Vectors 133 | Access a slot in a vector how you'd expect 134 | vector a = {0, 1, 2} 135 | a[0] => 0 136 | 137 | NOTE: There is no defined behavior for trying to access an element out of range. It will just fail silently and make you hate your life. 138 | 139 | `.size()` prints out the length of the vector 140 | 141 | # 16 - For Loops 142 | ``` 143 | for (int i=0; i < 5; i++) { 144 | cout << i << "\n"; 145 | } 146 | ``` 147 | 148 | Fairly standard 149 | - create an iterator 150 | - tell it what the stopping value is 151 | - iterator ++ (can also do iterator --) 152 | 153 | Iterating over a container: 154 | ``` 155 | vector a {1, 2, 3, 4, 5}; 156 | for (int i : a) { 157 | cout << i << "\n"; 158 | } 159 | ``` 160 | 161 | Iterating over a 2d vector: 162 | ``` 163 | vector> b {{1, 2}, 164 | {3, 4}, 165 | {5, 6}}; 166 | 167 | for(auto v : b) { 168 | for(int i : v) { 169 | cout << i << " "; 170 | } 171 | cout << "\n"; 172 | } 173 | ``` 174 | 175 | # 17 - Functions 176 | How to write a function: 177 | ``` 178 | return_type FunctionName(parameter_list) { 179 | // Body of function here. 180 | } 181 | ``` 182 | Use `void` for empty returns. 183 | 184 | 185 | # 18 - Code: Print the Board 186 | ``` 187 | void PrintBoard(const vector> board) { 188 | for (int i = 0; i < board.size(); i++) { 189 | for (int j = 0; j < board[i].size(); j++) { 190 | cout << board[i][j]; 191 | } 192 | cout << "\n"; 193 | } 194 | } 195 | ``` 196 | 197 | # 19 - If Statements and While Loops 198 | ``` 199 | if (conditional) { 200 | # thing you want to do 201 | } 202 | ``` 203 | 204 | ``` 205 | while (conditional) { 206 | # thing you want to do 207 | } 208 | ``` 209 | - Make sure your while conditional has a way of terminating 210 | 211 | # 20 - Reading from a File 212 | Create an Input Stream Object 213 | - use `std::iftream` object for creating streams 214 | - include `` in the header file 215 | - two ways of doing it: 216 | ``` 217 | std::ifstream my_file; 218 | my_file.open(path); 219 | ``` 220 | AND 221 | `std::ifstream my_file(path);` 222 | - if ifstream initialized successfully, ifstream will evaluate to true (use it as a truthy checker) 223 | 224 | ``` 225 | #include 226 | #include 227 | #include 228 | 229 | int main() { 230 | std::ifstream my_file; 231 | my_file.open("files/1.board"); 232 | if (my_file) { 233 | std::cout << "The file stream has been created!" << "\n"; 234 | std::string line; 235 | while (getline(my_file, line)) { 236 | std::cout << line << "\n"; 237 | } 238 | } 239 | } 240 | ``` 241 | - check if ifstream was successfully created 242 | - read line by line 243 | - print the lines to the screen 244 | 245 | # 21 - Code: Reading the Board from a File 246 | ``` 247 | void ReadBoardFile(string filepath) { 248 | ifstream board_file; 249 | board_file.open(filepath); 250 | if (board_file) { 251 | string line; 252 | while (getline(board_file, line)) { 253 | cout << line << "\n"; 254 | } 255 | } 256 | } 257 | ``` 258 | 259 | # 22 - Processing Strings 260 | Many ways to process each line and store the data when reading in a file 261 | - focus on `istringstream` 262 | - uses `` header file 263 | 264 | ``` 265 | #include 266 | #include 267 | #include 268 | 269 | using std::istringstream; 270 | using std::string; 271 | using std::cout; 272 | 273 | int main() 274 | { 275 | string a("1 2 3"); 276 | 277 | istringstream my_stream(a); 278 | 279 | int n; 280 | 281 | // Testing to see if the stream was successful and printing results. 282 | while (my_stream) { 283 | my_stream >> n; 284 | if (my_stream) { 285 | cout << "That stream was successful: " << n << "\n"; 286 | } 287 | else { 288 | cout << "That stream was NOT successful!" << "\n"; 289 | } 290 | } 291 | } 292 | ``` 293 | 294 | Extraction operator `>>` writes the stream to the variable on the right of the operator and returns `istringstream` object 295 | 296 | If string has mixed types, more care is needed in extraction 297 | - our example above only had whitespace chars and things that could coerce to `ints` 298 | 299 | ``` 300 | int main() 301 | { 302 | string b("1,2,3"); 303 | 304 | istringstream my_stream(b); 305 | 306 | char c; 307 | int n; 308 | 309 | while (my_stream >> n >> c) { 310 | cout << "That stream was successful:" << n << " " << c << "\n"; 311 | } 312 | cout << "The stream has failed." << "\n"; 313 | } 314 | ``` 315 | - in this case, we stream to an int then a char 316 | - this will fail before printing the 3 because it has to have both parts of the stream to evaluate to true (and there is no char after final 3) 317 | 318 | # 23 - Adding Data to a Vector 319 | Use `.push_back()` to add something to the end of a vector 320 | 321 | ``` 322 | vector v {1, 2, 3}; 323 | 324 | v.push_back(4); 325 | 326 | // v will now be {1, 2, 3, 4} 327 | ``` 328 | 329 | # 24 - Code: Parse Lines from the File 330 | ``` 331 | void ReadBoardFile(string path) { 332 | ifstream myfile (path); 333 | if (myfile) { 334 | string line; 335 | while (getline(myfile, line)) { 336 | cout << line << "\n"; 337 | } 338 | } 339 | } 340 | ``` 341 | 342 | # 25 - Code: Use the ParseLine Function 343 | Filled in gaps on existing code to use methods to print out the board. Did it like a boss! 344 | 345 | # 26 - Formatting the Printed Board 346 | `enum` 347 | - short for enumerator 348 | - way to define type in C++ with values restricted to a fixed range 349 | 350 | ``` 351 | // Create the enum Color with fixed values. 352 | enum class Color {white, black, blue, red}; 353 | 354 | // Create a Color variable and set it to Color::blue. 355 | Color my_color = Color::red; 356 | ``` 357 | 358 | Got exposed to syntax for switch statements and wanted to document that here: 359 | 360 | ``` 361 | switch (a) { 362 | case first : cout << "It was first"; 363 | break; 364 | case second : cout << "It was second"; 365 | break; 366 | case third : cout << "It was third"; 367 | break; 368 | default : cout << "Default situation"; 369 | } 370 | ``` 371 | 372 | # 27 - Code: Formatting the Printed Board 373 | I added this function! 374 | ``` 375 | string CellString(State square) { 376 | switch (square) { 377 | case State::kObstacle : return "⛰️ "; 378 | default: return "0 "; 379 | } 380 | } 381 | ``` 382 | 383 | # 28 - Code: Store the Board using the State Enum 384 | Walked through modifying the code to accept the new State types throughout so that the printed output would use the emoji 385 | 386 | # 29 - Great Work 387 | ``` 388 | #include 389 | #include 390 | #include 391 | #include 392 | #include 393 | using std::cout; 394 | using std::ifstream; 395 | using std::istringstream; 396 | using std::string; 397 | using std::vector; 398 | 399 | enum class State {kEmpty, kObstacle}; 400 | 401 | vector ParseLine(string line) { 402 | istringstream sline(line); 403 | int n; 404 | char c; 405 | vector row; 406 | while (sline >> n >> c && c == ',') { 407 | if (n == 0) { 408 | row.push_back(State::kEmpty); 409 | } else { 410 | row.push_back(State::kObstacle); 411 | } 412 | } 413 | return row; 414 | } 415 | 416 | vector> ReadBoardFile(string path) { 417 | ifstream myfile (path); 418 | vector> board{}; 419 | if (myfile) { 420 | string line; 421 | while (getline(myfile, line)) { 422 | vector row = ParseLine(line); 423 | board.push_back(row); 424 | } 425 | } 426 | return board; 427 | } 428 | 429 | string CellString(State cell) { 430 | switch(cell) { 431 | case State::kObstacle: return "⛰️ "; 432 | default: return "0 "; 433 | } 434 | } 435 | 436 | void PrintBoard(const vector> board) { 437 | for (int i = 0; i < board.size(); i++) { 438 | for (int j = 0; j < board[i].size(); j++) { 439 | cout << CellString(board[i][j]); 440 | } 441 | cout << "\n"; 442 | } 443 | } 444 | 445 | int main() { 446 | auto board = ReadBoardFile("1.board"); 447 | PrintBoard(board); 448 | } 449 | ``` 450 | --------------------------------------------------------------------------------