فصل سوم. 2 phases of c++ programs: 1.edit 2.preprocess 3.compile 4.link 5.load 6.execute...

32
ان ب ه ز ی ل م او ی ه ا ف مC وم س ل ص ف

Upload: felicia-fitzgerald

Post on 13-Dec-2015

215 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor

Cمفاهیم اولیه زبان فصل سوم

Page 2: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor

2

1.14 BASICS OF A TYPICAL C PROGRAM DEVELOPMENT ENVIRONMENT

• Phases of C++ Programs:1. Edit2. Preprocess3. Compile4. Link5. Load6. Execute

Program is created in

the editor and stored

on disk.Preprocessor

programprocesses the

code.

Loader puts program in

memory.

CPUtakes eachinstruction and

executes it, possibly storing

new data values as the program

executes.

Compiler creates object code and

storesit on disk.Linker links the

objectcode with the

librariesLoader

Primary Memory

Compiler

Editor

Preprocessor

Linker

 

Primary Memory

.

.

.

.

.

.

.

.

.

.

.

.

Disk

Disk

Disk

CPU

Disk

Disk

Page 3: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor
Page 4: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor

c:کلمات رزرو شده زبان

Page 5: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor

مثال ساده:

Page 6: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor
Page 7: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor

C STANDARD HEADER FILES YOU MAY WANT TO USE

استاندارد توابع :مهمترین stdio.h – file and console (also a file) IO: printf, open, close, read, write, scanf, etc.

string.h - string and byte manipulation: strlen, strcpy, strcat, memcpy, memset, etc.

errno.h – defines errno used for reporting system errors

math.h – math functions: sin, exp, floor, sqrt, etc.

time.h – time related facility: asctime, clock, time_t, etc.

Page 8: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor

: خروجی و ورودی دستورات

Page 9: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor
Page 10: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor
Page 11: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor

# include < stdio.h >void main (){const float pi = 3.14 ;float r,p,s;printf (" please enter reduce : \n ") ;scanf("%f",&r);p = 2*pi * r ;s = pi * r *r ;printf (" The S = %f , The P = % f " , s,p) ;while(1);}

مثال: برنامه ای بنویسید تا شعاع دایره را از ورودی

بخواند و محیط و مساحت آنرا حساب کند و نمایش دهد.

Page 12: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor
Page 13: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor
Page 14: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor

//9 simple program# include < conio.h >#include <stdio.h>void main(){int a=21,b=10,c;c=a%b;printf("a=%d ,b=%d c=%d \n",a,b,c);int x=0xf0,y=0x0f;printf(" %x ,%x , %x ,%x ",x&y,x|y,y<<4,x>>4);getch();}

Page 15: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor
Page 16: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor
Page 17: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor

; از آدرس float a[5]تمرین :فرض کنید محل ذخیره آرایه 0x0100 شروع می شود.تعیین کنید تا چه آدرسی به آرایه

است)AVR ATMEGA 16فوق اختصاص می یابد.(میکرو

Page 18: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor

آرایه های دو بعدی:

یعنی آرایه ای از آرایه های یک بعدی

مثال:

فرض کنید دو آرایه یک بعدی بشکل زیر داریم:

Int a[3]={1,2,3}

int b[3]={4,5,6}

حال می خواهیم انها را بصورت یک آرایه دو بعدی نمایش دهیم:

int c[2][3]={{1,2,3},{4,5,6}}

C(0,0)=1 C(0,1)=2

C(0,2)=3

C(1.0)=4 C(1,1)=5

C(1,2)=6

Page 19: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor

روش تعریف آرایه های دو بعدی:

[ اسم آرایه ] تعداد ستون ][ تعداد سطر نوع متغیرها

Page 20: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor
Page 21: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor

Main)(

{

Int i=0;

HERE:

i;++

If (i<10)

Goto HERE;

Printf(“THE MAX value of i is:%d “,i);

Getch;)(

}

Page 22: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor

مثال:

Page 23: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor
Page 24: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor
Page 25: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor
Page 26: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor
Page 27: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor
Page 28: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor
Page 29: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor
Page 30: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor

را عددی که بنویسید تابعیتوان و بگیرد ورودی 3از

نماید چاب و حساب انرا

Page 31: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor

تابعی: 2مثال عدد دو که بنویسید

و بگیرد ورودی از رارا آنها بزرگترین

نماید چاب و تعیین

Page 32: فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor