Topics
Sujets
المواضيع

Problem-solving approach

Approche de résolution

منهجية حل المسائل

By the end of this section, you should be able to read a short problem statement, separate what is given from what is asked, map it to Input → Process → Output, sketch a straight-line flow, and write the matching C++ steps in order.

À la fin de cette section, vous devriez pouvoir lire un court énoncé, séparer ce qui est donné de ce qui est demandé, le transformer en Entrée → Traitement → Sortie, esquisser un flux linéaire, puis écrire les étapes C++ dans le bon ordre.

بنهاية هذا القسم، يجب أن تكون قادراً على قراءة مسألة قصيرة، وفصل ما هو معطى عمّا هو مطلوب، وتحويلها إلى Input → Process → Output، ورسم تسلسل خطي بسيط، ثم كتابة خطوات C++ بالترتيب الصحيح.

Prep guideGuideدليل تحضيري L1

Start here: plan before you code

Commencez ici : planifier avant de coder

ابدأ من هنا: خطّط قبل أن تكتب الكود

Good beginner problem solving starts before syntax. When you see a short statement, slow down and ask three questions in order: What information do I receive? What must I do with it? What result should appear at the end?

For straight-line problems, the workflow is simple and stable:

  1. read the statement
  2. separate given from asked
  3. map the task to Input, Process, Output
  4. keep the steps in the same top-to-bottom order when you write code

You are not learning clever tricks in this section. You are learning a reliable habit you can reuse on almost every beginner problem.

Une bonne résolution de problème commence avant la syntaxe. Quand vous voyez un court énoncé, ralentissez et posez trois questions dans l’ordre : quelles informations je reçois ? Que dois-je en faire ? Quel résultat doit apparaître à la fin ?

Pour les problèmes linéaires, la méthode reste simple et stable :

  1. lire l’énoncé
  2. séparer le donné du demandé
  3. traduire la tâche en Entrée, Traitement, Sortie
  4. garder le même ordre de haut en bas quand on écrit le code

Dans cette section, vous n’apprenez pas une astuce. Vous apprenez une habitude fiable, réutilisable dans presque tous les exercices de débutant.

يبدأ حل المسائل الجيد قبل كتابة الصياغة البرمجية. عندما ترى مسألة قصيرة، تمهّل واسأل ثلاثة أسئلة بالترتيب: ما المعلومات التي أستقبلها؟ ماذا يجب أن أفعل بها؟ ما النتيجة التي يجب أن تظهر في النهاية؟

في المسائل الخطية، تبقى الطريقة بسيطة وثابتة:

  1. اقرأ نص المسألة
  2. افصل بين المعطى والمطلوب
  3. حوّل المهمة إلى Input وProcess وOutput
  4. حافظ على الترتيب نفسه من الأعلى إلى الأسفل عندما تكتب الكود

في هذا القسم أنت لا تتعلم خدعة. أنت تتعلم عادة موثوقة يمكنك إعادة استخدامها في معظم مسائل المبتدئين.

What you will practice
Ce que vous allez pratiquer
ما ستتمرّن عليه
  • Read a short statement and separate given information from the requested result.Lire un court énoncé et séparer les informations données du résultat demandé.قراءة مسألة قصيرة وفصل المعلومات المعطاة عن النتيجة المطلوبة.
  • Map a straight-line problem to Input, Process, and Output before writing syntax.Transformer une tâche linéaire en Entrée, Traitement et Sortie avant d'écrire la syntaxe.تحويل المسألة الخطية إلى Input وProcess وOutput قبل كتابة الصياغة البرمجية.
  • Keep assignments in a safe order, especially when one step depends on an earlier value.Garder les affectations dans un ordre sûr, surtout quand une étape dépend d'une valeur plus ancienne.الحفاظ على ترتيب آمن للتعيينات، خاصة عندما تعتمد خطوة على قيمة سابقة.
Keep in mind
À garder en tête
تذكّر
  • A straight-line problem runs from top to bottom once: read, compute, print.Un problème linéaire se déroule une seule fois de haut en bas : lire, calculer, afficher.المسألة الخطية تُنفَّذ مرة واحدة من الأعلى إلى الأسفل: اقرأ، احسب، ثم اطبع.
  • Do not guess code first. First decide what data you receive, what formula or assignment you apply, and what final value you show.Ne devinez pas le code d'abord. Décidez d'abord quelles données vous recevez, quelle formule ou affectation vous appliquez, puis quelle valeur finale vous affichez.لا تبدأ بتخمين الكود. حدّد أولاً ما البيانات التي تستقبلها، وما الصيغة أو التعيين الذي ستطبقه، ثم ما القيمة النهائية التي ستعرضها.
  • Clear variable names reduce mistakes when you convert a plan into code or a flowchart.Des noms de variables clairs réduisent les erreurs quand vous convertissez un plan en code ou en organigramme.تقلّل أسماء المتغيرات الواضحة من الأخطاء عندما تحوّل الخطة إلى كود أو إلى مخطط انسيابي.
ConceptConceptمفهوم L1

Given, asked, and the IPO map

Donné, demandé et carte IPO

المعطى والمطلوب وخريطة IPO

Before you write variables or operators, rewrite the problem in plain meaning. Separate what is already provided from what must be produced. Then map the statement to IPO: Input, Process, Output.

Part of the statement Question to ask Rectangle example
Given What values do I receive first? length, width
Process What formula or assignment uses those values? area = length * width
Asked / Output What final value should appear? area

The important habit is order. Input happens before Process. Process happens before Output. When your code or flowchart changes that order, the plan is probably wrong.

Avant d’écrire des variables ou des opérateurs, reformulez le problème avec son sens. Séparez ce qui est déjà fourni de ce qui doit être produit. Ensuite, transformez l’énoncé en IPO : Entrée, Traitement, Sortie.

Partie de l’énoncé Question à poser Exemple du rectangle
Donné Quelles valeurs je reçois d’abord ? length, width
Traitement Quelle formule ou affectation utilise ces valeurs ? area = length * width
Demandé / Sortie Quelle valeur finale doit apparaître ? area

L’habitude importante est l’ordre. L’Entrée vient avant le Traitement. Le Traitement vient avant la Sortie. Quand votre code ou votre organigramme change cet ordre, le plan est probablement faux.

قبل أن تكتب المتغيرات أو العوامل، أعد صياغة المسألة بمعناها البسيط. افصل بين ما هو موجود أصلاً وبين ما يجب إنتاجه. بعد ذلك حوّل نص المسألة إلى IPO: Input ثم Process ثم Output.

جزء من نص المسألة السؤال الذي تطرحه مثال المستطيل
المعطى ما القيم التي أستقبلها أولاً؟ length, width
المعالجة ما الصيغة أو التعيين الذي يستخدم هذه القيم؟ area = length * width
المطلوب / المخرج ما القيمة النهائية التي يجب أن تظهر؟ area

العادة الأهم هنا هي الترتيب. تأتي Input قبل Process، وتأتي Process قبل Output. عندما يغيّر الكود أو المخطط هذا الترتيب، فغالباً تكون الخطة غير صحيحة.

1double length, width;
2double area;
3cin >> length >> width;
4area = length * width;
5cout << area;
StartInput: length, widtharea = length * widthOutput: areaEnd
DebutEntrée : length, widtharea = length * widthSortie : areaFin
ابدأإدخال: length, widtharea = length * widthإخراج: areaنهاية
Worked exampleExemple guidéمثال محلول L1

Worked: rectangle area from statement to code

Exemple guidé : aire du rectangle, de l'énoncé au code

مثال محلول: مساحة المستطيل من نص المسألة إلى الكود

Suppose the statement says: read the rectangle length and width, compute the area, then print the area.

Do not start by guessing a cout line. First map the statement:

Step Meaning
Input read length, width
Process compute area = length * width
Output print area

Now the code almost writes itself. Read the two measurements first, compute area second, and print the result last. The plan and the code tell the same story in the same order.

Supposons que l’énoncé dise : lire length et width du rectangle, calculer l’aire, puis afficher l’aire.

Ne commencez pas par deviner une ligne cout. Commencez par traduire l’énoncé :

Étape Sens
Entrée lire length, width
Traitement calculer area = length * width
Sortie afficher area

Ensuite, le code s’écrit presque tout seul. Lisez d’abord les deux mesures, calculez area ensuite, puis affichez le résultat en dernier. Le plan et le code racontent la même chose dans le même ordre.

افترض أن نص المسألة يقول: اقرأ length وwidth للمستطيل، ثم احسب المساحة، ثم اطبع المساحة.

لا تبدأ بتخمين سطر cout. ابدأ أولاً بتحويل النص:

الخطوة المعنى
Input اقرأ length, width
Process احسب area = length * width
Output اطبع area

بعد ذلك يكاد الكود أن يكتب نفسه. اقرأ القياسين أولاً، ثم احسب area، ثم اطبع النتيجة أخيراً. الخطة والكود يرويان القصة نفسها وبالترتيب نفسه.

When you feel lost, return to the IPO map. If you cannot point to one Input step, one Process step, and one Output step, do not write more syntax yet.

Quand vous vous sentez perdu, revenez à la carte IPO. Si vous ne pouvez pas montrer une étape d’Entrée, une de Traitement et une de Sortie, n’écrivez pas encore plus de syntaxe.

عندما تشعر بالضياع، ارجع إلى خريطة IPO. إذا لم تستطع الإشارة إلى خطوة Input واحدة وخطوة Process واحدة وخطوة Output واحدة، فلا تكتب مزيداً من الصياغة البرمجية بعد.

1// Problem: read rectangle length and width, then print the area.
2double length, width;
3double area;
4cin >> length >> width;
5area = length * width;
6cout << "Area = " << area;
PracticePratiqueتمرين L1

These questions keep the answer shape narrow on purpose. Focus on identifying one role at a time: input, process, or output.

Ces questions gardent volontairement une forme de réponse étroite. Concentrez-vous sur un seul rôle à la fois : entrée, traitement ou sortie.

هذه الأسئلة تضيق شكل الإجابة عمداً. ركّز في كل مرة على دور واحد فقط: Input أو Process أو Output.

4 exercises below
4 exercices ci-dessous
4 تمارين أدناه
Practice 1 / 4Pratique 1 / 4تمرين ⁦1 / 4⁩ L1
Is area an input here? Type yes or no.
Ici, area est-elle une entrée ? Tapez oui ou non.
هل area مدخل هنا؟ اكتب نعم أو لا.
1// Problem: read length and width, compute area, print area.
Answer with yes or no only.
Répondez seulement par oui ou non.
أجب فقط بـنعم أو لا.
Practice 2 / 4Pratique 2 / 4تمرين ⁦2 / 4⁩ L1
Type the result variable name only.
Tapez seulement le nom de la variable résultat.
اكتب اسم متغير النتيجة فقط.
1// Problem: read length and width, compute area, print area.
Do not type a sentence or a full assignment.
Ne tapez ni phrase ni affectation complète.
لا تكتب جملة ولا تعييناً كاملاً.
Practice 3 / 4Pratique 3 / 4تمرين ⁦3 / 4⁩ L2
Type the exact process formula using length then width.
Tapez la formule exacte du traitement avec length puis width.
اكتب صيغة المعالجة الدقيقة مستخدماً length ثم width.
Type the right side only, not area =.
Tapez seulement la partie droite, pas area =.
اكتب الطرف الأيمن فقط، وليس area =.
Practice 4 / 4Pratique 4 / 4تمرين ⁦4 / 4⁩ L2
What variable does this flowchart output at the end?
Quelle variable cet organigramme affiche-t-il à la fin ?
ما المتغير الذي يخرجه هذا المخطط في النهاية؟
StartInput: length, widtharea = length * widthOutput: areaEnd
DebutEntrée : length, widtharea = length * widthSortie : areaFin
ابدأإدخال: length, widtharea = length * widthإخراج: areaنهاية
Type the variable name only.
Tapez seulement le nom de la variable.
اكتب اسم المتغير فقط.
ConceptConceptمفهوم L1

Process steps and variable names

Étapes de traitement et noms de variables

خطوات المعالجة وأسماء المتغيرات

Some beginner problems need more than one process step. In that case, the safest approach is to name each intermediate value clearly and keep the assignments in the same order as the plan.

Problem sentence Good variable name Why it helps
total number of seconds totalSeconds reminds you this is the original input
number of full minutes minutes tells you this is one computed result
leftover seconds seconds shows this is the remainder after minutes are removed

Process boxes in a flowchart correspond to assignments in code. If the second process step needs the original input, keep that input available. If the second step needs the first result, make sure the first assignment happens before it.

Certains problèmes de débutant demandent plus d’une étape de traitement. Dans ce cas, l’approche la plus sûre consiste à nommer clairement chaque valeur intermédiaire et à garder les affectations dans le même ordre que le plan.

Phrase du problème Bon nom de variable Pourquoi c’est utile
nombre total de secondes totalSeconds rappelle qu’il s’agit de l’entrée d’origine
nombre de minutes complètes minutes montre qu’il s’agit d’un premier résultat calculé
secondes restantes seconds indique qu’il s’agit du reste après les minutes retirées

Les boîtes de Traitement d’un organigramme correspondent aux affectations dans le code. Si la deuxième étape a besoin de l’entrée d’origine, gardez cette entrée disponible. Si elle a besoin du premier résultat, assurez-vous que la première affectation se produit avant elle.

تحتاج بعض مسائل المبتدئين إلى أكثر من خطوة معالجة واحدة. في هذه الحالة تكون الطريقة الأكثر أماناً هي تسمية كل قيمة وسيطة بوضوح، ثم الحفاظ على ترتيب التعيينات كما في الخطة.

جملة من المسألة اسم متغير جيد لماذا يساعد
العدد الكلي للثواني totalSeconds يذكّرك بأن هذه هي قيمة الإدخال الأصلية
عدد الدقائق الكاملة minutes يوضّح أن هذه أول نتيجة محسوبة
الثواني المتبقية seconds يبيّن أنها الباقي بعد إزالة الدقائق

تقابل صناديق Process في المخطط التعليمي أسطر التعيين في الكود. إذا كانت الخطوة الثانية تحتاج إلى الإدخال الأصلي فاحتفظ به متاحاً. وإذا كانت تحتاج إلى النتيجة الأولى، فتأكد من أن التعيين الأول يحدث قبلها.

1int totalSeconds = 125;
2int minutes = totalSeconds / 60;
3int seconds = totalSeconds % 60;
4cout << minutes << " " << seconds;
Worked exampleExemple guidéمثال محلول L2

Worked: break total seconds into minutes and seconds

Exemple guidé : transformer un total de secondes en minutes et secondes

مثال محلول: تحويل عدد الثواني الكلي إلى دقائق وثوانٍ

Now the plan has two process steps instead of one. The statement is: read a total number of seconds, compute full minutes, compute leftover seconds, then print both values.

Map it carefully:

IPO role Step
Input read totalSeconds
Process 1 minutes = totalSeconds / 60
Process 2 seconds = totalSeconds % 60
Output print minutes, then seconds

Notice that both process steps use the same original input. That is why totalSeconds stays unchanged after reading it. Each later line depends on it.

Cette fois, le plan contient deux étapes de traitement au lieu d’une. L’énoncé est : lire un nombre total de secondes, calculer les minutes complètes, calculer les secondes restantes, puis afficher les deux valeurs.

Traduisez-le avec soin :

Rôle IPO Étape
Entrée lire totalSeconds
Traitement 1 minutes = totalSeconds / 60
Traitement 2 seconds = totalSeconds % 60
Sortie afficher minutes, puis seconds

Remarquez que les deux étapes de traitement utilisent la même entrée d’origine. C’est pourquoi totalSeconds reste inchangé après la lecture. Chaque ligne suivante en dépend.

الآن تحتوي الخطة على خطوتي معالجة بدلاً من خطوة واحدة. نص المسألة هو: اقرأ العدد الكلي للثواني، واحسب الدقائق الكاملة، ثم احسب الثواني المتبقية، وبعد ذلك اطبع القيمتين.

حوّلها بعناية:

دور IPO الخطوة
Input اقرأ totalSeconds
Process 1 minutes = totalSeconds / 60
Process 2 seconds = totalSeconds % 60
Output اطبع minutes ثم seconds

لاحظ أن خطوتي المعالجة كلتيهما تستخدمان الإدخال الأصلي نفسه. لذلك يبقى totalSeconds دون تغيير بعد قراءته. فكل سطر لاحق يعتمد عليه.

When a problem has multiple process lines, keep the data story visible: original input, first computed value, second computed value, final output.

Quand un problème contient plusieurs lignes de traitement, gardez l’histoire des données visible : entrée d’origine, première valeur calculée, seconde valeur calculée, sortie finale.

عندما تحتوي المسألة على عدة أسطر معالجة، أبقِ قصة البيانات واضحة: الإدخال الأصلي، ثم أول قيمة محسوبة، ثم القيمة المحسوبة الثانية، ثم المخرج النهائي.

1int totalSeconds;
2int minutes;
3int seconds;
4cin >> totalSeconds;
5minutes = totalSeconds / 60;
6seconds = totalSeconds % 60;
7cout << minutes << " " << seconds;
PracticePratiqueتمرين L2

These exercises show the same IPO idea in two shapes: boxes and code. Keep the step order fixed, and notice whether each slot needs only a variable name or a full assignment.

Ces exercices montrent la même idée IPO sous deux formes : des boîtes et du code. Gardez l’ordre des étapes fixe et remarquez si chaque emplacement attend seulement un nom de variable ou une affectation complète.

تعرض هذه التمارين الفكرة نفسها بصورتين: مرة على شكل مخطط، ومرة على شكل كود. حافظ على ترتيب الخطوات ثابتاً، وانتبه هل المطلوب في كل موضع هو اسم متغير فقط أم سطر تعيين كامل.

4 exercises below
4 exercices ci-dessous
4 تمارين أدناه
Practice 1 / 4Pratique 1 / 4تمرين ⁦1 / 4⁩ L2
Which variable is output first?
Quelle variable est affichée en premier ?
ما المتغير الذي يُطبع أولاً؟
StartInput: totalSecondsminutes = totalSeconds/ 60seconds = totalSeconds% 60Output: minutesOutput: secondsEnd
DebutEntrée : totalSecondsminutes = totalSeconds/ 60seconds = totalSeconds% 60Sortie : minutesSortie : secondsFin
ابدأإدخال: totalSecondsminutes = totalSeconds/ 60seconds = totalSeconds% 60إخراج: minutesإخراج: secondsنهاية
Type only the first output variable name.
Tapez seulement le nom de la première variable de sortie.
اكتب اسم أول متغير يتم إخراجه فقط.
Practice 2 / 4Pratique 2 / 4تمرين ⁦2 / 4⁩ L2
Complete the missing flowchart labels exactly.
Complétez exactement les étiquettes manquantes de l'organigramme.
أكمل تسميات المخطط الناقصة بدقة.
1cin >> totalSeconds;
2minutes = totalSeconds / 60;
3seconds = totalSeconds % 60;
4cout << minutes << " " << seconds;
StartInput: [A][B][C]Output: minutesOutput: secondsEnd
DebutEntrée : [A][B][C]Sortie : minutesSortie : secondsFin
ابدأإدخال: [A][B][C]إخراج: minutesإخراج: secondsنهاية
Each blank must match the missing box label exactly.
Chaque blanc doit correspondre exactement à l'étiquette manquante.
يجب أن يطابق كل فراغ تسمية الصندوق الناقصة تماماً.
Practice 3 / 4Pratique 3 / 4تمرين ⁦3 / 4⁩ L2
Convert this flowchart into exact code tokens.
Convertissez cet organigramme en jetons de code exacts.
حوّل هذا المخطط إلى عناصر كود دقيقة.
StartInput: totalSecondsminutes = totalSeconds/ 60Output: minutesEnd
DebutEntrée : totalSecondsminutes = totalSeconds/ 60Sortie : minutesFin
ابدأإدخال: totalSecondsminutes = totalSeconds/ 60إخراج: minutesنهاية
Fill each blank with one exact variable name.
Remplissez chaque blanc avec un nom de variable exact.
املأ كل فراغ باسم متغير دقيق واحد.
1 cin >> ;
2 = / 60;
3 cout << ;
Practice 4 / 4Pratique 4 / 4تمرين ⁦4 / 4⁩ L2
Type the exact output with one space between the two numbers.
Tapez la sortie exacte avec un seul espace entre les deux nombres.
اكتب المخرجات الدقيقة مع مسافة واحدة بين الرقمين.
1int totalSeconds = 125;
2int minutes = totalSeconds / 60;
3int seconds = totalSeconds % 60;
4cout << minutes << " " << seconds;
Write only what appears on the screen.
Écrivez seulement ce qui apparaît à l'écran.
اكتب فقط ما يظهر على الشاشة.
ConceptConceptمفهوم L2

Why swaps need temp

Pourquoi un échange a besoin de temp

لماذا يحتاج التبديل إلى temp

A swap is the classic example of an order problem. If you overwrite one variable too early, the old value disappears before the second assignment can use it.

Order Result
left = right; then right = left; both variables end up the same
save old left in temp, then overwrite left, then restore into right values are truly exchanged

The key idea is simple: when a later step still needs an old value, save that old value first. A helper variable such as temp is not extra decoration. It protects information from being lost.

Un échange est l’exemple classique d’un problème d’ordre. Si vous écrasez une variable trop tôt, l’ancienne valeur disparaît avant que la seconde affectation puisse l’utiliser.

Ordre Résultat
left = right; puis right = left; les deux variables finissent identiques
sauvegarder l’ancien left dans temp, puis écraser left, puis restaurer dans right les valeurs sont réellement échangées

L’idée clé est simple : lorsqu’une étape plus tardive a encore besoin d’une ancienne valeur, sauvegardez d’abord cette ancienne valeur. Une variable d’aide comme temp n’est pas de la décoration. Elle protège l’information contre la perte.

يُظهر التبديل بوضوح لماذا يهم ترتيب التعيين. فإذا كتبت فوق أحد المتغيرات قبل حفظ قيمته القديمة، فلن تجد هذه القيمة عندما تحتاجها في السطر التالي.

ما الذي تفعله؟ ماذا يحدث؟
left = right; ثم right = left; تصبح القيمتان متماثلتين، لأن القيمة القديمة لـleft ضاعت
temp = left; ثم left = right; ثم right = temp; يتم التبديل فعلاً، لأن القيمة القديمة لـleft بقيت محفوظة داخل temp

الفكرة الأساسية بسيطة: عندما تكون خطوة لاحقة ما زالت تحتاج إلى قيمة قديمة، احفظ هذه القيمة أولاً. فالمتغير المساعد مثل temp ليس شيئاً إضافياً، بل هو ما يمنع ضياع المعلومة.

1int left = 3, right = 7;
2left = right;
3right = left;
4cout << left << " " << right; // 7 7
Worked exampleExemple guidéمثال محلول L2

Worked: swap with a temporary variable

Exemple guidé : échanger avec une variable temporaire

مثال محلول: التبديل باستخدام متغير مؤقت

To swap safely, read the three assignments as a chain of storage decisions:

  1. temp = left; saves the old left value.
  2. left = right; moves the right value into left.
  3. right = temp; restores the saved old left value into right.

This works because the old value is preserved before anything is overwritten. If you skip the first line, the later lines no longer have access to the original left.

Pour échanger sans erreur, lisez les trois affectations comme une chaîne de décisions de stockage :

  1. temp = left; sauvegarde l’ancienne valeur de gauche.
  2. left = right; déplace la valeur de droite dans left.
  3. right = temp; restaure dans right l’ancienne valeur sauvegardée.

Cela fonctionne parce que l’ancienne valeur est préservée avant tout écrasement. Si vous sautez la première ligne, les lignes suivantes n’ont plus accès au left d’origine.

لكي ترى فكرة التبديل بوضوح، اقرأ الأسطر الثلاثة كحركات تخزين متتابعة:

  1. temp = left; يحفظ قيمة left القديمة.
  2. left = right; ينقل قيمة right إلى left.
  3. right = temp; يعيد القيمة القديمة المحفوظة إلى right.

ينجح هذا لأننا حفظنا القيمة القديمة قبل أن نكتب فوق أي شيء. إذا حذفت السطر الأول، فلن يبقى أي مكان يحتفظ بقيمة left الأصلية.

The safest way to debug a swap is to trace values line by line. Ask after every assignment: what does each variable hold now?

La façon la plus sûre de vérifier un échange est de tracer les valeurs ligne par ligne. Après chaque affectation, demandez-vous : que contient chaque variable maintenant ?

أفضل طريقة لتصحيح التبديل هي تتبّع القيم سطراً بسطر. بعد كل تعيين، اسأل نفسك: ماذا يحمل كل متغير الآن؟

1int left = 3, right = 7;
2int temp = left;
3left = right;
4right = temp;
5cout << left << " " << right; // 7 3
PracticePratiqueتمرين L2

These questions connect directly to the previous block: the swap works only because the assignments happen in the right order. Read one line, update the stored values, then move to the next line.

Ces questions prolongent directement le bloc précédent : l’échange fonctionne seulement parce que les affectations arrivent dans le bon ordre. Lisez une ligne, mettez à jour les valeurs stockées, puis passez à la suivante.

ترتبط هذه الأسئلة مباشرة بالفقرة السابقة: ينجح التبديل فقط لأن التعيينات تأتي بالترتيب الصحيح. اقرأ سطراً واحداً، وحدّث القيم المخزنة، ثم انتقل إلى السطر التالي.

4 exercises below
4 exercices ci-dessous
4 تمارين أدناه
Practice 1 / 4Pratique 1 / 4تمرين ⁦1 / 4⁩ L2
After these lines, does right keep the original value of left? Type yes or no.
Après ces lignes, right garde-t-il la valeur d'origine de left ? Tapez oui ou non.
بعد هذه الأسطر، هل يحتفظ right بالقيمة الأصلية لـleft؟ اكتب نعم أو لا.
1int left = 3, right = 7;
2left = right;
3right = left;
Answer with yes or no only.
Répondez seulement par oui ou non.
أجب فقط بـنعم أو لا.
Practice 2 / 4Pratique 2 / 4تمرين ⁦2 / 4⁩ L2
Complete the safe swap with the exact helper variable name.
Complétez l'échange sûr avec le nom exact de la variable d'aide.
أكمل التبديل الآمن باستخدام اسم متغير المساعدة الدقيق.
Both blanks should contain the same helper variable name.
Les deux blancs doivent contenir le même nom de variable d'aide.
يجب أن يحتوي الفراغان على اسم متغير المساعدة نفسه.
1 int = left;
2 left = right;
3 right = ;
Practice 3 / 4Pratique 3 / 4تمرين ⁦3 / 4⁩ L3
Complete the hidden cells in the trace table.
Complétez les cellules cachées du tableau de trace.
أكمل الخلايا المخفية في جدول التتبع.
Row 2 means the state after line 2, and rows 3, 4, and 5 mean the state after those code lines. Fill only the left and temp cells.
La ligne 2 représente l'état après la ligne 2 du code, et les lignes 3, 4 et 5 représentent l'état après ces lignes. Remplissez seulement les cellules left et temp.
يمثل السطر 2 الحالة بعد السطر 2 من الكود، وتمثل الأسطر 3 و4 و5 الحالة بعد تلك الأسطر. املأ خلايا left وtemp فقط.
1int left = 3, right = 7;
2int temp = -1;
3temp = left;
4left = right;
5right = temp;
StepÉtapeالسطر leftleftleft rightrightright temptemptemp
2 7
3 7
4 7
5 3
Practice 4 / 4Pratique 4 / 4تمرين ⁦4 / 4⁩ L2
Type the exact output after the safe swap.
Tapez la sortie exacte après l'échange sûr.
اكتب المخرجات الدقيقة بعد التبديل الآمن.
1int left = 3, right = 7;
2int temp = left;
3left = right;
4right = temp;
5cout << left << " " << right;
Use one space between the two numbers.
Utilisez un seul espace entre les deux nombres.
استخدم مسافة واحدة بين الرقمين.
RecapSynthèseملخص L1

Recap

Synthèse

ملخص

Straight-line problem solving becomes easier when you keep one stable workflow: read the statement, separate given from asked, map IPO, then write the steps in the same order. If a later assignment still needs an older value, save that value before you overwrite it.

La résolution linéaire devient plus simple quand vous gardez une seule méthode stable : lire l’énoncé, séparer le donné du demandé, construire l’IPO, puis écrire les étapes dans le même ordre. Si une affectation plus tardive a encore besoin d’une ancienne valeur, sauvegardez cette valeur avant de l’écraser.

يصبح حل المسائل الخطية أسهل عندما تحافظ على طريقة ثابتة واحدة: اقرأ نص المسألة، وافصل بين المعطى والمطلوب، وابنِ خريطة IPO، ثم اكتب الخطوات بالترتيب نفسه. وإذا كانت خطوة لاحقة ما زالت تحتاج إلى قيمة أقدم، فاحفظ تلك القيمة قبل أن تكتب فوقها.

Key takeaways
Points clés
النقاط الأساسية
  • Read the statement first, then separate given data, process steps, and final output.Lisez d'abord l'énoncé, puis séparez les données données, les étapes de traitement et la sortie finale.اقرأ نص المسألة أولاً، ثم افصل بين البيانات المعطاة وخطوات المعالجة والمخرج النهائي.
  • Straight-line code keeps the same top-to-bottom order as the IPO plan and its flowchart.Le code linéaire garde le même ordre de haut en bas que le plan IPO et son organigramme.يحافظ الكود الخطي على الترتيب نفسه من الأعلى إلى الأسفل الموجود في خطة IPO وفي مخططها.
  • When an assignment would overwrite a value you still need, save it first in temp.Quand une affectation risque d'écraser une valeur encore utile, sauvegardez-la d'abord dans temp.عندما يكون التعيين سيكتب فوق قيمة ما زلت تحتاجها، احفظها أولاً في temp.