Advertisement
Shevec

13_3(Main.cs)

Apr 20th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.IO;
  4.  
  5. namespace program
  6. {
  7.     class Program
  8.     {
  9.         static public Publish[] Input()
  10.         {
  11.             using (StreamReader fileIn = new StreamReader("base.txt"))
  12.             {
  13.                 int n = int.Parse(fileIn.ReadLine());
  14.                 Publish[] ar = new Publish[n];
  15.  
  16.                 for (int i = 0; i < n; i++)
  17.                 {
  18.                     string[] text = fileIn.ReadLine().Split(' ');
  19.                     if (text[0] == "Book")
  20.                         ar[i] = new Book(text[1], text[2], Int32.Parse(text[3]), text[4]);
  21.                     else if (text[0] == "Article")
  22.                         ar[i] = new Article(text[1], text[2], Int32.Parse(text[3]), text[4], Int32.Parse(text[5]));
  23.                     else if (text[0] == "ElecResource")
  24.                         ar[i] = new ElecResource(text[1], text[2], text[3], text[4]);
  25.                 }
  26.                 return ar;
  27.             }
  28.         }
  29.  
  30.         public static void Main(string[] args)
  31.         {
  32.             Publish[] arr = Input();
  33.             Console.WriteLine("Все издания: \n");
  34.             for(int i = 0; i < arr.Length; i++){
  35.                 arr[i].displayInfo();
  36.                 Console.WriteLine();
  37.             }
  38.  
  39.             Array.Sort(arr);
  40.             Console.WriteLine("Все издания после сортировки: \n");
  41.             for(int i = 0; i < arr.Length; i++){
  42.                 arr[i].displayInfo();
  43.                 Console.WriteLine();
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement