Untitled

mail@pastecode.io avatar
unknown
csharp
a year ago
2.7 kB
3
Indexable
Never
using System.Dynamic;

namespace ConsoleApp13
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Введите данные человека через запятую (имя, возраст): ");
            string[] data = Console.ReadLine().Split(",");
            People human = new People(data[0], Convert.ToInt32(data[1]));
            Console.WriteLine(human.GetBaseInfo());

            Console.Write("Введите данные студента через запятую (имя, возраст, курс, группа): ");
            string[] studentData = Console.ReadLine().Split(",");

            Student student = new Student(studentData[0], Convert.ToInt32(studentData[1]), Convert.ToInt32(studentData[2]), studentData[3]);
            Console.WriteLine(student.GetInfo());

            Console.Write("Введите данные преподавателя через запятую (имя, возраст, стаж, уровень): ");
            string[] teacherData = Console.ReadLine().Split(",");

            Teacher teacher = new Teacher(teacherData[0], Convert.ToInt32(teacherData[1]), Convert.ToInt32(teacherData[2]), Convert.ToInt32(teacherData[3]));
            Console.WriteLine(teacher.GetInfo());
            Console.WriteLine($"Зарплата преподавателя: {teacher.GetSalary()}");
        }
    }

    class People
    {
        string name;
        int age;

        public People(string name, int age)
        {
            this.name = name;
            this.age = age;
        }

        public string GetBaseInfo() => $"{name}, лет: {age}";
    }

    class Student : People
    {
        int course;
        string group;
        public Student(string name, int age, int course, string group) : base(name, age)
        {   
            this.course = course;
            this.group = group; 
        }

        public string GetInfo()
        {
            return $"Студент {this.GetBaseInfo()}, {course} курс, группа: {group}";
        }
    }
    class Teacher : People
    {
        int yearsWorked;
        int level;
        public Teacher(string name, int age, int yearsWorked, int level) : base(name, age)
        {
            this.yearsWorked = yearsWorked;
            this.level = level;
        }

        public string GetInfo()
        {
            return $"Студент {this.GetBaseInfo()}, Лет стажа: {yearsWorked}, уровень: {level}";
        }

        public int GetSalary() {
            return 12130 + (yearsWorked * 500) + (level * 900);
        }

    }
}