Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp4
- {
- class Library {
- Book[] array;
- public Library() {
- array = new Book[0];
- }
- public Library(Book[] arr) {
- array = new Book[arr.Length];
- Array.Copy(arr, array, arr.Length);
- }
- public void AddBook(Book obj) {
- Array.Resize<Book>(ref array, array.Length+1);
- array[array.Length - 1] = obj;
- }
- public Book[] CountBooksWithTheLessAmountOfPages(int n) {
- Book[] arrOfLessBook = new Book[array.Length];
- int count = 0;
- for (int i = 0; i < array.Length; i++) {
- if (array[i].countPages < n) {
- arrOfLessBook[count] = array[i];
- count += 1;
- }
- }
- return arrOfLessBook;
- }
- public int Size {
- get {
- return array.Length;
- }
- }
- public void GetInfo() {
- for (int i = 0; i < array.Length; i++) {
- Console.WriteLine($"Количество страниц: {array[i].countPages}, номер секции: {array[i].sectionNumber}");
- }
- Console.WriteLine();
- }
- public Book this[int index] {
- get {
- return array[index];
- }
- }
- }
- class Book {
- int _countPages;
- int _sectionNumber;
- public Book(int _countPages, int _sectionNumber) {
- this._countPages = _countPages;
- this._sectionNumber = _sectionNumber;
- }
- public int countPages {
- get {
- return _countPages;
- }
- }
- public int sectionNumber {
- get {
- return _sectionNumber;
- }
- }
- public void GetBookInfo() {
- Console.WriteLine($"Количество страниц: {_countPages}, номер секции: {_sectionNumber}");
- }
- }
- class Program
- {
- static Random rnd = new Random();
- static void Main()
- {
- do
- {
- int N = rnd.Next(10, 21);
- Library lib = new Library();
- for (int i = 0; i < N; i++)
- {
- int countPages = rnd.Next(1, 501);
- int sectionNumber = rnd.Next(5, 11);
- lib.AddBook(new Book(countPages, sectionNumber));
- }
- lib.GetInfo();
- for (int i = 0; i < N; i++)
- {
- if (lib[i].countPages < 200)
- {
- lib[i].GetBookInfo();
- }
- }
- Console.WriteLine();
- } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement