Vladislav_Bezruk

Untitled

Apr 8th, 2022
1,031
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.82 KB | None | 0 0
  1. /*
  2. Визначити базовий клас «транспорт» і похідні від нього класи «вантажний
  3. транспорт» та «пасажирський транспорт». Загальним для них є «чистий
  4. прибуток».
  5. Елементами даних похідних класів та методами задатися САМОСТІЙНО! Хоча б
  6. один із методів повинен бути віртуальним.
  7. */
  8. /*
  9.  * Created by SharpDevelop.
  10.  * User: vladyslavbezruk
  11.  * Date: 08.04.2022
  12.  * Time: 17:30
  13.  *
  14.  * To change this template use Tools | Options | Coding | Edit Standard Headers.
  15.  */
  16. using System;
  17.  
  18. namespace task_1
  19. {
  20.     class Transport
  21.     {
  22.         protected double max_speed;
  23.         protected double hourly_profit;
  24.        
  25.         public Transport()
  26.         {
  27.             max_speed       = 0;
  28.             hourly_profit   = 0;
  29.         }
  30.        
  31.         public Transport(double max_speed, double hourly_profit)
  32.         {
  33.             this.max_speed      = max_speed;
  34.             this.hourly_profit  = hourly_profit;
  35.         }
  36.        
  37.         public virtual void input()
  38.         {
  39.             Console.WriteLine("Enter info about transport:");
  40.             Console.WriteLine("max speed:");
  41.             max_speed = Convert.ToDouble(Console.ReadLine());
  42.             Console.WriteLine("hourly profit:");
  43.             hourly_profit = Convert.ToDouble(Console.ReadLine());
  44.             Console.Write('\n');
  45.         }
  46.        
  47.         public virtual void output()
  48.         {
  49.             Console.WriteLine("Info about transport:");
  50.             Console.WriteLine("max speed: {0}", max_speed);
  51.             Console.WriteLine("hourly profit: {0}", hourly_profit);
  52.             Console.Write('\n');
  53.         }
  54.        
  55.         public virtual void calc_profit()
  56.         {
  57.             Console.WriteLine("There is no profit in casual transport");
  58.             Console.Write('\n');
  59.         }
  60.     }
  61.    
  62.     class Freight_transport : Transport
  63.     {
  64.         private double max_mas_cargo;
  65.        
  66.         public Freight_transport() : base()
  67.         {
  68.             max_mas_cargo = 0;
  69.         }
  70.        
  71.         public Freight_transport(double max_speed, double hourly_profit, double max_mas_cargo) : base(max_speed, hourly_profit)
  72.         {
  73.             this.max_mas_cargo = max_mas_cargo;
  74.         }
  75.        
  76.         public virtual void input()
  77.         {
  78.             Console.WriteLine("Enter info about freight transport:");
  79.             Console.WriteLine("max speed:");
  80.             max_speed = Convert.ToDouble(Console.ReadLine());
  81.             Console.WriteLine("hourly profit:");
  82.             hourly_profit = Convert.ToDouble(Console.ReadLine());
  83.             Console.WriteLine("max mas of cargo:");
  84.             max_mas_cargo = Convert.ToDouble(Console.ReadLine());
  85.             Console.Write('\n');
  86.         }
  87.        
  88.         public virtual void output()
  89.         {
  90.             Console.WriteLine("Info about freight transport:");
  91.             Console.WriteLine("max speed: {0}", max_speed);
  92.             Console.WriteLine("hourly profit: {0}", hourly_profit);
  93.             Console.WriteLine("max mas of cargo: {0}", max_mas_cargo);
  94.             Console.Write('\n');
  95.         }
  96.        
  97.         public virtual void calc_profit()
  98.         {
  99.             double profit = hourly_profit * 24 * 30 * 1.5;
  100.             Console.WriteLine("Profit on freight transport: {0}", profit);
  101.             Console.Write('\n');
  102.         }
  103.     }
  104.    
  105.     class Passenger_transport : Transport
  106.     {
  107.         private double count_seats;
  108.        
  109.         public Passenger_transport() : base()
  110.         {
  111.             count_seats = 0;
  112.         }
  113.        
  114.         public Passenger_transport(double max_speed, double hourly_profit, double count_seats) : base(max_speed, hourly_profit)
  115.         {
  116.             this.count_seats = count_seats;
  117.         }
  118.        
  119.         public virtual void input()
  120.         {
  121.             Console.WriteLine("Enter info about passenger transport:");
  122.             Console.WriteLine("max speed:");
  123.             max_speed = Convert.ToDouble(Console.ReadLine());
  124.             Console.WriteLine("hourly profit:");
  125.             hourly_profit = Convert.ToDouble(Console.ReadLine());
  126.             Console.WriteLine("count seats:");
  127.             count_seats = Convert.ToDouble(Console.ReadLine());
  128.             Console.Write('\n');
  129.         }
  130.        
  131.         public virtual void output()
  132.         {
  133.             Console.WriteLine("Info about passenger transport:");
  134.             Console.WriteLine("max speed: {0}", max_speed);
  135.             Console.WriteLine("hourly profit: {0}", hourly_profit);
  136.             Console.WriteLine("count seats: {0}", count_seats);
  137.             Console.Write('\n');
  138.         }
  139.        
  140.         public virtual void calc_profit()
  141.         {
  142.             double profit = hourly_profit * 24 * 30 * 1.25;
  143.             Console.WriteLine("Profit on passenger transport: {0}", profit);
  144.             Console.Write('\n');
  145.         }
  146.     }
  147.    
  148.     class Program
  149.     {
  150.         public static void Main(string[] args)
  151.         {
  152.             Transport transport = new Transport();
  153.             Freight_transport freight_transport = new Freight_transport();
  154.             Passenger_transport passenger_transport = new Passenger_transport();
  155.            
  156.             transport.input();
  157.             transport.output();
  158.             transport.calc_profit();
  159.            
  160.             freight_transport.input();
  161.             freight_transport.output();
  162.             freight_transport.calc_profit();
  163.            
  164.             passenger_transport.input();
  165.             passenger_transport.output();
  166.             passenger_transport.calc_profit();
  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