Advertisement
Guest User

trains

a guest
Dec 6th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.26 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 = 3;
  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 string station_out;
  52. public string station_in;
  53. public int time_out;
  54. public train (string stat_out, string 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 time;
  61. public string stan_out;
  62. int num_stat_out;
  63. public string stan_in;
  64. int num_stat_in;
  65. public vagon v;
  66.  
  67. public passanger(station[] st){
  68. stations = st;
  69. stan_out = get_station_out();
  70. stan_in = get_station_in();
  71. time = get_time();
  72. if(time != -1)
  73. {
  74. v = get_vagon();
  75. Console.WriteLine("FDfFSFSDFDSF");
  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. break;
  165. }
  166. }
  167. return va;
  168. }
  169.  
  170. public int get_time()
  171. {
  172. int t = -1;
  173. Console.WriteLine();
  174. Console.WriteLine("Введите время(число) из ниже указанных");
  175. bool ok = false;
  176. for(int i = 0; i < stations.Length; i++)
  177. for(int j = 0; j < stations[i].trains.Length; j++)
  178. {
  179. if(stations[i].trains[j].station_out == stan_out && stations[i].trains[j].station_in == stan_in)
  180. {
  181. Console.WriteLine(stations[i].trains[j].time_out);
  182. ok = true;
  183. }
  184. }
  185. if(!ok)
  186. {
  187. Console.WriteLine("Уходите. Нет таких поездов. Досвидос :D");
  188. return -1;
  189. }
  190. else
  191. {
  192. try
  193. {
  194. t = Convert.ToInt32(Console.ReadLine());
  195. }
  196. catch(Exception e)
  197. {
  198. t = get_time();
  199. }
  200. return t;
  201. }
  202. }
  203.  
  204. public string get_station_out()
  205. {
  206. bool ok = false;
  207. string s = "";
  208. Console.WriteLine("Выберите из списка желаемую станцию отправления");
  209. for(int i = 0; i < stations.Length; i++)
  210. Console.WriteLine(stations[i].Name);
  211. Console.WriteLine("-------------");
  212. while(!ok)
  213. {
  214. s = Console.ReadLine();
  215. for(int i = 0; i < stations.Length; i++)
  216. if(s == stations[i].Name)
  217. {
  218. num_stat_out = i;
  219. ok = true;
  220. break;
  221. }
  222. }
  223. return s;
  224. }
  225.  
  226. public string get_station_in()
  227. {
  228. bool ok = false;
  229. string s = "";
  230. Console.WriteLine("Выберите из списка желаемую станцию прибытия");
  231. for(int i = 0; i < stations.Length; i++)
  232. Console.WriteLine(stations[i].Name);
  233. Console.WriteLine("-------------");
  234. while(!ok)
  235. {
  236. s = Console.ReadLine();
  237. for(int i = 0; i < stations.Length; i++)
  238. if(s == stations[i].Name)
  239. {
  240. num_stat_in = i;
  241. ok = true;
  242. break;
  243. }
  244. }
  245. return s;
  246. }
  247.  
  248. public double distance(int i, int j)
  249. {
  250. station s1 = stations[i];
  251. station s2 = stations[j];
  252. return Math.Sqrt((s1.X - s2.X) * (s1.X - s2.X) + (s1.Y - s2.Y) * (s1.Y - s2.Y));
  253. }
  254. }
  255.  
  256. class Program
  257. {
  258. static void Main(string[] args)
  259. {
  260. station[] stations = new station[5];
  261. train[] trains = new train[4];
  262. vagon[] vagons = new vagon[3];
  263. vagons[0] = new s_vagon();
  264. vagons[1] = new p_vagon("купе", true, false);
  265. vagons[2] = new p_vagon("плацкарт", true, true);
  266. /*for(int i = 0; i < trains.Length; i++)
  267. {
  268. int j = i + 1;
  269. string s = "station " + i;
  270. string t = "station " + j;
  271. trains[i] = new train(s, t, i * 10, vagons, i * 13);
  272. }*/
  273. for(int i = 0; i < stations.Length; i++)
  274. {
  275. for(int ii = 0; ii < trains.Length; ii++)
  276. {
  277. int jj = ii + 1;
  278. string ss = "station " + ii;
  279. string tt = "station " + jj;
  280. trains[ii] = new train(ss, tt, i * 10, vagons, ii * 13 + i * 11);
  281. }
  282. int j = 4 - i;
  283. string s = "station " + j;
  284. stations[i] = new station(s, i * j * i, j * j * j * i * i * i * i, trains);
  285. }
  286. while(true)
  287. {
  288. Console.WriteLine("Начало покупки");
  289. Console.WriteLine("Нажмите ctrl+c или крестик, чтобы завершить работу программы");
  290. passanger ps = new passanger(stations);
  291. }
  292. }
  293.  
  294. }
  295.  
  296. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement