Advertisement
zed_com

Pract_6(2)

Oct 16th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.99 KB | None | 0 0
  1. using System;
  2. namespace car_shop
  3. {
  4.     class car
  5.     {
  6.         string brand;
  7.         double capacity;
  8.         double price;
  9.         double maxspeed;
  10.         int attribute;
  11.  
  12.         public void input(int n)
  13.         {
  14.             string s;
  15.             double b, d;
  16.  
  17.             Console.WriteLine("Enter brand of  {0} car", n + 1);
  18.             brand = Console.ReadLine();
  19.             Console.WriteLine("Enter it is capacity");
  20.             s = Console.ReadLine();
  21.             capacity = Convert.ToDouble(s);
  22.             Console.WriteLine("Enter it is price");
  23.             b = Convert.ToInt32(Console.ReadLine());
  24.             price = Convert.ToDouble(b);
  25.             Console.WriteLine("Enter it is maxspeed");
  26.             d = Convert.ToInt32(Console.ReadLine());
  27.             maxspeed = Convert.ToDouble(d);
  28.         }
  29.         public void analyses(ref double desire_price, ref double desire_capacity, ref double desire_maxspeed)
  30.         {
  31.             if (price <= desire_price && capacity <= desire_capacity && maxspeed <= desire_maxspeed)
  32.                 attribute = 1;
  33.         }
  34.         public void output(int n)
  35.         {
  36.             if (attribute != 0)
  37.             {
  38.                 Console.WriteLine("The car number {0} is suitable for you:", n + 1);
  39.                 Console.WriteLine("brand is '{0}' price is {1} capacity is {2} maxspeed is {3}", brand, price, capacity, maxspeed);
  40.             }
  41.             else
  42.                 Console.WriteLine("The {0} car is it not suitable for you ", n + 1);
  43.         }
  44.     }
  45.  
  46.     class Program
  47.     {
  48.         public static void Main(string[] args)
  49.         {
  50.             string s;
  51.             double b, d;
  52.             int count_of_cars;
  53.             Console.WriteLine("Enter count_of_cars");
  54.             s = Console.ReadLine();
  55.             count_of_cars = Convert.ToInt32(s);
  56.             car[] q = new car[count_of_cars];
  57.             for (int i = 0; i < q.Length; i++)
  58.             {
  59.                 q[i] = new car();
  60.                 q[i].input(i);
  61.             }
  62.             double desire_price;
  63.             double desire_capacity;
  64.             double desire_maxspeed;
  65.             Console.WriteLine("=========:Filter:=========");
  66.             Console.WriteLine("Enter desire capacity");
  67.             s = Console.ReadLine();
  68.             desire_capacity = Convert.ToDouble(s);
  69.             Console.WriteLine("Enter desire price");
  70.             b = Convert.ToInt32(Console.ReadLine());
  71.             desire_price = Convert.ToDouble(b);
  72.             Console.WriteLine("Enter desire maxspeed");
  73.             d = Convert.ToInt32(Console.ReadLine());
  74.             desire_maxspeed = Convert.ToDouble(d);
  75.             for (int i = 0; i<q.Length;i++)
  76.             {
  77.                 q[i].analyses(ref desire_capacity, ref desire_price, ref desire_maxspeed );
  78.                 q[i].output(i);
  79.  
  80.             }
  81.             Console.WriteLine("Finish");
  82.             Console.Write("Press any key to continue  .  .  .");
  83.             Console.ReadKey(true);
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement