Advertisement
Savonarolla

Untitled

Nov 17th, 2020
1,089
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.52 KB | None | 0 0
  1. /*1. Придумать класс, описывающий студента и предусмотреть в
  2. нем следующие поля: имя, фамилия, отчество, группа,
  3. возраст, массив (рваный) оценок по программированию,
  4. администрированию и дизайну. Также добавить методы по
  5. работе с перечисленными данными: возможность установки/
  6. получения оценки, получение среднего балла по данному
  7. предмету, распечатка данных о студенте.*/
  8.  
  9. using System;
  10.  
  11. namespace Classes
  12. {
  13.     public static class Student
  14.     {
  15.         public string FirstName;
  16.         public string LastName;
  17.         public string MiddleName;
  18.  
  19.         public int GroupId;
  20.         public int Age;
  21.  
  22.         public int[] GradesProgrammingArray;
  23.         public int[] GradesAdministrationArray;
  24.         public int[] GradesDesignArray;
  25.  
  26.        
  27.  
  28.         public static void SetGrades(int[] gradesArray)
  29.         {
  30.             int grade = Convert.ToInt32(Console.ReadKey());
  31.             gradesArray[gradesArray.Length] = grade;
  32.         }
  33.        
  34.         public static int [] GetGrades(int[] gradesArray)
  35.         {
  36.             return gradesArray;
  37.         }
  38.  
  39.         public static int GetAvgGrade(int[] gradesArray)
  40.         {
  41.             int sum = 0;
  42.             for (int i = 0; i < gradesArray.Length; i++)
  43.             {
  44.                 sum += gradesArray[i];
  45.             }
  46.  
  47.             return sum / (gradesArray.Length - 1);
  48.         }
  49.  
  50.  
  51.         public static void ShowStudentInfo()
  52.         {
  53.             Console.WriteLine($"Student name is: {FirstName} {LastName} {MiddleName}");
  54.             Console.WriteLine($"Student group is: {GroupId} ");
  55.             Console.WriteLine($"Student age is: {Age}");
  56.  
  57.             if (GradesProgrammingArray.Length > 0)
  58.             {
  59.                 Console.WriteLine("Student average grade in programming is: " + GetAvgGrade(GradesProgrammingArray));
  60.             }
  61.             if (GradesAdministrationArray.Length > 0)
  62.             {
  63.                 Console.WriteLine("Student average grade in administration is: " + GetAvgGrade(GradesAdministrationArray));
  64.             }
  65.             if (GradesDesignArray.Length > 0)
  66.             {
  67.                 Console.WriteLine("Student average grade in design is: " + GetAvgGrade(GradesDesignArray));
  68.             }
  69.         }
  70.        
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement