Академический Документы
Профессиональный Документы
Культура Документы
БЕЛАРУСЬ
Учреждение образования
Вариант 7
Минск 2019
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp8
{
class Program
{
interface Deleter
{
void Delete(List<BookList> l, int index);
}
class Delet{
public static void Deleter(Deleter d, List <BookList> l, int index)
{
d.Delete(l, index);
}
}
class People : Deleter
{
string aut;
string name;
ushort year;
virtual public void set()
{
Console.WriteLine("Введите имя автора: ");
aut = Console.ReadLine();
Console.WriteLine("Введите название: ");
name = Console.ReadLine();
year = 1;
while (year < 0 || year > 2019)
{
Console.WriteLine("Год выпуска: ");
year = vvodus();
}
}
virtual public void print()
{
Console.WriteLine("Сведения о книге:");
Console.WriteLine("Имя автора: " + aut);
Console.WriteLine("Название: " + name);
Console.WriteLine("Год выпуска: " + year);
}
public void Delete(List<BookList> l, int index)
{
Console.WriteLine("Удалить книгу");
}
}
class BookList : People, Deleter
{
public delegate void BookList Handler(string message);
public event BookList Handler addHandler;
public event BookList Handler deleteHandler;
string aut;
string name;
short mark;
ushort year;
decimal pages;
public int this[int i]
{
get
{
Console.WriteLine("get i = " + i);
return i;
}
}
public void Delete(List< BookList > st, int index)
{
st.RemoveAt(index);
if (deleteHandler != null)
deleteHandler($"Книга {this.name} была удалена.");
}
public override void set()
{
Console.WriteLine("Введите имя автора: ");
aut = Console.ReadLine();
Console.WriteLine("Введите название: ");
name = Console.ReadLine();
course = -1;
while (mark < 1 || mark > 10)
{
Console.WriteLine("Введите оценку: ");
mark = vvods();
}
year = 1;
while (year < 0 || year > 2019)
{
Console.WriteLine("Год выпуска: ");
year = vvodus();
}
pages = -1;
while (avgMark < 1 )
{
Console.WriteLine("Количество страниц: ");
pages = vvodD();
}
if (addHandler != null)
addHandler.Invoke($"Книга {name} была добавлена!!!");
}
public override void print()
{
Console.WriteLine("Сведения о книге:");
Console.WriteLine("имя: " + aut);
Console.WriteLine("фамилия: " + name);
Console.WriteLine("курс: " + mark);
Console.WriteLine("Дата рождения: " + year);
Console.WriteLine("средний балл: " + pages);
}
public static void sortByMark(List< BookList > s)
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 2; j++)
{
if (s[j].mark < s[j + 1].mark)
{
short tmp = s[j].mark;
s[j].mark = s[j + 1].mark;
s[j + 1].mark = tmp;
short temp = s[j].pages;
s[j].pages = s[j + 1].pages;
s[j + 1].pages = temp;
String temperary = s[j].aut;
s[j].aut = s[j + 1].aut;
s[j + 1].aut = temperary;
string tempe = s[j].name;
s[j].name = s[j + 1].name;
s[j + 1].name = tempe;
ushort temper = s[j].year;
s[j].year = s[j + 1].year;
s[j + 1].year = temper;
}
}
}
bool flag = false;
for(int i = 1; i < 3; i++)
{
if (s[i - 1].Equals(s[i]))
flag = true;
}
if(flag == true)
{
Console.WriteLine("Книги с одинаковыми оценками существуют!");
Console.WriteLine(s.GetType());
}
else
{
// Console.WriteLine("FALSE");
}
}
public override bool Equals(object obj)
{
var group = obj as BookList;
return group != null &&
mark == group.mark;
}
public override int GetHashCode()
{
return 164379502 + mark.GetHashCode();
}
}
private static void Show_Message(string message)
{
Console.WriteLine(message);
}
class WorkWithFil
{
public static void WriteToFile(List<BookList > Book)
{
try
{
StreamWriter sw = new
StreamWriter("C:/Users/DELL/Desktop/study/C#/Никита/ConsoleApp8/ConsoleApp4/text.txt",
false, Encoding.Default);
foreach (BookListi in Book)
{
sw.WriteLine("Имя автора: " + i.GetAut());
sw.WriteLine("Название книги: " + i.Getname());
sw.WriteLine("Оценка: " + i.GetMark());
sw.WriteLine("Год выпуска: " + i.GetYear());
sw.WriteLine("Количество страниц: " + i.GetPages());
sw.WriteLine();
}
i.print();
Console.WriteLine();
try
WorkWithFile.WriteToFile(st);
catch (IOException e)
Console.ReadKey();
{
label:
int num;
try
num = int.Parse(Console.ReadLine());
catch (FormatException e)
goto label;
return num;
label:
short num;
try
num = Int16.Parse(Console.ReadLine());
catch (Exception e)
return num;
label:
ushort num;
try
num = UInt16.Parse(Console.ReadLine());
catch (FormatException e)
goto label;
return num;
label:
Decimal num;
try
{
num = Decimal.Parse(Console.ReadLine());
catch (FormatException e)
goto label;
return num;
Контрольные вопросы:
4.
Наименование Описание