-
Notifications
You must be signed in to change notification settings - Fork 0
/
cplusplusNOTES.html
473 lines (441 loc) · 17.5 KB
/
cplusplusNOTES.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>C++</title>
<link rel="stylesheet" href="main.css">
<!-- FONTS.GOOGLE.COM -->
<!--h1-->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Shadows+Into+Light&family=Source+Sans+Pro:wght@300&display=swap" rel="stylesheet">
<!--h2-->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Mukta&display=swap" rel="stylesheet">
<!--navbar-->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@300&display=swap" rel="stylesheet">
</head>
<body>
<div id="top" class="page">
<div class="navbar" >
<nav>
<ul>
<li><a class="navACTIVE" href="index.html"><b>Home</b></a></li>
<li><a target="_blank" href="coursecontent.html">Course Content</a></li>
</ul>
<ul>
<li><h1>Conceptual</h1></li>
<li><a class="nav" href="#design">Design</a></li>
<li><a class="nav" href="#scope">Scope</a></li>
<li><a class="nav" href="#memory">Memory</a></li>
<li><a class="nav" href="#compiling/linking">Compiling/Linking</a></li>
</ul>
<ul>
<li><h1>Designing A Program</h1></li>
<!-- Building a Project -->
<li><a class="nav" href="#projects">Projects</a></li>
<li><a class="nav" href="#files">Files</a></li>
<li><a class="nav" href="#formatting">I/O Formatting</a></li>
<li><a class="nav" href="#testing">Unit Testing</a></li>
<li><a class="nav" href="#doxygen">Doxygen Comments</a></li>
</ul>
<ul>
<li><h1>Writing Code</h1></li>
<!-- procedural design approach -->
<!-- object-oriented design approach -->
<br>
<ul>
<li><h2>Object-Oriented Design Approach</h2></li>
<li><a class="nav" href="#uml">UML</a></li>
<li><a class="nav" href="#classes">Classes</a></li>
<li><a class="nav" href="#constructors">Constructors</a></li>
<li><a class="nav" href="#objects">Objects</a></li>
</ul>
<br>
<!-- functional design approach -->
<li><a class="nav" href="#syntax">Syntax</a></li>
<li><a class="nav" href="#pointer">Pointers</a></li>
<li><a class="nav" href="#datatypes">Data Types</a></li>
<li><a class="nav" href="#variables">Variables</a></li>
<li><a class="nav" href="#datastructure">Data Structures</a></li>
<li><a class="nav" href="#array">Arrays</a></li>
<li><a class="nav" href="#struct">Structs</a></li>
<li><a class="nav" href="#conditionals">Conditionals</a></li>
<li><a class="nav" href="#loops">Loops</a></li>
<li><a class="nav" href="#functions">Functions</a></li>
<li><a class="nav" href="#reference">Reference Parameters</a></li>
<li><a class="nav" href="#enums">Enumerations</a></li>
<li><a class="nav" href="#operators">Operators</a></li>
<li><a class="nav" href="#recursion">Recursion</a></li>
</ul>
<ul>
<li><h1>Debugging</h1></li>
<li><a class="nav" href="#debugging">Debugging</a></li>
</ul>
<ul>
<li><h1>ToolBox</h1></li>
<li><a class="nav" href="#commands">Commands</a></li>
<li><a class="nav" href="#ide">IDE</a></li>
<li><a class="nav" href="#html">HTML</a></li>
</ul>
</nav>
</div><!--navbar-->
<a href="https://www.learncpp.com/">Learn C++</a>
<!-- CONCEPTUAL -->
<div id="design">
<h1>Design</h1>
<a href="https://www.learncpp.com/cpp-tutorial/introduction-to-local-scope/">Scope</a>
<br>
<a href="https://www.learncpp.com/cpp-tutorial/header-guards/">Header Guards</a>
<pre>
Approaches to Programming Design:
1. Procedural Design Approach
Fortran, Assembly C
<em>Top-Down Desing, Bottom-Up Implementation</em>
can solve any problem with this approach
build a program by combining algorithms
algorithms work on data passed between them from function to function
<b>input/output</b>
<b>how to get from input to output</b>
<b>break complex tasks into smaller pieces</b>
<b>design functions to achieve these pieces</b>
<em>issues: scaling</em>
2. Object-Oriented Approach
C++, Java, Python
object: entity using data and behavior, may comprise other objects, has properties, can do things and have things done to it
program consists of interacting objects
design: identify objects and determine how objects need to interact
<b>determine data</b>
<b>determine represention of data as object(s)</b>
<b>define interactions between objects</b>
3. Functional Approach
Haskel, Clojure, F#
</pre>
<a href="#top">Back to Top</a>
</div>
<div id="scope">
<h1>Scope</h1>
<br>
<a href="https://pythontutor.com/cpp.html#mode=edit">Call Stack</a>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="memory">
<h1>Memory</h1>
<pre>
<a href="https://pythontutor.com/cpp.html#mode=edit">Visualization of Memory with Pointers</a>
Dynamic Memory
Memory Management
</pre>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="compiling/linking">
<h1>Compiling/Linking</h1>
<a href="https://www.tenouk.com/ModuleW.html">Compiling and Linking</a>
<br>
<a href="#top">Back to Top</a>
</div>
<!-- DESIGNING A PROGRAM -->
<div id="projects">
<h1>Projects</h1>
<pre>
Files
Unit Testing
Headers (.h)
doctest.h
main.h
Source (.cpp)
main.cpp
tester.cpp
</pre>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="files">
<h1>Files</h1>
<pre>
Separating Class Definition from Class Implementation
header file (.h) contains the class definition (simply list the data fields, constructor prototypes, function prototypes)
source file (.cpp) contains the class implementation of the constructors and functions
both the .h and .cpp should have the same file name
</pre>
<pre>
preprocessor directives
to prevent a header file from being included multiple times:
#indef // @ top
#define // @ top
#endif // @ bottom
</pre>
<a href="#top">Back to Top</a>
</div>
<div id="formatting">
<h1>I/O Formatting</h1>
<pre>
set width
set precision
set fill
</pre>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="testing">
<h1>Unit Testing</h1>
<a href="https://stackoverflow.com/questions/1383/what-is-unit-testing">Why Unit Testing?</a>
<a href="https://computerscience.chemeketa.edu/guides/unittesting/">Unit Testing Guide</a>
<a href="http://www.jamesshore.com/v2/books/aoad1/test_driven_development">Thorough Guide</a>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="doxygen">
<h1>Doxygen Comments</h1>
<br>
<a href="#top">Back to Top</a>
</div>
<!-- WRITING CODE -->
<!-- OOP -->
<div id="uml">
<h1>UML</h1>
<pre>
helper in designing classes
</pre>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="classes">
<h1>Classes</h1>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="constructors">
<h1>Constructors</h1>
a special kind of function which initializes an object
no return type
<h2>class naming nomenclature</h2>
<pre>
it must initialize all member variables
automatically called when object is declared
default constructor does nothing and has no arguments
overloading a function is providing multiple versions of the function with different Parameters
may overload a constructor
parameters in the function call determine which function is used
// use no-arg constructor
Circle c1;
// use one-arg constructor
Circle c2(5.5);
// use n-arg constructor
Circle c3(5.5, 10); // n = 2
avoid shadowed names, instead i.e. use m_ to proceed names of member variables
example:
private:
double m_radius;
Circle::Circle(double radius) {
m_radius = radius;
}
</pre>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="objects">
<h1>Objects</h1>
<br>
<a href="#top">Back to Top</a>
</div>
<!-- OOP -->
<div id="syntax">
<h1>Syntax</h1>
<pre>
comments
// single line
/* multi-line
/** machine readable
typedef
namespaces
using namespace std;
<a href="https://www.learncpp.com/cpp-tutorial/user-defined-namespaces-and-the-scope-resolution-operator/">Namespaces</a>
<a href="https://www.learncpp.com/cpp-tutorial/typedefs-and-type-aliases/">Typedefs</a>
preprocessor directives
<a href="https://www.learncpp.com/cpp-tutorial/introduction-to-the-preprocessor/">Intro to</a>
<a href="https://www.learncpp.com/cpp-tutorial/header-files/">Header Files</a>
anything that starts with a #
#include <>iostream
#ifndef // if not defined
#define
#endif // indicates end of header file
</pre>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="pointer">
<h1>Pointers</h1>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="datatypes">
<h1>Data Types</h1>
<pre>
<a href="#struct">struct</a> Structy {
};
class Classy {
};
strings
</pre>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="variables">
<h1>Variables</h1>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="datastructure">
<h1>Data Structures</h1>
<pre>
Linear
Tree
Graph
Non-Linear
Static
Array
Dynamic
Queue
Stack
Linked List
</pre>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="array">
<h1>Arrays</h1>
<pre>
1-D
Matrix
</pre>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="struct">
<h1>Structs</h1>
<a href="http://www.learncpp.com/cpp-tutorial/introduction-to-structs-members-and-member-selection/">Structs, Members</a>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="conditionals">
<h1>Conditionals</h1>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="loops">
<h1>Loops</h1>
<pre>
while loop
do while loop
for loop
for each loop
</pre>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="functions">
<h1>Functions</h1>
<pre>
pow()
rand()
time(0)
</pre>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="reference">
<h1>Reference Parameters</h1>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="enums">
<h1>Enumerations</h1>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="operators">
<h1>Operators</h1>
<pre>
stream insertion operators
cout <<
stream extraction operators
cin >>
</pre>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="recursion">
<h1>Recursion</h1>
<br>
<a href="#top">Back to Top</a>
</div>
<!-- DEBUGGING -->
<div id="debugging">
<h1>Debugging</h1>
<a href="https://youtu.be/lRW1-gXp5yU">DEBUGGING 1</a>
<br>
<a href="https://youtu.be/Hx9e3UUvhc8">DEBUGGING 2</a>
<br>
<a href="https://youtu.be/sGRcw0QoTGo">STRING DEBUGGING</a>
<br>
<a href="#top">Back to Top</a>
</div>
<!-- TOOLBOX -->
<div id="commands">
<h1>Commands</h1>
<a href="https://computerscience.chemeketa.edu/guides/command-line/">Commands</a>
<a href="www3.ntu.edu.sg/home/ehchua/programming/howto/CMD_Survival.html">Windows</a>
<a href="https://www3.ntu.edu.sg/home/ehchua/programming/howto/Unix_SurvivalGuide.html">Mac/Linux</a>
<pre>
mkdir create a new directory
cd move into directory (make current)
.. move up one directory
ls list items in directory
</pre>
<pre>
compile a main program from the command line:
g++ Circle.h Circle.cpp TestCircleWithHeader.cpp -o Main
</pre>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="ide">
<h1>IDE</h1>
<pre>
Visual Studio Code
CTRL-B toggle side bar
CTRL-/ comment out a line
PyCharm
CTRL-/ comment out a line
QT Creator
<a href="https://replit.com/languages/cpp">Short Term Code Box</a>
<a href="https://computerscience.chemeketa.edu/guides/qtcreator-setup/">Installation</a>
<a href="https://youtu.be/OMG5vfI1CXA">Installation Video Guide</a>
CTRL-S save
CTRL-B build
CTRL-R run
CTRL-/ comment out a line
</pre>
<br>
<a href="#top">Back to Top</a>
</div>
<div id="html">
<h1>HTML</h1>
<a href="https://codepict.com/link-to-jump-to-a-specific-part-of-a-page-in-html/">jump button</a>
<br>
<a href="#top">Back to Top</a>
</div>
<footer>
Site by <a href="TAG.html">TAG</a>
</footer>
</div>
</body>
</html>