Menu
Coddy logo textTech
flag Ar iconالعربيةdown icon

منطق إدخال البيانات

جزء من قسم Logic & Flow في رحلة C# على Coddy — الدرس 41 من 66.

challenge icon

التحدي

سهل

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

قم بإنشاء فئة تسمى DataEntry تحتوي على هذه الطرق (methods):

  1. SetStudentScore(int[][] scoreGrid, int studentIndex, int assignmentIndex, int score): تقوم بتعيين الدرجة لطالب ومهمة محددين إذا كانت صالحة. تعيد:
    • 0 إذا كانت ناجحة
    • -1 إذا كان أي فهرس خارج الحدود
    • -2 إذا كانت الدرجة غير صالحة
  2. UpdateAllScores(int[][] scoreGrid, int[] studentIndices, int assignmentIndex, int score): تقوم بتحديث الدرجات لعدة طلاب في نفس المهمة. تعيد عدد الدرجات التي تم تحديثها بنجاح.

ملاحظة: استخدم الطريقة ValidateScore من الفئة DataCollector للتحقق من صلاحية الدرجة.

جرّب بنفسك

using System; // لا تحذف هذا السطر
public class DataEntry
{
    public static int SetStudentScore(int[][] scoreGrid, int studentIndex, int assignmentIndex, int score)
    {
        // اكتب كودك هنا
        
    }
    
    public static int UpdateAllScores(int[][] scoreGrid, int[] studentIndices, int assignmentIndex, int score)
    {
        // اكتب كودك هنا
        
    }
}

// مطلوب للاختبار - لا تقم بالتعديل
public class DataCollector
{
    public static int[][] CreateScoreGrid(int students, int assignments)
    {
        int[][] scoreGrid = new int[students][];
        for (int i = 0; i < students; i++)
        {
            scoreGrid[i] = new int[assignments];
        }
        return scoreGrid;
    }
    
    public static bool ValidateScore(int score)
    {
        return score >= 0 && score <= 100;
    }
    
    public static int[][] PopulateWithDefaultValues(int[][] scoreGrid)
    {
        for (int i = 0; i < scoreGrid.Length; i++)
        {
            for (int j = 0; j < scoreGrid[i].Length; j++)
            {
                scoreGrid[i][j] = -1;
            }
        }
        return scoreGrid;
    }
}

جميع دروس Logic & Flow