Иерархия классов(задача решена, есть нюансы) - C#

Узнай цену своей работы

Формулировка задачи:

Разработать иeрapхию клaccов для учeтa пeрсoнaла вузa(препoдаватель, вспoмогaтельный пepcoнaл, руководство, студент, аспирант, мaгистрант. Нa укaзaннyю дaту вывести списoк всего персoнала, cгруперованный пo категориям. Для сoтрудников вывести стаж работы.

Извинения приношу за г-код, но сроки жмут. Задача решена, нужно указать на ошибки. Если кто-то может сам исправить, буду очень признателен.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ticket312
{
    class Person {
        public int[] staj= {2,3,4};
    }
    class Prepod : Person {
        public string status = "Преподаватели:";
        public string[] firstname = { "Стас", "Олег", "Антон" };
        public string[] lastname = { "Антипов", "Доставевский", "Нестеренко" };
        public DateTime[] dateTimes = new DateTime[]
        {
            new DateTime(2017, 10, 1),
            new DateTime(2010, 10, 2),
            new DateTime(2017, 10, 3),
        };
    }
    class VspomogPers : Person {
        public string status = "Вспомогательный персонал: ";
    }
 
    class Uborka : VspomogPers {
        public string statusUb = "Уборщиц: ";
        public string[] firstname = { "Алена", "Полина", "Женя" };
        public string[] lastname = { "Мотвеенко", "Гагарина", "Петрова" };
        public DateTime[] dateTimes = new DateTime[]
        {
            new DateTime(2010, 10, 1),
            new DateTime(2010, 10, 2),
            new DateTime(2017, 10, 3),
        };
    }
    class Rucovodstvo : Person {
        public string status = "Руководство: ";
 
        public string[] firstname = { "Стас", "Олег", "Антон" };
        public string[] lastname = { "Кепа", "Лизогуб", "Макаров" };
        public DateTime[] dateTimes = new DateTime[]
        {
            new DateTime(2010, 10, 1),
            new DateTime(2007, 10, 2),
            new DateTime(2017, 10, 3),
        };
    }
    class Student : Person {
        public string status = "Студент: ";
        public string[] firstname = { "Стас", "Олег", "Антон" };
        public string[] lastname = { "Ab4", "Cd4", "Ee4" };
        public DateTime[] dateTimes = new DateTime[]
        {
            new DateTime(2010, 10, 1),
            new DateTime(2017, 10, 2),
            new DateTime(2017, 10, 3),
        };
    }
    class Aspirant : Person {
        public string status = "Аспиранты: ";
        public string[] firstname = { "Стас", "Олег", "Антон" };
        public string[] lastname = { "Ab5", "Cd5", "Ee5" };
        public DateTime[] dateTimes = new DateTime[]
        {
            new DateTime(2010, 10, 1),
            new DateTime(2017, 10, 2),
            new DateTime(2017, 10, 3),
        };
    }
    class Magistrant : Person {
        public string status = "Магистранты";
        public string[] firstname = { "Стас", "Олег", "Антон" };
        public string[] lastname = { "Ab6", "Cd6", "Ee6" };
        public DateTime[] dateTimes = new DateTime[]
        {
            new DateTime(2017, 10, 1),
            new DateTime(2017, 10, 2),
            new DateTime(2011, 10, 3),
        };
    }
    class Program
    {
 
        static void Main(string[] args)
        {
            VspomogPers vspomogPers = new VspomogPers();
            Prepod prepod = new Prepod();
            Rucovodstvo rucovodstvo = new Rucovodstvo();
            Magistrant magistrant = new Magistrant();
            Student student = new Student();
            Aspirant aspirant = new Aspirant();
            Uborka uborka = new Uborka();
            DateTime defaultDateTime = new DateTime(2014, 10, 3);
 
            Console.WriteLine(prepod.status);
            for (int i = 0; i < 3; i++)
            {
                if (prepod.dateTimes[i] < defaultDateTime)
                {
                    Console.WriteLine("Имя: {0} {1} Стаж {2}", prepod.firstname[i], prepod.lastname[i], prepod.staj[i]);
                }
            }
            Console.WriteLine(uborka.status);
            Console.WriteLine(uborka.statusUb);
            for (int i = 0; i < 3; i++)
            {
                if (uborka.dateTimes[i] < defaultDateTime)
                {
                    Console.WriteLine("Имя: {0} {1} Стаж {2}", uborka.firstname[i], uborka.lastname[i], uborka.staj[i]);
                }
            }
            Console.WriteLine(rucovodstvo.status);
            for (int i = 0; i < 3; i++)
            {
                if (rucovodstvo.dateTimes[i] < defaultDateTime)
                {
                    Console.WriteLine("Имя: {0} {1} Стаж {2}", rucovodstvo.firstname[i], rucovodstvo.lastname[i], rucovodstvo.staj[i]);
                }
            }
            Console.WriteLine(magistrant.status);
            for (int i = 0; i < 3; i++)
            {
                if (magistrant.dateTimes[i] < defaultDateTime)
                {
                    Console.WriteLine("Имя: {0} {1} Стаж {2}", magistrant.firstname[i], magistrant.lastname[i], magistrant.staj[i]);
                }
            }
            Console.WriteLine(student.status);
            for (int i = 0; i < 3; i++)
            {
                if (student.dateTimes[i] < defaultDateTime)
                {
                    Console.WriteLine("Имя: {0} {1} Стаж {2}", student.firstname[i], student.lastname[i], student.staj[i]);
                }
            }
            Console.WriteLine(aspirant.status);
            for (int i = 0; i < 3; i++)
            {
                if (aspirant.dateTimes[i] < defaultDateTime)
                {
                    Console.WriteLine("Имя: {0} {1} Стаж {2}", aspirant.firstname[i], aspirant.lastname[i], aspirant.staj[i]);
                }
            }
            Console.ReadKey();
        }
    }
}
возможно нужно что-то подправить под LINQ

Решение задачи: «Иерархия классов(задача решена, есть нюансы)»

textual
Листинг программы
abstract class Person
{
    public string Firstname { get; set; }
    
    public string Lastname { get; set; }
}
 
abstract class Staff : Person
{
    public int Experience { get; set; }
    
    public string Position { get; set; }
}
 
class Teacher : Staff
{
}
 
class Support : Staff
{
}
 
class Management : Staff
{
}
 
abstract class Student : Person
{
}
 
class Bachelor : Student
{
}
 
class Graduate : Student
{
}
 
class Postgraduate : Student
{
}

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

14   голосов , оценка 3.929 из 5
Похожие ответы