zed_com

pract11

Nov 15th, 2016
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.20 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. namespace C
  4. {
  5.     class Program
  6.     {
  7.         class bus
  8.         {
  9.             string mark;
  10.             int cout_pas;
  11.             double speed_max;
  12.             double cost;
  13.             public void input(string m, int c, double s, double co)
  14.             {
  15.                 mark = m;
  16.                 cout_pas = c;
  17.                 speed_max = s;
  18.                 cost = co;
  19.             }
  20.             public void input()
  21.             {
  22.                 Console.Write("Марка:");
  23.                 mark = Console.ReadLine();
  24.                 Console.Write("Количество пассажиров:");
  25.                 cout_pas = Convert.ToInt32(Console.ReadLine());
  26.                 Console.Write("Максимальная скорость:");
  27.                 speed_max = Convert.ToDouble(Console.ReadLine());
  28.                 Console.Write("Цена:");
  29.                 cost = Convert.ToDouble(Console.ReadLine());
  30.             }
  31.             public void output()
  32.             {
  33.                 Console.WriteLine("Марка:{0}   кол.мес:{1}   мак.скор:{2}   цена:{3}", mark, cout_pas, speed_max, cost);
  34.             }
  35.             public void output (int b)
  36.             {
  37.                 Console.WriteLine("Марка[{4}]:{0}   кол.мес[{4}]:{1}   мак.скор[{4}]:{2}   цена[{4}]:{3}", mark, cout_pas, speed_max, cost, b);
  38.             }
  39.             public static bus operator +(bus a, bus b)
  40.             {
  41.                 bus v = new bus();
  42.                 v.mark = a.mark + b.mark;
  43.                 v.cout_pas = a.cout_pas + b.cout_pas;
  44.                 v.speed_max = a.speed_max + b.speed_max;
  45.                 v.cost = a.cost + b.cost;
  46.                 return v;
  47.             }
  48.             public static bus operator +(bus a)
  49.             {
  50.                 bus v = new bus();
  51.                 a.mark += a.mark;
  52.                 a.cout_pas += a.cout_pas;
  53.                 a.speed_max += a.speed_max;
  54.                 a.cost += a.cost;
  55.                 return a;
  56.             }
  57.             public static bool operator ==(bus a, bus b)
  58.             {
  59.                 if (a.mark == b.mark && a.cout_pas == b.cout_pas && a.speed_max == b.speed_max && a.cost == b.cost)
  60.                     return true;
  61.                 else
  62.                     return false;
  63.             }
  64.             public static bool operator !=(bus a, bus b)
  65.             {
  66.                 if (a.mark != b.mark && a.cout_pas != b.cout_pas && a.speed_max != b.speed_max && a.cost != b.cost)
  67.                     return true;
  68.                 else
  69.                     return false;
  70.             }
  71.             public static bool operator >=(bus a, bus b)
  72.             {
  73.                 if (a.cout_pas >= b.cout_pas && a.speed_max >= b.speed_max && a.cost >= b.cost)
  74.                     return true;
  75.                 else
  76.                     return false;
  77.             }
  78.             public static bool operator <=(bus a, bus b)
  79.             {
  80.                 if (a.cout_pas <= b.cout_pas && a.speed_max <= b.speed_max && a.cost <= b.cost)
  81.                     return true;
  82.                 else
  83.                     return false;
  84.             }
  85.  
  86.         }
  87.         static void Main(string[] args)
  88.         {
  89.             string[] bus_mark = { "Lolol", "Tesla", "Prost", "Supra", "Apach", "Mazda", "Audig" };
  90.             int[] bus_count_per = { 100, 200, 300, 35, 40, 50, 10, 20, 15, 5 };
  91.             double[] bus_speed_max = { 105.6, 120, 320, 650, 152.7, 250, 175.4, 152.3 };
  92.             double[] bus_cost = { 3000, 2000.50, 356.25, 2541, 150.60, 20863.58 };
  93.             int n, j = 0;
  94.             Console.Write("Количестов элементов:");
  95.             n = Convert.ToInt32(Console.ReadLine());
  96.             Random r = new Random();
  97.             bus[] b = new bus[n];
  98.             bus g = new bus();
  99.             for (int i = 0; i < n; i++)
  100.             {
  101.                 b[i] = new bus();
  102.                 b[i].input(bus_mark[r.Next(0, bus_cost.Length)], bus_count_per[r.Next(0, bus_count_per.Length)], bus_speed_max[r.Next(0, bus_speed_max.Length)], bus_cost[r.Next(0, bus_cost.Length)]);
  103.             }
  104.             for (int i = 0; i < n; i++)
  105.                 b[i].output(i);
  106.             Console.WriteLine("=============================================================================");
  107.             for (int i = 0; i < n; i++, Console.WriteLine())
  108.             {
  109.                 if (i + 1 != n)
  110.                 {
  111.                     if (b[i] >= b[i + 1])
  112.                         Console.Write("b[{0}] >= b[{1}]", i, i + 1);
  113.                     else
  114.                         Console.Write("b[{0}] <= b[{1}]", i, i + 1);
  115.                     if (b[i] == b[i + 1])
  116.                     {
  117.                         Console.Write("    b[{0}] == b[{1}]", i, i + 1);
  118.                         j = i;
  119.                     }
  120.                        
  121.                     else
  122.                         Console.Write("    b[{0}] != b[{1}]", i, i + 1);
  123.                 }
  124.             }
  125.             g = b[0] + b[1];
  126.             g.output();
  127.             g += b[0];
  128.             g.output();
  129.             Console.WriteLine("одинаковые значения в {0}", j);
  130.             Console.ReadKey();
  131.         }
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment