Advertisement
Guest User

Untitled

a guest
Jan 8th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Mashinki
  8. {
  9. abstract class Item
  10. {
  11. protected string name;
  12. protected double price;//с точностью до двух знаков
  13. public double Price
  14. {
  15. get {
  16. if (price >= 0)
  17. {
  18. return price;
  19. }
  20. else throw new ArgumentException();
  21. }
  22. }
  23. public Item(string name1, double price1)
  24. {
  25. name = name1;
  26. price = price1;
  27. }
  28. public Item()
  29. {
  30.  
  31. }
  32.  
  33. }
  34. class Food:Item
  35. {
  36. protected int weight;
  37. protected int Weight{ get { return weight; } }
  38.  
  39. public Food(string name1, double price1, int weight1)
  40. {
  41. name = name1;
  42. price = price1;
  43. weight = weight1;
  44. }
  45. public override string ToString()
  46. {
  47. return name + " " + Price + " " + weight;
  48. }
  49. }
  50. class Drink:Item
  51. {
  52. int volume;
  53. protected int Volume { get { return volume; } }
  54. public Drink(string name1, double price1, int volume1)
  55. {
  56. name = name1;
  57. price = price1;
  58. volume = volume1;
  59.  
  60. }
  61. public override string ToString()
  62. {
  63. return name + " " + Price + " " + Volume;
  64. }
  65. }
  66. class FoodBasket
  67. {
  68. Item[] foodBasket;
  69. int size;
  70. public FoodBasket(int n, Item[] arr)
  71. {
  72. foodBasket = new Item[n];
  73. for (int i = 0; i < n; i++)
  74. {
  75. foodBasket[i] = arr[i];
  76. }
  77. }
  78. public double BasketCost()
  79. {
  80. double m = 0;
  81. for (int i = 0; i < foodBasket.Length; i++)
  82. {
  83. m += foodBasket[i].Price;
  84. }
  85. return m;
  86. }
  87. public Item[] Basket{ get { return foodBasket; } }
  88.  
  89. }
  90. class Program
  91. {
  92. public static Random rnd = new Random();
  93. static string RandomString()
  94. {
  95. string r="";
  96. string n = "qwertyuiopasdfghjklzxcvbnm";
  97. for (int i = 0; i < rnd.Next(n.Length); i++)
  98. {
  99. r += n[rnd.Next(n.Length)];
  100. }
  101. return r;
  102. }
  103. static void Main(string[] args)
  104. {
  105. double maxuser = 0;
  106. FoodBasket[] user = new FoodBasket[rnd.Next(10, 15)];
  107. double[] maxarr = new double[user.Length];
  108. for (int i = 0; i <user.Length ; i++)
  109. {
  110. Item[] arr = new Item[7];
  111. for (int m = 0; m < arr.Length; m++)
  112. {
  113. int r = rnd.Next(9);
  114. if (r <= 3) arr[m] = new Food(RandomString(), rnd.Next(30, 3000), rnd.Next());
  115. else arr[m] = new Drink(RandomString(), rnd.Next(30, 3000), rnd.Next());
  116. if (arr[m].Price > maxarr[i]) maxarr[i] = arr[m].Price;
  117. }
  118. user[i] = new FoodBasket(7, arr);
  119. if (user[i].BasketCost() > maxuser) maxuser = user[i].BasketCost();
  120. }
  121. for (int i = 0; i < user.Length; i++)
  122. {
  123. Console.WriteLine("Корзина #{0}", i);
  124. for (int m = 0; m < 7; m++)
  125. {
  126. Console.WriteLine(user[i].Basket[m].ToString());
  127. }
  128. Console.WriteLine("Самый дорогой в козине:{0}", maxarr[i]);
  129. Console.WriteLine();
  130. }
  131. Console.WriteLine("Самая дорогая корзина:{0}",maxuser);
  132. Console.ReadLine();
  133. }
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement