Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace Ulyanov_Abstract
- {
- abstract class Person
- {
- public string Name;
- public int Birthdate;
- public string Faculty;
- public char Attach;
- abstract protected void print();
- abstract protected int getAge();
- protected bool CompareTo(ref Person arg1, ref Person arg2)
- {
- return arg1.Birthdate < arg2.Birthdate;
- }
- static public Person[] readFromFile(string inputFileName)
- {
- FileStream inputFile = new FileStream(inputFileName, FileMode.Open, FileAccess.Read);
- StreamReader inputReader = new StreamReader(inputFile);
- Int32 allocCnt = 0;
- while (inputReader.ReadLine() != null)
- {
- inputReader.ReadLine();
- inputReader.ReadLine();
- inputReader.ReadLine();
- inputReader.ReadLine();
- inputReader.ReadLine();
- allocCnt++;
- }
- Person[] arrPtr = new Person[allocCnt];
- string[] buff = new string[5];
- inputFile.Seek(0, SeekOrigin.Begin);
- for(Int32 i = 0; i < allocCnt; i++)
- {
- buff[0] = inputReader.ReadLine();
- buff[1] = inputReader.ReadLine();
- buff[2] = inputReader.ReadLine();
- buff[3] = inputReader.ReadLine();
- buff[4] = inputReader.ReadLine();
- if ( buff[4] != "n/a" )
- {
- arrPtr[i] = new Teacher(buff[0], Convert.ToInt32(buff[1]), buff[2], buff[3], buff[4]);
- }
- else if (buff[3] != "n/a")
- {
- arrPtr[i] = new Student(buff[0], Convert.ToInt32(buff[1]), buff[2], buff[3]);
- }
- else
- {
- arrPtr[i] = new Applicant(buff[0], Convert.ToInt32(buff[1]), buff[2]);
- }
- inputReader.ReadLine();
- }
- inputFile.Close();
- return arrPtr;
- }
- }
- class Teacher : Person
- {
- public string Position;
- public string Expierence;
- override protected void print()
- {
- }
- override protected int getAge()
- {
- return 0;
- }
- public Teacher(string arg1, Int32 arg2, string arg3, string arg4, string arg5)
- {
- this.Attach = 'T';
- this.Name = arg1;
- this.Birthdate = arg2;
- this.Faculty = arg3;
- this.Position = arg4;
- this.Expierence = arg5;
- }
- }
- class Applicant : Person
- {
- override protected void print()
- {
- }
- override protected int getAge()
- {
- return 0;
- }
- public Applicant(string arg1, Int32 arg2, string arg3)
- {
- this.Attach = 'A';
- this.Name = arg1;
- this.Birthdate = arg2;
- this.Faculty = arg3;
- }
- }
- class Student : Person
- {
- public string Course;
- override protected void print()
- {
- }
- override protected int getAge()
- {
- return 0;
- }
- public Student(string arg1, Int32 arg2, string arg3, string arg4)
- {
- this.Attach = 'S';
- this.Name = arg1;
- this.Birthdate = arg2;
- this.Faculty = arg3;
- this.Course = arg4;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Person.readFromFile("source.txt");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement