Menu
Coddy logo textTech

ניתוח נתונים

חלק מהיחידה לוגיקה וזרימת תוכנית במסלול ה-C# של Coddy. שיעור 42 מתוך 66.

challenge icon

אתגר

בינוני

כעת, כשאנחנו יכולים לאסוף ולעדכן נתוני תלמידים, בואו נממש את פונקציונליות הניתוח כדי להפיק תובנות מהציונים. צרו מחלקה בשם DataAnalyzer עם המתודות הבאות:

  1. CalculateStudentAverage(int[][] scoreGrid, int studentIndex): מחשבת ומחזירה את הציון הממוצע של תלמיד מסוים. יש להחזיר ‎-1 אם studentIndex אינו תקין.
  2. CalculateAssignmentAverage(int[][] scoreGrid, int assignmentIndex): מחשבת ומחזירה את הציון הממוצע של מטלה מסוימת בקרב כל התלמידים. יש להחזיר ‎-1 אם assignmentIndex אינו תקין.
  3. FindHighestScore(int[][] scoreGrid): מחזירה מערך של שלושה מספרים שלמים המייצגים את הציון הגבוה ביותר ואת מיקומו: [studentIndex, assignmentIndex, score]. אם לכמה רשומות יש אותו ציון גבוה ביותר, יש להחזיר את הראשונה שנמצאה.

הערה: בעת חישוב ממוצעים, יש להתחשב רק בציונים תקינים (0-100). יש להתעלם ממטלות שלא נבדקו (-1).

נסו בעצמכם

using System; // אין למחוק את השורה הזו
public class DataAnalyzer
{
    public static double CalculateStudentAverage(int[][] scoreGrid, int studentIndex)
    {
        // כתבו כאן את הקוד שלכם
        
    }
    
    public static double CalculateAssignmentAverage(int[][] scoreGrid, int assignmentIndex)
    {
        // כתבו כאן את הקוד שלכם
        
    }
    
    public static int[] FindHighestScore(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;
    }
}

כל השיעורים ביחידה לוגיקה וזרימת תוכנית

תרגלו בעצמכם: קומפיילר C# אונליין