Advertisement
Kenoru

Sad4thLab

May 26th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace cslab4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int studQty;
  14.             Console.Write("Введите количество студентов в группе: ");
  15.             studQty = Int32.Parse(Console.ReadLine());
  16.  
  17.             if (studQty < 0)
  18.                 throw new SystemException("Количество студентов не может быть отрицательным");
  19.  
  20.             string[] studNames = new string[studQty];
  21.             for (int i = 0; i < studQty; i++)
  22.             {
  23.                 Console.Write( $"Введите фамилию {i+1}-го студента: ");
  24.                 studNames[i] = Console.ReadLine();
  25.             }
  26.            
  27.             Random rng = new Random();
  28.  
  29.             int[][] marks = new int[studQty][];
  30.             for(int i = 0; i < studQty; i++)
  31.             {
  32.                 marks[i] = new int[rng.Next(2, 9)];
  33.                 for (int j = 0; j < marks[i].Length; j++)
  34.                     marks[i][j] = rng.Next(1, 11);
  35.             }
  36.  
  37.             Console.WriteLine("Баллы студентов");
  38.             for(int i = 0; i < studQty; i++)
  39.             {
  40.                 Console.WriteLine($"Оценки студента {studNames[i]}: ");
  41.                 foreach (int mark in marks[i])
  42.                     Console.Write($"{mark}   ");
  43.                 Console.WriteLine();
  44.             }
  45.  
  46.             for (int i = 0; i < studQty; i++)
  47.                 Console.WriteLine($"Сумма баллов студента {studNames[i]}: {sum(marks[i])}");
  48.  
  49.             showRating(marks);
  50.         }
  51.  
  52.         public static int sum(params int[] arr)
  53.         {
  54.             int sum = 0;
  55.             foreach (int elem in arr)
  56.                 sum += elem;
  57.             return sum;
  58.         }
  59.         public static double sum(params double[] arr)
  60.         {
  61.             double sum = 0;
  62.             foreach (double elem in arr)
  63.                 sum += elem;
  64.             return sum;
  65.         }
  66.  
  67.         public static void showRating(params int[][] marks)
  68.         {
  69.             int[] ratings = new int[marks.Length];
  70.             for (int i = 0; i < ratings.Length; i++)
  71.             {
  72.                 ratings[i] = sum(marks[i]);
  73.                 //Console.WriteLine($"{i + 1} : {ratings[i]} ");
  74.             }
  75.             Console.WriteLine($"Средний рейтинг группы: {(double)sum(ratings) / ratings.Length}");
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement