Advertisement
Vladislav_Bezruk

Untitled

Apr 7th, 2022
1,080
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.79 KB | None | 0 0
  1. /*
  2. Про любий корабель потрібно знати: ім’я, призначення, водотонажність, потужність
  3. двигуна, вид палива.
  4. Про авіаносець додатково треба знати які літаки і в якій кількості він несе. А про
  5. ракетоносець треба крім загальних даних знати тип ракет та їхню кількість.
  6. Описати базовий та похідні від нього класи. Продемонструвати роботу механізму
  7. наслідування.
  8. */
  9. /*
  10.  * Created by SharpDevelop.
  11.  * User: vladyslavbezruk
  12.  * Date: 07.04.2022
  13.  * Time: 18:48
  14.  *
  15.  * To change this template use Tools | Options | Coding | Edit Standard Headers.
  16.  */
  17. using System;
  18.  
  19. namespace task_1
  20. {
  21.     class Ship
  22.     {
  23.         protected string name;
  24.         protected string appointment;
  25.         protected double capacity;
  26.         protected double power;
  27.         protected string fuel_type;
  28.        
  29.         public Ship()
  30.         {
  31.             name        = "None";
  32.             appointment = "None";
  33.             capacity    = 0;
  34.             power       = 0;
  35.             fuel_type   = "None";
  36.         }
  37.        
  38.         public Ship(string name, string appointment, double capacity, double power, string fuel_type)
  39.         {
  40.             this.name           = name;
  41.             this.appointment    = appointment;
  42.             this.capacity       = capacity;
  43.             this.power          = power;
  44.             this.fuel_type      = fuel_type;
  45.         }
  46.        
  47.         public void input(bool flag = false)
  48.         {
  49.             if (flag == false)
  50.             {
  51.                 Console.WriteLine("Enter info about ship:");
  52.             }
  53.             Console.WriteLine("name:");
  54.             name = Console.ReadLine();
  55.             Console.WriteLine("appointment:");
  56.             appointment = Console.ReadLine();
  57.             Console.WriteLine("capacity:");
  58.             capacity = Convert.ToDouble(Console.ReadLine());
  59.             Console.WriteLine("power:");
  60.             power = Convert.ToDouble(Console.ReadLine());
  61.             Console.WriteLine("fuel type:");
  62.             fuel_type = Console.ReadLine();
  63.         }
  64.        
  65.         public void output(bool flag = false)
  66.         {
  67.             if (flag == false)
  68.             {
  69.                 Console.WriteLine("Info about ship:");
  70.             }
  71.             Console.WriteLine("name: " + name);
  72.             Console.WriteLine("appointment:" + appointment);
  73.             Console.WriteLine("capacity: {0}", capacity);
  74.             Console.WriteLine("power: {0}", power);
  75.             Console.WriteLine("fuel type: " + fuel_type);
  76.         }  
  77.     }
  78.    
  79.     class Aircraft_carrier : Ship
  80.     {
  81.         private int plane_count;
  82.         private string plane_type;
  83.        
  84.         public Aircraft_carrier() : base()
  85.         {
  86.             plane_count = 0;
  87.             plane_type = "None";   
  88.         }
  89.        
  90.         public Aircraft_carrier(string name, string appointment, double capacity, double power, string fuel_type, int plane_count, string plane_type) : base(name, appointment, capacity, power, fuel_type)
  91.         {
  92.             this.plane_count    = plane_count;
  93.             this.plane_type     = plane_type;
  94.         }
  95.        
  96.         public void input()
  97.         {
  98.             Console.WriteLine("Enter info about aircraft carrier:");
  99.             base.input(true);
  100.             Console.WriteLine("plane count:");
  101.             plane_count = Convert.ToInt32(Console.ReadLine());
  102.             Console.WriteLine("plane type:");
  103.             plane_type = Console.ReadLine();
  104.         }
  105.        
  106.         public void output()
  107.         {
  108.             Console.WriteLine("Info about aircraft carrier:");
  109.             base.output(true);
  110.             Console.WriteLine("plane count: {0}", plane_count);
  111.             Console.WriteLine("plane type: " + plane_type);
  112.         }
  113.     }
  114.    
  115.     class Rocket_carrier : Ship
  116.     {
  117.         private int rocket_count;
  118.         private string rocket_type;
  119.        
  120.         public Rocket_carrier() : base()
  121.         {
  122.             rocket_count = 0;
  123.             rocket_type = "None";  
  124.         }
  125.        
  126.         public Rocket_carrier(string name, string appointment, double capacity, double power, string fuel_type, int rocket_count, string rocket_type) : base(name, appointment, capacity, power, fuel_type)
  127.         {
  128.             this.rocket_count   = rocket_count;
  129.             this.rocket_type    = rocket_type;
  130.         }
  131.        
  132.         public void input()
  133.         {
  134.             Console.WriteLine("Enter info about rocket carrier:");
  135.             base.input(true);
  136.             Console.WriteLine("rocket count:");
  137.             rocket_count = Convert.ToInt32(Console.ReadLine());
  138.             Console.WriteLine("rocket type:");
  139.             rocket_type = Console.ReadLine();
  140.         }
  141.        
  142.         public void output()
  143.         {
  144.             Console.WriteLine("Info about rocket carrier:");
  145.             base.output(true);
  146.             Console.WriteLine("rocket count: {0}", rocket_count);
  147.             Console.WriteLine("rocket type: " + rocket_type);
  148.         }
  149.     }
  150.    
  151.     class Program
  152.     {
  153.         public static void Main(string[] args)
  154.         {
  155.             Ship ship = new Ship();
  156.             Aircraft_carrier aircraft_carrier = new Aircraft_carrier();
  157.             Rocket_carrier rocket_carrier = new Rocket_carrier();
  158.            
  159.             ship.input();
  160.             ship.output();
  161.            
  162.             aircraft_carrier.input();
  163.             aircraft_carrier.output();
  164.            
  165.             rocket_carrier.input();
  166.             rocket_carrier.output();
  167.            
  168.             // TODO: Implement Functionality Here
  169.            
  170.             Console.Write("Press any key to continue . . . ");
  171.             Console.ReadKey(true);
  172.         }
  173.     }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement