شاهد المحاضرة في فيديو مدته ٦ دقائق مع أمثلة تشتغلها بنفسك واختبار قصير، أو افتح «المحاضرة المكتوبة»: كل شريحة في صفحة بنفس نص المحاضرة الأصلية وترتيبها، وتنقّل بالأسهم أو بالسحب.
شرح صوتي مبسّط باللهجة المصرية مع المصطلحات التقنية بالإنجليزية، ومشاهد متحركة تلخص كل أفكار المحاضرة بالترتيب.
المدة: ٦ دقائق و٥ ثوانٍ. المحاضرة بنفس ترتيب الشرائح الأصلية، وللنص الكامل حرفيًا افتح تبويب «المحاضرة المكتوبة».
أمثلة الفيديو
أمثلة الكود — عدّل وشغّل بنفسك
نفس أمثلة الفيديو جاهزة للتجربة هنا. عدّل أي مثال واضغط «شغّل الكود» ليُترجم ويعمل مباشرة عبر خدمة Wandbox المجانية (مترجم GCC 13). يُرسل الكود إلى تلك الخدمة عند التشغيل.
المثال ١: الطباعة بـ cout
The output appears here after you run the code.
Runs on the free Wandbox service (wandbox.org), GCC 13.2.0. No account needed.
المثال ٢: الإدخال بـ cin
جرّب تدخل رقمين في خانة الـ input (كل رقم في سطر) وشغّل البرنامج.
The output appears here after you run the code.
Runs on the free Wandbox service (wandbox.org), GCC 13.2.0. No account needed.
المثال ٣: مساحة المربع
برنامج المحاضرة الأخير: يقرا طول ضلع المربع ويحسب مساحته. جرّب طول ٥ ثم غيّره.
The output appears here after you run the code.
Runs on the free Wandbox service (wandbox.org), GCC 13.2.0. No account needed.
اختبار قصير
اختبر فهمك بعد المشاهدة
اختبر نفسك
1. Which type of error happens while the program is running, like dividing a number by zero?
2. Which of the following is a valid identifier?
3. What is the usual size of an int in C++?
4. In the statement totalWeight = totalWeight + 3; what does the = sign mean?
5. What does the expression 10 % 2 evaluate to?
الشريحة ٢
Outlineالأجندة
Type of program errors
Variables and assignments
Data type and expression
Input and output
constants
Arithmetic operation
Convert algebraic expression to c++
الملخص بالعربيةأجندة المحاضرة كما وردت: أنواع أخطاء البرنامج، المتغيرات والتعيين، أنواع البيانات والتعبيرات، الإدخال والإخراج، الثوابت، العمليات الحسابية، وتحويل التعبيرات الجبرية إلى C++.
الشريحة ٣
Types of Program Errorsأنواع أخطاء البرنامج
syntax errors: the compiler will only tell you if you wrote a syntactically (that is, grammatically) correct C++ program. However, the compiler may be incorrect about either the location or the nature of the error.
runtime errors for example, if the computer attempts to divide a number by zero, that is normally a run-time error.
Logic errors : is a Mistakes in the underlying algorithm or in translating the algorithm into the C++ language. For example, if you were to mistakenly use the addition sign instead of the multiplication sign
warning message which indicates that you have done something that is not, technically speaking, a violation of the programming language syntax rules, but that is unusual enough to indicate a likely mistake.
الملخص بالعربيةأربع رسائل ممكن تقابلها: خطأ في قواعد اللغة syntax يلتقطه المترجم، وخطأ أثناء التشغيل runtime مثل القسمة على صفر، وخطأ منطقي logic في الخوارزمية نفسها، ورسالة تحذير warning لشيء غير معتاد لكنه ليس مخالفًا للقواعد.
اختبر نفسك
Dividing a number by zero while the program runs is an example of which error type?
Using the addition sign instead of the multiplication sign by mistake is a:
الشريحة ٤
Variablesالمتغيرات
We can store values in the computer memory.
We call each storage location in the computer’s memory a variable.
C++ variables are names for memory locations
We can write a value in them
We can change the value stored there
to make your program easy to understand, you should always use meaningful names for variables
The name of a variable is called an identifier.
x=10
الملخص بالعربيةالمتغير هو اسم لمكان تخزين في ذاكرة الكمبيوتر: نكتب فيه قيمة ونقدر نغيرها. اختار أسماء معبرة، واسم المتغير يسمى identifier. الشكل الأصلي يوضح: x = 10 حيث x اسم المتغير، و= عامل التعيين، و10 القيمة المُعيّنة.
الشريحة ٥
Rules for Constructing identifierقواعد بناء المعرّف
An identifier must start with either - a letter - or underscore symbol
all the rest of the characters must be: - letters - or digits - or the underscore
C++ is a case-sensitive language, it distinguishes between uppercase and lowercase letters in the spelling of identifiers. The following are three distinct identifiers that could be used to name three distinct variables: Rate rate RATE
keywords or reserved words you cannot use as names for variables or anything else.
الملخص بالعربيةقواعد التسمية: يبدأ بحرف أو underscore، وباقي الأحرف حروف أو أرقام أو underscore فقط، واللغة case-sensitive فـ Rate وrate وRATE ثلاثة أسماء مختلفة، والكلمات المحجوزة keywords ممنوعة كأسماء.
اختبر نفسك
Why are Rate, rate, and RATE three distinct identifiers in C++?
الشريحة ٦
Naming Conventionsنظام التسمية
A naming convention is the set of rules that are used to name identifiers.
Try to use meaningful identifiers
Camelback or camelCase: naming conventions with Compound words or phrases are together with the first letter of the next word in uppercase.
numberOfBarstotalSalary
الملخص بالعربيةالـ naming convention هو مجموعة قواعد لتسمية المعرّفات؛ استخدم أسماء معبرة. وطريقة camelCase تلزق الكلمات المركبة مع جعل أول حرف من كل كلمة تالية كبيرًا مثل numberOfBars.
الشريحة ٧
Find which of the following is a valid identifierتمرين: أيّها معرّف صحيح؟
Decide for each of the following whether it is a valid identifier, then check yourself:
1. X
2. x_1
3. 12
4. 3x
5. _x
6. Sum_Rate
7. Data2
8. %change
9. Data-1
10. Count
11. Myfirst.c
الشريحة ٨
Find which of the following is a valid identifier - answersإجابة التمرين كما وردت
Valid identifiers - the lecture’s answers
identifier
valid?
X
✓
x_1
✓
12
x
3x
x
_x
✓
Sum_Rate
✓
Data2
✓
%change
x
Data-1
x
Count
✓
Myfirst.c
x
الملخص بالعربيةإجابات التمرين كما وردت في المحاضرة: الصحيحة هي X وx_1 و_x وSum_Rate وData2 وCount، والباقي غير صحيح.
الشريحة ٩
Variable Declarationsإعلان المتغيرات وأنواع البيانات
Declaration: variables must be declared ;you are telling the compiler what kind of data you will be storing in the variable
Common C++ data types
Data type
definition
Size
int
store a whole number without decimals
size is usually 4 bytes. Meaning, it can store values from -2147483648 to 2147483647.
Boolean
has one of two possible values: true or false.
has a size of 1 byte
char
used to store a single character
size is 1 byte
float
store floating-point numbers, sufficient for storing 7 decimal digits
The size of float is 4
double
store floating-point numbers, sufficient for storing 15 decimal digits
the size of double is 8 bytes.
string
store a sequence of characters (text)
Special class
short
Used for small integers
size is usually 2 bytes. Range: -32768 to 32767
الملخص بالعربيةالإعلان يخبر المترجم بنوع البيانات المخزنة. الجدول كما ورد: int عدد صحيح (٤ بايت)، Boolean قيمة true أو false (١ بايت)، char حرف واحد (١ بايت)، float عشري ٧ خانات (٤ بايت)، double عشري ١٥ خانة (٨ بايت)، string نص، وshort صحيح صغير (٢ بايت).
اختبر نفسك
Which data type stores floating-point numbers with up to 15 decimal digits?
How much space does a char take?
الشريحة ١٠
Variable Declarationsصيغة الإعلان وأمثلة
All variables must be declared before they are used.
double price;
double moonDistance;
int age, numStudents;
int carsWaiting;
char firstChar=‘s’;
String myName=“ahmed”;
الملخص بالعربيةكل المتغيرات لازم تتعلن قبل الاستخدام. الصيغة: نوع البيانات ثم اسم المتغير، مع إمكانية إعطاء قيمة أولية initialization. والأمثلة كما وردت تشمل إعلان أكثر من متغير من نفس النوع في سطر واحد.
الشريحة ١١
Give good variable names and data type for each of the following:تمرين: اختر اسمًا ونوعًا مناسبًا
totalWeight is set to the sum oneWeight + numberOfBars
الملخص بالعربيةجملة التعيين: متغير على الشمال وتعبير على اليمين. علامة = ليست مساواة رياضية بل تعيين: totalWeight = totalWeight + 3 تعني أن القيمة الجديدة هي القديمة زائد ٣.
اختبر نفسك
In C++, the statement totalWeight = totalWeight + 3; means:
الشريحة ١٣
Initializing Variablesتهيئة المتغيرات
Declaring a variable does not give it a value
Giving a variable its first value is initializing the variable
Variables are initialized in assignment statements
double mpg; // declare the variable
mpg = 26.3; // initialize the variable
الملخص بالعربيةالإعلان وحده لا يعطي قيمة؛ أول قيمة تعطيها للمتغير هي initialization، وتتم في جملة تعيين كما في المثال: إعلان double mpg ثم تهيئته بـ 26.3.
الشريحة ١٤
constantsالثوابت
The value that the program is not allowed to changei it To do this, place the word const in front of the declaration
Syntax:
Const Data Type VarNAme = value;
Example :
Const int MAX_TRIES=3;
Const double PI=3.14
الملخص بالعربيةالقيمة التي لا يُسمح للبرنامج بتغييرها نضع قبل إعلانها كلمة const. الصيغة: Const ثم نوع البيانات ثم الاسم = القيمة، مثل MAX_TRIES=3 وPI=3.14.
اختبر نفسك
How do you declare a constant in C++?
الشريحة ١٥
Output using coutالإخراج باستخدام cout
cout is an output stream sending data to the monitor
Example:
cout << numberOfBars << " candy bars
";
This line sends two items to the monitor
The ‘
’ causes a new line to be started following the ‘s’ in bar
The backslash, , preceding a character tells the compiler that the character following the preceding does not have the same meaning as the character appearing by itself.
Another way to output a blank line is to use cout<<endl;
Escape sequences (as shown in the lecture)
Escape sequence
Action
prints a new line
backs up one character
moves the output position to the next tab stop
\
prints a backslash
"
prints a double quote
'
prints a single quote
الملخص بالعربيةcout مجرى إخراج يرسل البيانات للشاشة، والمثال يرسل عنصرين: قيمة المتغير ثم النص. العلامة \n تبدأ سطرًا جديدًا، والـ backslash يغيّر معنى الحرف التالي، ويمكن استخدام endl بدلًا منها. الجدول يعرض الـ escape sequences كما في المحاضرة.
الشريحة ١٦
Example: Output using coutمثال على الإخراج
#include<iostream>
using namespace std;
int main(){
double price = 78.5;
cout << "The price is $ " << price << endl;
}
The price is $ 78.5
الملخص بالعربيةمثال المحاضرة في بيئة Code::Blocks: إعلان double price = 78.5 ثم طباعة نص مع قيمة المتغير وendl، والمخرَج: The price is $ 78.5.
الشريحة ١٧
Input Using CINالإدخال باستخدام cin
cin is an input stream bringing data from the keyboard
The extraction operator (>>) removes data to be used
cin >> firstNumber;
Prompt the user for input that is desired
cout statements provide instructions
Example::
cout << "Enter your age: ";
cin >> age;
الملخص بالعربيةcin مجرى إدخال يجلب البيانات من الكيبورد بعامل الاستخراج >>. وقبل القراءة اطبع للمستخدم رسالة توضيحية prompt بـ cout كما في المثال.
الشريحة ١٨
Example of cinمثال على الإدخال
#include<iostream>
using namespace std;
int main(){
int firstNumber=0;
int secondNumber=0;
cout << "Enter the firstNumber
" ;
cin >> firstNumber;
cout << "Enter the secondNumber
";
cin >> secondNumber;
cout << "you enter these numbers
"<<firstNumber<<endl<<secondNumber;
}
الملخص بالعربيةمثال المحاضرة في Code::Blocks: برنامج يقرا رقمين firstNumber وsecondNumber بـ cin بعد طباعة رسالة لكل منهما، ثم يطبعهما مرة أخرى.
الشريحة ١٩
Arithmetic Operators:العمليات الحسابية
Arithmetic is performed with operators
+ for addition
- for subtraction
* for multiplication
/ for division
% a modular division operator. This operator returns the remainder on dividing one integer with another. Thus the expression 10 / 2 yields 5, whereas, 10 % 2 yields 0
Example: storing a product in the variable totalWeight
totalWeight = oneWeight * numberOfBars;
Arithmetic operators (as shown in the lecture)
Operators
Meaning
+
Addition or unary plus
-
Subtraction of unary minus
*
Multiplication
/
Division
%
Modulo Division
الملخص بالعربيةالعمليات الحسابية: + جمع و- طرح و* ضرب و/ قسمة و% باقي القسمة؛ فـ 10 / 2 تساوي 5 بينما 10 % 2 تساوي 0. والمثال يخزن ناتج الضرب في totalWeight.
اختبر نفسك
What does 17 % 5 evaluate to?
الشريحة ٢٠
Hierarchy of Operationsأولوية تنفيذ العمليات
The hierarchy of commonly used operators (as shown in the lecture)
Priority
Operators
Description
1st
* / %
Multiplication, Division, Modular division
2nd
+ -
Addition, Subtraction
3rd
=
Assignment
Determine the hierarchy of operations and evaluate the following expression
kk = 3 / 2 * 4 + 3 / 8
Sol:
kk = 3 / 2 * 4 + 3 / 8
kk = 1 * 4 + 3 / 8 operation: /
kk = 4 + 3 / 8 operation: *
kk = 4 + 0 operation: /
kk = 4 operation: +
Precedence rules for operators are the same as used in your algebra classes
Use parentheses to alter the order of operations: x + y * z ( y is multiplied by z first) (x + y) * z ( x and y are added first)
الملخص بالعربيةالأولوية كما في الجدول: الضرب والقسمة وباقي القسمة أولًا، ثم الجمع والطرح، ثم التعيين. ومثال kk = 3 / 2 * 4 + 3 / 8 نتيجته ٤ لأن القسمة الصحيحة تهمل الكسر. والأقواس تغيّر الترتيب.
اختبر نفسك
Following the hierarchy of operations, what is the value of kk = 3 / 2 * 4 + 3 / 8 ?
الشريحة ٢١
How to convert a general algebraic expression to a C++ statement.تحويل التعبير الجبري إلى C++
From algebra to C++
Algebraic Expression
C Expression
a x b - c x d
a * b - c * d
( m + n ) ( a + b )
( m + n ) * ( a + b )
3x2 + 2x + 5
3 * x * x + 2 * x + 5
(3x + 5) × (2x - 1) ÷ (3x + 5)
3*x+5/(3*x+5)*(2*x-1)
الملخص بالعربيةلتحويل أي تعبير جبري إلى C++ اكتب الضرب صريحًا بالنجمة: a * b - c * d، و( m + n ) * ( a + b )، و3 * x * x + 2 * x + 5 كما في الأمثلة.
الشريحة ٢٢
Example:مثال: مساحة المربع
#include<iostream>
using namespace std;
int main(){
// this program to calculate the area of the square
int length=0;
int area=0;
cout << "Enter the length of the square
" ;
cin >> length;
area=length*length;
cout << "the area of the square is:
"<<area<<endl;
}
Enter the length of the square
5
the area of the square is:
25
الملخص بالعربيةمثال المحاضرة الأخير: برنامج يحسب مساحة المربع؛ يقرا الطول بـ cin ويحسب area = length * length ويطبع النتيجة. عند إدخال ٥ تكون المساحة ٢٥.
جرّب الكود
Run the example yourselfشغّل المثال بنفسك
Edit the code and run it here. It compiles and runs on Wandbox, a free online compiler service (GCC 13). Short programs only, and the code leaves this page to that service when you run it.
عدّل الكود وشغّله من هنا مباشرة عبر خدمة Wandbox المجانية (مترجم GCC 13). للبرامج القصيرة فقط، ويُرسل الكود إلى تلك الخدمة عند التشغيل.
The output appears here after you run the code.
Runs on the free Wandbox service (wandbox.org), GCC 13.2.0. No account needed.