Advertisement
Guest User

sfsd

a guest
Dec 6th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Globalization;
  6.  
  7. namespace КР_Шпилев
  8. {
  9. public abstract class vagon {
  10. public int bileti = 10;
  11. public int price = 0;
  12. public string typesp;
  13. }
  14. public class s_vagon : vagon{
  15.  
  16. public s_vagon () {typesp = "служебный"; price = 13;}
  17. }
  18. public class p_vagon : vagon {
  19. public string type;
  20. public bool tv;
  21. public bool sv;
  22. public p_vagon (string typ, bool tv, bool sv) {
  23. typesp = "пассажирский";
  24. type = typ;
  25. this.sv = sv;
  26. this.tv = tv;
  27. if(tv)
  28. price += 99;
  29. if(sv)
  30. price += 34;
  31. if(type == "купе")
  32. price += 1000;
  33. else if(type == "плацкарт")
  34. price += 700;
  35. else if(type == "сидячий")
  36. price += 499;
  37. }
  38. }
  39.  
  40. public class station{
  41. public string Name;
  42. public int X;
  43. public int Y;
  44. public train[] trains;
  45. public station (string Name, int x, int y, train[] t) {this.Name = Name; X = x; Y = y; trains = t;}
  46. }
  47.  
  48. public class train{
  49. public int Number;
  50. public vagon[] v;
  51. public station station_out;
  52. public station station_in;
  53. public int time_out;
  54. public train (station stat_out, station stat_in, int Number, vagon[] v, int time_out)
  55. {station_out = stat_out; station_in = stat_in; this.v = v; this.time_out = time_out;}
  56. }
  57.  
  58. public class passanger {
  59. public station[] stations;
  60. //public int num;
  61. public int time;
  62. public string stan_out;
  63. int num_stat_out;
  64. public string stan_in;
  65. int num_stat_in;
  66. public vagon v;
  67.  
  68. public passanger(station[] st){
  69. stations = st;
  70. stan_out = get_station_out();
  71. stan_in = get_station_in();
  72. time = get_time();
  73. if(time != -1)
  74. {
  75. v = get_vagon();
  76. help();
  77. while(true)
  78. {
  79. string s = Console.ReadLine();
  80. if(s == "цена")
  81. Console.WriteLine(price());
  82. if(s == "билеты")
  83. Console.WriteLine(bilet());
  84. if(s == "купить")
  85. buy();
  86. if(s == "конец")
  87. break;
  88. }
  89. }
  90.  
  91. }
  92. public int bilet()
  93. {
  94. return v.bileti;
  95. }
  96. public int price()
  97. {
  98. return v.price + Convert.ToInt32(distance(num_stat_out, num_stat_in))*3;
  99. }
  100.  
  101. public void help()
  102. {
  103. Console.WriteLine("Введите (цена) чтобы посчитать цену билета");
  104. Console.WriteLine("Введите (билеты) чтобы посмотреть их наличие на данный поезд !!!пока не работает!!!");
  105. Console.WriteLine("Введите (купить) чтобы купить билет");
  106. Console.WriteLine("Введите (конец), чтобы завершить сеанс");
  107. }
  108.  
  109. public void buy()
  110. {
  111. if(v.bileti > 0)
  112. v.bileti -= 1;
  113. else
  114. Console.WriteLine("Билетов больше нет!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!)))");
  115. }
  116. public vagon get_vagon()
  117. {
  118. vagon va;
  119. Console.WriteLine("Укажите тип вагона(пассажирский или служебный)");
  120. while(true)
  121. {
  122. string s = Console.ReadLine();
  123. if(s == "служебный")
  124. {
  125. va = new s_vagon();
  126. break;
  127. } else if(s == "пассажирский")
  128. {
  129. string type;
  130. Console.WriteLine("Введите тип вагона(сидячий, плацкарт, купе)");
  131. while(true)
  132. {
  133. type = Console.ReadLine();
  134. if(type == "сидячий" || type == "плацкарт" || type == "купе")
  135. break;
  136. }
  137.  
  138. bool sv = false;
  139. bool tv = false;
  140. Console.WriteLine("Желаете ли вы воспользоваться связью?(да, нет)");
  141. string svz = Console.ReadLine();
  142. while(true)
  143. {
  144. if(svz == "да")
  145. {
  146. sv = true;
  147. break;
  148. } else if(svz == "нет")
  149. break;
  150. }
  151. Console.WriteLine("Желаете ли вы воспользоваться телевизором?(да, нет)");
  152. string tvz = Console.ReadLine();
  153. while(true)
  154. {
  155. if(tvz == "да")
  156. {
  157. tv = true;
  158. break;
  159. }
  160. else if(tvz == "нет")
  161. break;
  162. }
  163. va = new p_vagon(type, tv, sv);
  164. }
  165. }
  166. return va;
  167. }
  168.  
  169. public int get_time()
  170. {
  171. int t = -1;
  172. Console.WriteLine();
  173. Console.WriteLine("Введите время(число) из ниже указанных");
  174. bool ok = false;
  175. for(int i = 0; i < stations.Length; i++)
  176. for(int j = 0; j < stations[i].trains.Length; j++)
  177. {
  178. if(stations[i].trains[j].station_out.Name == stan_out && stations[i].trains[j].station_in.Name == stan_in)
  179. {
  180. Console.WriteLine(stations[i].trains[j].time_out);
  181. ok = true;
  182. }
  183. }
  184. if(!ok)
  185. {
  186. Console.WriteLine("Уходите. Нет таких поездов. Досвидос :D");
  187. return -1;
  188. }
  189. else
  190. {
  191. try
  192. {
  193. t = Convert.ToInt32(Console.ReadLine());
  194. }
  195. catch(Exception e)
  196. {
  197. t = get_time();
  198. }
  199. return t;
  200. }
  201. }
  202.  
  203. public string get_station_out()
  204. {
  205. bool ok = false;
  206. string s = "";
  207. Console.WriteLine("Выберите из списка желаемую станцию отправления");
  208. for(int i = 0; i < stations.Length; i++)
  209. Console.WriteLine(stations[i].Name);
  210. Console.WriteLine("-------------");
  211. while(!ok)
  212. {
  213. s = Console.ReadLine();
  214. for(int i = 0; i < stations.Length; i++)
  215. if(s == stations[i].Name)
  216. {
  217. num_stat_out = i;
  218. ok = true;
  219. break;
  220. }
  221. }
  222. return s;
  223. }
  224.  
  225. public string get_station_in()
  226. {
  227. bool ok = false;
  228. string s = "";
  229. Console.WriteLine("Выберите из списка желаемую станцию прибытия");
  230. for(int i = 0; i < stations.Length; i++)
  231. Console.WriteLine(stations[i].Name);
  232. Console.WriteLine("-------------");
  233. while(!ok)
  234. {
  235. s = Console.ReadLine();
  236. for(int i = 0; i < stations.Length; i++)
  237. if(s == stations[i].Name)
  238. {
  239. num_stat_in = i;
  240. ok = true;
  241. break;
  242. }
  243. }
  244. return s;
  245. }
  246.  
  247. public double distance(int i, int j)
  248. {
  249. station s1 = stations[i];
  250. station s2 = stations[j];
  251. return Math.Sqrt((s1.X - s2.X) * (s1.X - s2.X) + (s1.Y - s2.Y) * (s1.Y - s2.Y));
  252. }
  253. }
  254.  
  255. class Program
  256. {
  257. static void Main(string[] args)
  258. {
  259. /*for (int i = 1, i <= 10, i++);{
  260. train [i] = new train {9*i,
  261. station[i] = new station{"station"+i, i*20,i*35-253};
  262. }*/
  263.  
  264. while(true)
  265. {
  266. Console.WriteLine("Начало покупки");
  267. Console.WriteLine("Нажмите ctrl+c или крестик, чтобы завершить работу программы");
  268. passanger ps = new passanger(stations);
  269. }
  270. }
  271.  
  272. }
  273.  
  274. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement