Академический Документы
Профессиональный Документы
Культура Документы
WRITING
CaPasakmviFITUeTAmYyEdlsitenAkg
( High Level Programming Language) . eKbegIt C
PasakmviFIkMritx<s;
edIm,Isresr System program eKfa C CaPasa edIm kMeNItrbs; UNIX Operating
System.
C/C++
RtUv)aneKcat;TukCaPasamYymanRbCaRbiykgkarsresrPab;
Application CamYynig System edayPasa C/C++ CaPasakMritx<s; (High Level
Language) nig man Compiler bkERbBak bBaaeGayeTACaPasa ma:sIun rYc
mkCaPasaEdlGacGan)anedayPasarbs;mnusS. C minGaRsyEt enAelI
O.S(Operating
System)
rW ma:sIunNamYyedayELkeLIy mannyfa C
RtUv)aneKykeTAeRbIR)as; CamYy O.S nig ma:sIunepSgtam Object rbs;va.
qaM 1970 elak Ken Thompson )anerobcMPasa B Language
Edlman\TiBlenAelI Basic Computer Programming Language EdlbegIteday elak
Martin Richard.
qaM 1972 elak Dennis Ritchie )aneFVIkarEkERb B Programming Language
eGayeTACa C Programming Language enA Bell Telephone Laboratories.
C/C++
Programming
Language
257
cMnuccab;epImnkmviFI
statement1;
statement2;
.;
Block of statement
bBaak;fadMeNIrkardl;TIbBab;
}// cMnucbBab;nkmviFI
return 0;//
#include<iostream.h>//Header file/Preprocessor/Library
cMnuccab;epImnkmviFI
void main(){//
statement1;
statement2;
.;
}//
-
Block of statement
cMnucbBab;nkmviFI
ebIkkmviFI C/C++:
- C:\> TC\Bin\Tc.exe
- Compiler: Alt +F9
- Run (Make EXE): Ctrl +F9
- Copy: Ctrl+Insert
258
- Past: Shift+Insert
- Cut: Shift+Delete
Source Code
COMPILER
TEMPORARY
OBJECT + LINK
.EXE
Ex:
cout<< Hello world!<<endl;
cout>>x;
int x=10;
cout<< x=<<x;
- cin>>Var1,var2,var3, ...;
eRbIsMrab;bBalTinnytamryH Keyboard
eTAeGay var1,var2,...
Ex:
int x;
cin>>x;
259
CakarkMNt;lkNHeTAelIGefr (Variables)
maneRcInRbePTdUcCa
Scalars type
Structure type
Pointer type
Data Type
Scalar Type
Structure Type
- int
- array
- float
- file
- double
- struct
Pointer Type
- pointer
- Boolean
- ...
Keyword
Byte
Char
Int
Long
Float
Double
Unsigned int
Limited
dl; 128
-32768 dl; 32768
-2147483648 dl; 2147483648
3,4 .10 dl; 3,4 .10
1,7.10 dl; 1,7.10
0 dl; 65535
-128
260
-38
38
-308
308
Note:
Syntax:
int sizeof(Data-Type/var);
Ex:
cout<<Size of Integer=<< sizeof(int);
Output:
Size of Integer=2
VII. Variables:
CaGefr b Address
eRbIsMrab;rkSanUvtMlCabeNaHGasnkg Memory enAeBlkmviFIdMeNIrkar (Run time) .
tMlenHRtUv)an)at;bg;eTAvijenAeBleKQb;dMeNIrkar kmviFI (Stop Run) .
7.1. Definition of Variable:
7.2. Syntax:
Data-type VarName1, VarName2, ..., VarName n;
Ex:
int x,y;
float a,b,z;
7.3. Assignment Statement:
CakareprtMleTAeGayGefr (Variable) .
Ex1:
- int x;
x=20;
- int y=30;
Ex1:
+ 2x2 + 3x + 1
#include<iostream.h>
#include<math.h>
#include<conio.h>
void main(){
clrscr();
float x, y;
cout<< Please Input x=;
cin>>x;
y=4*pow(x,5)+2*pow(x,2)+3*x+1;
261
cout<< y=<<y<<endl;
getch( );
}
VIII. Constants:
VIII.1. Definition of Constants:
Ex1:
#define PI
Ex2:
3.14
kmviFIsMrab; KNnaRklaprgVg;
#include<iostream.h>
#include<conio.h>
#define PI
3.14
void main(){
clrscr();
float radius, circle_area;
cout<< Please Input radius of Circle=;
cin>>radius;
circle_area=PI * (radius * radius);
cout<< Circle Area =<<circle_area<<endl;
getch();
}
CarkareFVIkMNt;sMKal;enAkgkmviFI. vaminman
dMeNIrkareTenAeBl Run Time.
enAkg C ++ man Comments BIrKW
- Comments:
// One Line
262
- /* Multiple Line */
- Escape Code:
- \n : New line
- \t : Move one tab
- \a : Beeb
- \\ : \
- \r : Move cursor to the first of line
- \ :
Ex:
// This program used to change dollars to riels
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
const riel=4000;
float dollar, result;
cout<< \n Enter Dollar you have=;
cin>>dollar;
result =dollar * riel;
cout<< After dollar to riel=<<result<<endl;
getch();
}
eRbIsMrab;bMElgRbBneKal
- hex : CaRbBneKal 16
- dec : CaRbBneKal 10
- oct : CaRbBneKal 8
Ex:
//Convert to hex, dec, oct;
#include<iostream.h>
263
#include<conio.h>
void main(){
clrscr();
int num;
cout<< Enter num=;
cin>>num;
cout<< Decimal=<<dec<<num<<endl;
cout<< Octal=<<oct<<num<<endl;
cout<< Hexadecimal=<<hex <<num<<endl;
getch();
}
Ex:
//Convert to hex, dec, oct;
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int num;
cout<< Enter num=;
cin>>num;
cout<< Decimal=<<setbase(10)<<num<<endl;
cout<< Octal=<<setbase(8)<<num<<endl;
cout<< Hexadecimal=<<setbase(16)<<num<<endl;
getch();
}
10.4. setw():
eRbIsMrab;kMNt;TMhMbgajmkelI Screen .
Ex:
cout<< setw(4)<< Web<<setw(5)<< Site;
Output:
9Web9Site
264
Ex:
cout<<setfill(*);
cout<< setw(4)<< Web<<setw(5)<< Site;
Output:
*Web*Site
10.6. setprecision():
double
eRbIsMrab;kMNt;eRkayek,scMeBaHTinnyRbePT float or
.
Ex:
float a;
a=7/3;
cout<< a=setprecision(2)<<a<<endl;
Output:
a=2.33
Meaning
Addition
Subtraction
Multiplication
Division
Modulo
Example
c = a + b;
c = a b;
c = a * b;
c=a/b;
c = a % b;
Ex:
int a=20, b=40, c;
c= a+ b;
cout<< c=<<c<<endl;
XI.2. Assignment Operators:
Operators
=
+=
-=
/=
*=
%=
Meaning/Example
a = 10;
a + = 10; a = a + 10;
a - = 10; a = a 10;
a / = 10; a = a / 10;
a * = 10; a = a * 10;
a % = 10; a = a % 10;
265
>> =
<<=
n >> = 1; n = n >> 1;
n << = 1; n = n<<1;
Operators
<
>
<=
>=
==
!=
&&
||
!
Less than
Greater than
Less than or equal to
Greater than or equal to
Equal to
Not equal to
Logical AND
Logical OR
Not
Ex:
- Logical AND (&&):
X
1
1
0
0
Y
1
0
1
0
X && Y
1
0
0
0
X
1
1
0
0
Y
1
0
1
0
X || Y
1
1
1
0
- Logical OR (||):
266
Operators
&
|
^
>>
<<
~
Ex:
- Bit wise AND (&):
X
0101
0110
1111
0001
Y
0110
0010
0001
0000
X&Y
0100
0010
0001
0000
X
0101
0110
1111
0001
Y
0010
0010
0001
0000
X|Y
0111
0110
1111
0001
X
0101
0110
1111
0001
Y
0010
0011
0001
0000
X^Y
0111
0101
1110
0001
267
Y
11111111
~X
11110100
~Y
00000000
Ex:
++ i;
-- i;
i ++;
i--;
- Ternary Operator (?):
Functions
abs(i)
sin(d)
cos(d)
tang(d)
exp(d)
log(d)
pow(x1,x2)
flour(d)
ceil(d)
fmod(d1,d2)
sqrt(d)
random(d)
14.
Description
|i|
Sin(d)
Cos(d)
Tang(d)
Exp(d)
Log(d)
Pow(d)
Flour(d)
Ceil(d)
Fmod(d1,d2)
Sqrt(d)
Random(d)
GnuKmn_EdlmanenAkg <ctype.h>:
Functions
Ex:
toascii (ch)
tolower (ch)
Result Data
Type
int
char
toupper(ch)
char
#include<stdio.h>
#include<conio.h>
#include<math.h>
main( ){
clrscr( );
float a;
int result;
printf("Please, Input a=");
scanf(" %f",&a);
result =abs(a);
textcolor(6);
cprintf("Result are =%d",result);
getch( );
return 0;
269
Description
Convert ch to Ascii code
Convert ch to lower
character
Convert ch to upper
character
Exercises:
270