===== question1.dart ===== import 'dart:io'; // تعريف القيم الثابتة const int minTemp = 15; const int maxTemp = 30; void main() { // الحالة الابتدائية للأجهزة bool lightsOn = false; int thermostat = 20; bool securityArmed = false; print("مرحبا بك في نظام المنزل الذكي!"); while (true) { // عرض الخيارات للمستخدم print("\nاختر خيار:"); print("1. تشغيل/إطفاء الأضواء"); print("2. ضبط درجة الحرارة"); print("3. تشغيل/إيقاف نظام الأمن"); print("4. عرض حالة النظام"); print("5. خروج"); stdout.write("ادخل خيارك: "); String? choice = stdin.readLineSync(); if (choice == null) { print("الرجاء إدخال خيار صحيح."); continue; } switch (choice) { case "1": // تبديل حالة الأضواء lightsOn = !lightsOn; print("الأضواء الآن ${lightsOn ? "مشغلة" : "مطفيه"}"); break; case "2": // ضبط درجة الحرارة stdout.write("ادخل درجة الحرارة بين $minTemp و $maxTemp: "); String? tempInput = stdin.readLineSync(); if (tempInput != null) { int? temp = int.tryParse(tempInput); if (temp != null && temp >= minTemp && temp <= maxTemp) { thermostat = temp; print("درجة الحرارة الآن $thermostat°C"); } else { print("درجة حرارة غير صالحة، حاول مرة اخرى."); } } break; case "3": // تبديل حالة نظام الأمن securityArmed = !securityArmed; print("نظام الأمن الآن ${securityArmed ? "ARMED" : "DISARMED"}"); break; case "4": // عرض حالة النظام print("\n--- حالة النظام ---"); print("الأضواء: ${lightsOn ? "ON" : "OFF"}"); print("درجة الحرارة: $thermostat°C"); // FizzBuzz-like للتعليقات على الطقس if (thermostat % 3 == 0 && thermostat % 5 == 0) { print("Perfect Day!"); } else if (thermostat % 3 == 0) { print("Cool Day"); } else if (thermostat % 5 == 0) { print("Warm Day"); } print("نظام الأمن: ${securityArmed ? "ARMED" : "DISARMED"}"); break; case "5": print("الخروج من البرنامج. إلى اللقاء!"); return; default: print("خيار غير صالح، حاول مرة اخرى."); } } } ===== question2.dart ===== import 'dart:io'; void main() { print("مرحباً بك في نظام إدارة الميزانية!"); // قوائم الدخل والمصروفات List> incomeList = []; List> expenseList = []; while (true) { print("\n------ القائمة ------"); print("1. إضافة دخل"); print("2. إضافة مصروف"); print("3. عرض الملخص"); print("4. خروج"); stdout.write("اختر خيار: "); String? choice = stdin.readLineSync(); if (choice == "1") { addIncome(incomeList); } else if (choice == "2") { addExpense(expenseList); } else if (choice == "3") { viewSummary(incomeList, expenseList); } else if (choice == "4") { print("شكراً لاستخدامك النظام. إلى اللقاء!"); break; } else { print("❌ خيار غير صحيح، حاول مرة أخرى!"); } } } // إضافة الدخل void addIncome(List> incomeList) { stdout.write("ادخل وصف الدخل: "); String? desc = stdin.readLineSync(); stdout.write("ادخل المبلغ: "); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ""); if (amount == null || amount < 0) { print("❌ مبلغ غير صالح!"); return; } incomeList.add({desc ?? "دخل بدون وصف": amount}); print("✅ تم إضافة الدخل بنجاح!"); } // إضافة المصروف void addExpense(List> expenseList) { stdout.write("ادخل وصف المصروف: "); String? desc = stdin.readLineSync(); stdout.write("ادخل المبلغ: "); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ""); if (amount == null || amount < 0) { print("❌ مبلغ غير صالح!"); return; } expenseList.add({desc ?? "مصروف بدون وصف": amount}); print("✅ تم إضافة المصروف بنجاح!"); } // عرض الملخص والضرائب (اختياري) void viewSummary(List> incomeList, List> expenseList) { double totalIncome = 0; double totalExpense = 0; // حساب الدخل for (var item in incomeList) { totalIncome += item.values.first; } // حساب المصروفات for (var item in expenseList) { totalExpense += item.values.first; } double net = totalIncome - totalExpense; print("\n------ الملخص ------"); print("إجمالي الدخل: \$${totalIncome.toStringAsFixed(2)}"); print("إجمالي المصروفات: \$${totalExpense.toStringAsFixed(2)}"); if (net >= 0) { print("✅ صافي الربح: \$${net.toStringAsFixed(2)}"); } else { print("❌ صافي الخسارة: \$${net.abs().toStringAsFixed(2)}"); } // حساب الضريبة باستخدام ternary operator double tax = net > 0 ? net * 0.15 : 0; if (tax > 0) { print("💰 الضريبة المستحقة (15%): \$${tax.toStringAsFixed(2)}"); } }