introduction c++ i. elaf alhazmilab1 programming course

18
INTRODUCTION C++ I. Elaf Alhazmi LAB1 Programming course

Upload: derek-walker

Post on 03-Jan-2016

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

INTRODUCTION C++

I. Elaf Alhazmi LAB1

Programming course

Page 2: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

2

Microsoft Visual Studio 2010 (Open New File)

We will training on Microsoft Visual Studio 2010 for C++ program.

Open Visual Studio 2010

Ins. Elaf Alhazmi Computer Programming (lab)

Page 3: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

Ins. Elaf Alhazmi Computer Programming (lab)

3

Microsoft Visual Studio 2010 (Open New File)

Open New project Then win32 then Win32 Conslot project Or Empty Project if available

اسم نكتبالمشروع

Page 4: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

Ins. Elaf Alhazmi Computer Programming (lab)

4

Microsoft Visual Studio 2010 (Open New File)

نختار“Applica

tion Setting

In case you selectwin32 then Win32 Conslot project then Application Setting

Page 5: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

Ins. Elaf Alhazmi Computer Programming (lab)

5

Microsoft Visual Studio 2010 (Open New File)

نختار -1“Empty

project”

نختار -2“Finish”

Page 6: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

Ins. Elaf Alhazmi Computer Programming (lab)

6

Microsoft Visual Studio 2010 (Open New File)

مجلد على الفأرة في اليمين بزر Source fileضغطAddثم New itemثم

Page 7: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

Ins. Elaf Alhazmi Computer Programming (lab)

7

Microsoft Visual Studio 2010 (Open New File)

نختار -1“C++ File

(.cpp) “

نكتب -2إسم الملف

3-

نختار”Add

Page 8: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

Ins. Elaf Alhazmi Computer Programming (lab)

8

Microsoft Visual Studio 2010 (Open New File)

الكود نكتب

معرفة االخطاء

نختارStart

Debugging

Page 9: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

Ins. Elaf Alhazmi Computer Programming (lab)

9

Program 1

// my first program in C++

#include <iostream>

using namespace std;

int main()

{

cout<< "Hello World!“ ;

system("pause");

return 0;

}

Page 10: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

Ins. Elaf Alhazmi Computer Programming (lab)

10

Decleration

DataType Variable_Name = value/expression ;

Initialization مبدئية قيمة

int x;char grade;float PI=3.14;char yes= ‘y’;

Page 11: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

Ins. Elaf Alhazmi Computer Programming (lab)

11

Declarations (Variables)

Variable is symbol that represents storage location in the computer’s memory. The information that is stored in that location is called Value

Assignment StatementVariable = Expression ;

int x; int is called data type x is varible

Every variable in C++ program must be declared before it is used.

Page 12: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

Ins. Elaf Alhazmi Computer Programming (lab)

12

Variables name

المتغير تسمية شروط األبجدية الحروف غير حرف بأي المتغير يبدأ أن يمكن ال

( A-Z a-z ,)_( )وصاعدا الثاني من األحرف لكن السفلي التسطير حرف أوالسفلي التسطير حرف أو أحرف أو أعدادا تكون أن يمكن

حرف غير تنقيط عالمات أو فراغات على المتغير اسم يحتوي أن يمكن الالتسطير)_(

محجوزة كلمة يكون أن يمكن Reserved wordال االسم بنفس متغيران هناك يكون أن يمكن ال البرمجة لتسهيل معنى ذا المتغير اسم يكون أن األفضل

Page 13: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

Ins. Elaf Alhazmi Computer Programming (lab)

13

Reserved words

The syntax rules (or grammar) of C++ define certain symbols to have a unique meaning within a C++ program, must not be used for any other purposes

unsigned

struct short int float double

const auto

void switch signed

long for else continue

break

volatile typedef

sizeof register

goto enum

default

case

while union static return

if extern do char

Page 14: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

Ins. Elaf Alhazmi Computer Programming (lab)

14

Data types

String String note: you need #include<string>

Characters Char

Integer Numbers short int long unsigned short unsigned int unsigned long

Real/ Float Numbers float double long double

Page 15: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

Ins. Elaf Alhazmi Computer Programming (lab)

15

Arithmetic operation

Symbol Action

= Assignment

+ Addition

- Subtraction

* Multiplication

/ Division

% Modulus ( القسمة ( باقي

Page 16: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

Ins. Elaf Alhazmi Computer Programming (lab)

16

Operators and expressions

- (-3* (5 +2 *6)) + (3* 4+4)/2

12

17

- 51

51

12

16

8

59

Page 17: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

Ins. Elaf Alhazmi Computer Programming (lab)

17

Operators and Expressions

Priority األقل إلى األعلى من األفضلية the execution of an expression is from

left to right ( ) Negative sign *, / -, +

Page 18: INTRODUCTION C++ I. Elaf AlhazmiLAB1 Programming course

Ins. Elaf Alhazmi Computer Programming (lab)

18

Declarations & initialization

Just declaration

Declaration and initialization