Essays.club - Получите бесплатные рефераты, курсовые работы и научные статьи
Поиск

Наследование классов

Автор:   •  Август 22, 2023  •  Лабораторная работа  •  4,455 Слов (18 Страниц)  •  71 Просмотры

Страница 1 из 18

МИНИСТЕРСТВО ОБРАЗОВАНИЯ И НАУКИ РОССИЙСКОЙ ФЕДЕРАЦИИ

«Сибирский государственный университет науки и технологий

имени академика М.Ф. Решетнева»

Отчет по лабораторной работе №4

«Наследование классов»

Вариант: 5

Руководитель:

___________________ Д.В. Тихоненко

(подпись)

________________________________

(оценка, дата)

Выполнил:

студент группы БПЭ 21-02

____________________ А.М. Забелин

(подпись)

________________________________

(дата)

Красноярск 2022

[pic 1]

Текст программы:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace лаба_4

{

    abstract class Printing

    {

        protected int age;

        protected string name;

        protected string author;

        protected string agestr;

        abstract public void WriteBook();

        abstract public void ReadBook();

        abstract public bool FindBookAge(int age);

        abstract public bool FindBookName(string name);

        abstract public bool FindBookAuthor(string author);

    }

    class Magazine : Printing

    {

        public override bool Equals(object obj)

        {

            Magazine other = obj as Magazine;

            return (other.age == this.age && other.author == this.author && other.name == this.name);

        }

        public override int GetHashCode()

        {

            return age.GetHashCode();

        }

        public override void WriteBook()

        {

        link:

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

            this.agestr = Console.ReadLine();

            try

            {

                this.age = int.Parse(this.agestr);

                if (this.age > 2022 || this.age < 0)

                    goto link;

            }

            catch

            {

                goto link;

            }

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

            this.name = Console.ReadLine();

            Console.WriteLine("Введите главного редактора газеты");

            this.author = Console.ReadLine();

        }

        public override void ReadBook()

        {

            Console.WriteLine("год издания " + age + "\nназвание газеты " + name + "\nглавный редактор газеты " + author);

        }

        public override bool FindBookAge(int age)

        {

            return (this.age == age);

        }

        public override bool FindBookName(string name)

        {

            return (this.name == name);

        }

        public override bool FindBookAuthor(string author)

        {

            return (this.author == author);

        }

    }

    class Book : Printing

    {

        public override bool Equals(object obj)

        {

            Book other = obj as Book;

            return (other.age == this.age && other.author == this.author && other.name == this.name);

        }

        public override int GetHashCode()

        {

            return age.GetHashCode();

        }

        public override void WriteBook()

        {

        link:

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

            this.agestr = Console.ReadLine();

            try

            {

                if (this.age > 2022 || this.age < 0)

                    goto link;

                this.age = int.Parse(this.agestr);

            }

            catch

            {

                goto link;

            }

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

            this.name = Console.ReadLine();

            Console.WriteLine("Введите автора книги");

            this.author = Console.ReadLine();

        }

        public override void ReadBook()

        {

            Console.WriteLine("год издания " + this.age + "\nназвание книги " + this.name + "\nавтор книги " + this.author);

        }

        public override bool FindBookAge(int age)

        {

            return (this.age == age);

        }

...

Скачать:   txt (11.9 Kb)   pdf (132.9 Kb)   docx (53.1 Kb)  
Продолжить читать еще 17 страниц(ы) »
Доступно только на Essays.club