Advertisement
Guest User

Untitled

a guest
Dec 15th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.75 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.  
  38.             string[] buff = new string[5];
  39.  
  40.             inputFile.Seek(0, SeekOrigin.Begin);
  41.  
  42.             for(Int32 i = 0; i < allocCnt; i++)
  43.             {
  44.                 buff[0] = inputReader.ReadLine();
  45.                 buff[1] = inputReader.ReadLine();
  46.                 buff[2] = inputReader.ReadLine();
  47.                 buff[3] = inputReader.ReadLine();
  48.                 buff[4] = inputReader.ReadLine();
  49.  
  50.                 if ( buff[4] != "n/a" )
  51.                 {
  52.                     arrPtr[i] = new Teacher(buff[0], Convert.ToInt32(buff[1]), buff[2], buff[3], buff[4]);
  53.                 }
  54.                 else if (buff[3] != "n/a")
  55.                 {
  56.                     arrPtr[i] = new Student(buff[0], Convert.ToInt32(buff[1]), buff[2], buff[3]);
  57.                 }
  58.                 else
  59.                 {
  60.                     arrPtr[i] = new Applicant(buff[0], Convert.ToInt32(buff[1]), buff[2]);
  61.                 }
  62.  
  63.                 inputReader.ReadLine();
  64.             }
  65.  
  66.             inputFile.Close();
  67.  
  68.             return arrPtr;
  69.         }
  70.     }
  71.  
  72.     class Teacher : Person  
  73.     {
  74.         public string Position;
  75.         public string Expierence;
  76.  
  77.         override protected void print()
  78.         {
  79.  
  80.         }
  81.  
  82.         override protected int getAge()
  83.         {
  84.             return 0;
  85.         }
  86.  
  87.         public Teacher(string arg1, Int32 arg2, string arg3, string arg4, string arg5)
  88.         {
  89.             this.Attach = 'T';
  90.             this.Name = arg1;
  91.             this.Birthdate = arg2;
  92.             this.Faculty = arg3;
  93.             this.Position = arg4;
  94.             this.Expierence = arg5;
  95.         }
  96.     }
  97.  
  98.     class Applicant : Person
  99.     {
  100.  
  101.         override protected void print()
  102.         {
  103.  
  104.         }
  105.  
  106.         override protected int getAge()
  107.         {
  108.             return 0;
  109.         }
  110.  
  111.         public Applicant(string arg1, Int32 arg2, string arg3)
  112.         {
  113.             this.Attach = 'A';
  114.             this.Name = arg1;
  115.             this.Birthdate = arg2;
  116.             this.Faculty = arg3;
  117.         }
  118.     }
  119.  
  120.     class Student : Person
  121.     {
  122.         public string Course;
  123.  
  124.         override protected void print()
  125.         {
  126.  
  127.         }
  128.  
  129.         override protected int getAge()
  130.         {
  131.             return 0;
  132.         }
  133.  
  134.         public Student(string arg1, Int32 arg2, string arg3, string arg4)
  135.         {
  136.             this.Attach = 'S';
  137.             this.Name = arg1;
  138.             this.Birthdate = arg2;
  139.             this.Faculty = arg3;
  140.             this.Course = arg4;
  141.         }
  142.     }
  143.  
  144.     class Program
  145.     {
  146.         static void Main(string[] args)
  147.         {
  148.             Person.readFromFile("source.txt");
  149.         }
  150.     }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement