Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Globalization;
- namespace КР_Шпилев
- {
- public abstract class vagon {
- public int bileti = 10;
- public int price = 0;
- public string typesp;
- }
- public class s_vagon : vagon{
- public s_vagon () {typesp = "служебный"; price = 13;}
- }
- public class p_vagon : vagon {
- public string type;
- public bool tv;
- public bool sv;
- public p_vagon (string typ, bool tv, bool sv) {
- typesp = "пассажирский";
- type = typ;
- this.sv = sv;
- this.tv = tv;
- if(tv)
- price += 99;
- if(sv)
- price += 34;
- if(type == "купе")
- price += 1000;
- else if(type == "плацкарт")
- price += 700;
- else if(type == "сидячий")
- price += 499;
- }
- }
- public class station{
- public string Name;
- public int X;
- public int Y;
- public train[] trains;
- public station (string Name, int x, int y, train[] t) {this.Name = Name; X = x; Y = y; trains = t;}
- }
- public class train{
- public int Number;
- public vagon[] v;
- public station station_out;
- public station station_in;
- public int time_out;
- public train (station stat_out, station stat_in, int Number, vagon[] v, int time_out)
- {station_out = stat_out; station_in = stat_in; this.v = v; this.time_out = time_out;}
- }
- public class passanger {
- public station[] stations;
- //public int num;
- public int time;
- public string stan_out;
- int num_stat_out;
- public string stan_in;
- int num_stat_in;
- public vagon v;
- public passanger(station[] st){
- stations = st;
- stan_out = get_station_out();
- stan_in = get_station_in();
- time = get_time();
- if(time != -1)
- {
- v = get_vagon();
- help();
- while(true)
- {
- string s = Console.ReadLine();
- if(s == "цена")
- Console.WriteLine(price());
- if(s == "билеты")
- Console.WriteLine(bilet());
- if(s == "купить")
- buy();
- if(s == "конец")
- break;
- }
- }
- }
- public int bilet()
- {
- return v.bileti;
- }
- public int price()
- {
- return v.price + Convert.ToInt32(distance(num_stat_out, num_stat_in))*3;
- }
- public void help()
- {
- Console.WriteLine("Введите (цена) чтобы посчитать цену билета");
- Console.WriteLine("Введите (билеты) чтобы посмотреть их наличие на данный поезд !!!пока не работает!!!");
- Console.WriteLine("Введите (купить) чтобы купить билет");
- Console.WriteLine("Введите (конец), чтобы завершить сеанс");
- }
- public void buy()
- {
- if(v.bileti > 0)
- v.bileti -= 1;
- else
- Console.WriteLine("Билетов больше нет!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!)))");
- }
- public vagon get_vagon()
- {
- vagon va;
- Console.WriteLine("Укажите тип вагона(пассажирский или служебный)");
- while(true)
- {
- string s = Console.ReadLine();
- if(s == "служебный")
- {
- va = new s_vagon();
- break;
- } else if(s == "пассажирский")
- {
- string type;
- Console.WriteLine("Введите тип вагона(сидячий, плацкарт, купе)");
- while(true)
- {
- type = Console.ReadLine();
- if(type == "сидячий" || type == "плацкарт" || type == "купе")
- break;
- }
- bool sv = false;
- bool tv = false;
- Console.WriteLine("Желаете ли вы воспользоваться связью?(да, нет)");
- string svz = Console.ReadLine();
- while(true)
- {
- if(svz == "да")
- {
- sv = true;
- break;
- } else if(svz == "нет")
- break;
- }
- Console.WriteLine("Желаете ли вы воспользоваться телевизором?(да, нет)");
- string tvz = Console.ReadLine();
- while(true)
- {
- if(tvz == "да")
- {
- tv = true;
- break;
- }
- else if(tvz == "нет")
- break;
- }
- va = new p_vagon(type, tv, sv);
- }
- }
- return va;
- }
- public int get_time()
- {
- int t = -1;
- Console.WriteLine();
- Console.WriteLine("Введите время(число) из ниже указанных");
- bool ok = false;
- for(int i = 0; i < stations.Length; i++)
- for(int j = 0; j < stations[i].trains.Length; j++)
- {
- if(stations[i].trains[j].station_out.Name == stan_out && stations[i].trains[j].station_in.Name == stan_in)
- {
- Console.WriteLine(stations[i].trains[j].time_out);
- ok = true;
- }
- }
- if(!ok)
- {
- Console.WriteLine("Уходите. Нет таких поездов. Досвидос :D");
- return -1;
- }
- else
- {
- try
- {
- t = Convert.ToInt32(Console.ReadLine());
- }
- catch(Exception e)
- {
- t = get_time();
- }
- return t;
- }
- }
- public string get_station_out()
- {
- bool ok = false;
- string s = "";
- Console.WriteLine("Выберите из списка желаемую станцию отправления");
- for(int i = 0; i < stations.Length; i++)
- Console.WriteLine(stations[i].Name);
- Console.WriteLine("-------------");
- while(!ok)
- {
- s = Console.ReadLine();
- for(int i = 0; i < stations.Length; i++)
- if(s == stations[i].Name)
- {
- num_stat_out = i;
- ok = true;
- break;
- }
- }
- return s;
- }
- public string get_station_in()
- {
- bool ok = false;
- string s = "";
- Console.WriteLine("Выберите из списка желаемую станцию прибытия");
- for(int i = 0; i < stations.Length; i++)
- Console.WriteLine(stations[i].Name);
- Console.WriteLine("-------------");
- while(!ok)
- {
- s = Console.ReadLine();
- for(int i = 0; i < stations.Length; i++)
- if(s == stations[i].Name)
- {
- num_stat_in = i;
- ok = true;
- break;
- }
- }
- return s;
- }
- public double distance(int i, int j)
- {
- station s1 = stations[i];
- station s2 = stations[j];
- return Math.Sqrt((s1.X - s2.X) * (s1.X - s2.X) + (s1.Y - s2.Y) * (s1.Y - s2.Y));
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- /*for (int i = 1, i <= 10, i++);{
- train [i] = new train {9*i,
- station[i] = new station{"station"+i, i*20,i*35-253};
- }*/
- while(true)
- {
- Console.WriteLine("Начало покупки");
- Console.WriteLine("Нажмите ctrl+c или крестик, чтобы завершить работу программы");
- passanger ps = new passanger(stations);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement