Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Про любий корабель потрібно знати: ім’я, призначення, водотонажність, потужність
- двигуна, вид палива.
- Про авіаносець додатково треба знати які літаки і в якій кількості він несе. А про
- ракетоносець треба крім загальних даних знати тип ракет та їхню кількість.
- Описати базовий та похідні від нього класи. Продемонструвати роботу механізму
- наслідування.
- */
- /*
- * Created by SharpDevelop.
- * User: vladyslavbezruk
- * Date: 07.04.2022
- * Time: 18:48
- *
- * To change this template use Tools | Options | Coding | Edit Standard Headers.
- */
- using System;
- namespace task_1
- {
- class Ship
- {
- protected string name;
- protected string appointment;
- protected double capacity;
- protected double power;
- protected string fuel_type;
- public Ship()
- {
- name = "None";
- appointment = "None";
- capacity = 0;
- power = 0;
- fuel_type = "None";
- }
- public Ship(string name, string appointment, double capacity, double power, string fuel_type)
- {
- this.name = name;
- this.appointment = appointment;
- this.capacity = capacity;
- this.power = power;
- this.fuel_type = fuel_type;
- }
- public void input(bool flag = false)
- {
- if (flag == false)
- {
- Console.WriteLine("Enter info about ship:");
- }
- Console.WriteLine("name:");
- name = Console.ReadLine();
- Console.WriteLine("appointment:");
- appointment = Console.ReadLine();
- Console.WriteLine("capacity:");
- capacity = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("power:");
- power = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("fuel type:");
- fuel_type = Console.ReadLine();
- }
- public void output(bool flag = false)
- {
- if (flag == false)
- {
- Console.WriteLine("Info about ship:");
- }
- Console.WriteLine("name: " + name);
- Console.WriteLine("appointment:" + appointment);
- Console.WriteLine("capacity: {0}", capacity);
- Console.WriteLine("power: {0}", power);
- Console.WriteLine("fuel type: " + fuel_type);
- }
- }
- class Aircraft_carrier : Ship
- {
- private int plane_count;
- private string plane_type;
- public Aircraft_carrier() : base()
- {
- plane_count = 0;
- plane_type = "None";
- }
- 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)
- {
- this.plane_count = plane_count;
- this.plane_type = plane_type;
- }
- public void input()
- {
- Console.WriteLine("Enter info about aircraft carrier:");
- base.input(true);
- Console.WriteLine("plane count:");
- plane_count = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("plane type:");
- plane_type = Console.ReadLine();
- }
- public void output()
- {
- Console.WriteLine("Info about aircraft carrier:");
- base.output(true);
- Console.WriteLine("plane count: {0}", plane_count);
- Console.WriteLine("plane type: " + plane_type);
- }
- }
- class Rocket_carrier : Ship
- {
- private int rocket_count;
- private string rocket_type;
- public Rocket_carrier() : base()
- {
- rocket_count = 0;
- rocket_type = "None";
- }
- 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)
- {
- this.rocket_count = rocket_count;
- this.rocket_type = rocket_type;
- }
- public void input()
- {
- Console.WriteLine("Enter info about rocket carrier:");
- base.input(true);
- Console.WriteLine("rocket count:");
- rocket_count = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("rocket type:");
- rocket_type = Console.ReadLine();
- }
- public void output()
- {
- Console.WriteLine("Info about rocket carrier:");
- base.output(true);
- Console.WriteLine("rocket count: {0}", rocket_count);
- Console.WriteLine("rocket type: " + rocket_type);
- }
- }
- class Program
- {
- public static void Main(string[] args)
- {
- Ship ship = new Ship();
- Aircraft_carrier aircraft_carrier = new Aircraft_carrier();
- Rocket_carrier rocket_carrier = new Rocket_carrier();
- ship.input();
- ship.output();
- aircraft_carrier.input();
- aircraft_carrier.output();
- rocket_carrier.input();
- rocket_carrier.output();
- // TODO: Implement Functionality Here
- Console.Write("Press any key to continue . . . ");
- Console.ReadKey(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement