forked from johannesgerer/jburkardt-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpp.html
450 lines (407 loc) · 12.8 KB
/
cpp.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
<html>
<head>
<title>
CPP - Simple C++ Examples
</title>
</head>
<body bgcolor="#EEEEEE" link="#CC0000" alink="#FF3300" vlink="#000055">
<h1 align = "center">
CPP <br> Simple C++ Examples
</h1>
<hr>
<p>
<b>C++</b>
is a directory of C++ examples which
illustrate some of the features of the language.
</p>
<p>
Depending on your computer, you may invoke the <b>C++</b> compiler
by a command like <b>c++</b>, <b>CC</b>, <b>cxx</b>,
<b>g++</b> (the Gnu compiler),
<b>icc</b> (the Intel compiler),
<b>pcCC</b> (the Portland Group compiler),
or <b>xlc++</b> (the IBM compiler).
</p>
<p>
Depending on your compiler, your C++ files may need to have the
extension ".C", ".cc", ".cxx", ".cpp" or even ".c++". In particular,
Microsoft Visual C++ does not "know" the difference between upper
and lower case in file extensions. If you call your file
"fred.C", it will think your file is a C file, not a C++ file.
For Microsoft Visual C++, always use the file name extension ".cpp"!
</p>
<p>
It is customary for include files to have the extension ".H", but I have
also seen ".h", ".hxx" and ".hpp" extensions used.
</p>
<h3 align = "center">
Licensing:
</h3>
<p>
The computer code and data files described and made available on this web page
are distributed under
<a href = "../../txt/gnu_lgpl.txt">the GNU LGPL license.</a>
</p>
<h3 align = "center">
Languages:
</h3>
<p>
Directories related to <b>CPP</b> are available in
<a href = "../../c_src/c/c.html">a C version</a> and
<a href = "../../cpp_src/cpp/cpp.html">a C++ version</a> and
<a href = "../../f77_src/f77/f77.html">a FORTRAN77 version</a> and
<a href = "../../f_src/f90/f90.html">a FORTRAN90 version</a> and
<a href = "../../m_src/matlab/matlab.html">a MATLAB version</a> and
<a href = "../../py_src/py/py.html">a Python version</a>.
</p>
<h3 align = "center">
Related Data and Programs:
</h3>
<p>
<a href = "../../cpp_src/cpp_arrays/cpp_arrays.html">
CPP_ARRAYS</a>,
C++ programs which
illustrate the use of vectors, matrices and tensors.
</p>
<p>
<a href = "../../cpp_src/cpp_intrinsics/cpp_intrinsics.html">
CPP_INTRINSICS</a>,
a C++ program which
illustrates the use of intrinsic functions.
</p>
<p>
<a href = "../../cpp_src/cpp_random/cpp_random.html">
CPP_RANDOM</a>,
C++ programs which
illustrate the use of the random number generator routines.
</p>
<p>
<a href = "../../cpp_src/makefiles/makefiles.html">
MAKEFILES</a>,
C++ programs which
illustrate the use of MAKEFILES for maintaining a software project;
</p>
<p>
<a href = "../../cpp_src/mixed/mixed.html">
MIXED</a>,
C++ programs which
call a function written in another programming language.
</p>
<p>
<a href = "../../cpp_src/mpi/mpi.html">
MPI</a>,
C++ programs which
illustrate the use of the MPI application program interface
for carrying out parallel computations in a distributed memory environment.
</p>
<p>
<a href = "../../cpp_src/openmp/openmp.html">
OPENMP</a>,
C++ programs which
illustrate the use of the OpenMP application program interface
for carrying out parallel computations in a shared memory environment.
</p>
<h3 align = "center">
Reference:
</h3>
<p>
<ol>
<li>
Paul Deitel, Harvey Deitel,<br>
C++: How to Program,<br>
Seventh Edition,<br>
Prentice Hall, 2011,<br>
ISBN: 978-013-216541-9,<br>
LC: QA76.73.C153.D45.
</li>
<li>
Steve Oaulline,<br>
Practical C++ Programming,<br>
Second Edition,<br>
O'Reilly, 2003,<br>
ISBN: 1-56592-139-9,<br>
LC: QA76.73.C15.O84.
</li>
<li>
Bjarne Stroustrup,<br>
The C++ Programming Language,<br>
Addison-Wesley, 2000,<br>
ISBN: 0-201-70073-5,<br>
LC: QA76.73.C153.S77.
</li>
</ol>
</p>
<h3 align = "center">
Examples and Tests:
</h3>
<p>
<b>ARRAY_RETURN</b> demonstrates how a function can call another
function which creates and returns several arrays in its argument
list. To do this requires some tricky use of pointers.
<ul>
<li>
<a href = "array_return.cpp">array_return.cpp</a>,
the source code;
</li>
<li>
<a href = "array_return.sh">array_return.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "array_return_output.txt">array_return_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>BIG_INTS_REAL</b> shows what can go wrong when you try to move
large integer values into and out of real variables.
<ul>
<li>
<a href = "big_ints_real.cpp">big_ints_real.cpp</a>, the source code;
</li>
<li>
<a href = "big_ints_real.sh">big_ints_real.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "big_ints_real_output.txt">big_ints_real_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>CHARACTER_ARG</b> demonstrates how a C++ function can return character
information through its argument.
<ul>
<li>
<a href = "character_arg.cpp">character_arg.cpp</a>,
the source code;
</li>
<li>
<a href = "character_arg.sh">character_arg.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "character_arg_output.txt">character_arg_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>COMPLEX_VALUES</b> demonstrates the use of the ANSI COMPLEX
class for complex arithmetic. (At the moment, I am having
a terrible time just trying to use the assignment operator!)
<ul>
<li>
<a href = "complex_values.cpp">complex_values.cpp</a>,
the source code;
</li>
<li>
<a href = "complex_values.sh">complex_values.sh</a>,
a script to compile and run the program.
</li>
<li>
<a href = "complex_values_output.txt">complex_values_output.txt</a>,
the output file.
</li>
</ul>
</p>
<p>
<b>DYNAMIC_ARRAY_2D</b> shows how to create a 2D array dynamically,
so that addresses like "a[2][5]" are legal.
<ul>
<li>
<a href = "dynamic_array_2d.cpp">dynamic_array_2d.cpp</a>,
the source code;
</li>
<li>
<a href = "dynamic_array_2d.sh">dynamic_array_2d.sh</a>,
a script to compile and run the program.
</li>
<li>
<a href = "dynamic_array_2d_output.txt">dynamic_array_2d_output.txt</a>,
the output file.
</li>
</ul>
</p>
<p>
<b>FUNCTION_POINTER</b> shows how a variable can be created which can
point to a function; the target of the pointer can be changed so that
a different function is indicated.
<ul>
<li>
<a href = "function_pointer.cpp">function_pointer.cpp</a>,
the source code;
</li>
<li>
<a href = "function_pointer.sh">function_pointer.sh</a>,
a script to compile and run the program.
</li>
<li>
<a href = "function_pointer_output.txt">function_pointer_output.txt</a>,
the output file.
</li>
</ul>
</p>
<p>
<b>FUNCTION_POINTER_ARRAY</b> shows how a variable can be created which can
be an array of pointers to function.
<ul>
<li>
<a href = "function_pointer_array.cpp">function_pointer_array.cpp</a>,
the source code;
</li>
<li>
<a href = "function_pointer_array.sh">function_pointer_array.sh</a>,
a script to compile and run the program.
</li>
<li>
<a href = "function_pointer_array_output.txt">function_pointer_array_output.txt</a>,
the output file.
</li>
</ul>
</p>
<p>
<b>FUNCTION_POINTER_ARRAY_NEW</b> shows how a variable can be created which can
be a DYNAMICALLY ALLOCATED array of pointers to function. In other words,
this is one way to create an array of function pointers whose dimension
is not specified in advance. Then the array can be sized with the NEW
command and freed with the DELETE command.
<ul>
<li>
<a href = "function_pointer_array_new.cpp">function_pointer_array_new.cpp</a>,
the source code;
</li>
<li>
<a href = "function_pointer_array_new.sh">function_pointer_array_new.sh</a>,
a script to compile and run the program.
</li>
<li>
<a href = "function_pointer_array_new_output.txt">function_pointer_array_new_output.txt</a>,
the output file.
</li>
</ul>
</p>
<p>
<b>HELLO</b> is just a "Hello, world!" program.
<ul>
<li>
<a href = "hello.cpp">hello.cpp</a>,
the source code;
</li>
<li>
<a href = "hello.sh">hello.sh</a>,
a script to compile and run the program.
</li>
<li>
<a href = "hello_output.txt">hello_output.txt</a>,
the output file.
</li>
</ul>
</p>
<p>
<b>LIMITS</b> prints out some information about the range and accuracy
of various numeric types.
<ul>
<li>
<a href = "limits.cpp">limits.cpp</a>,
the source code;
</li>
<li>
<a href = "limits.sh">limits.sh</a>,
a script to compile and run the program.
</li>
<li>
<a href = "limits_output.txt">limits_output.txt</a>,
the output file.
</li>
</ul>
</p>
<p>
<b>NOT_ALLOCATED_ARRAYS</b> shows that you should initialize your
array pointers to NULL, and reset them to NULL after you delete
your arrays. Otherwise, an unallocated or delete array is liable
to have a deceptive nonnull value!
<ul>
<li>
<a href = "not_allocated_arrays.cpp">not_allocated_arrays.cpp</a>,
the source code;
</li>
<li>
<a href = "not_allocated_arrays.sh">not_allocated_arrays.sh</a>,
a script to compile and run the program.
</li>
<li>
<a href = "not_allocated_arrays_output.txt">not_allocated_arrays_output.txt</a>,
the output file.
</li>
</ul>
</p>
<p>
<b>POISSON</b> solves the Poisson equation on a 2D grid.
This program uses dynamically allocated doubly dimensioned arrays.
<ul>
<li>
<a href = "poisson.cpp">poisson.cpp</a>,
the source code;
</li>
<li>
<a href = "poisson.sh">poisson.sh</a>,
a script to compile and run the program.
</li>
<li>
<a href = "poisson_output.txt">
poisson_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>PRECISION_OUTPUT</b> shows how the manipulator function setprecision()
changes the precision for all subsequent floating point output operations,
and how the precision() function can be better used, to record the initial
precision, change it, or reset it to the default value.
<ul>
<li>
<a href = "precision_output.cpp">precision_output.cpp</a>,
the source code;
</li>
<li>
<a href = "precision_output.sh">precision_output.sh</a>,
a script to compile and run the program.
</li>
<li>
<a href = "precision_output_output.txt">precision_output_output.txt</a>,
the output file.
</li>
</ul>
</p>
<p>
<b>SIZES</b> prints out the sizes of various datatypes.
<ul>
<li>
<a href = "sizes.cpp">sizes.cpp</a>,
the source code;
</li>
<li>
<a href = "sizes.sh">sizes.sh</a>,
a script to compile and run the program.
</li>
<li>
<a href = "sizes_output.txt">sizes_output.txt</a>,
the output file.
</li>
</ul>
</p>
<p>
You can go up one level to <a href = "../cpp_src.html">
the C++ source codes</a>.
</p>
<hr>
<i>
Last revised on 15 March 2012.
</i>
<!-- John Burkardt -->
</body>
</html>