Menu
Coddy logo textTech

Data Analysis

Coddy C# 여정의 논리 및 흐름 섹션에 포함된 레슨 — 66개 중 42번째.

challenge icon

챌린지

중급

이제 학생 데이터를 수집하고 업데이트할 수 있으니, 점수에서 통찰력을 얻기 위해 분석 기능을 구현해 보겠습니다. DataAnalyzer라는 클래스에 다음 메서드들을 구현하세요:

  1. CalculateStudentAverage(int[][] scoreGrid, int studentIndex): 특정 학생의 평균 점수를 계산하여 반환합니다. studentIndex가 유효하지 않으면 -1을 반환하세요.
  2. CalculateAssignmentAverage(int[][] scoreGrid, int assignmentIndex): 특정 과제에 대한 모든 학생의 평균 점수를 계산하여 반환합니다. assignmentIndex가 유효하지 않으면 -1을 반환하세요.
  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)
    {
        // 여기에 코드를 작성하세요
        
    }
}

// Required for testing - do not modify
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;
    }
}

논리 및 흐름의 모든 레슨