lab 8
unknown
csharp
a month ago
3.2 kB
0
Indexable
Never
namespace lab8 { internal class Program { static void Main(string[] args) { Console.WriteLine("Введите через запятую: номер автобуса, время в пути (в часах), количество мест, имя человека, количество дней в туре, отель: "); string[] tour1Data = Console.ReadLine().Split(", "); Tour<Bus> tour1 = new Tour<Bus>(tour1Data[3], new Bus(Int32.Parse(tour1Data[0]), Int32.Parse(tour1Data[1]), Int32.Parse(tour1Data[2])), Int32.Parse(tour1Data[4]), tour1Data[5]); Console.WriteLine(tour1.Info()); Console.WriteLine("Введите через запятую: номер поезда, время в пути (в часах), номер места, станция, имя человека, количество дней в туре, отель: "); string[] tour2Data = Console.ReadLine().Split(", "); Tour<Train> tour2 = new Tour<Train>(tour2Data[3], new Train(Int32.Parse(tour2Data[0]), tour2Data[4], Int32.Parse(tour2Data[1]), Int32.Parse(tour1Data[2])), Int32.Parse(tour2Data[5]), tour2Data[6]); Console.WriteLine(tour2.Info()); } } public class Tour<T> where T : ITransport { string name; T transport; int days; string hotel; public Tour(string name, T transport, int days, string hotel) { this.name = name; this.transport = transport; this.days = days; this.hotel = hotel; } public string Info() { return $"{name}, дней: {days}, отель: {hotel}, {transport.Type} no.{transport.No} "; } } public struct Bus : ITransport { public string Type { get; } = "bus"; public int No { get; set; } public int Time { get; set; } int seats; public Bus(int seats, int no, int time) { this.seats = seats; this.No = no; this.Time = time; } public int Seats { get { return seats; } set { seats = value; } } } public struct Train : ITransport { public string Type { get; } = "train"; public int No { get; set; } public int Time { get; set; } int seat_no; string station; public Train(int seat_no, string station, int no, int time) { this.seat_no = seat_no; this.station = station; this.No = no; this.Time = time; } public int Seat_no { get { return seat_no; } set { seat_no = value; } } public string Station { get { return station; } set { station = value; } } } public interface ITransport { public string Type { get; } public int No { get; set; } public int Time { get; set; } } }