انتقل إلى المحتوى
أمين أبوزيد
BEG-010

العوامل

  • 6 درس
  • 72 دقيقة قراءة
  • 3 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • الحسابية
  • المقارنة
  • المنطقية
  • الإسناد
  • الأسبقية
  • الزيادة/النقصان

تعلّم أولًا

72 دقيقة قراءة · 3 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Evaluate expressions using arithmetic, comparison, logical, and assignment operators.
  2. Predict results involving integer division, modulo, and operator precedence.
  3. Explain the difference between prefix and postfix increment.
  4. Use short-circuit evaluation (&&, ||) to avoid errors.

الدروس

  1. 01العوامل الحسابية وقسمة الأعداد الصحيحة12 د قراءة
  2. 02عوامل المقارنة والعوامل المنطقية12 د قراءة
  3. 03الإسناد والإسناد المركّب12 د قراءة
  4. 04الزيادة والنقصان والأسبقية13 د قراءة
  5. 05التقييم المختصر (Short-circuit)12 د قراءة
  6. 06عرض عملي: تحدّي توقّع نتيجة التعبير ثم تشغيله11 د قراءة

المختبر والتمارين

Lab

BEG-010-LAB1 · Expression predictor

Outcomes: 1–4 · Time: ~3 h Predict the output of the 20 expressions below on paper, then run them in code. Record each prediction before running and explain each mismatch.

  1. 7 / 2 2. 7 % 2 3. -7 / 2 4. 7 / 2.0 5. 10 % 3 + 1 6. 2 + 3 * 4 7. (2 + 3) * 4 8. 5 > 3 9. 5 == 5.0 10. !(3 > 5)
  2. true && false 12. true || false && false 13. int x = 5; x += 3; (x) 14. int x = 5; x *= 2 + 1; (x) 15. int i = 3; i++; (i)
  3. int i = 3; int j = i++; (i, j) 17. int i = 3; int j = ++i; (i, j) 18. int d = 0; d != 0 && 10 / d > 1 19. 1 + 2 + "3" 20. "1" + 2 + 3

Acceptance: predictions recorded before running; each mismatch explained.

Exercises (assessment: six)

IDOutcomeTask
BEG-010-EX011Write an expression that is true when n is even.
BEG-010-EX021Write an expression for "year is a leap year": divisible by 4 and (not by 100 or divisible by 400).
BEG-010-EX032Compute the average of the ints 7 and 8 as a decimal; first get it wrong, then fix it.
BEG-010-EX042Convert 135 minutes into hours and remaining minutes using / and %.
BEG-010-EX053Predict the final values of a and b: int a = 2; int b = a++ + ++a;
BEG-010-EX064Rewrite 10 / d > 1 && d != 0 so it can never divide by zero.
أظهر الحلول
  • Lab: 1: 3 · 2: 1 · 3: -3 · 4: 3.5 · 5: 2 · 6: 14 · 7: 20 · 8: true · 9: true · 10: true · 11: false · 12: true · 13: 8 · 14: 15 · 15: 4 · 16: i=4, j=3 · 17: i=4, j=4 · 18: false (no crash) · 19: 33 · 20: 123.
  • EX01 n % 2 == 0.
  • EX02 (y % 4 == 0) && (y % 100 != 0 || y % 400 == 0).
  • EX03 (7 + 8) / 2 gives 7; fix: (7 + 8) / 2.0 gives 7.5.
  • EX04 135 / 60 is 2 hours; 135 % 60 is 15 minutes.
  • EX05 a++ yields 2 (a becomes 3); ++a makes a 4 and yields 4; b is 6, a is 4.
  • EX06 d != 0 && 10 / d > 1.

الاختبار

Outcomes: O1 evaluate · O2 division, modulo, precedence · O3 prefix/postfix · O4 short-circuit.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 15 == 5 is:O1
  2. 2x += 2 means:O1
  3. 3true && false is:O1
  4. 49 / 2 is:O2
  5. 59 % 4 is:O2
  6. 62 + 3 * 2 is:O2
  7. 7int i = 1; int j = i++; leaves:O3
  8. 8int i = 1; int j = ++i; leaves:O3
  9. 9In a && b, if a is false then:O4
  10. 10The valid way to write "x between 1 and 10" is:O1

الجزء العملي

Six exercises BEG-010-EX01 to EX06. Pass: at least five correct, and all lab mismatches explained.

أخطاء شائعة

= vs ==; 5/2 returning 2; chaining comparisons like 1 < x < 10.

التقييم

6 exercises.

الصلة بالمسار الوظيفي

Exact reasoning about expressions underpins debugging (BEG-018) and test boundaries (BEG-045).

اكتب للبحث في المستويات والمراحل والوحدات والدروس.