Topic 7. Arrays
1. One dimensional Array.
Arrays are very important in numerical computations. They are defined by
double a ;
This means that we defined a one-dimensional array containing ten numbers of type double, i.e. a0, a1, ,a9
so that a0 is plac
Topic 03. Using Functions and Header Files
/ Calculation Factorial: n!
long fact(int n)
f = 1;
for (i = 1; i <= n; i+)
f *= i;
/ Calculation Factorial: n!
/ Recursion function (call itself)
long factR (int n)
Page 1 of 7
1.1 A Sample Program
Every program in C+ must have a function naimed main, which contains a number of statements
enclosed in braces cfw_ . Each statement can extend to more than one line, but must end with a semicolon.
Comments must b
Topic 17. ODE (continuous)
1. Taylor Series Method of Higher Order
Assume that our solutions function x is represented by its
x(t h) x(t ) hx ' (t )
1 2 '
h x (t ) h 3 x ' (t ) . h m x ( m ) (t ) .
For numerical purposes,
Topic 18. C+ File IO
1. Stream Classes
There are three C+ classes basis form for the file input/output:
istream class for input
ostream class for output
iostream class for input/output
These are referred to as stream classes.
There are four class varia
Topic 20. Templates
Ternary conditional operator?:
We have already met the ternary conditional operator? :,
meaning "if a then x else y".
This enables very concise conditional expressions and
statements to be written.
Topic 15 Complex Numbers Class
Let us consider the design of a simple class which will involve little data and
several functions. A complex number consists of the real and imaginary part
as the data so a complex number class must have two double numbers a
Topic 12. Classes
1. Introduction to classes
C+ was designed by Bjarne Stroustrup of AT&T Bell Laboratories during
the 1980s as an extended version of C. Its most significant feature is the class.
C+ was originally named C with Classes. A class is an abst
Topic 14. Main Parts of a Class
Let us now consider in more details the basic items of a class
Private and Public
1. Private and Public
Usually data is declared private so
Topic 16. Ordinary Differential Equations
1. Taylor Series Method
The numerical method described in this section does not have the
utmost generality, but it is natural and capable of high precision. Its
principle is to represent the solution of a differen
Topic 13. Grid Program
Let us look at a more elaborate example of a class that defines a grid in twodimensions. Thus for each point we must have the x and y coordinates and the index;
each of these is stored in an array and since we do not know how big a
Topic 10 C+ Keywords and Preprocessor Directives
1. C+ Keywords
Keywords are reserved to the compiler for use by the language.
You cannot define classes, variables, or functions that have these keywords as
their names. The list is a bit arbitrary, as some
Topic 04. Control and Iterative Statements
1. The if Statement
The if statement is used to implement a decision.
It has two parts: a test and a body.
if (condition) statement;
Here condition is an integer expression and statement is any executable
Topic 06. Advanced Control Flow. Simulations
To be able to program loops with do/while statements
To implement approximations and simulations
1. The do Loop
Sometimes you want to execute the body of a loop at least
once and perform the loop test aft
Topic 8. Memory and Pointers
An object variable contains an object, but a pointer specifies where an
object is located.
Pointers are one of the C+ most important features.
Pointers can refer to objects that are dynamically allocated whenever t
Topic 2. Basic C+.
The basic operator is the assignment operator =.
It assigns the value 10 to the variable k.
The table below gives the basic operators that we will require. Later we will extend the list.
+ is addition
1. Basic C+ Definitions
C+ programs have various components,
such as preprocessor directives,
using namespace std;
function, variables, statements, comments, and
Preprocessor directive makes available the standar
Topic 11. Inline Functions
When a function is called its arguments are copied and the
program branches out to a new location (on the runtime
stack) and comes back after the function is executed.
If function is small,
inline functions can be defined using
Topic 05. Functions.
Let us begin with a simple example
1. Program to illustrate the use of a function
/The function will return the value of the polynomial
double f(double x);
Data Type Ranges
Page 1 of 2
Data Type Ranges
C/C+ recognizes the types shown in the table below.
Range of Values
Topic 9. Advanced Uses of Pointers
1. Numeric Integration
Let's develop a program to perform numeric integration. The idea is to calculate an
approximation of the area under the function's curve between a low point and a high point, as
in the following di