Data Entry Logic
Часть раздела Логика и управление потоком путешествия по C# на Coddy — урок 41 из 66.
Задание
ЛегкоТеперь, когда у нас есть наша структура данных, давайте реализуем логику для ввода и обновления оценок студентов.
Создайте класс под названием DataEntry с этими методами:
SetStudentScore(int[][] scoreGrid, int studentIndex, int assignmentIndex, int score): Устанавливает оценку для конкретного студента и задания, если она действительна. Возвращает:- 0 в случае успеха
- -1 если любой индекс выходит за границы
- -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)
{
// Напишите ваш код здесь
}
}
// 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