Data Entry Logic
Coddy C# 여정의 논리 및 흐름 섹션에 포함된 레슨 — 66개 중 41번째.
챌린지
쉬움이제 데이터 구조를 갖췄으니, 학생 점수를 입력하고 업데이트하는 로직을 구현해 보겠습니다.
DataEntry라는 클래스를 만들고 다음 메서드들을 구현하세요:
SetStudentScore(int[][] scoreGrid, int studentIndex, int assignmentIndex, int score): 유효한 경우 특정 학생과 과제의 점수를 설정합니다. 반환값:- 성공 시 0
- 인덱스가 범위를 벗어난 경우 -1
- 점수가 유효하지 않은 경우 -2
UpdateAllScores(int[][] scoreGrid, int[] studentIndices, int assignmentIndex, int score): 같은 과제에 대해 여러 학생의 점수를 업데이트합니다. 성공적으로 업데이트된 점수의 수를 반환합니다.
참고: 점수 유효성을 확인하기 위해 DataCollector 클래스의 ValidateScore 메서드를 사용하세요.
직접 해보기
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)
{
// 여기에 코드를 작성하세요
}
}
// 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;
}
}논리 및 흐름의 모든 레슨
1Multi-dimensional Arrays
2D Arrays BasicsDeclaring and Initializing 2DAccessing 2D Array ElementsNested Loops with 2D ArraysJagged ArraysCommon Matrix OperationsRecap - Multi-dimensional4Flow Control Techniques
Early ReturnsGuard ClausesJump Statements (goto)Break and ContinueFlatten Nested Conditionals7Logical Operators Advanced
Short-Circuit EvaluationConditional Logical OperatorsOperator PrecedenceRecap - Advanced Operators2Advanced Decision Making
Multiple ConditionsComplex Boolean LogicIf vs. Switch ComparisonNested Switch StatementsRecap - Advanced Decisions5Exception Handling
Try-Catch BasicsException TypesMultiple Catch BlocksWorking with FilesFinally BlockUsing vs. Try-FinallyCustom ExceptionsRecap - Error Handling8Data Analysis System
Data Collection SetupData Entry Logic3Loop Enhancements
Loop PerformanceIterating ComplexEach Loop TypeRefactoring LoopsRecap - Optimized Loops6Null Handling
Null Reference BasicsNullable Value TypesNull Checking PatternsDefensive ProgrammingRecap - Null Safety