Professional Documents
Culture Documents
Ali AL-musharfawi
C++ Programming
Part one
By:
م.م عل ر
المشفاوي ي
C++ / First stage M.Sc. Ali AL-musharfawi
Introduction
Variables types:
1. Integer (int) 4-bytes
ex: int a; int a,b; int a=3;
2. Float 4-bytes
ex: float a; float x,y,z; float a=3.5;
3. Double 8-bytes
ex: double a; double a,b; double a=8.95;
4.character (char) 1-byte
ex: char x; char x='a'; char y='A';
5.string
ex: string x; string x="computer engineering";
1
C++ / First stage M.Sc. Ali AL-musharfawi
Equivalent
Example Result
Statement
X += 5 X=X+5 X=7
Y -= 8 Y=Y-8 Y = -5
Z *= 5 Z=Z*5 Z=
V /= 4 V=
C %= 3 C=
Relational operators:
< less than
> greater than
<= less than or equal
>= greater than or equal
Equality operators:
= = equal to
!= not equal to
Logical operators:
Not (!)
And (&&)
or (||)
2
C++ / First stage M.Sc. Ali AL-musharfawi
Cout<<var.1<<var2<<…<<var.n;
Cin>>var.1>>var.2>>…>>var.n;
3
C++ / First stage M.Sc. Ali AL-musharfawi
#include<iostream.h> output
int main( )
{ Welcome
Example:
#include<iostream.h>
output:
void main( )
hello
{
students
cout << “hello” << endl;
cout << “students”;
}
4
C++ / First stage M.Sc. Ali AL-musharfawi
Expample: Write a program that reads the radius of a circle, then computes and
outputs its area.
#include<iostream.h>
int main( )
{ Output:
const float pi = 3.14; enter the radius of circle: 5
int r; the area of circle : 78.5
float c;
cout << “enter the radius of circle:”;
cin>>r;
cout<<endl;
c = r * r * pi
cout << “the area of circle :” << c;
}
#include<iostream.h>
Example: Write the following equation as a C++ expression and state the
order of evaluation of the binary operators: