Topic 7. Arrays
1. One dimensional Array.
Arrays are very important in numerical computations. They are defined by
double a[10] ;
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
1. Functions
/ Calculation Factorial: n!
long fact(int n)
cfw_
long i,f;
f = 1;
for (i = 1; i <= n; i+)
f *= i;
return f;
/ Calculation Factorial: n!
/ Recursion function (call itself)
long factR (int n)
cfw_
if

Lesson 1
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
Taylor series:
x(t h) x(t ) hx ' (t )
1 2 '
1
1
h x (t ) h 3 x ' (t ) . h m x ( m ) (t ) .
2!
3!
m!
(1)
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
1.
Ternary conditional operator?:
We have already met the ternary conditional operator? :,
The expression
a?x:y
meaning "if a then x else y".
This enables very concise conditional expressions and
statements to be written.
For example,

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
Data
Constructors
Destructors
Member functions
Friends
Operator overloading
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.
Syntax:
if (condition) statement;
Here condition is an integer expression and statement is any executable

Topic 06. Advanced Control Flow. Simulations
Goals
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
1. 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+.
1. Operators
The basic operator is the assignment operator =.
k=10;
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.
o
o
o
o
o
o
o
o
+ is addition

1. Basic C+ Definitions
C+ programs have various components,
#include <iostream>
such as preprocessor directives,
using namespace std;
function, variables, statements, comments, and
identifiers
int main()
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
p(x)=x*x+10*x+5
#include <iostream.h>
double f(double x);
int main()
cfw_
double x;
cout<"Input va

Data Type Ranges
Page 1 of 2
Data Type Ranges
C/C+ recognizes the types shown in the table below.
Type Name
Bytes
Other Names
Range of Values
int
*
signed,
signed int
System dependent
unsigned int
*
unsigned
System dependent
_int8
1
char,
signed char
128

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