Vladislav_Bezruk

Untitled

Apr 8th, 2022
1,202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.69 KB | None | 0 0
  1. /*
  2. Створити абстрактний клас «літак» і похідні від нього «винищувач» та
  3. «пасажирський лайнер». Функції введення та виведення даних в базовому класі
  4. зробити абстрактними і визначити їх конкретно в похідних класах.
  5. Продемонструвати їхню роботу.
  6. */
  7. /*
  8.  * Created by SharpDevelop.
  9.  * User: vladyslavbezruk
  10.  * Date: 08.04.2022
  11.  * Time: 23:21
  12.  *
  13.  * To change this template use Tools | Options | Coding | Edit Standard Headers.
  14.  */
  15. using System;
  16.  
  17. namespace lab_1
  18. {
  19.     abstract class Plane
  20.     {
  21.         protected double max_speed;
  22.        
  23.         protected Plane()
  24.         {
  25.             max_speed = 0;
  26.         }
  27.        
  28.         public abstract void input();
  29.        
  30.         public abstract void output();
  31.     }
  32.    
  33.     class Fighter_aircraft : Plane
  34.     {
  35.         private double rockets_count;
  36.        
  37.         public Fighter_aircraft() : base()
  38.         {
  39.             rockets_count = 0;
  40.         }
  41.        
  42.         public override void input()
  43.         {
  44.             Console.WriteLine("Enter info about fighter aircraft:");
  45.             Console.WriteLine("max speed:");
  46.             max_speed = Convert.ToDouble(Console.ReadLine());
  47.             Console.WriteLine("rockets count:");
  48.             rockets_count = Convert.ToDouble(Console.ReadLine());
  49.             Console.Write("\n");
  50.         }
  51.        
  52.         public override void output()
  53.         {
  54.             Console.WriteLine("Info about fighter aircraft:");
  55.             Console.WriteLine("max speed: {0}", max_speed);
  56.             Console.WriteLine("rockets count: {0}", rockets_count);
  57.             Console.Write("\n");
  58.         }
  59.     }
  60.    
  61.     class Passenger_liner : Plane
  62.     {
  63.         private int passengers_count;
  64.        
  65.         public Passenger_liner() : base()
  66.         {
  67.             passengers_count = 0;
  68.         }
  69.        
  70.         public override void input()
  71.         {
  72.             Console.WriteLine("Enter info about passenger liner:");
  73.             Console.WriteLine("max speed:");
  74.             max_speed = Convert.ToDouble(Console.ReadLine());
  75.             Console.WriteLine("passengers count:");
  76.             passengers_count = Convert.ToInt32(Console.ReadLine());
  77.             Console.Write("\n");
  78.         }
  79.        
  80.         public override void output()
  81.         {
  82.             Console.WriteLine("Info about passenger liner:");
  83.             Console.WriteLine("max speed: {0}", max_speed);
  84.             Console.WriteLine("passengers count: {0}", passengers_count);
  85.             Console.Write("\n");
  86.         }
  87.     }
  88.    
  89.     class Program
  90.     {
  91.         public static void Main(string[] args)
  92.         {
  93.             Plane fighter_aircraft = new Fighter_aircraft();
  94.             Plane passenger_liner = new Passenger_liner();
  95.            
  96.             fighter_aircraft.input();
  97.             fighter_aircraft.output();
  98.            
  99.             passenger_liner.input();
  100.             passenger_liner.output();
  101.            
  102.             // TODO: Implement Functionality Here
  103.            
  104.             Console.Write("Press any key to continue . . . ");
  105.             Console.ReadKey(true);
  106.         }
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment