Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

задачи

.docx
Скачиваний:
4
Добавлен:
10.02.2015
Размер:
56.77 Кб
Скачать

return res;

}

public static Drob operator >(Drob ob1, Drob ob2)

{

Drob res = ob1 - ob2;

if (res.chisl * res.znam > 0)

return true;

return false;

}

public static Drob operator <(Drob ob1, Drob ob2)

{

Drob res = ob1 - ob2;

if (res.chisl * res.znam > 0)

return true;

return false;

}

}

static void Main(string[] args)

{

Drob d1 = new Drob(1, 5);

Drob d2 = new Drob(2, 6);

Drob d3 = new Drob();

d3 = d1 + d2;//перегрузка

d1 > d2;

d3.Print();

if (true)

Console.WriteLine(d1 + " больше,чем " + d2);

else

Console.WriteLine(d1 + " меньше,чем " + d2);

}

}

}

  1. Массив-делегаты

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

namespace Массив__делегаты_

{

class Program

{

class Text

{

delegate int MethodDelegate();

MethodDelegate method = null;

public Text(int i)

{

if (i != 1 && i != 2 && i != 3)

throw new Exception("Не определен метод сортировки");

if (i == 1)

method = GetX1;

if (i == 2)

method = GetX2;

if (i == 3)

method = GetX3;

}

int GetX1()

{

return 0;

}

int GetX2()

{

return 2;

}

int GetX3()

{

return 3;

}

public void Sort(StreamReader sr)

{

int[] a = new int[5];

string[] b = new string[5];

int z = 0;

string str = "";

while ((str = sr.ReadLine()) != null)

{

string[] s = str.Split(' ');

a[z] = Convert.ToInt32(s[method()]);

b[z] = str;

z++;

}

for (int i = 0; i < 4; i++)

{

for (int j = i+1; j < 5; j++)

{

if (a[i] > a[j])

{

int t = a[j];

a[j] = a[i];

a[i] = t;

string t2 = b[j];

b[j] = b[i];

b[i] = t2;

}

}

}

Console.WriteLine();

for (int i = 0; i < 5; i++)

{

Console.WriteLine(b[i]);

}

}

}

static void Main(string[] args)

{

try

{

Console.WriteLine("1 - Сортировка по номеру, 2 - Сортировка по цене, 3-Сортировка по количеству");

StreamReader sr = new StreamReader("D://Делегаты.txt", Encoding.Default);

int i = int.Parse(Console.ReadLine());;

Text s = new Text(i);

s.Sort(sr);

}

catch (Exception e)

{

Console.WriteLine(e.Message);

}

}

}

  1. Функции

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication5

{

delegate double MathFunction(double x);//делегат для представления математической функции

class Solve

{

delegate double MethodDelegate(MathFunction f, double a, double b);//делегат для определенния точки деления исхдного отрезка

MathFunction f = null;

double a, b, eps;

MethodDelegate method = null;

public double A

{

get { return a; }

}

public double B

{

get { return b; }

}

public Solve(MathFunction f, double a, double b, double eps, int i)

{

this.f = f;

this.a = a;

this.b = b;

this.eps = eps;

if (i != 1 && i != 2 && i != 3)

throw new Exception("Не определен метод решения уравнения");

if (i == 1)

method = GetX1;//иницилизация делегата функцией GetX1

if (i == 2)

method = GetX2;

if (i == 3)

method = GetX3;

}

//получение середины отрезка

double GetX1(MathFunction f, double a, double b)

{

return (a + b) / 2;

}

//поление точки пересечения хрды с осью ОХ

double GetX2(MathFunction f, double a, double b)

{

return a - f(a) * (b - a) / (f(b) - f(a));

}

//получение точки переечения касательной с осю ОХ

static double GetX3(MathFunction f, double a, double b)

{

// приближенное вычисление производной в точке a

double fa = (f(a + 0.001) - f(a)) / 0.001;

if (fa != 0)

{

double c = a - f(a) / fa;// получение точки пересечения касательной с осью абсцисс

if (a <= c && c <= b)// если точка c принадлежит отрезку,выбираем ее

return c;

}

double fb = (f(b + 0.001) - f(b)) / 0.001; // приближенное вычисление производной в точке b

if (fb != 0)

{

double c = b - f(b) / fb; // получение точки пересечения касательной с осью абсцисс

if (a <= c && c <= b)

return c;

}

throw new Exception("Возможно, на этом отрезке корней нет");

}

public double Root()

{//корень сущ-ет если на кнцах отрезка ф-ия принемает знчения разных знаков

if (f(a) * f(b) > 0)

throw new Exception("Возможно, на данном отрезке корней нет");

double c = method(f, a, b);

if (f(c) == 0)

return c;

if (f(a) * f(c) < 0)

b = c;

else

a = c;

//выбор приближенного знчения корня

if (Math.Abs(f(a)) < eps)

return a;

if (Math.Abs(f(b)) < eps)

return b;

return Root();

}

}

class Program

{//ф-ия определения ур-ия

static double F(double x)

{

return x * x - 5;

}

static void Main(string[] args)

{

try

{

Console.WriteLine("1 - метод деления пополам, 2 - метод хорд,3-метод касательных");

int i = int.Parse(Console.ReadLine());

Solve s = new Solve(Math.Sin, 2, 4, 0.00001, i);

Console.WriteLine("Корень на отрезке [{0}, {1}] = {2}", s.A, s.B, s.Root());//вызов метода решения уравнения

}

catch (Exception e)

{

Console.WriteLine(e.Message);

}

}

}

}

  1. Домохозяйства

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication3

{

class Program

{

class House //базовый класс Домохозяйства

{

class Operation //класс Операция для хранения информации о денежных операциях, которые происходят в домохозяйстве

{

public int summa; //переменна хранящая сумму операции

public int date; //переменная хранящая дату операции

public Operation(int summa, int date)

{

this.summa = summa;

this.date = date;

}

public void Show()

{

Console.WriteLine("Operation: summa={0} date={1}", summa, date);

}

public void OperationSumma()

{

Console.Write("Введите сумму операции:");

}

public override void OperationSumma()

{

Console.WriteLine("1520");

}

public void OperationDate()

{

Console.Write("Введите дату операции:");

}

public override void OperationDate()

{

Console.WriteLine("15-10-2012");

}

}

}

}

class Dohod : House

{

public string place;

public string name;

public Dohod(string place, string name)

{

this.place = place;

this.name = name;

}

public void DohodPlace()

{

Console.Write("Введите откуда был получен доход:");

}

public override void DohodPlace()

{

Console.WriteLine("Продажа капусты");

}

public void DohodName()

{

Console.Write("Введите кем был получен доход:");

}

public override void DohodName()

{

Console.WriteLine("Петр Иванович");

}

}

class Rashod : House

{

public string aim;

public Rashod(string aim)

{

this.aim = aim;

}

public void RashodAim()

{

Console.Write("Введите цель расхода:");

}

public override void RashodAim()

{

Console.WriteLine("Доставка");

}

}

class Sample

{

static void Main(string[] args)

{

Console. Write ("Введите дату для поиска:")

Dohod.PrintDohodPlace();//наследуемый метод

Dohod.PrintDohodName();

Rashod.PrintRashodAim();

try

{

Operation[] arr=new Operation[6];

arr[0]=new Operation("Без имени");

arr[1]=new DohodPlace ("Продажа капусты");

arr[2]=new DohodName("Петр Иванович");

arr[3]=new RashodAim("Доставка");

arr[4]=new OperationSumma("1520");

arr[5]=new OperationDate("15-10-2012");

for(int i=0; i<arr.Lenght; i++)

arr[i].Operation();

}

catch (Exception e){

Console.WriteLine(else.Message);

}

Console.Read();

}

}

}

  1. Дробь

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication18

{

class Ration

{

int chisl;

int znam;

public Ration()

{

chisl = 0;

znam = 1;

}

public Ration(int ch, int zn)

{

chisl = ch;

znam = zn;

}

~Ration()

{

Console.WriteLine("Дробь {0}/{1} уничтожена", chisl, znam);

}

/* public Ration Summa(Ration ob)

{

Ration res = new Ration();

res.chisl = chisl * ob.znam + ob.chisl * znam;

res.znam = znam * ob.znam;

return res;

}

public Ration Ymnozhenie(Ration ob)

{

Ration res = new Ration();

res.chisl = chisl * ob.chisl;

res.znam = znam * ob.znam;

return res;

}

* public Ration Delenie(Ration ob)

{

Ration res = new Ration();

res.chisl = chisl * ob.znam;

res.znam = znam * ob.chisl;

return res;

}

* public Ration Raznitsa(Ration ob)

{

Ration res = new Ration();

res.chisl = chisl * ob.znam - ob.chisl * znam;

res.znam = znam * ob.znam;

return res;

}

*/

public static Ration operator+(Ration ob1, Ration ob2)

{

Ration res = new Ration();

res.chisl = ob1.chisl * ob2.znam + ob1.znam * ob2.chisl;

res.znam = ob1.znam * ob2.znam;

return res;

}

public static Ration operator *(Ration ob1, Ration ob2)

{

Ration res = new Ration();

res.chisl = ob1.chisl*ob2.chisl;

res.znam = ob1.znam * ob2.znam;

return res;

}

public static Ration operator /(Ration ob1, Ration ob2)

{

Ration res = new Ration();

res.chisl = ob1.chisl * ob2.znam;

res.znam = ob1.znam * ob2.chisl;

return res;

}

public static Ration operator -(Ration ob1, Ration ob2)

{

Ration res = new Ration();

res.chisl = ob1.chisl * ob2.znam - ob2.chisl * ob1.znam;

res.znam = ob1.znam * ob2.znam;

return res;

}

public static bool operator >(Ration ob1, Ration ob2)

{

Ration res=ob1-ob2;

if(res.chisl*res.znam>0)

return true;

return false;

}

public static bool operator <(Ration ob1, Ration ob2)

{

Ration res = ob1 - ob2;

if (res.chisl * res.znam > 0)

return false;

return true;

}

public void Print()

{

Console.Write("{0}/{1} ", chisl, znam);

}

public string ToString()

{

return "" + chisl + "/" + znam;

}

}

class Program

{

static void Main(string[] args)

{

Ration r1 = new Ration(5, 2);

Ration r2 = new Ration(1, 3);

Ration r3 = r1+r2;

Ration r4 = r1-r2;

Ration r5 = r1*r2;

Ration r6 = r1/r2;

Console.WriteLine("Сумма дробей:");

r3.Print();

Console.WriteLine("Разница дробей:");

r4.Print();

Console.WriteLine("Умножения дробей:");

r5.Print();

Console.WriteLine("Деления дробей:");

r6.Print();

if (r1 > r2)

Console.WriteLine(r1.ToString()+" > "+r2.ToString());

}

}

  1. Гипербола

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace график

{

enum TypeInequation { le, ge, e, l, g, n };

abstract class Function

{

public abstract double Сalculate(double x, double y);

public virtual void Input()

{

Console.WriteLine("Введите данные, определяющие функцию");

}

public abstract string Output();

}

class Hyperbola : Function

{

double a, b;

double x0, y0;

public Hyperbola(double a1, double b1, double x, double y)

{

a = a1;

b = b1;

x0 = x;

y0 = y;

}

public override double Сalculate(double x, double y)

{

return (x - x0) * (x - x0) / (a * a) - (y - y0) * (y - y0) / (b * b);

}

public override void Input()

{

base.Input();

a = double.Parse(Console.ReadLine());

b = double.Parse(Console.ReadLine());

x0 = double.Parse(Console.ReadLine());

y0 = double.Parse(Console.ReadLine());

}

public override string Output()

{

return "(x-" + x0 + ")^2/" + a * a + "-(y -" + y0 + ")^2/" + b * b;

}

}

class Constraint

{

Function function;

double b;

TypeInequation type;

public Constraint()

{

Input();

}

public bool IsExecute(double x, double y)

{

double val = function.Сalculate(x, y);

switch (type)

{

case TypeInequation.le:

if (val <= b) return true; break;

case TypeInequation.ge:

if (val >= b) return true; break;

case TypeInequation.e:

if (val == b) return true; break;

case TypeInequation.l:

if (val < b) return true; break;

case TypeInequation.g:

if (val > b) return true; break;

case TypeInequation.n:

if (val != b) return true; break;

}

return false;

}

public bool IsOnBound(double x, double y)

{ // равенство не должно выполняться

if (type == TypeInequation.l ||

type == TypeInequation.g || type == TypeInequation.n)

return false;

// вычисление значения функции в точке

double val = function.Сalculate(x, y);

// сравнение с правой частью на выполнение равенства

return (val == b);

}

public void Input()

{

int choice;

while (true)

{

Console.WriteLine("Линейная - 1, Эллиптическая - 2,Гиперболическая - 3, Параболическая - 4");

choice = int.Parse(Console.ReadLine());

if (choice >= 1 && choice <= 4)

break;

}

switch (choice)

{

//case 1: function = new Line(); break;

//case 2: function = new Ellipse(); break;

case 3: function = new Hyperbola(1,1,1,1); break;

//case 4: function = new Parabola(); break;

}

function.Input();

while (true)

{

Console.WriteLine("<= - 0, >= - 1, = - 2,< - 3, > - 4, <> - 5");

choice = int.Parse(Console.ReadLine());

if (choice >= 0 && choice <= 5)

break;

}

type = (TypeInequation)choice;

Console.WriteLine("Правая часть");

b = double.Parse(Console.ReadLine());

}

static public implicit operator string(Constraint ob)

{

string res = ob.function.Output();

switch (ob.type)

{

case TypeInequation.le:

res = res + "<="; break;

case TypeInequation.ge:

res = res + ">="; break;

case TypeInequation.e:

res = res + "="; break;

case TypeInequation.l:

res = res + "<"; break;

case TypeInequation.g:

res = res + ">"; break;

case TypeInequation.n:

res = res + "<>"; break;

default:

throw new Exception("Не существует такого вида ограничения");

}

res = res + ob.b;

return res;

}

}

class Set

{

Constraint[] constraints;

int n;

public Set(int n1)

{

n = n1;

constraints = new Constraint[n];

for (int i = 0; i < n; i++)

constraints[i] = new Constraint();

}

public bool Belongs(double x, double y)

{

for (int i = 0; i < n; i++)

if (!constraints[i].IsExecute(x, y))

return false;

return true;

}

public bool IsOnBound(double x, double y)

{

if (Belongs(x, y))

for (int i = 0; i < n; i++)

if (constraints[i].IsOnBound(x, y))

return true;

return false;

}

static public implicit operator string(Set ob)

{

string res = "";

for (int i = 0; i < ob.n; i++)

res = res + ob.constraints[i] + "\n";

return res;

}

}

class Program

{

static void Main(string[] args)

{

Set set = new Set(3);

double x1 = 0, y1 = 1;

double x2 = 1, y2 = 1;

if (set.Belongs(x1, y1))

Console.WriteLine("Точка (0,1) принадлежит множеству");

else

Console.WriteLine("Точка (0,1) не принадлежит множеству");

if (set.IsOnBound(x1, y1))

Console.WriteLine("Точка (0,1) лежит на границе множества");

else

Console.WriteLine("Точка (0,1) не лежит на границе множества");

if (set.Belongs(x2, y2))

Console.WriteLine("Точка (1,1) принадлежит множеству");

else

Console.WriteLine("Точка (1,1) не принадлежит множеству");

if (set.IsOnBound(x2, y2))

Console.WriteLine("Точка (1,1) лежит на границе множества");

else

Console.WriteLine("Точка (1,1) не лежит на границе множества");

Console.ReadLine();

}

}

}

  1. Книга

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Класс_книга

{

class Program

{

class book //класс Книга

{

string name; //переменная,хранящая название книги

string autor; //переменная,хранящая название книги

int price; //переменная,хранящая название книги

int year; //переменная,хранящая название книги

string edition; //переменная,хранящая название книги

public book() //конструктор класса книги. Все переменные создаются,но получают пустые(null),либо нулевые(0) значения

{

name = null;

autor = null;

price = 0;

year = 0;

edition = null;

}

public void vvod() //функция ввода книги

{

Console.WriteLine("Введите название книги:"); //1)выводим на экран сообщение

name = Console.ReadLine(); //2)считываем введенные данные и присваиваем соответствующим переменным класса

Console.WriteLine(); //3)пропускаем одну строку для красоты)))

Console.WriteLine("Введите автора:"); //дальше все аналогично шагам 1-2-3

autor = Console.ReadLine();

Console.WriteLine();

Console.WriteLine("Введите цену:");

price = int.Parse(Console.ReadLine());

Console.WriteLine();

Console.WriteLine("Введите год:");

year = int.Parse(Console.ReadLine());

Console.WriteLine();

Console.WriteLine("Введите издание:");

edition = Console.ReadLine();

}

public void Print() //функция печати

{

Console.WriteLine();

Console.WriteLine("Название: "+name); //распечатываем сообщение для пользователя и соответсвужщую переменную. Далее аналогично

Console.WriteLine("Автор: " + autor);

Console.WriteLine("Цена: " + price);

Console.WriteLine("Год: " + year);

Console.WriteLine("Издание: " + edition);

}

public void increase() //функция уменьшения цены на 10%

{

Console.WriteLine();

Console.WriteLine("Внимание,в магазине акция!!!");

Console.WriteLine("На книги,изданные раньше 2000 года, установить цену со скидкой 10%");

if (year < 2000) //если год введенной нами книги меньше 2000

{

price = price - (price / 100) * 10; // уменьшаем ее цену по формуле: Цена=Цена-(Цена : 100%) * 10

Console.WriteLine();

Console.WriteLine("Цена с учетом скидки: "+price); // выводим новую цену

}

else //если год от 2000 и больше,выводим сообщение,что скидка не распространяется

Console.WriteLine("На данную книгу скидка не распространяется");

}

}

static void Main(string[] args)

{

book b = new book(); //создаем новый пустой класс b

b.vvod(); //вызываем для этого класса функцию ввода данных

b.Print(); //вызываем для этого класса функцию печати и на экран выводятся данные о введенной книге

b.increase(); //вызываем для этого класса функцию уменьшения цены на 10% на книги раньше 2000 года выпуска

Console.WriteLine();

}

}

}

  1. Метод деления и метод хорд делегатов

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication5

{

delegate double MathFunction(double x);

class Solve

{

delegate double MethodDelegate();

MathFunction f=null;

double a, b, eps;

MethodDelegate method = null;

public double A

{

get { return a; }

}

public double B

{

get { return b; }

}

public Solve(MathFunction f, double a, double b, double eps, int i)

{

this.f = f;

this.a = a;

this.b = b;

this.eps = eps;

if (i != 1 && i != 2)

throw new Exception("Не определен метод решения уравнения");

if (i == 1)

method = GetX1;

if (i == 2)

method = GetX2;

}

double GetX1()

{

return (a + b) / 2;

}

double GetX2()

{

return a - f(a) * (b - a) / (f(b) - f(a));

}

public double Root()

{

if (f(a) * f(b) > 0)

throw new Exception("Возможно, на данном отрезке корней нет");

double c = method();

if (f(c) == 0)

return c;

if (f(a) * f(c) < 0)

b = c;

else

a = c;

if (Math.Abs(f(a)) < eps)

return a;

if (Math.Abs(f(b)) < eps)

return b;

return Root();

}

}

class Program

{

static double F(double x)

{

return x * x - 5;

}

static void Main(string[] args)

{

try

{

Console.WriteLine("1 - метод деления пополам, 2 - метод хорд");

int i = int.Parse(Console.ReadLine());

Solve s = new Solve(Math.Sin, 2, 4, 0.00001,i);

Console.WriteLine("Корень на отрезке [{0}, {1}] = {2}",s.A, s.B, s.Root());

}

catch (Exception e)

{

Console.WriteLine(e.Message);

}

}

}

}

  1. Проба

using System;

using System.Collections;

using System.Linq;

using System.Text;

namespace Mnozestvo

{

class Proba

{

int a;

double b;

public Proba(int a, double b) { this.a = a; this.b = b; }

public override bool Equals(object obj)

{

Proba p = obj as Proba;

return a == p.a && b == p.b;

}

public override string ToString()

{

return "(a = " + a + ", b = " + b + ")";

}

}

class Set<T>

{

ArrayList list;

public Set()

{ list = new ArrayList(); }

public void Add(T element)

{

foreach(T a in list)

if(a.Equals(element))

{

// Console.WriteLine("Такой элемент уже есть");

return;

}

list.Add(element);

}

public T this[int i]

{

get

{

if (i < 0 && i >= list.Count)

throw new Exception("Некорректный индекс");

return (T)list[i];

}

set

{

if (i < 0 && i >= list.Count)

throw new Exception("Некорректный индекс");

list[i] = value;

}

}

public void Print()

{

if (list.Count == 0)

{

Console.WriteLine("Множество пустое"); return;

}

foreach (T a in list)

Console.Write(a.ToString() + " ");

Console.WriteLine();

}

static public Set<T> Intersection(Set<T> set1, Set<T> set2)

{

Set<T> res = new Set<T>();

foreach (T a in set1.list)

foreach (T b in set2.list)

if (a.Equals(b))

{

res.Add(a); break;

}

return res;

}

//объединение множеств

static public Set<T> operator +(Set<T> set1, Set<T> set2)

{

Set<T> res = new Set<T>();

foreach (T a in set1.list)

res.Add(a);

foreach (T a in set2.list)

res.Add(a);

return res;

}

}

class Program

{

static void Main(string[] args)

{

Set<int> s1 = new Set<int>();

for (int i = 0; i < 5; i++)

s1.Add(i);

s1.Print();

Set<int> s2 = new Set<int>();

for (int i = 4; i >= 0; i--)

s2.Add(i);

s2.Print();

Set<int> res = Set<int>.Intersection(s1, s2);

res.Print();

Set<string> s11 = new Set<string>();

for (int i = 0; i < 5; i++)

s11.Add("a"+i);

s11.Print();

Set<string> s12 = new Set<string>();

for (int i = 6; i >= 0; i--)

s12.Add("b"+i);

s12.Print();

Set<string> res1 = Set<string>.Intersection(s11, s12);

res1.Print();

Set<Proba> s21 = new Set<Proba>();

for (int i = 0; i < 5; i++)

s21.Add(new Proba(i,((double)i)/2));

s21.Print();

Set<Proba> s22 = new Set<Proba>();

for (int i = 6; i >= 3; i--)

s22.Add(new Proba(i, ((double)i) / 2));

s22.Print();

Console.WriteLine("Пересечение");

Set<Proba> res2 = Set<Proba>.Intersection(s21, s22);

res2.Print();

Console.WriteLine("Объединение");

Set<Proba> res3 = s21 + s22;

res3.Print();

s21.Print(); s22.Print();

//Console.WriteLine();

Console.ReadLine();

}

}

}

  1. Порабола

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Parabola

{

enum TypeInequation { le, ge, e, l, g, n };

abstract class Function

{

public abstract double Сalculate(double x, double y);

public virtual void Input()

{

Console.WriteLine("Введите данные");

}

public abstract string Output();

}

class Parabola : Function

{

double y0;

double p;

public Parabola(double p1 = 1, double y = 0)

{

p = p1;

y0 = y;

}

public override double Сalculate(double x, double y)

{

return (y - y0) * (y - y0) - 2 * p * x;

}

public override void Input()

{

base.Input();

p = double.Parse(Console.ReadLine());

y0 = double.Parse(Console.ReadLine());

}

public override string Output()

{

return "(y- "+"- y0)-"+ "* (y -"+" y0)-"+ - 2 * p +"* x";

}

}

class Constraint

{

Function function;

double b;

TypeInequation type;

public Constraint()

{

Input();

}

public bool IsExecute(double x, double y)

{

double val = function.Сalculate(x, y);

switch (type)

{

case TypeInequation.le:

if (val <= b) return true; break;

case TypeInequation.ge:

if (val >= b) return true; break;

case TypeInequation.e:

if (val == b) return true; break;

case TypeInequation.l:

if (val < b) return true; break;

case TypeInequation.g:

if (val > b) return true; break;

case TypeInequation.n:

if (val != b) return true; break;

}

return false;

}

public bool IsOnBound(double x, double y)

if (type == TypeInequation.l ||

type == TypeInequation.g || type == TypeInequation.n)

return false;

double val = function.Сalculate(x, y);

return (val == b);

}

public void Input()

{

int choice;

while (true)

{

Console.WriteLine("Линейная - 1, Эллиптическая - 2,Гиперболическая - 3, Параболическая - 4");

choice = int.Parse(Console.ReadLine());

if (choice >= 1 && choice <= 4)

break;

}

switch (choice)

{

//case 1: function = new Line(); break;

//case 2: function = new Ellipse(); break;

// case 3: function = new Hyperbola(1,1,1,1); break;

case 4: function = new Parabola(); break;

}

function.Input();

while (true)

{

Console.WriteLine("<= - 0, >= - 1, = - 2,< - 3, > - 4, <> - 5");

choice = int.Parse(Console.ReadLine());

if (choice >= 0 && choice <= 5)

break;

}

type = (TypeInequation)choice;

Console.WriteLine("Правая часть");

b = double.Parse(Console.ReadLine());

}

static public implicit operator string(Constraint ob)

{

string res = ob.function.Output();

switch (ob.type)

{

case TypeInequation.le:

res = res + "<="; break;

case TypeInequation.ge:

res = res + ">="; break;

case TypeInequation.e:

res = res + "="; break;

case TypeInequation.l:

res = res + "<"; break;

case TypeInequation.g:

res = res + ">"; break;

case TypeInequation.n:

res = res + "<>"; break;

default:

throw new Exception("");

}

res = res + ob.b;

return res;

}

}

class Set

{

Constraint[] constraints;

int n;

public Set(int n1)

{

n = n1;

constraints = new Constraint[n];

for (int i = 0; i < n; i++)

constraints[i] = new Constraint();

}

public bool Belongs(double x, double y)

{

for (int i = 0; i < n; i++)

if (!constraints[i].IsExecute(x, y))

return false;

return true;

}

public bool IsOnBound(double x, double y)

{

if (Belongs(x, y))

for (int i = 0; i < n; i++)

if (constraints[i].IsOnBound(x, y))