Таксопарк. Как сделать сортировку, подсчитать стоимость автомобилей? - C#
Формулировка задачи:
Таксопарк. Как сделать сортировку ? Подсчитать стоимость автомобилей?
Посчитать стоимость автопарка. Провести сортировку автомобилей парка по типу кузова или году выпуска
я здесь попытался сделать сортировку и то это не сортировка)
может быть через какие нибудь функции получиться?
program.cs
car.cs
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication3
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Транспорт\n");
- #region Auto1
- try
- {
- car P1 = new car() { auto = "Toyota Camry 50",Coachbuilder = "Седан", YearOfCreation = 2012, price=25000, rental = 2500, transfer = 3500, leasing = 280000 };
- Console.WriteLine("Автомобиль: {0}", P1.auto);
- Console.WriteLine("Тип кузова: {0}", P1.Coachbuilder);
- Console.WriteLine("Год выпуска: {0}", P1.YearOfCreation);
- Console.WriteLine("Цена авто: {0} $", P1.price);
- Console.WriteLine("1 час аренды(тг): {0} тг", P1.rental);
- Console.WriteLine("трансфер(тг): {0} тг", P1.transfer);
- Console.WriteLine("долгосрочная аренда(тг/мес): {0} тг", P1.leasing);
- Console.WriteLine();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- #endregion
- #region Auto2
- try
- {
- car P1 = new car() { auto = "MERCEDES-BENZ VIANO NEW", Coachbuilder = "Минивэн", YearOfCreation = 2014,price=35000, rental = 7000, transfer = 12000};
- Console.WriteLine("Автомобиль: {0}", P1.auto);
- Console.WriteLine("Тип кузова: {0}", P1.Coachbuilder);
- Console.WriteLine("Год выпуска: {0}", P1.YearOfCreation);
- Console.WriteLine("Цена авто: {0} $", P1.price);
- Console.WriteLine("1 час аренды(тг): {0} тг", P1.rental);
- Console.WriteLine("трансфер(тг): {0} тг", P1.transfer);
- Console.WriteLine("долгосрочная аренда(тг/мес): {0} тг", P1.leasing);
- Console.WriteLine();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- #endregion
- #region Auto3
- try
- {
- car P1 = new car() { auto = "MERCEDES S-CLASS W 222", Coachbuilder = "Седан", YearOfCreation = 2014,price=51000, rental = 10000, transfer = 21000, leasing = 7500000 };
- Console.WriteLine("Автомобиль: {0}", P1.auto);
- Console.WriteLine("Тип кузова: {0}", P1.Coachbuilder);
- Console.WriteLine("Год выпуска: {0}", P1.YearOfCreation);
- Console.WriteLine("Цена авто: {0} $", P1.price);
- Console.WriteLine("1 час аренды(тг): {0} тг", P1.rental);
- Console.WriteLine("трансфер(тг): {0} тг", P1.transfer);
- Console.WriteLine("долгосрочная аренда(тг/мес): {0} тг", P1.leasing);
- Console.WriteLine();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- #endregion
- #region Auto4
- try
- {
- car P1 = new car() { auto = "KIA GRANBIRD", Coachbuilder = "Автобус", YearOfCreation = 2010,price=31500, rental = 6000, transfer = 12000, leasing = 550000 };
- Console.WriteLine("Автомобиль: {0}", P1.auto);
- Console.WriteLine("Тип кузова: {0}", P1.Coachbuilder);
- Console.WriteLine("Год выпуска: {0}", P1.YearOfCreation);
- Console.WriteLine("Цена авто: {0} $", P1.price);
- Console.WriteLine("1 час аренды(тг): {0} тг", P1.rental);
- Console.WriteLine("трансфер(тг): {0} тг", P1.transfer);
- Console.WriteLine("долгосрочная аренда(тг/мес): {0} тг", P1.leasing);
- Console.WriteLine();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- #endregion
- char x, y = 'y';
- Console.WriteLine("Wanna Sort Coachbuilder ? :D [y]eap/[n]ope");
- x = Convert.ToChar(Console.ReadLine());
- if (x == y)
- {
- #region Auto1
- try
- {
- car P1 = new car() { auto = "Toyota Camry 50", Coachbuilder = "Седан", YearOfCreation = 2012, price = 25000, rental = 2500, transfer = 3500, leasing = 280000 };
- Console.WriteLine("Автомобиль: {0}", P1.auto);
- Console.WriteLine("Тип кузова: {0}", P1.Coachbuilder);
- Console.WriteLine("Год выпуска: {0}", P1.YearOfCreation);
- Console.WriteLine("Цена авто: {0} $", P1.price);
- Console.WriteLine("1 час аренды(тг): {0} тг", P1.rental);
- Console.WriteLine("трансфер(тг): {0} тг", P1.transfer);
- Console.WriteLine("долгосрочная аренда(тг/мес): {0} тг", P1.leasing);
- Console.WriteLine();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- #endregion
- #region Auto3
- try
- {
- car P1 = new car() { auto = "MERCEDES S-CLASS W 222", Coachbuilder = "Седан", YearOfCreation = 2014, price = 51000, rental = 10000, transfer = 21000, leasing = 7500000 };
- Console.WriteLine("Автомобиль: {0}", P1.auto);
- Console.WriteLine("Тип кузова: {0}", P1.Coachbuilder);
- Console.WriteLine("Год выпуска: {0}", P1.YearOfCreation);
- Console.WriteLine("Цена авто: {0} $", P1.price);
- Console.WriteLine("1 час аренды(тг): {0} тг", P1.rental);
- Console.WriteLine("трансфер(тг): {0} тг", P1.transfer);
- Console.WriteLine("долгосрочная аренда(тг/мес): {0} тг", P1.leasing);
- Console.WriteLine();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- #endregion
- #region Auto2
- try
- {
- car P1 = new car() { auto = "MERCEDES-BENZ VIANO NEW", Coachbuilder = "Минивэн", YearOfCreation = 2014, price = 35000, rental = 7000, transfer = 12000 };
- Console.WriteLine("Автомобиль: {0}", P1.auto);
- Console.WriteLine("Тип кузова: {0}", P1.Coachbuilder);
- Console.WriteLine("Год выпуска: {0}", P1.YearOfCreation);
- Console.WriteLine("Цена авто: {0} $", P1.price);
- Console.WriteLine("1 час аренды(тг): {0} тг", P1.rental);
- Console.WriteLine("трансфер(тг): {0} тг", P1.transfer);
- Console.WriteLine("долгосрочная аренда(тг/мес): {0} тг", P1.leasing);
- Console.WriteLine();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- #endregion
- #region Auto4
- try
- {
- car P1 = new car() { auto = "KIA GRANBIRD", Coachbuilder = "Автобус", YearOfCreation = 2010, price = 31500, rental = 6000, transfer = 12000, leasing = 550000 };
- Console.WriteLine("Автомобиль: {0}", P1.auto);
- Console.WriteLine("Тип кузова: {0}", P1.Coachbuilder);
- Console.WriteLine("Год выпуска: {0}", P1.YearOfCreation);
- Console.WriteLine("Цена авто: {0} $", P1.price);
- Console.WriteLine("1 час аренды(тг): {0} тг", P1.rental);
- Console.WriteLine("трансфер(тг): {0} тг", P1.transfer);
- Console.WriteLine("долгосрочная аренда(тг/мес): {0} тг", P1.leasing);
- Console.WriteLine();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- #endregion
- Console.ReadKey();
- }
- }
- }
- }
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication3
- {
- class car:Program
- {
- public string auto; // Автомобиль
- public string Coachbuilder; //тип Кузова
- public int YearOfCreation; //Год
- public int price; //цена Автомобиля
- public int rental; //1 час аренды(тг)
- public int transfer; //трансфер(тг)
- public int leasing; //долгосрочная аренда(тг/мес)
- }
- }
Решение задачи: «Таксопарк. Как сделать сортировку, подсчитать стоимость автомобилей?»
textual
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication4
- {
- class Program
- {
- public static void Main()
- {
- List<car> AUTO = new List<car>()
- {
- new car {auto= "Toyota Camry",Coachbuilder="Sedan", YearOfCreation=47, price = 20000, rental = 2000, transfer = 20004, leasing = 41000},
- new car {auto= "Mers W222",Coachbuilder="Sedan", YearOfCreation=45, price = 204000, rental = 20500, transfer = 20050, leasing = 15000},
- new car {auto= "Kia Grandis",Coachbuilder="Minivan", YearOfCreation=41, price = 20500, rental = 20100, transfer = 2000, leasing = 14000},
- new car {auto= "Kia Optima",Coachbuilder="Sedan", YearOfCreation=46, price = 200065, rental = 20050, transfer = 26000, leasing = 10400}
- };
- Console.WriteLine("Количество автомобилей: {0}\n", AUTO.Count);
- foreach (car p in AUTO)
- {
- Console.WriteLine("Модель: {0}", p.auto);
- Console.WriteLine("Тип Кузова: {0}", p.Coachbuilder);
- Console.WriteLine("Год выпуска: {0}", p.YearOfCreation);
- Console.WriteLine("Цена: {0} $", p.price);
- Console.WriteLine("Аренда: {0} тг", p.rental);
- Console.WriteLine("Трансфер: {0} тг", p.transfer);
- Console.WriteLine("Долгосрочная аренда: {0} тг\n\n", p.leasing);
- }
- Console.ReadKey();
- }
- }
- class car
- {
- public string auto; // Автомобиль
- public string Coachbuilder; //тип Кузова
- public int YearOfCreation; //Год
- public int price; //цена Автомобиля
- public int rental; //1 час аренды(тг)
- public int transfer; //трансфер(тг)
- public int leasing; //долгосрочная аренда(тг/мес)
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д