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

منطق التقييم

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

challenge icon

التحدي

سهل

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

  1. ConvertToLetterGrade(double score): يحول الدرجة الرقمية إلى درجة حرفية وفقاً لهذا المقياس:
    • A: 90-100
    • B: 80-89
    • C: 70-79
    • D: 60-69
    • F: 0-59
    • غير صالح: إرجاع "N/A" لأي درجة غير صالحة (سالبة أو > 100)
  2. GetStudentGrade(int[][] scoreGrid, int studentIndex): يحسب متوسط الطالب ويعيد درجته الحرفية. أرجع "N/A" لفهارس الطلاب غير الصالحة.
  3. GetClassDistribution(int[][] scoreGrid): يعيد مصفوفة من الأعداد الصحيحة تمثل عدد كل درجة حرفية في الفصل [A, B, C, D, F]. اعتمد في ذلك على متوسط درجة كل طالب.

جرّب بنفسك

using System; // لا تحذف هذا السطر
public class GradingSystem
{
    public static string ConvertToLetterGrade(double score)
    {
        // اكتب الكود الخاص بك هنا
        
    }
    
    public static string GetStudentGrade(int[][] scoreGrid, int studentIndex)
    {
        // اكتب الكود الخاص بك هنا
        
    }
    
    public static int[] GetClassDistribution(int[][] scoreGrid)
    {
        // اكتب الكود الخاص بك هنا
        
    }
}

// مطلوب للاختبار - لا تقم بالتعديل
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;
    }
}

public class DataEntry
{
    public static int SetStudentScore(int[][] scoreGrid, int studentIndex, int assignmentIndex, int score)
    {
        // التحقق من الفهارس الخارجة عن الحدود
        if (studentIndex < 0 || studentIndex >= scoreGrid.Length || 
            assignmentIndex < 0 || assignmentIndex >= scoreGrid[studentIndex].Length)
        {
            return -1;
        }
        
        // التحقق من صحة الدرجة
        if (!DataCollector.ValidateScore(score))
        {
            return -2;
        }
        
        // تعيين الدرجة
        scoreGrid[studentIndex][assignmentIndex] = score;
        return 0;
    }
    
    public static int UpdateAllScores(int[][] scoreGrid, int[] studentIndices, int assignmentIndex, int score)
    {
        int successCount = 0;
        
        for (int i = 0; i < studentIndices.Length; i++)
        {
            int result = SetStudentScore(scoreGrid, studentIndices[i], assignmentIndex, score);
            if (result == 0)
            {
                successCount++;
            }
        }
        
        return successCount;
    }
}

public class DataAnalyzer
{
    public static double CalculateStudentAverage(int[][] scoreGrid, int studentIndex)
    {
        // التحقق مما إذا كان فهرس الطالب صالحاً
        if (studentIndex < 0 || studentIndex >= scoreGrid.Length)
        {
            return -1;
        }
        
        int sum = 0;
        int count = 0;
        
        // حساب مجموع الدرجات الصالحة
        for (int j = 0; j < scoreGrid[studentIndex].Length; j++)
        {
            int score = scoreGrid[studentIndex][j];
            if (score != -1)  // تجاهل التكليفات غير المصححة
            {
                sum += score;
                count++;
            }
        }
        
        // إرجاع المتوسط أو 0 إذا لم تكن هناك درجات صالحة
        return count > 0 ? (double)sum / count : 0;
    }
    
    public static double CalculateAssignmentAverage(int[][] scoreGrid, int assignmentIndex)
    {
        // التحقق مما إذا كان هناك أي طلاب
        if (scoreGrid.Length == 0)
        {
            return -1;
        }
        
        // التحقق مما إذا كان فهرس التكليف صالحاً
        if (assignmentIndex < 0 || assignmentIndex >= scoreGrid[0].Length)
        {
            return -1;
        }
        
        int sum = 0;
        int count = 0;
        
        // حساب مجموع الدرجات الصالحة للتكليف
        for (int i = 0; i < scoreGrid.Length; i++)
        {
            if (assignmentIndex < scoreGrid[i].Length)
            {
                int score = scoreGrid[i][assignmentIndex];
                if (score != -1)  // تجاهل التكليفات غير المصححة
                {
                    sum += score;
                    count++;
                }
            }
        }
        
        // إرجاع المتوسط أو 0 إذا لم تكن هناك درجات صالحة
        return count > 0 ? (double)sum / count : 0;
    }
    
    public static int[] FindHighestScore(int[][] scoreGrid)
    {
        int highestStudentIndex = 0;
        int highestAssignmentIndex = 0;
        int highestScore = -1;
        
        // البحث عن أعلى درجة
        for (int i = 0; i < scoreGrid.Length; i++)
        {
            for (int j = 0; j < scoreGrid[i].Length; j++)
            {
                int currentScore = scoreGrid[i][j];
                if (currentScore > highestScore)
                {
                    highestScore = currentScore;
                    highestStudentIndex = i;
                    highestAssignmentIndex = j;
                }
            }
        }
        
        return new int[] { highestStudentIndex, highestAssignmentIndex, highestScore };
    }
}

جميع دروس Logic & Flow