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.Threading.Tasks;
- using System.IO;
- namespace TasksOOP
- {
- // 1 task
- /*class Weather: ICloneable
- {
- private string city;
- private int temperature;
- private DateTime data = new DateTime();
- public string City { get => city;}
- public int Temperature { get => temperature; set => temperature = value; }
- public DateTime Data { get => data; set => data = value; }
- public Weather(string city, int temperature, DateTime dateTime)
- {
- this.city = city;
- Temperature = Converse(temperature);
- Data = dateTime;
- }
- public int Converse(int t)
- {
- return t * (9 / 5) + 32;
- }
- public object Clone()
- {
- //return new Weather(City, Temperature, Data);
- return MemberwiseClone();
- }
- }*/
- // 2 task
- /*class Tourist
- {
- private string name;
- private string direction;
- private int duration;
- //public string Name { get => name; }
- public string Direction { get => direction; set => direction = value; }
- public int Duration { get => duration; set => duration = value; }
- public string Name { get => name; set => name = value; }
- public Tourist(string name, string direction)
- {
- this.Name = name;
- Direction = direction;
- }
- public override string ToString()
- {
- return $"Турист: Имя {Name} Направление {Direction} Продолжительность {Duration} дней";
- }
- public static int operator +(Tourist tourist, int val)
- {
- return tourist.Duration + val;
- }
- }*/
- //3 task
- /*class Meropriyatie: IComparable
- {
- private string name;
- private DateTime date;
- private string mesto;
- public Meropriyatie(string name, DateTime dateTime, string mesto)
- {
- this.name = name;
- Date = dateTime;
- Mesto = mesto;
- }
- public string Name { get => name; }
- public DateTime Date { get => date; set => date = value; }
- public string Mesto { get => mesto; set => mesto = value; }
- public bool Check()
- {
- if (Date >= DateTime.Now) return true;
- else return false;
- }
- public int CompareTo(object o)
- {
- if (o is Meropriyatie os)
- {
- if (os != null)
- {
- return DateTime.Compare(this.date, os.Date);
- }
- else throw new ArgumentNullException("Нулевой элемент");
- }
- else
- {
- throw new ArgumentException("Аргумент неправильного типа!");
- }
- }
- }*/
- //4 task
- /*class Cube
- {
- private int riblength;
- public Cube(int rl)
- {
- Riblength = rl;
- }
- public int Riblength { get => riblength; set => riblength = value; }
- public int Volume()
- {
- return riblength * riblength * riblength;
- }
- public static int operator +(Cube c1, Cube c2)
- {
- return c1.Volume() + c2.Volume();
- }
- public override string ToString()
- {
- return $"Куб с ребрами = {Riblength} и объемом = {Volume()}";
- }
- }*/
- //5 task
- /*class Teacher
- {
- private string surname;
- private string kaf;
- private double rating;
- public string Surname { get => surname; set => surname = value; }
- public string Kaf { get => kaf; set => kaf = value; }
- public double Rating { get => rating; set => rating = value; }
- public override string ToString()
- {
- return $"Учитель - {Surname} с кафедры - {Kaf} с рейтингом - {Rating}";
- }
- }*/
- //6 task
- /*class Driver
- {
- private string surname;
- private List<string> categories = new List<string>();
- private int experience;
- public Driver(string surname, string category, int experience)
- {
- Surname = surname;
- categories.Add(category);
- Experience = experience;
- }
- public string Surname { get => surname; set => surname = value; }
- public int Experience { get => experience; set => experience = value; }
- public override int GetHashCode()
- {
- return surname.Length + experience;
- }
- public string this[int i]
- {
- get => categories[0];
- }
- public override string ToString()
- {
- return $"{Surname} {Experience}";
- }
- }*/
- //7 task
- /*class TK
- {
- private string name;
- private int count;
- public List<string> countries = new List<string>();
- public string Name { get => name; }
- public int Count { get => count; set => count = value; }
- public string this[int index]
- {
- get => countries[index];
- }
- public TK(string name, int count, List<string> vs)
- {
- this.name = name;
- Count = count;
- countries.AddRange(vs);
- }
- public override string ToString()
- {
- return $"Транспортная компания - {Name} с автопарком в {Count} машин, который сотрудничает с такими странами, как {string.Join(", ", countries)}";
- }
- }*/
- //9 task
- class Creditka<T>
- {
- private T number;
- private int dolg;
- private DateTime date = DateTime.Now;
- public Creditka(T number, int dolg)
- {
- Number = number;
- Dolg = dolg;
- }
- public bool CheckOverdue()
- {
- if (Date > DateTime.Now) return true;
- else return false;
- }
- public static bool operator ==(Creditka<T> c1, Creditka<T> c2)
- {
- if (ReferenceEquals(c1, c2)) return true;
- if ((((object)c1) == null) || (((object)c2) == null)) return false;
- return false;
- }
- static public bool operator !=(Creditka<T> c1, Creditka<T> c2)
- {
- return !(c1 == c2);
- }
- public T Number { get => number; set => number = value; }
- public int Dolg { get => dolg; set => dolg = value; }
- public DateTime Date { get => date; set => date = value; }
- public override string ToString()
- {
- return $"Номер счета: {Number}; Дата задолженности: {Date}";
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- //1 task
- /*List<Weather> weathers = new List<Weather>();
- Weather weather1 = new Weather("Nurlat", 37, new DateTime(2023, 01, 17));
- Weather weather2 = new Weather("Kazan", 10, new DateTime(2023, 03, 15));
- Weather weather3 = new Weather("Nurlat", -78, new DateTime(2023, 05, 27));
- weathers.Add(weather1);
- weathers.Add(weather2);
- weathers.Add(weather3);
- var linqweathers = weathers.GroupBy(c => c.Data);
- foreach (var weathers1 in linqweathers)
- {
- foreach (var item in weathers1)
- {
- Console.WriteLine($"{item.City} \t {item.Temperature} \t {item.Data}");
- }
- }*/
- // 2 task
- /*int n = 0;
- Console.Write("Введите кол-во туристов: ");
- n = Int32.Parse(Console.ReadLine());
- Tourist[] tourists = new Tourist[n];
- for (int i = 0; i < tourists.Length; i++)
- {
- Console.Write($"Введите имя для {i + 1}-го туриста: ");
- string tname = (string)(Console.ReadLine());
- Console.Write($"Введите направление для {i + 1}-го туриста: ");
- string tdirection = (string)(Console.ReadLine());
- tourists[i] = new Tourist(tname, tdirection);
- }
- for (int i = 0; i < tourists.Length; i++)
- {
- Console.Write($"Введите продолжительность отдыха для {tourists[i].Name}: ");
- int d = Int32.Parse(Console.ReadLine());
- tourists[i].Duration += d;
- }
- var selectedtourusts = tourists.Where(t => t.Duration < 7);
- foreach (var item in selectedtourusts)
- {
- Console.WriteLine(item.ToString());
- }
- Console.WriteLine($"Минимальная продолжительность отдыха: {tourists.Min(x => x.Duration)}");*/
- // 3 task
- /*Meropriyatie[] meropriyaties = { new Meropriyatie("Самы", new DateTime(2022, 05, 22), "Nurlat"), new Meropriyatie("sdasdas", new DateTime(2022, 06, 11), "Dubai"), new Meropriyatie("dasdada", new DateTime(2022, 08, 11), "Ddsai"), new Meropriyatie("fsdfsdfs", new DateTime(2022, 09, 12), "Kazan") };
- var groupMP = meropriyaties.GroupBy(x => x.Mesto);
- foreach (var item in groupMP)
- {
- foreach (var elem in item)
- {
- Console.WriteLine($"{elem.Name} - {elem.Date} - {elem.Mesto}");
- }
- }
- var cs = meropriyaties.Where(x => x.Check() == false);
- //meropriyaties
- Console.WriteLine($"Количество прошедних мероприятий {cs.Count()}");*/
- // 4 task
- /*List<Cube> cubes = new List<Cube>() { new Cube(3), new Cube(5), new Cube(4), new Cube(2), new Cube(7) };
- cubes.Add(new Cube(cubes[0] + cubes[1]));
- var selected = cubes.OrderByDescending(x => x.Riblength);
- foreach (var item in selected)
- {
- Console.WriteLine(item + "\n");
- }
- Console.WriteLine(cubes.Any(x => x.Volume() >= 5));*/
- //5 task
- /*StreamWriter streamWriter = new StreamWriter("C:\\Users\\ПК\\Desktop\\OOP\\output.txt");
- List<Teacher> teachers = new List<Teacher>();
- teachers.Add(new Teacher());
- teachers.Add(new Teacher());
- teachers.Add(new Teacher());
- teachers[0].Surname = "Musin";
- teachers[1].Surname = "Habibi";
- teachers[2].Surname = "Garfiev";
- teachers[0].Kaf = "Kaifa";
- teachers[1].Kaf = "Ne Kaifa";
- teachers[2].Kaf = "Информационная безопасность";
- teachers[0].Rating = 7.0;
- teachers[1].Rating = 3.5;
- teachers[2].Rating = 6.0;
- var ashkerer = teachers.OrderBy(x => x.Rating);
- foreach (var item in ashkerer)
- {
- Console.WriteLine(item + "\t");
- streamWriter.WriteLine(item + "\t");
- }
- Console.WriteLine("Имеются ли среди преподавателей сотрудики кафедры Информационная безопасность: " + teachers.Any(x => x.Kaf == "Информационная безопасность"));
- streamWriter.Close();*/
- // 6 task
- /*List<Driver> drivers = new List<Driver>() { new Driver("Musin", "A", 12), new Driver("Garfiev", "B", 2), new Driver("Razjevalov", "C", 3), new Driver("Valiev", "B", 22) };
- var orderedbyexp = drivers.OrderBy(x => x.Experience);
- for (int i = 0; i < orderedbyexp.Count(); i++)
- {
- string s = drivers[i][i];
- Console.WriteLine(orderedbyexp + "\t" + s);
- }
- foreach (var item in orderedbyexp)
- {
- for (int i = 0; i < drivers.Count; i++)
- {
- Console.WriteLine(item + "\t" + item[i]);
- }
- }*/
- //7 task
- /*List<TK> tKs = new List<TK>() { new TK("dada", 6, new List<string>(){"bdadda", "dadad", "dasdasdasdsad", "nurlat", "sdsadadasdsa", "OAE"}), new TK("dada", 5, new List<string>() { "bdsa", "dadadasdasdd", "dasda12sdasdsad", "dubai", "aseqs"}), new TK("aedd", 4, new List<string>() { "aoas", "fvs", "sdad", "nurlat" }), };
- var svs = tKs.Max(x => x.countries.Count);
- Console.WriteLine($"Max: {svs}");
- var selected = tKs.Where(x => x.countries.Count == svs);
- foreach (var item in selected)
- {
- Console.WriteLine(item + "\t");
- }
- Console.WriteLine("\nSorted by Name");
- var sorted = tKs.OrderBy(x => x.Name);
- foreach (var item in sorted)
- {
- Console.WriteLine(item + "\t");
- }*/
- // 9 task
- List<Creditka<int>> creditkas = new List<Creditka<int>>() { new Creditka<int>(1111, 100000), new Creditka<int>(1112, 10000), new Creditka<int>(1113, 20000), new Creditka<int>(1114, 200000), new Creditka<int>(1115, 14000) };
- creditkas[0].Date = new DateTime(2022, 12, 12);
- creditkas[1].Date = new DateTime(2022, 11, 22);
- creditkas[3].Date = new DateTime(2023, 05, 26);
- Console.WriteLine(creditkas[0] == creditkas[1]);
- Console.WriteLine(creditkas[0] != creditkas[1]);
- Console.WriteLine($"Количество карт с просроченной задолженностью: {creditkas.Count(x => x.CheckOverdue() == true)}");
- var l2 = creditkas.OrderByDescending(x => x.Date);
- Console.WriteLine("Отфильтровать кредитные карты по задолженности в порядке убывания:");
- foreach (var item in l2)
- {
- Console.WriteLine(item + "\t");
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement