Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace example
- {
- public abstract class Pupil
- {
- protected int a, b, c, d;
- public abstract void Score();
- }
- public class Schoolboy : Pupil
- {
- public Schoolboy(int _a, int _b)
- {
- a = _a;
- b = _b;
- }
- public override void Score()
- {
- Console.WriteLine("Ученик, наименьшая оценка: {0}", a < b ? a : b);
- }
- }
- public class Entrant : Pupil
- {
- public Entrant(int _a, int _b, int _c)
- {
- a = _a;
- b = _b;
- c = _c;
- }
- public override void Score()
- {
- Console.WriteLine("Абитуриент, сумма баллов: {0}", a + b + c);
- }
- }
- public class Student : Pupil
- {
- public Student(int _a, int _b, int _c, int _d)
- {
- a = _a;
- b = _b;
- c = _c;
- d = _d;
- }
- public override void Score()
- {
- Console.WriteLine("Студент, средний балл: {0:F2}", (a + b + c + d) / 4.0);
- }
- }
- public class Program
- {
- static void Main(string[] args)
- {
- int a, b, c, d;
- Console.WriteLine("Введите тип обучаемого(школьник/абитуриент/студент):");
- string pupil = Console.ReadLine();
- switch (pupil)
- {
- case "школьник":
- Console.Write("Введите первую оценку школьника: ");
- a = int.Parse(Console.ReadLine());
- Console.Write("Введите вторую оценку школьника: ");
- b = int.Parse(Console.ReadLine());
- Schoolboy schoolboy = new Schoolboy(a, b);
- schoolboy.Score();
- break;
- case "абитуриент":
- Console.Write("Введите первую оценку абитуриента: ");
- a = int.Parse(Console.ReadLine());
- Console.Write("Введите вторую оценку абитуриента: ");
- b = int.Parse(Console.ReadLine());
- Console.Write("Введите третью оценку абитуриента: ");
- c = int.Parse(Console.ReadLine());
- Entrant entrant = new Entrant(a, b, c);
- entrant.Score();
- break;
- case "студент":
- Console.Write("Введите первую оценку студента: ");
- a = int.Parse(Console.ReadLine());
- Console.Write("Введите вторую оценку студента: ");
- b = int.Parse(Console.ReadLine());
- Console.Write("Введите третью оценку студента: ");
- c = int.Parse(Console.ReadLine());
- Console.Write("Введите четвёртую оценку студента: ");
- d = int.Parse(Console.ReadLine());
- Student student = new Student(a, b, c, d);
- student.Score();
- break;
- default:
- Console.WriteLine("Ошибка!");
- break;
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement