Professional Documents
Culture Documents
. البرنامج عبارة عن مجموعة من التعليمات التي تخبر الكمبيوتر أن تفعل أشياء مختلفة:التعريف
The representation of a computer program which is actually read and understood by the computer.
Operation Address
Programming in assembly language is slow and error-prone but is more efficient in terms of hardware
performance.
البرمجة في لغة التجميع بطيئة وعرضة للخطأ ولكن هي أكثر كفاءة من حيث األداء األجهزة
A programming language which use statements consisting of English-like keywords such as "FOR", "PRINT"
or “IF“, ... etc.
الخ... ،IF"" " أوPRINT" ،FOR"" لغة البرمجة التي تستخدم البيانات التي تتكون من كلمات اللغة اإلنجليزية مثل مثل
The first programming languages designed to communicate instructions to a computer were written in the
1950s.
.1950 تم كتابة لغات البرمجة األولى تهدف إلى التواصل تعليمات إلى جهاز كمبيوتر في عام
C was developed between 1969 and 1973 as a system programming language.
كلغة برمجة نظام1973 و1969 بين عاميC وقد وضعت
Prolog, designed in 1972, was the first logic programming language.
By focusing on these concepts, you are better able to learn any programming language.
. وأنت أقدر على تعلم أي لغة برمجة، من خالل التركيز على هذه المفاهيم
Hence, by learning Java, you are poised to learn other languages, such as C++ or Perl.
.أو بيرلC ++ تستعد لك ل تعلم لغات أخرى مثل، من خالل تعلم جافا،وبالتالي
By learning the core concepts, you are also much more marketable as you are able to learn new technologies
quicker.
. وأنت أيضا أكثر قابلية للتسويق قدر كنت قادرا على تعلم التكنولوجيات الجديدة أسرع، من خالل تعلم المفاهيم األساسية
Note: Java is an object oriented programming language. However, we will not touch upon the concepts which
categorize it as one.
. فإننا لن أتطرق إلى المفاهيم التي تصنف على انها واحدة، ومع ذلك. جاوة هو كائن المنحى لغة البرمجة:مالحظة
Introduction of C Language
اللغةC مقدمة من
C is a general purpose computer programming language, it Supports Structure programming.
C was originally developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs.
.مختبرات بيلAT & T في1973 و1969 في األصل من قبل دينيس ريتشي بين عاميC وقد وضعت
.1979 بدءا من عام،التي كتبها بيارن ستروستروب في مختبرات بيلC ++ وقد وضعت
C++ is standardized by the International Organization for Standardization (ISO), with the latest (and current)
standard version.
مع أحدث (والحالي) اإلصدار القياسي،من قبل المنظمة الدولية للتوحيد القياسيC ++ وموحدة
C++ is one of the most popular programming language for graphical application and it based on C language.
C هي واحدة من لغة البرمجة األكثر شعبية بالنسبة للتطبيق رسومية وذلك على أساس اللغةC ++
خاصة، خوارزمية هي عملية أو مجموعة من القواعد التي يجب اتباعها في الحسابات أو غيرها من عمليات حل المشكلة- :تعريف •
.من قبل جهاز كمبيوتر
The Word “Algorithm” comes from the Arabic Writer Muhammed bin Musa Khwarizmi. •
. كإخراج، كمدخل وتنتج بعض القيم أو مجموعة من القيم،الخوارزمية هو اإلجراء الذي يأخذ بعض القيم أو مجموعة من القيم
Input: - An Algorithm has zero or more inputs, taken from a specified set of Object. Example •
{a1,a2,…..,an}
مأخوذة من مجموعة محددة من الكائنات، خوارزمية لديه صفر أو أكثر من المدخالت- :المدخالت
Output: - An Algorithm has zero or more outputs, taken from a specified set of object. •
Example: - a1<=a2<=……<=an
مأخوذة من مجموعة محددة من الجسم، خوارزمية لديه صفر أو أكثر النواتج- :اإلخراج
Step 1: Start
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 6: Stop
.الرسوم البيانية تسمح لك لرسم صورة للطريقة عملية في الواقع يعمل بحيث تتمكن من فهم العملية الحالية وتطوير األفكار حول كيفية تحسينه
• These flowcharts make it easy to identify rework loops and complexity in a process.
.هذه المخططات االنسيابية تجعل من السهل تحديد الحلقات إعادة صياغة والتعقيد في العملية
• It Identifies steps that do not add value to the internal or external customer, including: delays; needless
storage and transportation; unnecessary work, duplication, and added expense; breakdowns in
communication.
، واالزدواجية، تخزين غني والنقل؛ العمل ال لزوم لها. التأخير: بما في ذلك،ويحدد الخطوات التي ال تضيف قيمة للعميل داخلي أو خارجي
.وحساب المضافة؛ أعطال في االتصاالت
• It helps team members gain a shared understanding of the process and use this knowledge to collect
data, identify problems, focus discussions, and identify resources. ƒ
والتركيز، وتحديد المشاكل،كما أنه يساعد أعضاء الفريق الحصول على فهم مشترك لهذه العملية واستخدام هذه المعرفة لجمع البيانات
. وتحديد الموارد،المناقشات
. تحتاج إلى أن يكون لبرامج التاليين على جهاز الكمبيوتر الخاص بك،C ++إذا كنت ال تزال على استعداد القامة بيئتك ل
1. Text Editor: محرر النص:
This will be used to type your program.
2. Turbo c++:
++توربو ج
The files you create with your editor are called source files and for C++ they typically are named with the
extension .cpp.
. التمديد.CPP أنها عادة ما تتم تسمية معC ++ ويطلق على الملفات التي تقوم بإنشائها مع محرر الملفات المصدر ول
When we consider a C++ program, it can be defined as a collection of objects that communicate via invoking
each other's methods. Let us now briefly look into what a class, object, methods, and instant variables mean.
دعونا اآلن. فإنه يمكن تعريفها بأنها مجموعة من الكائنات التي تتصل عن طريق استدعاء أساليب بعضهم البعض، C ++عندما ننظر برنامج
. والمتغيرات الفورية، يعني الطرق، وجوه،ننظر لفترة وجيزة في ما فئة
Object - Objects have states and behaviors. Example: A dog has states - color, name, breed as well as
behaviors - wagging, barking, and eating. An object is an instance of a class.
كائن مثيل من. وتناول الطعام، نباح، يهز- اللون واالسم وتولد وكذلك السلوكيات- كلب الدول: مثال. كائنات لها الدول والسلوكيات- •وجوه
.فئة
Class - A class can be defined as a template/blueprint that describes the behaviors/states that object of its
type support.
. تنص على أن الهدف من دعم نوعه/ مخططا أن يصف السلوكيات/ فئة يمكن تعريفها بأنها قالب- •الفئة
Methods - A method is basically a behavior. A class can contain many methods. It is in methods where
the logics are written, data is manipulated and all the actions are executed.
يتم التالعب بها البيانات، هو في طرق حيث تتم كتابة المنطق. يمكن أن تحتوي فئة العديد من األساليب. طريقة هو في األساس السلوك- •طرق
.ويتم تنفيذ جميع اإلجراءات
Instant Variables - Each object has its unique set of instant variables. An object's state is created by the
values assigned to these instant variables.
يتم إنشاء دولة كائن من حيث القيم المعينة لهذه. كل كائن له مجموعة فريدة من نوعها من المتغيرات حظة- •المتغيرات فوري
.المتغيرات الفورية
#include<iostream.h>
int main()
cout<<“Hello World”;
return 0;
All lines begin with two slash signs(//) are comments and they do not have any effects on the program.
.) هي تعليقات وليس لديهم أي تأثير على البرنامج//( جميع خطوط تبدأ مع اثنين من عالمات مائل
#include<iostream.h>
Pre-processor directive: Lines begin with hash sign (#) are called preprocessor directive.
. التوجيه قبل المعالج:) توجيه المعالج#( وتسمى خطوط تبدأ مع عالمة التجزئة
int main()
This is the point where all C++ programs start their execution.
This line is a C++ statement. It is the statement that produce some effect in the program.
. هو بيان أن تنتج بعض التأثير في البرنامج.البيانC ++ وهذا الخط هو
The statement always ends with a semi colon (;).
.)بيان ينتهي دائما مع فاصلة منقوطة (؛
This character is used to mark the end of the statement.
.ويستخدم هذا الحرف بمناسبة نهاية البيان
return 0;
The return statement causes the main function to finish.
.يتسبب في بيان عودة وتتمثل المهمة الرئيسية إلنهاء
cout<<“Hello World”;
This line is a C++ statement. It is the statement that produce some effect in the program.
cout<<”variable names”;
cin>> a >>b ;
3. Open a command prompt and go to the directory where you saved the file.
4. You will be able to see ' Hello World ' printed on the window.
x = y;
y = y+1;
add(x, y);
A block is a set of logically connected statements that are surrounded by opening and closing braces.
.كتلة عبارة عن مجموعة من البيانات منطقيا المتصلة التي تحيط بها؟ االفتتاح والختام األقواس
For example:
{
cout << "Hello World"; // prints Hello World
return 0;
}
C++ does not recognize the end of the line as a terminator. For this reason, it does not matter where you put a
statement in a line.
. أليس كذلك؟ ال يهم أين كنت وضعت بيانا في خط، لهذا السبب.نهاية السطر كما فاصلC ++ تعترف
For example:
x = y;
y = y+1;
add(x, y);
is the same as
؟.مترجم يتجاهل تماماC ++ و، كما هو معروف فارغ؟ الخط، مع تعليق،؟ والسطر الذي يحتوي فقط على مساحات
• Whitespace is the term used in C++ to describe blanks, tabs, newline characters
and comments.
• Whitespace separates one part of a statement from another and enables the compiler to identify where
one element in a statement, such as int, ends and the next element begins.
؟ ينتهي ويبدأ العنصر، مثل كثافة العمليات،بيضاء يفصل جزء واحد من بيان من آخر وتمكن المترجم لتحديد أين عنصر واحد في بيان لها
.التالي
Statement 1:
int age;
In the above statement there must be at least one whitespace character (usually a space) between int and age for
the compiler to be able to distinguish them.
في البيان المذكور أعاله أن يكون هناك واحد على األقل حرف مسافة بيضاء (عادة مسافة) بين الباحث والعمر للمترجم أن يكون قادرا على
.التمييز بينها
Statement 2:
fruit = apples + oranges; // Get the total fruit
In the above statement 2, no whitespace characters are necessary between fruit and =, or between = and apples,
although you are free to include some if you wish for readability purpose.
على الرغم من أنت حر لتشمل بعض إذا كنت، أو بين = والتفاح،= لم أحرف المسافات البيضاء الضرورية بين الفواكه و، أعاله2 في البيان
.ترغب لغرض القراءة
C ++ أنواع البيانات
• While doing programming in any programming language, you need to use various variables to store
various information.
. تحتاج إلى استخدام متغيرات مختلفة لتخزين المعلومات المختلفة،في حين تقوم البرمجة في أي لغة برمجة
• This means that when you create a variable you reserve some space in memory.
.وهذا يعني أنه عند إنشاء المتغير الذي حجز بعض المساحة في الذاكرة
• You may like to store information of various data types like character, wide character, integer, floating
point, double floating point, boolean etc.
منطقية الخ، نقطة عائمة مزدوجة، النقطة العائمة، صحيح، حرف واسع،قد ترغب في تخزين المعلومات من أنواع البيانات المختلفة مثل حرف
• Based on the data type of a variable, the operating system allocates memory and decides what can be
stored in the reserved memory.
. نظام التشغيل يخصص الذاكرة ويقرر ما يمكن تخزينها في ذاكرة محفوظة،استنادا إلى نوع البيانات متغير
Double: This data type is used to represent double precision floating point number.
. يستخدم هذا النوع من البيانات لتمثيل الدقة المزدوجة العائمة عدد النقطة:نقرا
Long double: This data type is used to represent double precision floating poin
طويل مزدوج:يستخدم هذا النوع من البيانات لتمثيل الدقة المزدوجة النقطة العائمةt
bool: This data type is used to represent Boolean value. Using variable names and data
باستخدام أسماء وبيانات متغيرة. يستخدم هذا النوع من البيانات لتمثيل قيمة منطقية:منطقي
يسرد الجدول التالي أسفل سبعة أنواع.تقديم مبرمج تشكيلة غنية من أنواع البيانات المعرفة من قبل المستخدم المدمج في وكذلكC ++
C ++: البيانات األساسية
Type Keyword
Boolean bool
Character char
Integer int
Valueless void
The following table shows the variable type, how much memory it takes to store the value in memory, and what
is maximum and minimum value which can be stored in such type of variables.
وما هي قيمة الحد األقصى والحد األدنى الذي يمكن تخزينها، مقدار الذاكرة ما يلزم لتخزين القيمة في الذاكرة،ويبين الجدول التالي نوع متغير
.في مثل هذا النوع من المتغيرات
The sizes of variables might be different from those shown in the table, depending on the compiler and the
computer you are using.
. وهذا يتوقف على مترجم وجهاز الكمبيوتر الذي تستخدمه،أحجام متغيرات قد تكون مختلفة عن تلك التي تظهر في الجدول
. والتي سوف تنتج حجم الصحيح من أنواع البيانات المختلفة على جهاز الكمبيوتر الخاص بك،فيما يلي سبيل المثال
#include <iostream.h>
int main()
cout << "Size of short int : " << sizeof(short int) << endl;
cout << "Size of long int : " << sizeof(long int) << endl;
return 0;
This example uses endl, which inserts a new-line character after every line and << operator is being used to pass
multiple values out to the screen. We are also using sizeof() operator to get size of various data types.
ونحن أيضا. التي إدراج حرف سطر جديد بعد كل سطر و<< يستخدم المشغل لتمرير قيم متعددة إلى الشاشة،ENDL يستخدم هذا المثال
.المشغل () للحصول على حجم أنواع البيانات المختلفةsizeof استخدام
A variable provides us with named storage that our programs can use.
Each variable in C++ has a specific type, which determines the size and layout of the variable's memory.
كل متغير فيC ++ . والذي يحدد حجم وشكل من الذاكرة للمتغير،لديه نوع معين
The name of a variable can be composed of letters, digits, and the underscore character. It must begin with
either a letter or an underscore.
. يجب أن يبدأ مع أي بريد إلكتروني أو تسطير. والسفلية،يمكن أن تتكون اسم متغير من الحروف واألرقام
There are following basic types of variable in C++ as explained in last chapter:
Type Description
A variable definition means to tell the compiler where and how much to create the storage for the variable.
.تعريف متغير يعني أن نقول للمترجم حيث وكم إلنشاء لتخزين المتغير
A variable definition specifies a data type, and contains a list of one or more variables of that type as follows:
ويحتوي على قائمة واحدة أو أكثر من،ويحدد تعريف متغير نوع البيانات
type variable_list;
Here, type must be a valid C++ data type including char, w_char, int, float, double, bool or any user-defined
object, etc., and variable_list may consist of one or more identifier names separated by commas.
منطقي أو أي كائن المعرفة من قبل، مزدوجة، تطفو، كثافة،w_char ،نوع البيانات بما في ذلك شارC ++ يجب أن يكون نوع صالحة،هنا
من واحد أو أكثر من أسماء معرف مفصولة بفواصلvariable_list ويمكن أن تتكون، الخ،المستخدم
: حيث يمكن أن يتم تعريف المتغيرات،ونطاق غير منطقة من البرنامج وبشكل عام هناك ثالثة أماكن
:المتغيرات المحلية
Variables that are declared inside a function or block are local variables.
They can be used only by statements that are inside that function or block of code.
.ويمكن استخدامه فقط من قبل البيانات الموجودة داخل تلك الوظيفة أو كتلة من التعليمات البرمجية
#include <iostream.h>
int main ()
int a, b;
int c;
a = 10;
b = 20;
c = a + b;
cout << c;
return 0;
Output:
30
:المتغيرات العالمية
Global variables are defined outside of all the functions, usually on top of the program.
. وعادة على الجزء العلوي من البرنامج،يتم تعريف المتغيرات العالمية خارج عن وظائف
The global variables will hold their value throughout the life-time of your program.
.سوف المتغيرات العالمية تعقد قيمتها في جميع أنحاء الحياة مرة من البرنامج
That is, a global variable is available for use throughout your entire program after its declaration.
. متغير عمومي متوفرة لالستخدام في جميع أنحاء البرنامج بأكمله بعد إعالنها،وهذا يعني
#include <iostream.h>
int g;
int main ()
int a, b;
a = 10;
b = 20;
g = a + b;
cout << g;
return 0;
Output:
30
غنية المدمج في المشغلين وتوفير األنواع التالية من. C ++ المشغل هو الرمز الذي يقول المترجم لتأدية معالجات رياضية أو منطقية محددة
:مشغلي
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Misc Operators
•العوامل الحسابية
•مشغلي العالئقية
•العوامل المنطقية
•مشغلي المختصة بالبت
•عوامل التعيين
•مشغلي متفرقات
This chapter will examine the arithmetic, relational, logical, bitwise, assignment and other operators one by one.
. وتعيين والمشغلين اآلخرين واحدا تلو اآلخر، أحادي المعامل، والعالئقية ومنطقية،وهذا الفصل دراسة الحساب
Arithmetic Operators:
•العوامل الحسابية
It provides operators for five basic arithmetical calculations: addition, subtraction, multiplication, division, and
taking the modulus.
. وأخذ معامل، الجمع والطرح والضرب والقسمة:ويوفر المشغلين لمدة خمس الحسابات الحسابية األساسية
Assume variable A holds 10 and variable B holds 20, then:
#include <iostream.h>
main()
{
int a = 21;
int b = 10;
int c ;
c = a + b;
cout << "Line 1 - Value of c is :" << c << endl ;
c = a - b;
cout << "Line 2 - Value of c is :" << c << endl ;
c = a * b;
cout << "Line 3 - Value of c is :" << c << endl ;
c = a / b;
cout << "Line 4 - Value of c is :" << c << endl ;
c = a % b;
cout << "Line 5 - Value of c is :" << c << endl ;
c = a++;
cout << "Line 6 - Value of c is :" << c << endl ;
c = a--;
cout << "Line 7 - Value of c is :" << c << endl ;
return 0;
Output:
When the above code is compiled and executed, it produces the following result:
Line 1 - Value of c is :31
Line 2 - Value of c is :11
Line 3 - Value of c is :210
Line 4 - Value of c is :2
Line 5 - Value of c is :1
Line 6 - Value of c is :21
Line 7 - Value of c is :22
In computer science, a relational operator is a programming language construct oroperator that tests or defines
some kind of relation between two entities.
. مشغل العالئقية هو بناء لغة البرمجة أو المشغل الذي يختبر أو تحدد نوعا من العالقة بين كيانين،في علوم الكمبيوتر
العوامل المنطقية
Bitwise Operators
أحادي المعامل مشغلي
Bitwise operator works on bits and perform bit-by-bit operation. The truth tables for &, |, and ^ are as follows:
: و^ هي كما يلي،| ، جداول الحقيقة لو.مشغل أحادي المعامل يعمل على اجزاء وإجراء العملية بعض الشيء من قبل بت
Assume if A = 60; and B = 13; now in binary format they will be as follows:
A = 0011 1100
B = 0000 1101
-----------------
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
Assignment Operators:
:مشغلي المهمة
Misc Operators:
مشغلي متفرقات:
The following table lists some other operators that C++ supports.
Operator Description
sizeof sizeof operator returns the size of a variable. For
example, sizeof(a), where ‘a’ is integer, and will
return 4.
Condition ? X : Y Conditional operator (?). If Condition is true then it
returns value of X otherwise returns value of Y.
, Comma operator causes a sequence of operations to
be performed. The value of the entire comma
expression is the value of the last expression of the
comma-separated list.
. (dot) and -> (arrow) Member operators are used to reference individual
members of classes, structures, and unions.
Cast Casting operators convert one data type to another.
For example, int(2.2000) would return 2.
& Pointer operator ‘&’ returns the address of a
variable. For example &a; will give actual address of
the variable.
* Pointer operator * is pointer to a variable. For
example *var; will pointer to a variable var.
C ++. ملف الرأس الذي هو جزء من المكتبة القياسية في، iostream اإلخراج في المقام األول من قبلC ++ / يتم تعريف إدخال تيارات
Like the cstdio header inherited from C's stdio.h, iostream provides basic input and output services for C++
programs.
C ++.توفر المدخالت والمخرجات الخدمات األساسية للبرامجiostream و، stdio.h C الموروثة منcstdio مثل رأس
iostream uses the objects cin, cout, cerr, and clog for sending data to and from the standard streams input,
output, error (unbuffered), and log (buffered) respectively.
وتسد إلرسال البيانات من وإلى تيارات القياسية المدخالت والمخرجات والخطأ (غير،cerr ،cout ، CIN الكائناتiostream يستخدم
. وسجل (مخزنة) على التوالي،)مصقول
As part of the C++ standard library, these objects are a part of the std namespace.
. هذه الكائنات هي جزء من مساحة األمراض المنقولة جنسيا، C ++كجزء من المكتبة القياسية في
Header files
رأس الملفات
The classes of the input/output library reside in several headers.
<ios> contains the definitions of ios_base and basic_ios classes, that manage formatting information and the
associated stream buffer.
. التي تدير معلومات التنسيق والمخزن المؤقت تيار المرتبطة بها،basic_ios وios_base يحتوي على تعريفات الطبقات
<istream> contains the definition of basic_istream class template, which implements formatted input.
<ostream> contains the definition of basic_ostream class template, which implements formatted output.
<iostream> contains the definition of basic_iostream class template, which implements formatted input and
output.
<fstream> contains the definitions of basic_ifstream, basic_ofstream and basic_fstream class templates which
implement formatted input, output and input/output on file streams.
/ التي تنفذ تنسيق إدخال واإلخراج واإلدخالbasic_fstream والطبقةbasic_ofstream ، basic_ifstreamيحتوي على تعريفات قوالب
.اإلخراج على تدفقات الملف
The first statement in a function is executed first, followed by the second, and so on.
. وهلم جرا، تليها في المرتبة الثانية،يتم تنفيذ العبارة األولى في وظيفة أوال
Programming languages provide various control structures that allow for more complicated execution paths.
.توفر لغات البرمجة هياكل المراقبة المختلفة التي تسمح لمسارات تنفيذ أكثر تعقيدا
A loop statement allows us to execute a statement or group of statements multiple times and following is the
general from of a loop statement in most of the programming languages:
:وجاء في بيان حلقة يسمح لنا لتنفيذ بيان أو مجموعة من البيانات عدة مرات وفيما يلي العامة من بيان حلقة في معظم لغات البرمجة
C++ programming language provides the following type of loops to handle looping requirements.
. لغة برمجة النوع التالي من الحلقات على التعامل مع متطلبات حلقات++ C يوفر
Syntax
while(condition)
{
statement(s);
}
The condition may be any expression, and true is any non-zero value.
والصحيح هو أي قيمة غير الصفر،قد تكون حالة أي تعبير
When the condition becomes false, program control passes to the line immediately following the loop.
. يمر برنامج مراقبة خط فورا بعد الحلقة،عندما تصبح حالة كاذبة
Flowchart
#include <iostream.h>
int main ()
{
// Local variable declaration:
int a = 10;
// while loop execution
while( a < 20 )
{
cout << "value of a: " << a << endl;
a++;
}
return 0;
}
Output:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
.وللحلقة هو بنية تحكم التكرار الذي يسمح لك لكفاءة إرسال حلقة التي تحتاج إلى تنفيذ عدد معين من المرات
Syntax
Example:
#include <iostream.h>
int main ()
{
// for loop execution
for( int a = 10; a < 20; a = a + 1 )
{
cout << "value of a: " << a << endl;
}
return 0;
}
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one
time.
. في حين حلقة لتنفيذ مرة واحدة على األقل... إال أن مضمونة القيام به، في حين حلقة مشابهة لحلقة في حين... وبه
Syntax
The syntax of a do...while loop in C++ is:
do
{
statement(s);
}
while( condition );
Flowchart:
#include <iostream.h>
int main ()
{
// Local variable declaration:
int a = 10;
// do loop execution
do
{
cout << "value of a: " << a << endl;
a = a + 1;
}while( a < 20 );
return 0;
}
Output:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
The following program uses a nested for loop to find the prime numbers from 2 to 10:
#include <iostream.h>
int main ()
{
int i, j;
for(i=2; i<10; i++)
{
for(j=2; j <= (i/j); j++)
if(!(i%j)) break; // if factor found, not prime
if(j > (i/j)) cout << i << " is prime\n";
}
return 0;
Output:
2 is prime
3 is prime
5 is prime
7 is prime
When the break statement is encountered inside a loop, the loop is immediately terminated and program
control resumes at the next statement following the loop.
يتم إنهاء فورا حلقة وبرنامج مراقبة يستأنف في البيان التالي لحلقة، داخل حلقةbreak عند مواجهة اإلفادة
It can be used to terminate a case in the switch statement (covered in the next chapter).
(ويمكن استخدامه إلنهاء حالة في بيان التبديل (المشمولة في الفصل التالي
If you are using nested loops (i.e., one loop inside another loop), the break statement will stop the execution of
the innermost loop and start executing the next line of code after the block.
.
وبيان كسر سيوقف تنفيذ حلقة أعمق وبدء تنفيذ السطر التالي من،)إذا كنت تستخدم الحلقات المتداخلة (أي حلقة واحدة داخل حلقة أخرى
.التعليمات البرمجية بعد كتلة
Syntax
The syntax of a break statement in C++ is:
break;
Flowchart:
#include <iostream.h>
int main ()
{
// Local variable declaration:
int a = 10;
// do loop execution
do
{
cout << "value of a: " << a << endl;
a = a + 1;
if( a > 15)
{
// terminate the loop
break;
}
}while( a < 20 );
return 0;
Output:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
continue Statement:
مواصلة اإلعالن:
The continue statement works somewhat like the break statement. Instead of forcing termination, however,
continue forces the next iteration of the loop to take place, skipping any code in between.
، ال تزال قوات التكرار التالي من الحلقة ليأخذ مكان، ومع ذلك، بدال من إجبار اإلنهاء.ويواصل اإلدالء يعمل الى حد ما مثل بيان الشوط االول
.وتخطي أي رمز بينهما
For the for loop, continue causes the conditional test and increment portions of the loop to execute. For the
while and do...while loops, program control passes to the conditional tests.
برنامج، في حين تمرير التحكم الحلقات... وتفعل، لبعض الوقت. ومواصلة أسباب االختبار وزيادة أجزاء المشروط من الحلقة لتنفيذ،لللحلقة
.لالختبارات المشروطة
Syntax
The syntax of a continue statement in C++ is:
continue;
Example
#include <iostream.h>
int main ()
{
// Local variable declaration:
int a = 10;
// do loop execution
do
{
if( a == 15)
{
// skip the iteration.
a = a + 1;
continue;
}
cout << "value of a: " << a << endl;
a = a + 1;
while( a < 20 );
return 0;
}
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 16
value of a: 17
value of a: 18
value of a: 19
goto Statement:
:غوتو بيان
A goto statement provides an unconditional jump from the goto to a labeled statement in the same function.
.وينص بيان غوتو قفزة غير المشروط من غوتو بيان وصفت في نفس الوظيفة
Syntax
The syntax of a goto statement in C++ is:
goto label;
..
.
label: statement;
Where label is an identifier that identifies a labeled statement. A labeled statement is any statement that is
preceded by an identifier followed by a colon (:).
Flowchart:
#include <iostream.h>
int main ()
{
// Local variable declaration:
int a = 10;
// do loop execution
LOOP:do
{
if( a == 15)
{
// skip the iteration.
a = a + 1;
goto LOOP;
}
cout << "value of a: " << a << endl;
a = a + 1;
}while( a < 20 );
return 0;
Output:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 16
value of a: 17
value of a: 18
value of a: 19
Decision-making statements:
:البيانات صنع القرار
Decision making structures require that the programmer specify one or more conditions to be evaluated or
tested by the program, along with a statement or statements to be executed if the condition is determined to be
true, and optionally, other statements to be executed if the condition is determined to be false.
جنبا إلى جنب مع بيان أو،تتطلب هياكل صنع القرار أن مبرمج تحديد واحد أو أكثر من الشروط التي سيتم تقييمها أو اختبارها من قبل البرنامج
تصريحات أخرى ليتم تنفيذها إذا كان الشرط عازمة على أن تكون، واختياريا،البيانات ليتم تنفيذها إذا تم تحديد شرط أن يكون ذلك صحيحا
.كاذبة
:تبعه عام من هيكل صنع القرار نموذجية وجدت في معظم لغات البرمجة
Statement Description
if statement An ‘if’ statement consists of a boolean expression
followed by one or more statements.
if...else statement An ‘if’ statement can be followed by an optional
‘else’ statement, which executes when the boolean
expression is false.
switch statement A ‘switch’ statement allows a variable to be tested
for equality against a list of values.
nested if statements You can use one ‘if’ or ‘else if’ statement inside
another ‘if’ or ‘else if’ statement(s).
nested switch statements You can use one ‘switch’ statement inside another
‘switch’ statement(s).
Syntax
if(boolean_expression)
{
// statement(s) will execute if the boolean expression is true
}
If the boolean expression evaluates to true, then the block of code inside the if statement will be executed.
. ثم كتلة من التعليمات البرمجية داخل إذا البيان انه سيتم تنفيذها، trueإذا تقييم التعبير المنطقي إلى
If boolean expression evaluates to false, then the first set of code after the end of the if statement (after the
closing curly brace) will be executed.
. ثم أول مجموعة من التعليمات البرمجية بعد نهاية إذا بيان (بعد متعرج إغالق) سيتم تنفيذها،إذا تقييم التعبير المنطقي لكاذبة
Flowchart:
#include <iostream.h>
int main ()
{
// local variable declaration:
int a = 10;
// check the boolean condition
if( a < 20 )
{
// if condition is true then print the following
cout << "a is less than 20;" << endl;
}
cout << "value of a is : " << a << endl;
return 0;
}
Output:
if…else Statement:
: بيان آخر... إذا
An if statement can be followed by an optional else statement, which executes when the boolean expression is
false.
. والتي يتم تنفيذها عند التعبير منطقية غير صحيح،يمكن اتباعها لبيان إذا كان عن طريق بيان آخر اختياري
Syntax
The syntax of an if...else statement in C++ is:
if(boolean_expression)
{
// statement(s) will execute if the boolean expression is true
}
else
{
// statement(s) will execute if the boolean expression is false
}
If the boolean expression evaluates to true, then the if block of code will be executed, otherwise else block of
code will be executed.
. وسيتم تنفيذ كتلة خالف آخر من التعليمات البرمجية، ثم إذا كان سيتم تنفيذها كتلة من التعليمات البرمجية، trueإذا تقييم التعبير المنطقي إلى
Example:
#include <iostream.h>
int main ()
{
// local variable declaration:
int a = 100;
// check the boolean condition
if( a < 20 )
{
// if condition is true then print the following
cout << "a is less than 20;" << endl;
}
else
{
// if condition is false then print the following
cout << "a is not less than 20;" << endl;
}
cout << "value of a is : " << a << endl;
return 0;
}
Output:
a is not less than 20;
value of a is : 100
Syntax
The syntax for a switch statement in C++ is as follows:
switch(expression){
case constant-expression :
statement(s);
break; //optional
case constant-expression :
statement(s);
break; //optional
// you can have any number of case statements.
default : //Optional
statement(s);
}
Flowchart:
Nested if Statement:
:متداخلة إذا البيان
It is always legal to nest if-else statements, which means you can use one if or else if statement inside another if
or else if statement(s).
( مما يعني أنه يمكنك استخدام واحدة إذا وإال إذا بيان داخل آخر إذا وإال إذا بيان (ق،هو دائما القانوني إلى عش إذا بين آخر البيانات
Syntax
The syntax for a nested if statement is as follows:
if( boolean_expression 1)
{
// Executes when the boolean expression 1 is true
if(boolean_expression 2)
{
// Executes when the boolean expression 2 is true
}
}
}
cout << "Exact value of a is : " << a << endl;
cout << "Exact value of b is : " << b << endl;
return 0;
}
Output:
Arrays
صالحة
C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same
type.
. والذي يقوم بتخزين ذات حجم ثابت جمع متتابعة من العناصر من نفس النوع، ومجموعة، بنية بياناتC ++ يوفر
An array is used to store a collection of data, but it is often more useful to think of an array as a collection of
variables of the same type.
ولكن غالبا ما يكون أكثر فائدة للتفكير في مجموعة كمجموعة من المتغيرات من نفس،يتم استخدام مجموعة لتخزين مجموعة من البيانات
.النوع
تقوم بتعريف متغير مجموعة واحدة مثل أرقام وأرقام،number99 و،... و،number1 ، number0 مثل،بدال من تصريح المتغيرات الفردية
.] لتمثيل المتغيرات الفردية99[ وأرقام،... و،]1[ أرقام،]0[ استخدام
Declaring Arrays:
: إعالن صالحة
To declare an array in C++, the programmer specifies the type of the elements and the number of elements
required by an array as follows:
: يحدد مبرمج نوع من العناصر وعدد من العناصر المطلوبة من قبل مجموعة على النحو التالي، C ++لإلعالن صفيف في
The array Size must be an integer constant greater than zero and type can be any valid C++ data type.
. نوع بيانات صالحةC ++ يجب أن يكون مجموعة الحجم عدد صحيح ثابت أكبر من الصفر ونوع يمكن أن يكون أي
For example, to declare a 10-element array called balance of type double, use this statement:
: استخدم هذا البيان، عنصرا يسمى توازن من نوع مزدوج10 إلعالن مجموعة،على سبيل المثال
double balance[10];
Initializing Arrays:
: تهيئة صالحة
You can initialize C++ array elements either one by one or using a single statement as follows:
: إما واحدا تلو اآلخر أو باستخدام عبارة واحدة على النحو التاليC ++ يمكنك تهيئة عناصر مجموعة
The number of values between braces { } cannot be larger than the number of elements that we declare for the
array between square brackets [ ].
[].عدد القيم بين األقواس {} ال يمكن أن يكون أكبر من عدد من العناصر التي نعلن للمجموعة بين األقواس المربعة
You will create exactly the same array as you did in the previous example.
.سوف تقوم بإنشاء بالضبط نفس مجموعة كما فعلت في المثال السابق
balance[4] = 50.0;
Arrays in C++:
C ++: المصفوفات في
Arrays are important to C++ and should need lots of more detail. There are following few important concepts,
which should be clear to a C++ programmer:
هناك التالية بعض المفاهيم المهمة التي يجب أن تكون واضحة. وينبغي بحاجة الى الكثير من المزيد من التفاصيل،C ++صفائف مهمة ل
C ++:لمبرمج
Concept Description
Multi-dimensional Arrays:
:المصفوفات متعددة األبعاد
C++ allows multidimensional arrays. Here is the general form of a multidimensional array declaration:
: هنا هو الشكل العام إلعالن مجموعة متعددة األبعاد.يسمح المصفوفات متعددة األبعادC ++
type name[size1][size2]...[sizeN];
For example, the following declaration creates a three dimensional 5 . 10 . 4 integer array:
: صحيح مجموعة4 .10 . الثالث5 التصريح التالي الذي يخلق األبعاد،على سبيل المثال
int threedim[5][10][4];
To declare a two-dimensional integer array of size x,y, you would write something as follows:
: وكنت أكتب شيئا على النحو التالي، ص،إلعالن مجموعة عددية ثنائية األبعاد من حجم س
type arrayName [ x ][ y ];
Where type can be any valid C++ data type and arrayName will be a valid C++ identifier.
. معرفC ++ نوع البيانات ومجموعة اسم سيكون ساري المفعولC ++ حيث نوع يمكن أن يكون أي صحيح
A two-dimensional array can be think as a table, which will have x number of rows and y number of columns.
. والتي سيكون لها × عدد الصفوف وعدد ذ األعمدة،وهناك مجموعة ثنائية األبعاد يمكن أن يفكر كجدول
A 2-dimensional array a, which contains three rows and four columns can be shown as below:
: والتي تحتوي على ثالثة صفوف وأربعة أعمدة على النحو التالي،األبعاد لذلك-2 يمكن أن تظهر هناك مجموعة
Thus, every element in array a is identified by an element name of the form a[ i ][ j ], where a is the name of the
array, and i and j are the subscripts that uniquely identify each element in a.
هي السفلية التي تنفردj وi و، حيث هو اسم مجموعة،] يتم تحديد كل عنصر في مجموعة ومن اسم عنصر النموذج على [أنا] [ي،وبالتالي
.بتحديد كل عنصر في
Every C++ program has at least one function, which is main(), and all the most trivial programs can define
additional functions.
ولكن منطقيا تقسيم عادة هو من هذا، كيفية تقسيم الشفرة بين وظائف مختلفة متروك لكم.يمكنك تقسيم التعليمات البرمجية إلى وظائف منفصلة
القبيل أن كل وظيفة بأداء مهمة معينة
You can divide up your code into separate functions. How you divide up your code among different functions is
up to you, but logically the division usually is such that each function performs a specific task.
. ويمكن لجميع برامج أتفه تحديد الوظائف اإلضافية،)( وهو الرئيسية، لديه وظيفة واحدة على األقلC ++ كل برنامج
Defining a Function:
: تحديد وظيفة
A C++ function definition consists of a function header and a function body. Here are all the parts of a function:
: هنا جميع أجزاء من وظيفة. من ضربة رأس وظيفة وظيفة الجسمC تعريف الدالة++ يتكون
Return Type: A function may return a value. The return_type is the data type of the value the function
returns. Some functions perform the desired operations without returning a value. In this case, the
return_type is the keyword void.
بعض أداء مهام العمليات المطلوبة دون.هو نوع البيانات من قيمة ترجع الدالةreturn_type و. وظيفة قد ترجع قيمة:عودة النوع
.هو الفراغ الكلمةreturn_type ، في هذه الحالة.إرجاع قيمة
Function Name: This is the actual name of the function. The function name and the parameter list
together constitute the function signature.
. اسم الدالة وقائمة المعلمة تشكل معا التوقيع وظيفة. هذا هو االسم الفعلي الدالة:وظيفة اسم
ويشار إلى هذه القيمة إلى المعلمة كما الفعلية. يمكنك تمرير قيمة إلى المعلمة، عندما يتم استدعاء وظيفة. معلمة يشبه نائبا:المعلمات
قد تحتوي على وظيفة، وهذا هو. معلمات اختيارية. وعدد من المعلمات وظيفة، والنظام، تشير قائمة المعلمة إلى نوع.أو وسيطة
.بدون معلمات
Function Body: The function body contains a collection of statements that define what the function
does.
. وظيفة الجسم يحتوي على مجموعة من البيانات التي تحدد ما تفعله وظيفة: وظيفة الجسم
• File Processing:
:• معالجة الملف
Basic input/output
The C++ standard libraries provide an extensive set of input/output capabilities which we will see in subsequent
chapters.
. اإلخراج التي سنرى في الفصول الالحقة/ مجموعة واسعة من القدرات اإلدخالC ++ توفر المكتبات القياسية
This chapter will discuss very basic and most common I/O operations required for C++ programming.
C ++. الالزمة لبرمجةI / وهذا الفصل يناقش يا العمليات األساسية جدا واألكثر شيوعا
C++ I/O occurs in streams, which are sequences of bytes. If bytes flow from a device likes a keyboard, a
disk drive, or a network connection etc. to main memory, this is called input operation and if bytes flow from
main memory to a device likes a display screen, a printer, a disk drive, or a network connection, etc., this is
called output operation.
أو اتصال الشبكة، محرك األقراص، إذا تدفق بايت من جهاز يحب لوحة المفاتيح. التي هي تسلسل بايت،يحدث في مجاري المياهC ++ I / O
محرك أقراص، طابعة، وهذا ما يسمى عملية اإلدخال وإذا تدفق بايت من الذاكرة الرئيسية للجهاز يحب شاشة العرض،وما إلى الذاكرة الرئيسية
. وهذا ما يسمى عملية االنتاج، وما إلى ذلك،أو اتصال الشبكة
The cout object is said to be "connected to" the standard output device, which usually is the display screen.
. والتي عادة هو شاشة العرض، إلى أن "متصلة" جهاز اإلخراج القياسيةcout ويقال الكائن
The cout is used in conjunction with the stream insertion operator, which is written as << which are two less
than signs as shown in the following example.
. التي كما هو مكتوب << وهما أقل من عالمات كما هو موضح في المثال التالي، بالتعاون مع المشغل تيار اإلدراجcout يتم استخدام
The cin object is said to be attached to the standard input device, which usually is the keyboard.
. والتي عادة ما يكون لوحة المفاتيح، لضمها الى جهاز اإلدخال القياسيةCIN ويقال الكائن
The cin is used in conjunction with the stream extraction operator, which is written as >> which are two greater
than signs as shown in the following example.
. والتي كما هو مكتوب >> وهما أكبر من عالمات كما هو موضح في المثال التالي، بالتعاون مع المشغل استخراج تيارCIN يتم استخدام
#include <iostream.h>
int main( )
{
char name[50];
cout << "Please enter your name: ";
cin >> name;
cout << "Your name is: " << name << endl;
}
Output:
Please enter your name: afreen
Your name is: afreen
فإن هيكل يجمع البيانات ذات الصلة منطقيا من، وهكذا.)هيكل عبارة عن مجموعة من العناصر من أي نوع (باستثناء نوع الفراغ •
.أنواع مختلفة
• struct structure_name
{
elements_description
};
• It should be noted that in MQL4 structure elements follow one another directly, without alignment.
. دون المحاذاة، عناصر هيكل الواحدة تلو األخرى مباشرةMQL4 وتجدر اإلشارة إلى أنه في •
• In C++ such an order is made to the compiler using the following instruction:
يتم مثل هذا األمر إلى مترجم باستخدام التعليمات التاليةC ++ في •
• If you want to do another alignment in the structure, use auxiliary members, "fillers" to the right size.
"الحشو" إلى الحجم الصحيح، واستخدام أعضاء المساعدة،إذا كنت تريد أن تفعل محاذاة أخرى في الهيكل •
Classes فصول
• Classes differ from structures in the following:
• By default, all class members have access specified private, unless otherwise indicated.
• Data-members of the structure have the default type of access as public, unless otherwise indicated;
. ما لم يذكر خالف ذلك،بيانات أعضاء بنية يكون النوع االفتراضي من وصول وعلنية •
• Class OBJECTS always have a table of virtual functions, even if there are no virtual functions declared
in the class. Structures can't have virtual functions;
هياكل ال يمكن أن يكون لها وظائف. حتى إذا لم تكن هناك وظائف افتراضية أعلن في الصف،كائنات فئة دائما جدول وظائف افتراضية •
افتراضية