Advertisement
Guest User

Untitled

a guest
Dec 14th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace Ulyanov_Abstract
  5. {
  6.     abstract class Person
  7.     {
  8.         public string Name;
  9.         public int Birthdate;
  10.         public string Faculty;
  11.  
  12.         public char Attach;
  13.  
  14.         abstract protected void print();
  15.         abstract protected int getAge();
  16.         protected bool CompareTo(ref Person arg1, ref Person arg2)
  17.         {
  18.             return arg1.Birthdate < arg2.Birthdate;
  19.         }
  20.  
  21.         static public Person[] readFromFile(string inputFileName)
  22.         {
  23.             FileStream inputFile = new FileStream(inputFileName, FileMode.Open, FileAccess.Read);
  24.             StreamReader inputReader = new StreamReader(inputFile);
  25.             Int32 allocCnt = 0;
  26.             while (inputReader.ReadLine() != null)
  27.             {
  28.                 inputReader.ReadLine();
  29.                 inputReader.ReadLine();
  30.                 inputReader.ReadLine();
  31.                 inputReader.ReadLine();
  32.                 inputReader.ReadLine();
  33.                 allocCnt++;
  34.             }
  35.  
  36.             Person[] arrPtr = new Person[allocCnt];
  37.             string[] buff = new string[2];
  38.  
  39.             inputFile.Seek(0, SeekOrigin.Begin);
  40.  
  41.             for(Int32 i = 0; i < allocCnt; i++)
  42.             {
  43.                 arrPtr[i].Name = inputReader.ReadLine();
  44.                 arrPtr[i].Birthdate = Convert.ToInt32(inputReader.ReadLine());
  45.                 arrPtr[i].Faculty = inputReader.ReadLine();
  46.  
  47.                 buff[0] = inputReader.ReadLine();
  48.                 if( (buff[1] = inputReader.ReadLine() )
  49.                     != "n/a")
  50.                 {
  51.                     ((Teacher)arrPtr[i]).Position = buff[0];
  52.                     ((Teacher)arrPtr[i]).Expierence = buff[1];
  53.                     arrPtr[i].Attach = 'T';
  54.                 }
  55.                 else if( (buff[0] = inputReader.ReadLine())
  56.                                  != "n/a")
  57.                 {
  58.                     ((Student)arrPtr[i]).Course = buff[0];
  59.                     arrPtr[i].Attach = 'S';
  60.                 }
  61.                 else
  62.                 {
  63.                     arrPtr[i].Attach = 'A';
  64.                 }
  65.             }
  66.  
  67.             inputFile.Close();
  68.  
  69.             return arrPtr;
  70.         }
  71.     }
  72.  
  73.     class Teacher : Person  
  74.     {
  75.         public string Position;
  76.         public string Expierence;
  77.  
  78.         override protected void print()
  79.         {
  80.  
  81.         }
  82.  
  83.         override protected int getAge()
  84.         {
  85.             return 0;
  86.         }
  87.     }
  88.  
  89.     class Applicant : Person
  90.     {
  91.  
  92.         override protected void print()
  93.         {
  94.  
  95.         }
  96.  
  97.         override protected int getAge()
  98.         {
  99.             return 0;
  100.         }
  101.     }
  102.  
  103.     class Student : Person
  104.     {
  105.         public string Course;
  106.  
  107.         override protected void print()
  108.         {
  109.  
  110.         }
  111.  
  112.         override protected int getAge()
  113.         {
  114.             return 0;
  115.         }
  116.     }
  117.  
  118.     class Program
  119.     {
  120.         static void Main(string[] args)
  121.         {
  122.             Person.readFromFile("source.txt");
  123.         }
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement