Professional Documents
Culture Documents
WWW - Kutub.info 866
WWW - Kutub.info 866
.
1
Hardware Software
.
:
.1 .
.2
.3
.4
.5
.6
.7
:
.1 Machine Language
.
.2 Assembly Language add,
. sub
.3
....basic, c, c+ Cobol, simula, prolog
.......
:
.
.
: .
:
.
.
.
.
.
:
.1 " "procedural languages
...........fortoran,basic,cobol
.2 " "structural languages
...........prolog,C,pascal
.3 " "object oriented languages
.Java,C++
.
:
:
.1 .
.2
, use-case state diagram .
2
.3
.4
.5
.6
:
flow charts algorithms
.
: .
:
:
. syntax error
.
.
.
flow charts
:
)(1.1
:
:
:
.1 3
.2
.3
:
=++
=)++(3/
"" .
=0
=0
= +
=1+
>
= /
C++
.
C++ main
Header Files
math
.
C++
)(Void main
}{
4
void
{ } .
.....
.....
.....
.....
cout cin
iostream
cout
;"cout<<" text
.
cin
;cin>>variable
variable .
:
>#include<file_name
file_name
C++
Prog1
welcome to C++
>#include<iostream.h
)(void main
{
;"cout<<"welcome to C++ world
}
iostream h
:
\n \t .
:
//
*/. */
Prog2
:
Welcome
to C++ world
>#include<iostream.h
)(void main
{ //start of main function
;"cout<<"\twelcome\n to C++ world
} /*end of main function
this a multi_line comment */
1
.1
.2 C++ :
This is my first program in
C++ language
:C++
-32768 32767 4
2 95 NT
int
-21474836482147483647
short
-3276832767
2
int
long
-21474836482147483647
4
int
-1.2e-383.4e38
4
float
-2.2e-308 1.8e308
8
double
1
char
.....
.....
signed unsigned
unsigned
signed
.signed
unsigned short int 0. 65535
signed short int short int -32768.32767
int, short int, long int .
float, double .
Char
.
:
;variable_type variable_name
; int x x ; float area .area
1
; char a,b,c a,b,c .
.1
.2
.3
.4
.
............@#./*-+
.
for,
........................ if, else, int, float, long,
.
.
.AREA
area
:
=
:
;x=5 5 x .x
Mathematical Operators
:
/
23%7=2
%
C++
.
.
.
)(2.1 x :
X=4+2*5 .
X=5%3*7+2 .
X=5+(4%3) .
:
X=4+10=14 .
X=2*7+2=14+2=16 .
X=5+1=6 .
=
:
x+=3
x=x+3
a*=2
a=a*2
) (2.2 C++
: length width, area
. perimeter int
float
. :
Prog3
= *
=)*2 +(
" "++ pre_ incrimination
post_ incrimination
.
" "-- pre_ decrimintation
post_ decrimintation
.
Prog4
" "++" ":
a=6
b=8
after incrimination b=9
Constants
.
const
.
Prog5
.
.int
2
.1 y int :
y=10*7%(5+8-3) .
y=18/5+4 .
.2 total_income
bs %5" t " e
total_income=bs+t+e :
.3
:
Control Structures
:C++
" " .
.....
.....
)if(condition
{
statements if true
....................
}
else
{
statements if false
.
if
"
. else
.
} {
.
.
.
Relational Operators
>
=>
<
=<
==
=!
= ==
=
. ==
.if
10
) (1.3 .C++
.1 x y .d=5
.2 d 60 pass .fail
.3 sr 0 "."imaginary number
.4 a 5 b=2a+3 c=3a-4b b=2a-11.c=3a+b
:
)1. if(x>y
;d=5
)2. if(d>=60
;cout<<pass
else
;cout<<fail
)3. if(sr<0
;cout<< imaginary number
)4. if(a!=5
{
;b=2a+3
;c=3a-4b
}
else
{
;b=2a-11
;c=3a+b
}
Logical Operators
&&
||
!
" and"
" or"
not
.
Truth Tables
true or false
discrete mathematics truth tables
" . A,B T "F
&&
Result
T
F
F
F
T
F
T
F
T
T
F
F
11
||
Result
T
T
T
F
T
F
T
F
T
T
F
F
!B
F
T
T
F
) (2.3 .C++
.1 x y y 0 .d=5
.2 d 80 d 90 .B
.3 ) x y y (0 x 3 d 10 d .20
:
)1. if(x>y&&y==0
;d=5
)2. if(d>=80||d<90
;cout<<B
)3. if(!(x>y&&y==10)||x==3
;d=10
else
;d=20
Carno Maps
.
)(3.3
L :
X
X
X
X
12
X
.
nx
ny
) (x,y
:
A- nx==1
nx==2
B- ny==1
C- ny==2
D- x+ nx<=8
E- x- nx>=1
F- y+ ny<=8
G- y- ny>=1
H,G,F,E
&& D,C,B,A L
D,C,B,A
24 4 2
:
!A !B
0
0
0
0
!A B
0
1
0
0
A !B
0
0
1
0
AB
0
0
0
0
CD
C !D
!C D
!C !D
0 1
D,C,B,A:
)(A &&!B&&!C&&D)||(!A&&B&&C&&!D
:
])(E&&F&&G&&H)&&[ (A &&!B&&!C&&D)||(!A&&B&&C&&!D
A,B,C,D,E,F,G,H :
])if[(x+nx<=8&&x-nx>=1&&y+ny<=8&&y-ny>=1)]&&[(nx==1&&ny==2)||(nx==2&&ny==1
.
:
if-else " "
.switch-case
)switch(variable
.....
.....
{
case value1:
statement/statements
;break
case value2:
statement/statements
;break
case value3:
statement/statements
;break
.
.
default:
statement/statements
;break
}
value3 value2 value1 variable switch
case " "
default break
.
)(3.4
C++ , total_income grade
:
total_income=bsaic_salary+bonus+fees
bsaic_salary bonus fees
:
13
grade
1
2
3
4
Other grades
bsaic_salary
6000
5200
5000
3000
2000
bonus
=.04*bsaic_salary
=.04*bsaic_salary
=.03*bsaic_salary
=.02*bsaic_salary
=.01*bsaic_salary
fees
700
700
500
400
200
:
Grade
fees bonus bsaic_salary
: . total_income
grade
yes
bsaic_salary=6000;
bonus=.04*bsaic_salary;
fees=700;
grade=1
No
yes
grade=2
No
yes
grade=3
No
yes
grade=4
No
bsaic_salary=5200;
bonus=.04*bsaic_salary;
fees=700;
bsaic_salary=5000;
bonus=.03*bsaic_salary;
fees=500;
bsaic_salary=3000;
bonus=.02*bsaic_salary;
fees=400;
No
bsaic_salary=2000;
bonus=.01*bsaic_salary;
fees=200;
total_income=bsaic_salary+bonus+fees
total_income
14
Prog6
#include<iostream.h>
void main()
{
int grade;
float bonus, total_income,bsaic_salary,fees;
cout<<"\n enter the employee grade: ";
cin>>grade;
switch(grade)
{
case 1:
bsaic_salary=6000;
bonus=.04*bsaic_salary;
fees=700;
break;
case 2:
bsaic_salary=5200;
bonus=.04*bsaic_salary;
fees=700;
break;
case 3:
bsaic_salary=5000;
bonus=.03*bsaic_salary;
fees=500;
break;
case 4:
bsaic_salary=3000;
bonus=.02*bsaic_salary;
fees=400;
break;
default:
bsaic_salary=2000;
bonus=.01*bsaic_salary;
fees=200;
break;
}
total_income=bsaic_salary+bonus+fees;
cout<<" the total income for this employee is "<<total_income;
}
switch
. case
15
.....
.....
Loops
" "
. :
.
int
.
-1 for
)for(counter_initial_value;condition;counter_incrementation/decrementation
{
.
"statements " loop body
.
}
:
for :
counter_initial_value counter
.
condition
.
counter_incrimintation/decrimintation incrimination
decrimintation
:
x++
x=x+1
x-x=x-1
"x=variable "mathematical_operator" " value
"x"mathematical_operator"= " value
for(int i=3;i<=8;i++) {.} for
;int i=3
for
}for( ;i<=8;i--) {.
}for(int i=3;i<=8;) { i*=3;.
;int i=3
}for( ;i<=8;) { i/=3;.
16
.....
.....
-2 while
)while(condition
{
.
"statements " loop body
.
}
:while
Prog8
.....
.....
-3 do-while
do
{
.
"statements " loop body
.
}
;)while(condition
while
do-while
:do-while
Prog9
Nested Loops
.
.
17
) (3.6 :
18
Prog10
3
.1 :
)a. for(i=1;i<15;i=i+3
)b. for(int i=0,int j=9;i<=16&&j>6;i++,j-=2
;c. int t=4
)while(t<=17
{.
};t+=3
;d. int t=4
do
{.
;)t+=3;} while(t>17
)e. for(i=9;i>5;i++
)f. while(6>3
}{.
.2 prog5 n
.3 C++ " "primary numbers 10100
.4 C++ :
""degree
95
-90 95
-85 90
-80 85
-75 80
-70 75
-65 70
-60 65
60
""grade
A+
A
B+
B
C+
C
D+
D
F
19
int
float
20
.....
.....
Arrays
.
.0
:
;]array_type array_name[elements_number
;] int x[5
.x[0],x[1],x[2],x[3],x[4]:
"="
:
;}array_type array_name[elements_number]={values
][0
0 .
.
Prog11
)(1.4
.char
.
. :
]float w[4][5
20 " "5*4
.
21
) (2.4
:
Prog12
.
) (3.4 6 :
34
67
45
89
45
47
78
90
23
78
78
58
56
89
78
56
63
78
38
90
76
34
54
63
.
:
22
Prog13
degree first_name
.last_name
:
bubble sort
n-1 n .
=
:x,y
1
SWAP
:
:
)]If(x[i]<x[i-1
X
2
)Loop(i=0 toi<n-1
)Loop(j=0 toj<n-1
)]If(x[i]>x[i-1
]Swap=x[i
]x[i]=x[i-1
x[i-1]=swap
)(4
.1
.2
C++ n
12 n m
23
return
.
Function D
return
Main( )
{
statements
Function A
statements
Function B
statements
}
return
24
Function
) (Main
{
statements
Function A
statements
Function B
statements
}
Function A
.
Function D
return
Function D
return
Function B
return
sqrt
math.h
math
tan
sin
cos
abs
ceil
floor
pow
sqrt
fmod
log
Log10
)tan(x
)sin(x
)cos(x
)abs(y
)ceil(t
)floor(t
)pow(x,y
)sqrt(w
)fmod(t,y
)log(x
)Log10(x
tan(0)=0
sin(0)=0
cos(0)=1
abs(-7)=7
ceil(4.2)=5, ceil(-4.2)=-4
floor(4.2)=4, floor(-4.2)=-5
pow(2,3)=8, pow(.16,.5)=.4
sqrt(9)=3, sqrt(.01)=.1
fmod(5,3)=2,fmod(3,.7)=.2
Log(4)=1.38629
Log10(100)=2
string.h
strcpy
strcat
Strlen
)strcpy(s1,s2
)strcat(s1,s2
)strlen(s1
s2s1
s1
0 1 s1
-1 s2 s1 s2
carrac
strcmp
strrev
)strcmp(s1,s2
)strrev(s1
25
)(2.5 strrev
C++ programming language is an object oriented language
Prog15
Function Creation
arguments sqrt
pow .
:
.
.
.
.....
.....
Function Declaration
returned type
arguments type .function name
:
;)Returned type function name(arg1 type name,arg2 type name,.
arg1 type,arg2 type " "
name .
:
.
)(3.5 :
. swap
. invert
. print
:
float swap(int, int) .
long int invert(long int) .
Void print() .
.....
.....
.
:
)Returned type function name(arg1 type name,arg2 type name,.
{
function body
}
27
return .
.
void .
) (4.5
max, min
:
" " int
max min ?:
:
Prog16
:
C++
.
.
prog 16 :
28
Prog17
Recursive Function
:)(=))((
)(=)(+)(1+
:
) (5.5
)int xx(int a
{
.
)return xx(a
}
;) float ww( int b
{
.
.
;)return ww(b)+ww(b-1
29
Hanoi Tower
A, B, C
A
C B
.
:
:
A .B
A .C
B .C
3 3 A B
" 3" A B
B C 3" 7
:
n-1 A B
A C
n-1 B C
.
n-1
)(=*2)1+(1-
= 5
)*2=(5) 1+(4 )(4
)*2=(4)1+(3
)*2=(3)1+(2
)*2=(2)1+(1
)1=(1
) 31=(5 :
30
Prog18
31
Function Overloading
dd
int double :
Prog20
Inline Function
inline inline .
inline
inline
.
y
. a
.
Prog21
32
Header Files
h
"#includefile_name
)(5
.1 :
cout<<strlen("I love C++ programming") .
cout<<strrev("I love C++ programming") .
strcat("death to ","israil") .
pow(4,2) .
sqrt(.36) .
ceil(2.05) .
floor(3.99) .
ceil(-8.2) .
floor(-.99) .
.2 :
. aa .
. bb .
.3
33