| Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате |
| Форум программистов > Общие вопросы по .NET и C# > Создание библиотек классов |
| Автор: karabickay 25.1.2014, 12:30 |
| Подключить к консольному приложению созданную библиотеку классов. Разместить в консольном приложении код, позволяющий осуществить тестирование класса из созданной библиотеки классов Как сделать? Код я написала. using System; class program { static void Main() { Triangle tr1 = new Triangle(new Point(0, 0), new Point(0, 3), new Point(3, 0)), tr2 = new Triangle(new Point(0, 0), new Point(0, 3), new Point(10, 1)); Console.WriteLine("Треугольник 1: {0}, P = {1}, S = {2}, Прямоугольный = {3}", tr1, tr1.P(), tr1.S(), tr1.IsRightAngled()); Console.WriteLine("Треугольник 2: {0}, P = {1}, S = {2}, Прямоугольный = {3}", tr2, tr2.P(), tr2.S(), tr2.IsRightAngled()); switch (tr1.CompareTo(tr2)) { case 1: Console.WriteLine("Треугольник 1 больше"); break; case -1: Console.WriteLine("Треугольник 2 больше"); break; case 0: Console.WriteLine("Треугольники равны"); break; } Console.WriteLine("Типы треугольников {0}", tr1.Equals(tr2) ? "совпадают" : "различны"); Console.Read(); } struct Point : IEquatable<Point> { int x, y; public int X { get { return x; } } public int Y { get { return y; } } public Point(int x, int y) { this.x = x; this.y = y; } public bool Equals(Point other) { return this.x == other.x && this.y == other.y; } public static double Length(Point a, Point b) { return Math.Sqrt(Math.Pow(b.x - a.x, 2) + Math.Pow(b.y - a.y, 2)); } public override string ToString() { return string.Format("(x:{0}, y:{1})", this.x, this.y); } } class Triangle : IComparable<Triangle>, IEquatable<Triangle> { Point A, B, C; public Triangle(Point a, Point b, Point c) { if (a.Equals(b) || a.Equals© || b.Equals©) throw new ArgumentException("Это не треугольник"); this.A = a; this.B = b; this.C = c; } public Triangle(Triangle triangle) : this(triangle.A, triangle.B, triangle.C) { } public double S() { return 0.5 * Math.Abs(((A.X - C.X) * (B.Y - C.Y) - (B.X - C.X) * (A.Y - C.Y))); } public double P() { return Point.Length(this.A, this.B) + Point.Length(this.A, this.C) + Point.Length(this.B, this.C); } public bool IsRightAngled() { return (this.B.X - this.A.X) * (this.C.X - this.A.X) + (this.B.Y - this.A.Y) * (this.C.Y - this.A.Y) == 0 || (this.A.X - this.B.X) * (this.C.X - this.B.X) + (this.A.Y - this.B.Y) * (this.C.Y - this.B.Y) == 0 || (this.B.X - this.C.X) * (this.A.X - this.C.X) + (this.B.Y - this.C.Y) * (this.A.Y - this.C.Y) == 0; } public int CompareTo(Triangle other) { return this.S().CompareTo(other.S()); } public bool Equals(Triangle other) { return this.IsRightAngled() == other.IsRightAngled(); } public override string ToString() { return string.Format("A:{0}, B:{1}, C:{2}", this.A, this.B, this.C); } } } |
| Автор: jonie 25.1.2014, 15:47 |
| Давай еще пару дублей создадим?) Никто за Вас ничего делать не будет. http://forum.vingrad.ru/forum/topic-375448/kw-%D0%BA%D0%BB%D0%B0%D1%81%D1%81%D1%8B.html |