Обобщенное программирование, шаблоны - Лабораторная работа

бесплатно 0
4.5 69
Разработка шаблонной функции FindMax, выполняющей поиск максимального элемента в массиве. Разработка шаблонного класса CMyArray, представляющего собой массив элементов некоторого типа. Иерархия классов и интерфейсов. Индексированный доступ к элементам.


Аннотация к работе
Текст программы class Program { static bool method(T[] t,ref T a) { if (t.Length == 0) { return false; } else { a = t.Max(); return true; } } static void Main(string[] args) { string control = ; while (control != ex) { Console.WriteLine(1 - Create String Array *); Console.WriteLine(2 - Create Char Array *); Console.WriteLine(3 - Create Int Array *); Console.WriteLine(4 - Create Double Array *); Console.WriteLine(5 - Create Byte Array *); Console.WriteLine(**************************); control = Console.ReadLine(); Console.Clear(); switch (control) { case 1: string s_max_string = ; Console.Write(Enter array lenght : ); int len_s = int.Parse(Console.ReadLine()); string[] stroki = new string[len_s]; for (int i = 0; i { T[] aa; int index = 0; public MyGenericClass(int q) { aa = new T[q]; } public MyGenericClass(MyGenericClass q) { aa = q.aa; } public void ArrayAdd(T value) { aa[index ] = value; } public int GetLength() { return aa.Length; } public void ArrayResize(int newSize) { if (newSize a1 = null; MyGenericClass a2 = null; MyGenericClass a3 = null; MyGenericClass a4 = null; string control = ; while (control != ex) { Console.WriteLine(1 - Create Array *); Console.WriteLine(2 - Get Lenght Array *); Console.WriteLine(3 - Get Element *); Console.WriteLine(4 - Resize Array *); Console.WriteLine(5 - Clear Array *); Console.WriteLine(6 - Copy Array *); Console.WriteLine(*************************); control = Console.ReadLine(); Console.Clear(); switch (control) { case 1: Console.WriteLine(What array create? string,int,double,char?); string s_c = Console.ReadLine(); prov = s_c; if (s_c == string) { Console.Write(Enter array lenght: ); index = int.Parse(Console.ReadLine()); a1 = new MyGenericClass(index); for (int i = 0; i (index); for (int i = 0; i (index); for (int i = 0; i (index); for (int i = 0; i copy_a1 = new MyGenericClass(a1); copy_a1.Show(); } if (prov == int) { MyGenericClass copy_a2 = new MyGenericClass(a2); copy_a2.Show(); } if (prov == double) { MyGenericClass copy_a3 = new MyGenericClass(a3); copy_a3.Show(); } if (prov == char) { MyGenericClass copy_a4 = new MyGenericClass(a4); copy_a4.Show(); } Console.ReadKey(); Console.Clear(); break; } } } } Результат выполнения программы Задание 3 Имеется следующая иерархия классов и интерфейсов, моделирующих иерархию объектов в обществе (человек, учитель, ученик, студент, рабочий, аспирант): Свойства, которыми обладают сущности данной иерархии: Сущность Свойства Человек Имя Фамилия Отчество Адрес Ученик Название школы Класс Преподаватель Название предмета Студент Название ВУЗ-а Номер студенческого билета Аспирант Тема диссертации Рабочий Специальность Текст программы interface IPerson { string Name { get; set; } string Surname { get; set; } string Otchestvo { get; set; } string Adress { get; set; } } interface IPupil { string NameScholl { get; set; } string NameKlass { get; set; } } interface ITeacher { string NamePredmet { get; set; } } interface IStudent { string NameUniver { get; set; } string NomerStud { get; set; } } interface IWorker { string Special { get; set; } } interface IAdvancedStudent { string TemaDeklarazii { get; set; } } class CPupil : IPupil, IPerson { public string Name { get; set; } public string Surname { get; set; } public string Otchestvo { get; set; } public string Adress { get; set; } public string NameScholl { get; set; } public string NameKlass { get; set; } public override string ToString() { return PUPIL- Name: Name Surname: Surname Otchestvo: Otchestvo Adress: Adress NameScholl: NameScholl NameKlass: NameKlass; } } class CTeacher : ITeacher, IPerson { public string Name { get; set; } public string Surname { get; set; } public string Otchestvo { get; set; } public string Adress { get; set; } public string NamePredmet { get; set; } public override string ToString() { return TEACHER- Name: Name Surname: Surname Otchestvo: Otchestvo Adress: Adress NamePredmet: NamePredmet; } } class CStudent : IStudent, IPerson { public string Name { get; set; } public string Surname { get; set; } public string Otchestvo { get; set; } public string Adress { get; set; } public string NameUniver { get; set; } public string NomerStud { get; set; } public override string ToString() { return STUDENT- Name: Name Surname: Surname Otchestvo: Otchestvo Adress: Adress NameUniver: NameUniver NomerStud: NomerStud; } } class CWorker : IWorker, IPerson { public string Name { get; set; } public string Surname { get; set; } public string Otchestvo { get; set; } public string Adress { get; set; } public string Special { get; set; } public override string ToString() { return WORKER- Name: Name Surname: Surname Otchestvo: Otchestvo Adress: Adress Special: Special; } } class CAdvanceStudent : IAdvancedStudent, IStudent, IPerson { public string Name { get; set; } public string Surname { get; set; } public string Otchestvo { get; set; } public string Adress { get; set; } public string Name
Заказать написание новой работы



Дисциплины научных работ



Хотите, перезвоним вам?