Advertisement
NickAndNick

Выбор

Mar 10th, 2013
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.59 KB | None | 0 0
  1. using System;
  2.  
  3. namespace example
  4. {
  5.     public abstract class Pupil
  6.     {
  7.         protected int a, b, c, d;
  8.         public abstract void Score();
  9.     }
  10.  
  11.     public class Schoolboy : Pupil
  12.     {
  13.         public Schoolboy(int _a, int _b)
  14.         {
  15.             a = _a;
  16.             b = _b;
  17.         }
  18.  
  19.         public override void Score()
  20.         {
  21.             Console.WriteLine("Ученик, наименьшая оценка: {0}", a < b ? a : b);
  22.         }
  23.     }
  24.  
  25.     public class Entrant : Pupil
  26.     {
  27.         public Entrant(int _a, int _b, int _c)
  28.         {
  29.             a = _a;
  30.             b = _b;
  31.             c = _c;
  32.         }
  33.  
  34.         public override void Score()
  35.         {
  36.             Console.WriteLine("Абитуриент, сумма баллов: {0}", a + b + c);
  37.         }
  38.     }
  39.  
  40.     public class Student : Pupil
  41.     {
  42.         public Student(int _a, int _b, int _c, int _d)
  43.         {
  44.             a = _a;
  45.             b = _b;
  46.             c = _c;
  47.             d = _d;
  48.         }
  49.  
  50.         public override void Score()
  51.         {
  52.             Console.WriteLine("Студент, средний балл: {0:F2}", (a + b + c + d) / 4.0);
  53.         }
  54.     }
  55.  
  56.     public class Program
  57.     {
  58.         static void Main(string[] args)
  59.         {
  60.             int a, b, c, d;
  61.             Console.WriteLine("Введите тип обучаемого(школьник/абитуриент/студент):");
  62.             string pupil = Console.ReadLine();
  63.  
  64.             switch (pupil)
  65.             {
  66.                 case "школьник":
  67.                     Console.Write("Введите первую оценку школьника: ");
  68.                     a = int.Parse(Console.ReadLine());
  69.                     Console.Write("Введите вторую оценку школьника: ");
  70.                     b = int.Parse(Console.ReadLine());
  71.                     Schoolboy schoolboy = new Schoolboy(a, b);
  72.                     schoolboy.Score();
  73.                     break;
  74.                 case "абитуриент":
  75.                     Console.Write("Введите первую оценку абитуриента: ");
  76.                     a = int.Parse(Console.ReadLine());
  77.                     Console.Write("Введите вторую оценку абитуриента: ");
  78.                     b = int.Parse(Console.ReadLine());
  79.                     Console.Write("Введите третью оценку абитуриента: ");
  80.                     c = int.Parse(Console.ReadLine());
  81.                     Entrant entrant = new Entrant(a, b, c);
  82.                     entrant.Score();
  83.                     break;
  84.                 case "студент":
  85.                     Console.Write("Введите первую оценку студента: ");
  86.                     a = int.Parse(Console.ReadLine());
  87.                     Console.Write("Введите вторую оценку студента: ");
  88.                     b = int.Parse(Console.ReadLine());
  89.                     Console.Write("Введите третью оценку студента: ");
  90.                     c = int.Parse(Console.ReadLine());
  91.                     Console.Write("Введите четвёртую оценку студента: ");
  92.                     d = int.Parse(Console.ReadLine());
  93.                     Student student = new Student(a, b, c, d);
  94.                     student.Score();
  95.                     break;
  96.                 default:
  97.                     Console.WriteLine("Ошибка!");
  98.                     break;
  99.             }
  100.             Console.ReadKey();
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement