Menu
Coddy logo textTech

לוגיקת הזנת נתונים

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

challenge icon

אתגר

קל

עכשיו, כשיש לנו את מבנה הנתונים, ניישם את הלוגיקה להזנה ולעדכון של ציוני התלמידים.

צרו מחלקה בשם DataEntry עם המתודות הבאות:

  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;
    }
}

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

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