Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Визначити базовий клас «транспорт» і похідні від нього класи «вантажний
- транспорт» та «пасажирський транспорт». Загальним для них є «чистий
- прибуток».
- Елементами даних похідних класів та методами задатися САМОСТІЙНО! Хоча б
- один із методів повинен бути віртуальним.
- */
- /*
- * Created by SharpDevelop.
- * User: vladyslavbezruk
- * Date: 08.04.2022
- * Time: 17:30
- *
- * To change this template use Tools | Options | Coding | Edit Standard Headers.
- */
- using System;
- namespace task_1
- {
- class Transport
- {
- protected double max_speed;
- protected double hourly_profit;
- public Transport()
- {
- max_speed = 0;
- hourly_profit = 0;
- }
- public Transport(double max_speed, double hourly_profit)
- {
- this.max_speed = max_speed;
- this.hourly_profit = hourly_profit;
- }
- public virtual void input()
- {
- Console.WriteLine("Enter info about transport:");
- Console.WriteLine("max speed:");
- max_speed = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("hourly profit:");
- hourly_profit = Convert.ToDouble(Console.ReadLine());
- Console.Write('\n');
- }
- public virtual void output()
- {
- Console.WriteLine("Info about transport:");
- Console.WriteLine("max speed: {0}", max_speed);
- Console.WriteLine("hourly profit: {0}", hourly_profit);
- Console.Write('\n');
- }
- public virtual void calc_profit()
- {
- Console.WriteLine("There is no profit in casual transport");
- Console.Write('\n');
- }
- }
- class Freight_transport : Transport
- {
- private double max_mas_cargo;
- public Freight_transport() : base()
- {
- max_mas_cargo = 0;
- }
- public Freight_transport(double max_speed, double hourly_profit, double max_mas_cargo) : base(max_speed, hourly_profit)
- {
- this.max_mas_cargo = max_mas_cargo;
- }
- public virtual void input()
- {
- Console.WriteLine("Enter info about freight transport:");
- Console.WriteLine("max speed:");
- max_speed = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("hourly profit:");
- hourly_profit = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("max mas of cargo:");
- max_mas_cargo = Convert.ToDouble(Console.ReadLine());
- Console.Write('\n');
- }
- public virtual void output()
- {
- Console.WriteLine("Info about freight transport:");
- Console.WriteLine("max speed: {0}", max_speed);
- Console.WriteLine("hourly profit: {0}", hourly_profit);
- Console.WriteLine("max mas of cargo: {0}", max_mas_cargo);
- Console.Write('\n');
- }
- public virtual void calc_profit()
- {
- double profit = hourly_profit * 24 * 30 * 1.5;
- Console.WriteLine("Profit on freight transport: {0}", profit);
- Console.Write('\n');
- }
- }
- class Passenger_transport : Transport
- {
- private double count_seats;
- public Passenger_transport() : base()
- {
- count_seats = 0;
- }
- public Passenger_transport(double max_speed, double hourly_profit, double count_seats) : base(max_speed, hourly_profit)
- {
- this.count_seats = count_seats;
- }
- public virtual void input()
- {
- Console.WriteLine("Enter info about passenger transport:");
- Console.WriteLine("max speed:");
- max_speed = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("hourly profit:");
- hourly_profit = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("count seats:");
- count_seats = Convert.ToDouble(Console.ReadLine());
- Console.Write('\n');
- }
- public virtual void output()
- {
- Console.WriteLine("Info about passenger transport:");
- Console.WriteLine("max speed: {0}", max_speed);
- Console.WriteLine("hourly profit: {0}", hourly_profit);
- Console.WriteLine("count seats: {0}", count_seats);
- Console.Write('\n');
- }
- public virtual void calc_profit()
- {
- double profit = hourly_profit * 24 * 30 * 1.25;
- Console.WriteLine("Profit on passenger transport: {0}", profit);
- Console.Write('\n');
- }
- }
- class Program
- {
- public static void Main(string[] args)
- {
- Transport transport = new Transport();
- Freight_transport freight_transport = new Freight_transport();
- Passenger_transport passenger_transport = new Passenger_transport();
- transport.input();
- transport.output();
- transport.calc_profit();
- freight_transport.input();
- freight_transport.output();
- freight_transport.calc_profit();
- passenger_transport.input();
- passenger_transport.output();
- passenger_transport.calc_profit();
- // TODO: Implement Functionality Here
- Console.Write("Press any key to continue . . . ");
- Console.ReadKey(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment