Доработать лабораторную работу по теме "Наследование" - C#
Формулировка задачи:
Нужно доработать лабу , добавив при этом
1. Добавить класс потомок;
2. Добавить метод реализуемый в потомке
3. Использовать в классе потомке доступ к полям базового класса
4. Добавить класс клиент в котором использовать клиентский статический и динамический метод.
5. Выполнить описание добавляемых методов.
Смотрел много примеров , вродь все понятно , в примерах обычно берут стандарт типо студент - имя , курс , средний балл и тд тп , как взялся делать свою лабу , вообще нечего не клеиться , не могу продвинуться . Не особо понимаю что можно бы добавить к моему коду. Если кто то может , помогите пожалуйста хотя бы начать.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication19 { class Program { class laba1 { public laba1(int a, int b) // заполнение массива { Random r = new Random(); for (int i = 0; i < a; i++) for (int j = 0; j < b; j++) Matrix[i, j] = r.Next(-100, 100); } public int[,] Matrix = new int[100, 100]; public void Vivod(int c, int d) //метод вывода матрицы { //выводим матрицу for (int i = 0; i < c; i++) { for (int j = 0; j < d; j++) Console.Write(Matrix[i, j] + "\t"); Console.WriteLine(""); } } public int this[int i, int j] // индексатор массива { get { return Matrix[i, j]; } set { Matrix[i, j] = value; } } } class podmatrix { public podmatrix(ref int[,] matr, int a, int b) //в конструктор передаём параметры: указатель на исходную матрицу, длинну ширину создаваемой матрицы { A = a; B = b; for (int i = 0; i < a; i++) for (int j = 0; j < b; j++) Array[i, j] = matr[i, j]; //передаём элементы исходную матрицы в подматрицу } private int A, B; // А,В - размер матрицы private int[,] Array = new int[300, 300]; //объявляем матрицу public void showArray() //метод вывода подматрицы { for (int i = 0; i < A; i++) { for (int j = 0; j < B; j++) Console.Write(Array[i, j] + "\t"); Console.Write("\n"); } } } class mainlaba1 { public static void Main() { int a = 0, b = 0, c = 0, d = 0; Console.WriteLine("Дана матрица: Martix[a, b]"); try { do { Console.Write("Введите количество строк a = "); a = Int32.Parse(Console.ReadLine()); if (a > 100) { Console.WriteLine("Вы вышли за пределы массива "); } } while (a > 100); do { Console.Write("Введите количество столбцов b = "); b = Int32.Parse(Console.ReadLine()); if (b > 100) { Console.WriteLine("Вы вышли за пределы массива "); } } while (b > 100); } catch { Console.WriteLine("Неверный ввод"); } laba1 rev = new laba1(a, b); rev.Vivod(a, b); try { Console.WriteLine("Доступ к элементу массива по индексу:"); Console.Write("Введите индекс строки матрицы:"); a = Convert.ToInt32(Console.ReadLine()); Console.Write("Введите индекс столбца матрицы:"); b = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(+rev[a - 1, b - 1]); Console.WriteLine("Выводим на экран подматрицу:"); Console.WriteLine("Дана матрица: PodMatr[c, d]"); do { Console.Write("Введите количество строк подматрицы с= "); c = Int32.Parse(Console.ReadLine()); if (c > 300) { Console.WriteLine("Вы вышли за пределы массива "); } } while (c > 300); do { Console.Write("Введите количество столбцов подматрицы d = "); d = Int32.Parse(Console.ReadLine()); if (d > 300) { Console.WriteLine("Вы вышли за пределы массива"); } } while (d > 300); } catch { Console.WriteLine("Неверный ввод"); } podmatrix A = new podmatrix(ref rev.Matrix, c, d); A.showArray(); Console.ReadKey(); } } } }
Решение задачи: «Доработать лабораторную работу по теме "Наследование"»
textual
Листинг программы
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication19 { class Student { protected string name; protected double kurs; public Student(string name, double kurs) { this.name = name; this.kurs = kurs; } public void Show() { Console.WriteLine("Имя: " + name + "\nКурс: " + kurs); } } class PotomokStudent : Student { private string uspevaemost; private bool proverka; // Передача параметров в базовый конструктор public PotomokStudent(string name, double kurs, string uspevaemost, bool proverka) : base(name, kurs) { this.uspevaemost = uspevaemost; this.proverka = proverka; } public void Showinfo() { // Обращение к методу базового класса, используя ключевое слово base base.Show(); string temp; Console.WriteLine("\nУспеваемость: " + uspevaemost + "\nБюджет/Контракт: " + (temp = proverka == true ? "1\n" : "2\n")); } } class laba1 { public laba1(int a, int b) // заполнение массива { Random r = new Random(); for (int i = 0; i < a; i++) for (int j = 0; j < b; j++) Matrix[i, j] = r.Next(-100, 100); } public int[,] Matrix = new int[100, 100]; public void Vivod(int c, int d) //метод вывода матрицы { //выводим матрицу for (int i = 0; i < c; i++) { for (int j = 0; j < d; j++) Console.Write(Matrix[i, j] + "\t"); Console.WriteLine(""); } } public int this[int i, int j] // индексатор массива { get { return Matrix[i, j]; } set { Matrix[i, j] = value; } } } class podmatrix { public podmatrix(ref int[,] matr, int a, int b) //в конструктор передаём параметры: указатель на исходную матрицу, длинну ширину создаваемой матрицы { A = a; B = b; for (int i = 0; i < a; i++) for (int j = 0; j < b; j++) Array[i, j] = matr[i, j]; //передаём элементы исходную матрицы в подматрицу } private int A, B; // А,В - размер матрицы private int[,] Array = new int[300, 300]; //объявляем матрицу public void showArray() //метод вывода подматрицы { for (int i = 0; i < A; i++) { for (int j = 0; j < B; j++) Console.Write(Array[i, j] + "\t"); Console.Write("\n"); } } } class mainlaba1 { public static void Main() { Console.WriteLine("Автор кода:"); PotomokStudent myStudent = new PotomokStudent("Пётр", 2, "Отличник", true); myStudent.Showinfo(); int a = 0, b = 0, c = 0, d = 0; Console.WriteLine("Код:"); Console.WriteLine("Дана матрица: Martix[a, b]"); try { do { Console.Write("Введите количество строк a = "); a = Int32.Parse(Console.ReadLine()); if (a > 100) { Console.WriteLine("Вы вышли за пределы массива "); } } while (a > 100); do { Console.Write("Введите количество столбцов b = "); b = Int32.Parse(Console.ReadLine()); if (b > 100) { Console.WriteLine("Вы вышли за пределы массива "); } } while (b > 100); } catch { Console.WriteLine("Неверный ввод"); } laba1 rev = new laba1(a, b); rev.Vivod(a, b); try { Console.WriteLine("Доступ к элементу массива по индексу:"); Console.Write("Введите индекс строки матрицы:"); a = Convert.ToInt32(Console.ReadLine()); Console.Write("Введите индекс столбца матрицы:"); b = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(+rev[a - 1, b - 1]); Console.WriteLine("Выводим на экран подматрицу:"); Console.WriteLine("Дана матрица: PodMatr[c, d]"); do { Console.Write("Введите количество строк подматрицы с= "); c = Int32.Parse(Console.ReadLine()); if (c > 300) { Console.WriteLine("Вы вышли за пределы массива "); } } while (c > 300); do { Console.Write("Введите количество столбцов подматрицы d = "); d = Int32.Parse(Console.ReadLine()); if (d > 300) { Console.WriteLine("Вы вышли за пределы массива"); } } while (d > 300); } catch { Console.WriteLine("Неверный ввод"); } podmatrix A = new podmatrix(ref rev.Matrix, c, d); A.showArray(); Console.ReadKey(); } } }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д