// كود تطبيق أتمتة المنزل الذكي (Smart Home Automation Problem) import 'dart:io'; // 7. Final/Const Variables const int MIN_TEMP = 15; const int MAX_TEMP = 30; // Device Status bool lightsOn = false; int thermostatTemp = 20; bool securityArmed = false; void main() { print("مرحبًا بك في نظام أتمتة المنزل الذكي."); print("الحالة الافتراضية: الأضواء مطفأة، درجة الحرارة 20°C، نظام الأمان غير مفعل."); // 3. User Interaction: Use a loop while (true) { print("\nاختر الإجراء:"); print("1. التحكم في الأضواء (تشغيل/إطفاء)"); print("2. ضبط منظم الحرارة (15°C - 30°C)"); print("3. التحكم في نظام الأمان (تفعيل/إلغاء تفعيل)"); print("4. عرض حالة النظام"); print("5. خروج"); stdout.write("أدخل رقم الخيار: "); String? choice = stdin.readLineSync(); if (choice == '5') { print("شكرًا لاستخدامك نظام المنزل الذكي. إلى اللقاء!"); break; } // 5. Control Flow: Use if/else statements to handle user choices if (choice == '1') { controlLights(); } else if (choice == '2') { setThermostat(); } else if (choice == '3') { controlSecurity(); } else if (choice == '4') { viewStatus(); } else { print("خيار غير صالح. يرجى إدخال رقم من 1 إلى 5."); } } } void controlLights() { stdout.write("هل تريد تشغيل الأضواء (on) أم إطفاءها (off)؟ "); String? input = stdin.readLineSync()?.toLowerCase(); // 5. Control Flow: Use a switch statement to handle device commands switch (input) { case 'on': lightsOn = true; print("تم تشغيل الأضواء."); break; case 'off': lightsOn = false; print("تم إطفاء الأضواء."); break; default: print("إدخال غير صالح. يرجى كتابة 'on' أو 'off'."); } } void setThermostat() { stdout.write("أدخل درجة الحرارة الجديدة بين $MIN_TEMP و $MAX_TEMP: "); String? input = stdin.readLineSync(); try { int newTemp = int.parse(input!); // 4. Input Validation & 8. Logical & Relational Operators if (newTemp >= MIN_TEMP && newTemp <= MAX_TEMP) { thermostatTemp = newTemp; print("تم ضبط منظم الحرارة على $thermostatTemp°C."); } else { print("درجة الحرارة خارج النطاق المسموح به ($MIN_TEMP - $MAX_TEMP)."); } } catch (e) { print("إدخال غير صالح. يرجى إدخال رقم صحيح."); } } void controlSecurity() { stdout.write("هل تريد تفعيل نظام الأمان (arm) أم إلغاء تفعيله (disarm)؟ "); String? input = stdin.readLineSync()?.toLowerCase(); // 5. Control Flow: Use a switch statement to handle device commands switch (input) { case 'arm': // 8. Logical & Relational Operators if (!securityArmed) { securityArmed = true; print("تم تفعيل نظام الأمان."); } else { print("نظام الأمان مفعل بالفعل."); } break; case 'disarm': // 8. Logical & Relational Operators if (securityArmed) { securityArmed = false; print("تم إلغاء تفعيل نظام الأمان."); } else { print("نظام الأمان غير مفعل بالفعل."); } break; default: print("إدخال غير صالح. يرجى كتابة 'arm' أو 'disarm'."); } } void viewStatus() { // 6. String Interpolation and Operations String lightsStatus = lightsOn ? "مضاءة" : "مطفأة"; String securityStatus = securityArmed ? "مفعل" : "غير مفعل"; // 6. String Operations: Convert status to uppercase for emphasis String securityDisplay = securityStatus.toUpperCase(); String tempMessage = ""; // 5. Implement a FizzBuzz-like exercise if (thermostatTemp % 3 == 0 && thermostatTemp % 5 == 0) { tempMessage = "يوم مثالي (Perfect Day)"; } else if (thermostatTemp % 3 == 0) { tempMessage = "يوم بارد (Cool Day)"; } else if (thermostatTemp % 5 == 0) { tempMessage = "يوم دافئ (Warm Day)"; } else { tempMessage = "درجة حرارة عادية"; } print("\n--- حالة نظام المنزل الذكي ---"); print("الأضواء: $lightsStatus"); print("منظم الحرارة: $thermostatTemp°C ($tempMessage)"); print("نظام الأمان: $securityDisplay"); print("------------------------------"); }