Advertisement
Guest User

Hueta

a guest
Nov 19th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 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. /*Вариант 2*/
  7. namespace SR5_Karabash_Radimir_BSE195_1
  8. {
  9.     public class CourseWorkThemes
  10.     {
  11.         int Length;
  12.         int count = 0;
  13.         string[] Tutors;
  14.         string[] Themes;
  15.         public CourseWorkThemes(int Length,params string[] Tutors)
  16.         {
  17.             this.Length = Length;
  18.             this.Tutors = Tutors;
  19.             Themes = new string[Length];
  20.         }
  21.         public void Append(string Theme)
  22.         {
  23.             Themes[count] = Theme;
  24.             count++;
  25.         }
  26.         public string this[int i]
  27.         {
  28.             get
  29.             {
  30.                 return this.Themes[i];
  31.             }
  32.         }
  33.         public string GetTutors()
  34.         {
  35.             string res = "Список научруков: \n\n";
  36.             for (int i = 0; i < Tutors.Length; i++)
  37.             {
  38.                 res = res + $"{i + 1}. {Tutors[i]}\n";
  39.             }
  40.             return res;
  41.         }
  42.         public override string ToString()
  43.         {
  44.            
  45.                 string res = "Список курсовых тем: \n\n";
  46.                 for (int i = 0; i < Themes.Length; i++)
  47.                 {
  48.                     res = res + $"{i+1}. {Themes[i]}\n";
  49.                 }
  50.                 return res;                
  51.            
  52.         }
  53.     }
  54.     class Program
  55.     {
  56.         static Random generator = new Random();
  57.         static void Main(string[] args)
  58.         {
  59.             try
  60.             {
  61.                 do
  62.                 {
  63.                     string[] Tutors = new string[5] { "Шершаков", "Чуйкин", "Авдошин", "Баканов", "Самоненко" };
  64.                     int n;
  65.                     do Console.WriteLine("Введите количество курсовых тем: ");
  66.                     while (!int.TryParse(Console.ReadLine(), out n) | n <= 0);
  67.                     CourseWorkThemes courseWork = new CourseWorkThemes(n, Tutors);
  68.                     for (int i = 0; i < n; i++)
  69.                     {
  70.                         Console.WriteLine("Введите название курсовой: ");
  71.                         courseWork.Append(Console.ReadLine());
  72.                     }
  73.                     Console.WriteLine($"Рандомная курсовая: {courseWork[generator.Next(0, n)]}");
  74.                     Console.WriteLine(courseWork);
  75.                     Console.WriteLine(courseWork.GetTutors());
  76.                 } while (true);
  77.             }
  78.             catch (Exception e)
  79.             {
  80.  
  81.                 Console.WriteLine($"Ошибка: {e.Message}");
  82.             }
  83.            
  84.            
  85.  
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement