You are on page 1of 97

www.voiceofsindh.

net


0332-3803120
Sindh_desh@yahoo.com

www.voiceofsindh.net
www.voiceofsindh.net

Page 1 of 97

www.voiceofsindh.net









Page 2 of 97

www.voiceofsindh.net

www.voiceofsindh.net

...

Page 3 of 97

www.voiceofsindh.net

www.voiceofsindh.net

.!

Age of probots

Page 4 of 97

www.voiceofsindh.net

!.

www.voiceofsindh.net

!...

28-07-2008

Page 5 of 97

www.voiceofsindh.net

www.voiceofsindh.net


What is c++
.
) (C++
. .

.
) (C++) (C .
.
) (IDE .
1 0 .
) (IDE Integrated development
.


C++ TURBO 3.0 .
.
.

C .

Page 6 of 97

www.voiceofsindh.net

www.voiceofsindh.net


TC
.
:

C => TC => BIN => TC.exe

.
c .

Page 7 of 97

www.voiceofsindh.net

www.voiceofsindh.net

TC .

Alt + Enter .



New .

Page 8 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Message Box
.
C
Directories .

C .

C
E C E
.

Page 9 of 97

www.voiceofsindh.net

www.voiceofsindh.net


Help .

.

Page 10 of 97

www.voiceofsindh.net

www.voiceofsindh.net


C++ Programming basic
Geting started
.

.


.
) ( .

>#include<iostream.h
>#include<conio.h
)(int main
{
;)(Clrscr
;"!cout<<"Hello tech in sindhi
;)(getch
;return 0
}

) Run(
Page 11 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Run .
ctrl+F9 .

out put
! Hello tech in sindhi .
Enter . .

function

. ;)( int main() , clrscr ;)(getch
)( Int main ) Gate way ( int main()
.
;)( clrscr Clear screen

Run clrscr(); .
;)( clrscr
;)( clrscr .
;)( getch ) ( get a character
.

Page 12 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Function name
) ( .
)
( . main .

Braces and function body


{ }
.

Programm statement

;! cout<<Hello tech in sindhi ;o
;o

.return

.
Retrun

;! cout<<Hello tech in sindhi .


; .

) main() (
.

White spaces

) (
.

Page 13 of 97

www.voiceofsindh.net

www.voiceofsindh.net

cout

!in sindhi

tech

cout<<Hello

) cout . ( )
( cout .
.

cout << ) (

cout cout
.

1
.
)(
.

Straing constant
) (
.
!Hello tech in sindhi

.

.

Directives
1
.
.

Page 14 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Preprocessor Directives

>#include<iostream.h
>#include<conio.h

1 . #
.
#include
.

Header files

><iostream.h
><conio.h

.

. iostream.h << cout
conio.h ;)( clrscr ;)( getch .
C

C:\tc\INCLUDE

iostream note paid


.

.

Comments
.
.


.
.

Page 15 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Use of comments

.
. .

:Classic comments
/*This is old type comment*/

.
.

/*this is first programm*/


#include<iostream.h> /*Preprocessor Directive*/
#include<conio.h>
/*Preprocessor Directive*/
int main()
/*Function name "main"*/
{
/*Start body of programm*/
clrscr();
/*Clear screen function*/
cout<<"Hello tech in sindhi!"; /*Statement*/
getch();
/*Getch Function*/
return 0;
/*Statement*/
}
/*End body old programm*/

.
.

// this is new type comment

New type comments


.

//this is first programm


#include<iostream.h> //Preprocessor Directive
#include<conio.h>
//Preprocessor Directive
int main()
//Function name "main"
www.voiceofsindh.net

Page 16 of 97

www.voiceofsindh.net

{
//Start body of programm
clrscr();
//Clear screen function
cout<<"Hello tech in sindhi!"; //Statement
getch();
//Getch Function
return 0;
//Statement
}
//End body new programm

.
.

www.voiceofsindh.net

Page 17 of 97

www.voiceofsindh.net


Variable
.

. .

.
.

Integer variable
130000 : -27.

Defining integer variable


. int .
. (Bit 32) 32 )( 4 Bytes
.
-2,147,483,648 2,147,483,647 .
4
2 .
.

>#include<iostream.h
>#include<conio.h
)(int main
{
;)(clrscr
;int var1
// Define var1
;int var2
// Define var2
;)(getch
;return 0
}

2 ; int var1 ;. int var2


Page 18 of 97

www.voiceofsindh.net

www.voiceofsindh.net

int
var1 . var2 . .
int var1 int var2 ) (Declarations .
.
.
. .
;int var1, var2

Variable name
2 var1 var2
. ) (identifiers .
. . A to Z 1 to 9
) _ ( .
.

.
.
) (
.
int.

Assignments statement
)=( .
.

;int var1=20
;int var2=var1+10

Page 19 of 97

www.voiceofsindh.net

www.voiceofsindh.net

var1
20 . 20 var1 .
+
+ +
.
var1 20 + var1 20
10 30 var2 .
.
.

Out put
.
.
.

>#include<iostream.h
>#include<conio.h
)(int main
{
;)(clrscr
;int var1=20
;int var2=var1+10
;cout<<var2
;)(getch
;return 0
}

3 cout
cout<<var2; var2
var2 30 var1 20
10 30 30 var2 cout
var2 30 .

endl manipulator

4
>#include<iostream.h
>#include<conio.h
)(int main

Page 20 of 97

www.voiceofsindh.net

www.voiceofsindh.net

{
;)(clrscr
cout<<"Hello tech in sindh!"<<endl; //endl use for new line
;cout<<"C++ in sindhi"<<endl
;cout<<"My computer & C++"<<endl
;)(getch
;return 0
}

4 .

4 ) endl (
1 ! Hello tech in sindhi
.

Hello tech in sindhi ! .1


C++ in sindhi .2
My computer & C++ .3

1 4
.
.

\n .

;"cout<<"Hello tech in sindh!\n


>#include<iostream.h
>#include<conio.h
)(int main
{
;)(clrscr
;"!cout<<"Hello tech in sindh
;"cout<<"C++ in sindhi
;"cout<<"My computer & C++
;)(getch
;return 0
}

5 .
.
Page 21 of 97

www.voiceofsindh.net

www.voiceofsindh.net

.
endl .
4 5
.

setw
) (Set width .
Look .
.

>#include<constream.h
)(int main
{
;)(clrscr
cout<<"LOCATION
;POPULATION"<<endl
;cout<<"Dadu 129374"<<endl
;cout<<"Hala 1234376"<<endl
cout<<"Karachi
;7543334"<<endl
;)(getch
;return 0
}

>#include<constream.h
>#include<iomanip.h
)(int main
{
;)(clrscr
;cout<<setw(6)<<"LOCATION"<<setw(15)<<"POPULATION"<<endl
;cout<<setw(6)<<"Dadu"<<setw(15)<<"129374"<<endl

Page 22 of 97

www.voiceofsindh.net

www.voiceofsindh.net

;cout<<setw(6)<<"Hala"<<setw(15)<<"1234376"<<endl
;cout<<setw(6)<<"Karachi"<<setw(15)<<"7543334"<<endl
;)(getch
;return 0
}

setw(6) 6
Setw(15) . 15 .
Iomanip .

Character variable

. @ A, B, C, $,.
0 127 0 256
.

Declaration of ch:v:able
Syntax .
int char .

;char a
;char b


;char a,b,c,d,e
A B A B C D E
.

Character constant
. a b.

Page 23 of 97

www.voiceofsindh.net

www.voiceofsindh.net

>#include<iostream.h
>#include<conio.h
)(int main
{
;)(clrscr
;'char var1='A
;'char var2='B
;cout<<var1
;cout<<var2
;)(getch
;return 0
}

.
var1 var2 var1 .
A var2 B .
cout . .

Float type variable



. 1.50 234.99.

>#include<iostream.h
>#include<conio.h
)(int main
{
;)(clrscr
;float a=10.2
;float b
;b=a+1.2
;cout<<b
;)(getch
;return 0
}

3
3 .
3
.
Page 24 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Page 25 of 97

www.voiceofsindh.net

www.voiceofsindh.net


Cin

) (cin Consol input cin stand for consol in put .


.

Cin syntex
.

;cin>>a

>> a
.

2

.
.

10

>#include<constream.h
)(int main
{
;)(clrscr
;int a,b
;cout<<"Enter 1st Value"<<endl
;cin>>a
;cout<<"Enter 2nd Value"<<endl
;cin>>b
;cout<<"Addition is "<<a+b
;)(getch
;return 0
}

10 constream
.
Page 26 of 97

www.voiceofsindh.net

www.voiceofsindh.net

constream header file


iostream conio
.
10 Enter 1st value
20
Enter 2nd value
13 Addition is
A B A B 33
.
.

.
Page 27 of 97

www.voiceofsindh.net

www.voiceofsindh.net

cin>>a>>b;

www.voiceofsindh.net

Page 28 of 97

www.voiceofsindh.net


Arithmetic operators

. .

+
*
/
%


.
.
.

Plus operator
.

11

>#include<constream.h
)(int main
{
;)(clrscr
;int a,b,c
;cout<<"Enter 1st value"<<endl
;cin>>a
;cout<<"Enter 2nd value"<<endl
;cin>>b
;cout<<"Enter 3rd value"<<endl
;cin>>c
;cout<<"Addition is "<<a+b+c
;)(getch
;return 0
}

Page 29 of 97

www.voiceofsindh.net

www.voiceofsindh.net

. a,b,c

minus operaters
.

12
#include<constream.h>
int main()
{
clrscr();
int a,b;
cout<<"Enter 1st value"<<endl;
cin>>a;
cout<<"Enter 2nd value"<<endl;
cin>>b;
cout<<"subtraction is "<<a-b;
getch();
return 0;
}

. B A

Multiplction operator
.

13

#include<constream.h>
int main()
{
clrscr();
int a,b;
cout<<"Enter 1st value"<<endl;
cin>>a;
cout<<"Enter 2nd value"<<endl;
cin>>b;
cout<<"subtraction is "<<a*b;
getch();
return 0;
}

. B A

Division operator
www.voiceofsindh.net

Page 30 of 97

www.voiceofsindh.net

14

>#include<constream.h
)(int main
{
;)(clrscr
;int a,b
;cout<<"Enter 1st value"<<endl
;cin>>a
;cout<<"Enter 2nd value"<<endl
;cin>>b
;cout<<"subtraction is "<<a/b
;)(getch
;return 0
}

Remainder operator

.

15

>#include<constream.h
)(int main
{
;)(clrscr
;int a,b
;cout<<"Enter 1st value"<<endl
;cin>>a
;cout<<"Enter 2nd value"<<endl
;cin>>b
;cout<<"subtraction is "<<a/b
;cout<<remainder is <<a%b
;)(getch
;return 0
}


.
.
.

Arithmetic assignment operators

Page 31 of 97

www.voiceofsindh.net

www.voiceofsindh.net



.
.

;a=a+b

a+=b

=/
=*
=-
.
16

=%

>#include<constream.h
)(int main
{
;)(clrscr
;int ans=27
;ans+=10
;" cout<<ans<<" ,
;ans-=7
;" cout<<ans<<" ,
;ans*=2
;" cout<<ans<<".
;ans/=3
;" cout<<ans<<" ,
;ans%=3
;cout<<ans<<endl
;)(getch
;return 0
}

Page 32 of 97

www.voiceofsindh.net

www.voiceofsindh.net

ans
27 .
; ans+=10 Logic
.
ans 27 27 10 ans
37.
cout cout ans
) ( ans .
ans-=7 ans 37 7
ans 30 .
ans *=2 ans 30 2
ans 60 .
ans/=3 ans 60 3
ans 20 .
ans%=3 ans 20 3 2
.
13
.

Page 33 of 97

www.voiceofsindh.net

www.voiceofsindh.net


Relation operator
:
.
.

>
<
==
=!
=>
=<


)(greater than
)(less than
)(equal to
)(not equal to
)(greater than or equal to
)(less than or equal to


10 >1 : 10 1 10 1
1 .
10 >11 : 10 11 10
11 0 .
.

17

>#include<constream.h
)(int main
{
;)(clrscr
;int numb
;cout<<"Enter a number"<<endl
;cin>>numb
;cout<<"Number < 10 is "<<(numb<10)<<endl
;cout<<"Number > 10 is "<<(numb>10)<<endl
;cout<<"Number == 10 is "<<(numb==10)<<endl
;)(getch
;return 0
}

.
Page 34 of 97

www.voiceofsindh.net

www.voiceofsindh.net

.
numb .
Enter a number . cin numb
20 .
cout Number < 10 .
(numb < 10) . numb 20
20 10 0 .
Number > 10 .
(num > 10) numb 20
20 10 1 .
Number == 10
(numb == 10) numb 20
20 10 0 .
.

18

>#include<constream.h
)(int main
{
;)(clrscr
;int numb
;cout<<"Enter a number"<<endl
;cin>>numb
;cout<<"Number < 10 is "<<(numb<10)<<endl
;cout<<"Number > 10 is "<<(numb>10)<<endl
;cout<<"Number == 10 is "<<(numb==10)<<endl
;cout<<"Number != 10 is "<<(numb!=10)<<endl
;cout<<"Number >= 10 is "<<(numb>=10)<<endl
;cout<<"Number <= 10 is "<<(numb<=10)<<endl
;)(getch
;return 0
}

18 .

Page 35 of 97

www.voiceofsindh.net

www.voiceofsindh.net

17 .
) (numb != 10 numb 20
20 10 1 .
) (numb > =10
numb 20 10 20 20 10
1 .
) (numb < = 10 numb
20 20 10 10
0 .
.

Page 36 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Loops
.
Loop

Concept .
.

.
.
.1 )(for loop
.2 )(while loop
.3 )(do while loop
.

.1 :For loop

: Sindh 10 .
.

3

.

Page 37 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Initialization expression 3 a
1 . test expression increment expression
.
Test expression
.
Increment expression 1 a 1
Increment expression Increment expression a
2 . Increment expression decrement expression
1 .

.
.
.

19

>#include<constream.h
)(int main
{
;)(clrscr
;int a
)for(a=1; a<=10; a++
;cout<<a
;)(getch
;return 0
}

a . a
1 .
.

Page 38 of 97

www.voiceofsindh.net

www.voiceofsindh.net

1 10 1 10
.

cout a .1
.

a 1 2.
.

2 10 .

a 2 cout 2 .
a
3
.
a 10 10
10 10 10 .
a 11
11 10 10
.

Page 39 of 97

www.voiceofsindh.net

www.voiceofsindh.net

4
4

.

Decrement expression

1 .
1 .
.

20

>#include<constream.h
)(int main
{
;)(clrscr
;int a
)for(a=10; a>=1; a--
;cout<<a
;)(getch
;return 0
}

17 .
Page 40 of 97

www.voiceofsindh.net

www.voiceofsindh.net

.
19 .
a 10
a>=1 10 1 10 1
a 10 .
a 10 1 a
9 .
a 9 .
a 1
1 1 1 1 1 . 1 1
1 a 1
a 1 0
0 1 0 1 .
0 1 .

for loop statement


10 SINDHI
.
Page 41 of 97

www.voiceofsindh.net

www.voiceofsindh.net

21
#include<constream.h>
int main()
{
clrscr();
cout<<"SINDHI"<<endl;
cout<<"SINDHI"<<endl;
cout<<"SINDHI"<<endl;
cout<<"SINDHI"<<endl;
cout<<"SINDHI"<<endl;
cout<<"SINDHI"<<endl;
cout<<"SINDHI"<<endl;
cout<<"SINDHI"<<endl;
cout<<"SINDHI"<<endl;
cout<<"SINDHI"<<endl;
getch();
return 0;
}

22

#include<constream.h>
int main()
{
clrscr();
int a;
for(a=1; a<=10; a++)
cout<<"SINDHI"<<endl;
getch();
return 0;
}

. 21

www.voiceofsindh.net

Page 42 of 97

www.voiceofsindh.net

19 19
19 12345678910 :
sindhi .

other statement
.
.

23

>#include<constream.h
)(int main
{
;)(clrscr
;int a
)for(a=1; a<=10; a++
;" "<<cout<<a+a
;)(getch
;return 0
}

23 .
23
a a 1 1+1
2 . a
2+2 4 .
.

Page 43 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Multipul statement in loop body


. !
. .
.

24

>#include<constream.h
>#include<iomanip.h
)(void main
{
;)(clrscr
)for(int numb=1; numb<=10; numb++
{
;cout<<setw(4)<<numb
;int cube=numb*numb*numb
;cout<<setw(6)<<cube<<endl
}
;)(getch
}

.
.
.

Void
.
int
; return 0 ; return 0
.

Page 44 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Variable in for loop


; int a
for(int numb=1; .
1 .

.
cout<<setw(4)<<numb; numb 4
. 123 4

cube cube
numb*numb*numb . 5 125 . 5*5*5
125.
.
cout<<setw(6)<<cube; cube
.

Multipul initialization
for(a=1
.

25

>#include<constream.h
)(void main
{
;)(clrscr
)for(int a=1, b=1; a<=100; a=a+b, b=a+b
;" "<<cout<<a<<" "<<b
;)(getch
}

.
Page 45 of 97

www.voiceofsindh.net

www.voiceofsindh.net

.
1+1=2 1 2 3 .2 3 5 .
.
a b 1 .
.
a=a+b, b=a+b
a=a+b, b=a+b
.
.
b=a+b a b 1 2 b . b
2 a=a+b . a 1
b 2 3 a
.
a b .

Nestes for loop


.

. .

26

>#include<constream.h
)(void main
{
;)(clrscr
)for(int a=1; a<=5; a++
{
)for(int b=1; b<=a; b++
;"cout<< "#
;cout<<endl
}
;)(getch
}

Page 46 of 97

www.voiceofsindh.net

www.voiceofsindh.net

.
a 1 .
. 1 5 . .
) (# .

.
.

.2 :While loop

.
.

5

.
5 .
5
. .
.

27

Page 47 of 97

www.voiceofsindh.net

www.voiceofsindh.net

>#include<constream.h
)(void main
{
;)(clrscr
;int a=99
)while(a!=0
;cin>>a
;cout<<endl
;)(getch
}

1
.
26 . a .
99 0 .

) while(a!=0 .

a 0 .
. 2
34
. 0 )( .
1 0 .

6
6 .

Page 48 of 97

www.voiceofsindh.net

www.voiceofsindh.net

While with increment Exp:

28

>#include<constream.h
)(void main
{
;)(clrscr
;int a=2
)while(a<=10
{
;a+=2
;cout<<a<<endl
}
;)(getch
}

a+=2 a
2 . a 10
10 .

- Do-while loop

.
.

Page 49 of 97

www.voiceofsindh.net

www.voiceofsindh.net

7

.
.

29
>#include<constream.h
)(void main
{
;)(clrscr
;int a,b
;char test
do
{
;cout<<"Enter 1st value"<<endl
;cin>>a
;cout<<"Enter 2nd value"<<endl
;cin>>b
;cout<<"Addition is"<<a+b<<endl
;cout<<"Do another? (y/n)"<<endl
;cin>>test
}
;)'while(test != 'n
;)(getch
}

.
.

Page 50 of 97

www.voiceofsindh.net

www.voiceofsindh.net

a b .
) Do another? (y/n .
test . )(
Test n ) test n( test n
.

8
8 . 8
.

Page 51 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Decisions
.

.
. .
.
) . ( .

) .
(.
.
.

If

. :
.
.

9
.
Page 52 of 97

www.voiceofsindh.net

www.voiceofsindh.net

30
>#include<constream.h
)(void main
{
;)(clrscr
;int a
;cout<<"Enter a number"<<endl
;cin>>a
)if(a>10
;"cout<<"Number is greater than 10
;)(getch
}

.
a .
if(a>10) a 10
a 10 .

10
10 .

Page 53 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Multipule statement
.

31

>#include<constream.h
)(void main
{
;)(clrscr
;int a
;cout<<"Enter a number"<<endl
;cin>>a
)if(a>10
{
;cout<<"The number "<<a
;"cout<<" is geater than 10
}
;)(getch
}

30
.

Nested if inside loop

.
. .
.
.

32

>#include<constream.h
>#include<process.h
)(void main
{
;)(clrscr
;int n,j
;cout<<"Enter a number"<<endl
;cin>>n
)for(j=2; j<=n/2; j++
)if(n%j==0
{
;cout<<"its not prime number; divisible by"<<j<<endl
;)exit(0
}
;"cout<<"Its prime number

Page 54 of 97

www.voiceofsindh.net

www.voiceofsindh.net


;)(getch
}


. 2
. j
2 Its prime number 3 its not prime number;
divisible by . Exit .

Exit

.
0
. 0 .
process .

If else

31 10
10 .
.
.

Page 55 of 97

www.voiceofsindh.net

www.voiceofsindh.net

11
. 11
.

33

#include<constream.h>
void main()
{
clrscr();
int a;
cout<<"Enter a number"<<endl;
cin>>a;
if(a>30)
cout<<"Number greater than 30";
else
cout<<"Number less than or equal to 30";
getch();
}

.
www.voiceofsindh.net

Page 56 of 97

www.voiceofsindh.net

a .
30 Number greater than 30
30 number less than or equal to 30 .

)( getche


.
getche .

34

>#include<constream.h
)(void main
{
;)(clrscr
;int chcount=0
;int wdcount=1
;'char ch='a
;" cout<<"Enter a phrase:
)'while (ch!='\r
{
;)(ch=getche
)' '==if(ch
;wdcount++
else
;chcount++
}
;cout<<"\nWord= "<<wdcount<<endl
;cout<<"Letters= "<<(chcount-1)<<endl
;)(getch
}

Page 57 of 97

www.voiceofsindh.net

www.voiceofsindh.net

.
Microsoft windows xp 18
3 .

. 34
.
.
chcount wdcount wdcount 1
. ch . )while(ch!=\r
.
.
) = = If (ch ch
wdcount + + Microsoft
wdcount++ 2 wdcount 1
2 . windows wdcount 3
xp xp wdcount 3
.
chcount wdcount
chcount .

Page 58 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Escape sequence
\r \n
.
10 .

\a

\b
\f
\n
\r
\t
\\
\
\
\xdd

35

>#include<constream.h
)(void main
{
;)(clrscr
;"cout<<"Information Technology \a
;)(getch
}

\a
.
\a

Page 59 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Nested if

36

#include<constream.h>
void main()
{
clrscr();
int a,b,c;
cout<<"Enter three numbers: use space B/W num"<<endl;
cin>>a>>b>>c;
if(a==b)
if(b==c)
cout<<"Both numbers are same";
else
cout<<"Numbers not same here";
getch();
}

36 .
.

else is constraction ...

37

#include<constream.h>
void main()
{
clrscr();
int test;
cout<<"Enter a number"<<endl;
cin>>test;
if(test>0)
cout<<"Your entered number greater than 0";
else if(test<0)
cout<<"Your entered number less than 0";
else if(test==0)
cout<<"Your entered number equal to 0";
getch();
}

www.voiceofsindh.net

Page 60 of 97

www.voiceofsindh.net

.

.

Switch statement
... : 37
.
:
.
.

.
.

Page 61 of 97

www.voiceofsindh.net

www.voiceofsindh.net

12


.
.
.

38

>#include<constream.h
)(void main
{
;)(clrscr
;int a,b
;int choice
;cout<<"Enter 1st number"<<endl
;cin>>a
;cout<<"Enter 2nd number"<<endl
;cin>>b
;cout<<"Choice one from following"<<endl
;cout<<"(1 for +)(2 for -)(3 for *)(4 for /)"<<endl
;cin>>choice
)switch(choice
{
case 1:
;cout<<"Addition is "<<a+b
;break
case 2:
;cout<<"Subtaction is "<<a-b

Page 62 of 97

www.voiceofsindh.net

www.voiceofsindh.net


;break

case 3:
;cout<<"Multiplication is "<<a*b
;break
case 4:
;cout<<"Division is "<<a/b
;break

default:
;"cout<<"Your input not valid
}
;)(getch
}

:1 34 , 56 4 1
+ 56 34 .
:2 7 .
Your input not valid .
a , b , choice . a b
.
. choice .
. choice 1 case 1
. choice 2 case 2
. 2 Your input not valid
7 case
.

Page 63 of 97

www.voiceofsindh.net

www.voiceofsindh.net

13
13 .
.

Break statement
38
)( .
.

39

>#include<constream.h
)(void main
{
;)(clrscr
)for(int a=1; a<=10; a++
{
)if(a==7
;break
;" "<<cout<<a
}
;)(getch
}

Page 64 of 97

www.voiceofsindh.net

www.voiceofsindh.net

39 .

10 6 7
)( .

continue statement
.

. .
.

40

>#include<constream.h
)(void main
{
;)(clrscr
)for(int a=1; a<=10; a++
{
)if(a==7
;continue
;" "<<cout<<a
}
;)(getch
}

7
.

Sw: with Char varble

38
.

.

Page 65 of 97

www.voiceofsindh.net

www.voiceofsindh.net

41
#include<constream.h>
void main()
{
clrscr();
textmode(3);
char dir='a';
int x=10, y=10;
while(dir != '\r')
{
cout<<"\n Your location is "<<x<<" , "<<y;
cout<<"\n Enter direction (n, s, e, w,): ";
dir=getche();
switch(dir)
{
case 'n':
y;
break;
case 's':
y++;
break;
case 'e':
x++;
break;
case 'w':
x;
break;
case '\r':
cout<<"Exiting \n";
break;
default:
cout<<"Try again\n";
}
}
getch();
}

.
www.voiceofsindh.net

Page 66 of 97

www.voiceofsindh.net

n, s, e, w, . s
y 10 11 s y 12 .
e x 10 11 .
x y 10 .
w n x y .
e x . s
y .

Defaulat

:
Error: Invalid selection.

.
.

Logical operator
+, -, *, /, % <, >, <=, >=,

=! ==, .
.
.


and operator
&&
or operator
||
:
.
.

and operator
.
Page 67 of 97

www.voiceofsindh.net

www.voiceofsindh.net

:
.
.
or operator ) (
.


. .
.

42

>#include<constream.h
)(void main
{
;)(clrscr
;int a,b
;cout<<"Enter User Name"<<endl
;cin>>a
;cout<<"Enter Password"<<endl
;cin>>b
)if(a==23 && b==11
;"cout<<"Welcome to microsoft windows
else
;"cout<<"Sorry user name or password are invalid
;)(getch
}

Page 68 of 97

www.voiceofsindh.net

www.voiceofsindh.net

42 .

42 a 23 b 11
. 1 23 11
. 23 44
.

Or operator
.
.
.
43

>#include<constream.h
)(void main
{
;)(clrscr
;int a,b
;cout<<"Enter User Name"<<endl
;cin>>a
;cout<<"Enter Password"<<endl
;cin>>b
)if(a==23 || b==11
;"cout<<"Welcome to microsoft windows
else
;"cout<<"Sorry user name or password are invalid
;)(getch
}

1 23 44 11
.
.
Page 69 of 97

www.voiceofsindh.net

www.voiceofsindh.net

goto satatement
.

.
.

44

>#include<iostream.h
>#include<conio.h
)(int main
{
;)(clrscr
;int a,b
restart:
;cout<<"Enter 1st value"<<endl
;cin>>a
;cout<<"Enter 2nd value"<<endl
;cin>>b
;cout<<"Addition is "<<a+b<<endl
;goto restart
;)(getch
;return 0
}


Enter 1st value . 44
restart .
restart .
goto restart

Page 70 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Function
.
.

.
.
.
. .
.

14
.

45

>#include<constream.h
;)(void starline
)(void main
{
;)(clrscr
;)(starline
cout<<"Data type
;Range "<<endl
;)(starline
cout<<"char
;-128 to 127"<<endl
cout<<"short
;-32,768 to 32, 767"<<endl
cout<<"int
;System dependent"<<endl
cout<<"long
;-2,147,483,648 to 2,147,483,647"<<endl

Page 71 of 97

www.voiceofsindh.net

www.voiceofsindh.net


;)(starline
;)(getch
}
)(void starline
{
)for(int a=1; a<=42; a++
;'*'<<cout
;cout<<endl
}

.
)( void main
)( void satarline void starline()
.

.
;)( clrscr ;)( starline
;)( starline
42 .
;)( starline
.

Function Declaration

.
.

.
45 ;)( starline
.
. .
Page 72 of 97

www.voiceofsindh.net

www.voiceofsindh.net

46
>#include<constream.h
)(void starline
{
)for(int a=1; a<=42; a++
;'*'<<cout
;cout<<endl
}
)(void main
{
;)(clrscr
;)(starline
cout<<"Data type
;Range "<<endl
;)(starline
cout<<"char
;-128 to 127"<<endl
cout<<"short
;-32,768 to 32, 767"<<endl
cout<<"int
;System dependent"<<endl
cout<<"long
;-2,147,483,648 to 2,147,483,647"<<endl
;)(starline
;)(getch

45 .

Calling function
45 46 ) ( .
. starline(); .
.

.

Function Defination
.
45 46
.
Page 73 of 97

www.voiceofsindh.net

www.voiceofsindh.net

)(void starline
{
)for(int a=1; a<=42; a++
;'*'<<cout
;cout<<endl
}

.
.
Purpose
Example
Specifies function name, argument, types and
;)(void starline
return values. Alert compiler that a function
coming up later.
Causes the function to be executed
;)(Starline
)(Void starline
{
//lines of code
}
)(Void starline

Component
)Declaration (prototype

Call

The function its self. Contains the lines of


codes that constitute the function.

Definition

First line of definition

Decelerator

;)(ch=getche

)
( .
)
;)( getche ( conio.h
.

Passing arguments to function


) :( .
.
.

Page 74 of 97

www.voiceofsindh.net

www.voiceofsindh.net

passing constant
42 46 45
.

.

47

#include<constream.h>
void repchar(char, int);
void main()
{
clrscr();
repchar('=',50);
cout<<"Data type
Range "<<endl;
repchar('-', 20);
cout<<"char
-128 to 127"<<endl;
cout<<"short
-32,768 to 32, 767"<<endl;
cout<<"int
System dependent"<<endl;
cout<<"long
-2,147,483,648 to 2,147,483,647"<<endl;
repchar('-', 40);
cout<<"I Love And Every Body Loves C++"<<endl;
repchar('=', 50);
getch();
}
void repchar(char ch, int n)
{
for(int j=0; j<=n; j++)
cout<<ch;
cout<<endl;
}

www.voiceofsindh.net

Page 75 of 97

www.voiceofsindh.net

47 = 50 20 40
50
.
47 ;)( repchar
. ) (=,-
) (=,- .
n
.

Passing variabe
47 - 50
.

48

>#include<constream.h
;)void repchar(char, int
)(void main
{
;)(clrscr
;char chain
;int nin
;cout<<"Enter character"<<endl
;cin>>chain
;cout<<"Enter number of times to repeat it"<<endl
;cin>>nin
;)repchar(chain, nin
;)(getch
}
)void repchar(char ch, int n
{
)for(int j=0; j<=n; j++
;cout<<ch
;cout<<endl
}

47 . 47
47
.
Page 76 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Diff: no of argument
48 47 46 45

.

49

>#include<constream.h
;)(void repchar
;)void repchar(char
;)void repchar(char, int
)(void main
{
;)(clrscr
;)(repchar
;)'='(repchar
;)repchar('+', 30
;)(getch
}
)(void repchar
{
)for(int j=0; j<=45; j++
;'*'<<cout
;cout<<endl
}
)void repchar(char ch
{
)for(int j=0; j<45; j++
;cout<<ch
;cout<<endl
}
)void repchar(char ch, int n
{
)for(int j=0; j<n; j++
;cout<<ch
;cout<<endl
}

48 47 46 45
.
.

Page 77 of 97

www.voiceofsindh.net

www.voiceofsindh.net


Work with more

textmode
.
.

50

>#include<constream.h
)(int main
{
;)(clrscr
;)textmode(3
;cout<<"Go.....Go"<<endl
;)(getch
}

:
.

;) Textmode(3 3
3 .

Text color
.
.

51

>#include<constream.h
)(void main
{
;)(clrscr
;)textcolor(12
;)"cputs("Information technology
;)(getch
}

.
Page 78 of 97

www.voiceofsindh.net

www.voiceofsindh.net

12 .
cout cputs
.
.

0
1
2
3
4
5
6
7
8
9
10
11
12
13

Page 79 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Text beckground

.

52

>#include<constream.h
)(void main
{
;)(clrscr
;)textcolor(12
;)textbackground(2
;)"cputs("Information technology
;)(getch
}

High video
.

53

>#include<constream.h
)(int main
{
;)(clrscr
;)textmode(3
;)(highvideo
;)"!cputs("Hello tech in sindhi
;)(getch
;return 0
}

Normal video
.
Page 80 of 97

www.voiceofsindh.net

www.voiceofsindh.net

54
#include<constream.h>
int main()
{
clrscr();
textmode(3);
normvideo();
cputs("Hello tech in sindhi!");
getch();
return 0;
}

Low video
.

55

#include<constream.h>
int main()
{
clrscr();
textmode(3);
lowvideo();
cputs("Hello tech in sindhi!");
getch();
return 0;
}

clreol();
. . clear end of line Clreol

56

#include <constream.h>
void main()
{
clrscr();
cputs("clreol stand fo clear end of line\r\n");
cputs("c plus plus\r\n");
cputs("current text window, without moving the cursor.\r\n");
cputs("Press any key to continue . . .");
gotoxy(14, 4);
getch();
clreol();
getch();
}

goto xy
.

57

#include <constream.h>
void main()

www.voiceofsindh.net

Page 81 of 97

www.voiceofsindh.net

{
clrscr();
gotoxy(12, 12);
cout<<"Hello world";
getch();
}

Delline();
. . delete line Delline
.

58

#include <constream.h>
void main()
{
clrscr();
cout<<"Information technology"<<endl;
cout<<"C plus pluse"<<endl;
cout<<"Hello world"<<endl;
cout<<"window. Press any key to continue . . ."<<endl;
gotoxy(1,2);
getch();
delline();
getch();
}

Insline();
insert line Insline
.

60

#include <constream.h>
void main()
{
clrscr();
cout<<"INSLINE inserts an empty line in the text window"<<endl;
cout<<"at the cursor position using the current text"<<endl;
cout<<"background color. All lines below the empty one"<<endl;
cout<<"move down one line and the bottom line scrolls"<<endl;
cout<<"off the bottom of the window."<<endl;
cout<<"Press any key to continue:";
gotoxy(1, 3);
getch();
insline();
getch();
}

windows function
. goto xy

61
www.voiceofsindh.net

Page 82 of 97

www.voiceofsindh.net

>#include <conio.h
>#include <iostream.h
)int main(void
{
;)(clrscr
;)window(10,10,40,91
;)textcolor(BLACK
;)textbackground(WHITE
;)"cputs("This is a test\r\n
;)(getch
;return 0
}

Delay,sound no sound
.

62
>#include <dos.h
)int main(void
{
;)sound(440
;)delay(1000
;)(nosound
;return 0
}

dos.h .
.
440 .
.
.
1000 .
.

Page 83 of 97

www.voiceofsindh.net

www.voiceofsindh.net

Square root
.

63

#include<constream.h>
#include<math.h>
void main()
{
clrscr();
int no, result;
cout<<"Enter any number for square root"<<endl;
cin>>no;
result=sqrt(no);
cout<<"Square root is"<<result;
getch();
}

. math.h

power function

.

64

#include<constream.h>
#include<math.h>
void main()
{
clrscr();
int no, result,power;
cout<<"Enter any value"<<endl;
cin>>no;
cout<<"Enter any power"<<endl;
cin>>power;
result=pow(no,power);
cout<<"power is"<<result;
getch();
}

. math.h
. pow power

www.voiceofsindh.net

Page 84 of 97

www.voiceofsindh.net


ASCII Chart
DEC

HEX
0
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

www.voiceofsindh.net

00
01
02
03
04
05
06
07
08
09
0A
0B
0C
0D
0E
0F
10
11
12
13
14
15
17
18
19
1A
1B
1C
1D
1E
1F
20
21

Symbol
(NULL)

Key
Ctrl 2
Ctrl A
Ctrl B
Ctrl C
Ctrl D
Ctrl E
Ctrl E
Ctrl G
Backspace
Tab
Ctrl J
Ctrl K
Ctrl L
Enter
Ctrl N
Ctrl O
Ctrl P
Ctrl Q
Ctrl R
Ctrl S
Ctrl T
Ctrl U
Ctrl W
Ctrl X
Ctrl Y
Ctrl Z
Esc
Ctrl \
Ctrl ]
Ctrl 6
Ctrl Spacebar
!

Use in c

beep
Backspace
tab
New line
Vertical tab
Form feed
Carriage return

Page 85 of 97


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

www.voiceofsindh.net

www.voiceofsindh.net
22
23
24
25
26
27
28
27
2A
2B
2C
2D
2E
2F
30
31
32
33
34
35
36
37
38
39
3A
3B
3C
3D
3E
3F
40
41
42
43
44
45
46
47
48
49

"
#
$
%
&
'
)
(
*
+
,
.
/
0
1
2
3
4
5
6
7
8
9
:
;
>
=
<
?
@
A
B
C
D
E
F
G
H
I

#
$
%
&

)
(
*
+
,
.
/
0
1
2
3
4
5
6
7
8
9
:
;
>
=
<
?
@
A
B
C
D
E
F
G
H
I
Page 86 of 97


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

www.voiceofsindh.net

www.voiceofsindh.net
4A
4B
4C
4D
4E
4F
50
51
52
53
54
55
56
57
58
59
5A
5B
5C
5D
5E
5F
60
61
62
63
64
65
66
67
68
69
6A
6B
6C
6D
6E
6F
70
71

J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
]
\
[
^
_
`
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q


J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
]
\
[
^
_
`
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
Page 87 of 97


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

www.voiceofsindh.net

www.voiceofsindh.net
72
73
74
75
76
77
78
79
7A
7B
7C
7D
7E
7F
80
81
82
83
84
85
86
87
88
89
8A
8B
8C
8D
8E
8F
90
91
92
93
94
95
96
97
98
99

r
s
t
u
v
w
x
y
z
{
|
}
~


r
s
t
u
v
w
x
y
z
{
|
}
~
Ctrl
Alt 128
Alt 129
Alt 130
Alt 131
Alt 132
Alt 133
Alt 134
Alt 135
Alt 136
Alt 137
Alt 138
Alt139
Alt 140
Alt 141
Alt 142
Alt 143
Alt 144
Alt 145
Alt 146
Alt 147
Alt 148
Alt 149
Alt 150
Alt 151
Alt 152
Alt 153
Page 88 of 97


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

www.voiceofsindh.net

www.voiceofsindh.net
9A
9B
9C
9D
9E
9F
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
AA
AB
AC
AD
AE
AF
B3
B4
B5
B6
B7
B8
B9
BA
BB
BC
BD
BE
BF
C0
C1
C2
C3
C4


Alt 154
Alt 155
Alt 156
Alt 157
Alt 158
Alt 159
Alt 160
Alt 161
Alt 162
Alt 163
Alt 164
Alt 165
Alt 166
Alt 167
Alt 168
Alt 169
Alt 170
Alt 171
Alt 172
Alt 173
Alt 174
Alt 175
Alt 179
Alt 180
Alt 181
Alt 182
Alt 183
Alt 184
Alt 185
Alt 186
Alt 187
Alt 188
Alt 189
Alt 190
Alt 191
Alt 192
Alt 193
Alt 194
Alt 195
Alt 196
Page 89 of 97


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

www.voiceofsindh.net

www.voiceofsindh.net
C5
C6
C7
C8
C9
CA
CB
CC
CD
CE
CF
D0
D1
D2
D3
D4
D5
D6
D7
D8
D9
DA
DB
DC
DD
DE
DF
E0
E1
E2
E3
E4
E5
E7
E8
E9
EA
EB
EC
ED


Alt 197
Alt 198
Alt 199
Alt 200
Alt 201
Alt 202
Alt 203
Alt 204
Alt 205
Alt 206
Alt 207
Alt 208
Alt 209
Alt 210
Alt 211
Alt 212
Alt 213
Alt 214
Alt 215
Alt 216
Alt 217
Alt 218
Alt 219
Alt 220
Alt 221
Alt 222
Alt 223
Alt 224
Alt 225
Alt 226
Alt 227
Alt 228
Alt 229
Alt 231
Alt 232
Alt 233
Alt 234
Alt 235
Alt 236
Alt 237
Page 90 of 97

www.voiceofsindh.net
Alt 238
Alt 239
Alt 240
Alt 241
Alt 242
Alt 243
Alt 244
Alt 245
Alt 246
Alt 247
Alt 247
Alt 249
Alt 250
Alt 251
Alt 252
Alt 253
Alt 254
Alt 255

)(blank


EE
EF
F0
F1
F2
F3
F4
F5
F6
F7
F8
F9
FA
FB
FC
FD
FE
FF

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250

ASCII Amrican standard code for information interchange



.
.

.
.
ctrl L alt 228 .
Page 91 of 97

www.voiceofsindh.net

www.voiceofsindh.net


.

.

66

#include<constream.h>
void main()
{
clrscr();
int choice;
cout<<"Choice one from following"<<endl;
cout<<"1. Fahrenheit to Centigrad"<<endl;
cout<<"2. Centigrad to Fahrenheit"<<endl;
cin>>choice;
switch(choice)
{
case 1:
float centi, forn;
cout<<"Enter temp: in fahrenheit"<<endl;
cin>>forn;
centi=(forn-32)*5/9;
cout<<"Centigrad is "<<centi;
break;
case 2:
float cnti, fahr;
cout<<"Enter temp: in centigrad"<<endl;
cin>>cnti;
fahr=cnti*9/5+32;
cout<<"Fahrenheit is "<<fahr;
break;
default:
cout<<"Your input not valid";
}
getch();
}

67

#include<constream.h>
void main()
{
int notes;
clrscr();
cout<<"Enter value for notes"<<endl;
cin>>notes;
if(notes>=1000)
{
cout<<"Notes of one thousands are "<<notes/1000<<endl;
notes=notes%1000;
}
if(notes>=500)

www.voiceofsindh.net

Page 92 of 97

www.voiceofsindh.net

{
cout<<"Notes of five hundred are "<<notes/500<<endl;
notes=notes%500;
}
if(notes>=100)
{
cout<<"Notes of one hundred are "<<notes/100<<endl;
notes=notes%100;
}
if(notes>=50)
{
cout<<"Notes of fifty are"<<notes/50<<endl;
notes=notes%50;
}
if(notes>=10)
{
cout<<"Notes of ten are"<<notes/10<<endl;
notes=notes%10;
}
if(notes>=5)
{
cout<<"Notes of five are "<<notes/5<<endl;
notes=notes%5;
}
if(notes>=0)
{
cout<<"notes of one are "<<notes/1<<endl;
notes=notes%1;
}
getch();
}

68

#include<constream.h>
void main()
{
clrscr();
int choice;
cout<<"Choice one from following"<<endl;
cout<<"1. Inchs To Feets"<<endl;
cout<<"2. Feets to inchs"<<endl;
cin>>choice;
switch(choice)
{
case 1:
float inchs, feet;
cout<<"Enter Feets"<<endl;
cin>>feet;
inchs=feet*12;
cout<<"Inch(s) are "<<inchs;
break;
case 2:
float inch, feets;
cout<<"Enter Inchs"<<endl;
cin>>inch;
feet=inch/12;
cout<<"Feet(s) are"<<feets;
break;
default:

www.voiceofsindh.net

Page 93 of 97

www.voiceofsindh.net

cout<<"Your input not valid";


}
getch();
}

69

#include<constream.h>
void main()
{
clrscr();
int table;
cout<<"Enter any table"<<endl;
cin>>table;
for(int a=1; a<=10; a++)
cout<<table<<"*"<<a<<"="<<a*table<<endl;
getch();
}

70

#include<constream.h>
void main()
{
int eng, sindhi, ps, science, drawing, math;
float per, total;
clrscr();
textmode(3);
cout<<"Enter marks of English"<<endl;
cin>>eng;
cout<<"Enter marks of Sindhi"<<endl;
cin>>sindhi;
cout<<"Enter marks of Pakistan study"<<endl;
cin>>ps;
cout<<"Enter marks of Science"<<endl;
cin>>science;
cout<<"Enter marks of Drawing"<<endl;
cin>>drawing;
cout<<"Enter marks of Math"<<endl;
cin>>math;
total=eng+sindhi+ps+science+drawing+math;
per=total*100/600;
cout<<"Total marks are 600"<<endl;
cout<<"Your marks are "<<total<<endl;
cout<<"Your percantage is "<<per<<endl;
if(per>=80 && per<=100)
cout<<"Your grad is A"<<endl;
else if(per>=60 && per<=80)
cout<<"Yoyr grad is B"<<endl;
else if(per>=50 && per<=60)
cout<<"Your grad is C"<<endl;
else if(per>=40 && per<=50)
cout<<"Your grad is D"<<endl;
else if(per<40)
cout<<"Your are fail"<<endl;
getch();
}

www.voiceofsindh.net

Page 94 of 97

www.voiceofsindh.net


Error reporting

.

1

.

345 .
Function clrscr should have prototype clrscr
.
.
Undefined symbol cout
.
)( Getch .

2
.
int main(); :

Page 95 of 97

www.voiceofsindh.net

www.voiceofsindh.net

3
.

it main(); :

4
.

5
.
clrscr() :

6
.
cout<Hello; :

7

.
cout<<hello; :

.

.
Page 96 of 97

www.voiceofsindh.net

www.voiceofsindh.net

www.voiceofsindh.net

www.voiceofsindh.net

Page 97 of 97

You might also like