By GokiSoft.com| 09:53 07/10/2021|
C Sharp

Chương trình quản lý sách - Develop Book Project - Lập Trình C# - OOP trong C# - C Sharp BT1458

Cài đặt lớp Book gồm các thuộc tính:

private String bookName;

private String bookAuthor;

private String producer;

private int yearPublishing;

private float price;

 

Cài đặt 2 constructors, các phương thức set/get cho các thuộc tính của lớp.

Cài đặt 2 phương thức input() và display để nhập và hiển thị các thuộc tính của lớp.

 

Cài đặt lớp AptechBook kế thừa lớp Book và bổ sung thêm vào thuộc tính:

private String language;

private int semester;

 

Cài đặt 2 constructor trong đó sử dụng super để gọi đến constructor của lớp cha.

Cài đặt các phương thức get/set cho các thuộc tính bổ sung

Override các phương thức input() và display().

 

Cài đặt lớp Test trong đó tạo menu và thực hiện theo các chức năng của menu:
1.    Nhập thông tin n cuốn sách của Aptech
2.    Hiển thị thông tin vừa nhập
3.    Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị
4.    Tìm kiếm theo tên sách
5.    Tìm kiếm theo tên tác giả
6. Lưu thông tin sách đã nhập vào file
7. Đọc nội dung từ file và lưu vào mang quản lý sách
8.    Thoát.

Liên kết rút gọn:

https://gokisoft.com/1458

Bình luận

avatar
Hoàng Thiện Thanh [community,AAHN-C2009G]
2021-09-28 02:10:06


#Program.cs


using System;
using System.IO;

namespace BookManagement
{

    
    class BookMenu
    {
        private static Book[] books = new Book[0];

        static bool IsNumber(string s)
        {
            bool value = true;
            if (string.IsNullOrEmpty(s))
            {
                value = false;
            }
            else
            {
                foreach (char c in s.ToCharArray())
                {
                    value = value && char.IsDigit(c);
                }
            }
            return value;
        }

        static void Main(string[] args)
        {
            int choose;

            do
            {
                ShowMenu();
                var input = Console.ReadLine();
                while (!IsNumber(input)) {
                    input = Console.ReadLine();
                }

                choose = int.Parse(input);

                switch (choose)
                {
                    case 1:
                        Input();
                        break;
                    case 2:
                        Display();
                        break;
                    case 3:
                        SortByYear();
                        Display();
                        break;
                    case 4:
                        SearchByName();
                        break;
                    case 5:
                        SearchByAuthor();
                        break;
                    case 6:
                        SaveToFile();
                        break;
                    case 7:
                        ReadFromFile();
                        break;
                    case 8:
                        Console.WriteLine("Thoat!!!");
                        break;
                    default:
                        Console.WriteLine("Nhap sai!!!");
                        break;
                }
            } while (choose != 8);
        }

        static void Input()
        {
            Console.WriteLine("Input the number of books to add: ");
            int N = int.Parse(Console.ReadLine());

            books = new Book[N];

            for(int i = 0; i < N; i++)
            {
                Book b = new AptechBook();
                b.input();
                books[i] = b;
            }

        }

        static void Display()
        {
            if (books.Length == 0) return;
            for (int i = 0; i < books.Length; i++)
            {
                books[i].display();
            }
        }

        static void SortByYear()
        {
            if (books.Length == 0) return;

            Array.Sort<Book>(books, new Comparison<Book>(
                (p1, p2) => (p1.YearPublishing < p2.YearPublishing) ? 1 : -1
                ));
        }

        static void SearchByName()
        {
            if (books.Length == 0) return;
            string searchBook = Console.ReadLine();
            int kq = 0;
            foreach(Book b in books)
            {
                if(b.BookName == searchBook)
                {
                    b.display();
                    kq++;
                }
            }

            if (kq == 0)
            {
                Console.WriteLine("No Result");
            }
        }

        static void SearchByAuthor()
        {
            if (books.Length == 0) return;
            string searchAuthor = Console.ReadLine();
            int kq = 0;
            foreach (Book b in books)
            {
                if (b.BookAuthor == searchAuthor)
                {
                    b.display();
                    kq++;
                }
            }

            if (kq == 0)
            {
                Console.WriteLine("No Result");
            }
        }

        static void SaveToFile()
        {
            if (books.Length == 0) return;
            using (Stream filepath = File.Open(@"Book.dat", FileMode.Create))
            {
                var format1 = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                format1.Serialize(filepath, books);
            }

            Console.WriteLine("Save Complete");
        }

        static void ReadFromFile()
        {
            
            using (Stream filepath1 = File.Open(@"Book.dat", FileMode.Open))
            {
                var format = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                books = (Book[])format.Deserialize(filepath1);
            }
            Console.WriteLine("Read Complete");
            Display();
        }
        static void ShowMenu()
        {
            Console.WriteLine("1. Insert amount of books");
            Console.WriteLine("2. Show books");
            Console.WriteLine("3. Sort by Year Published in descending");
            Console.WriteLine("4. Search by name");
            Console.WriteLine("5. Search by author");
            Console.WriteLine("6. Save in file");
            Console.WriteLine("7. Read from file");
            Console.WriteLine("8. Thoat");
            Console.WriteLine("Choose: ");
        }
    }
}


#AptechBook.cs


using System;
[Serializable]
public class AptechBook : Book
{

    private string language;

    public string Language { get { return this.language; }
        set { this.language = value; }
    }

    private int semester;
    public int Semester { get { return this.semester; }
        set { while (value <= 0)
            {
                Console.WriteLine("Enter semester again, must be greater than 0");
                value = int.Parse(Console.ReadLine());
            } 
            this.semester = value; }
    }

	public AptechBook() : base()
	{

	}

	public AptechBook(string bookName, string bookAuthor, string producer, int yearPublishing, float price, string language, int semester) 
		: base(bookName, bookAuthor, producer, yearPublishing, price)
	{
		this.language = language;
		this.semester = semester;
	}

    public override void input()
    {
        base.input();

        Console.WriteLine("Nhap ngon ngu: ");
        language = Console.ReadLine();

        Console.WriteLine("Nhap hoc ky: ");
        semester = int.Parse(Console.ReadLine());
    }

    public override void display()
    {
        Console.WriteLine("Name: {0}, Author: {1}, Producer: {2}, Year Published: {3}, Price: {4}, Language: {5}, Semester: {6}",
            base.BookName, base.BookAuthor, base.Producer, base.YearPublishing, base.Price, Language, Semester);
    }

}


#Book.cs


using System;
[Serializable]
public class Book
{
    private string bookName;
    public string BookName
    {
        get { return this.bookName; }
        set { this.bookName = value; }
    }
    private string bookAuthor;
    public string BookAuthor
    {
        get { return this.bookAuthor; }
        set { this.bookAuthor = value; }
    }


    private string producer;
    public string Producer
    {
        get { return this.producer; }
        set { this.producer = value; }
    }


    private int yearPublishing;

    public int YearPublishing {
        get { return this.yearPublishing; }
        set { this.yearPublishing = value; }
    }
    private float price { get; set; }

    public float Price
    {
        get { return this.price; }
        set { while (value < 0)
            {
                Console.WriteLine("Enter the price again: ");
                value = float.Parse(Console.ReadLine());
                return;
            }
            this.price = value; }
    }

    public Book()
    {

    }

    public Book(string bookName, string bookAuthor, string producer, int yearPublishing, float price)
    {
        this.bookName = bookName;
        this.bookAuthor = bookAuthor;
        this.producer = producer;
        this.yearPublishing = yearPublishing;
        this.price = price;
    }

    public virtual void input()
    {
        Console.WriteLine("Nhap ten sach: ");
        bookName = Console.ReadLine();

        Console.WriteLine("Nhap tac gia: ");
        bookAuthor = Console.ReadLine();

        Console.WriteLine("Nhap nha xuat ban: ");
        producer = Console.ReadLine();

        Console.WriteLine("Nhap nam phat hanh: ");
        yearPublishing = int.Parse(Console.ReadLine());

        Console.WriteLine("Nhap gia ban: ");
        price = float.Parse(Console.ReadLine());
    }

    public virtual void display()
    {
        Console.WriteLine("Name: {0}, Author: {1}, Producer: {2}, Year Published: {3}, Price{4}", bookName, bookAuthor, producer, yearPublishing, price);
    }
}


avatar
Nguyễn Việt Hoàng [community,AAHN-C2009G]
2021-09-27 14:27:43


#AptechBook.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

 namespace Ss3
{
    [Serializable] 
    class AptechBook : Book
    {
       
        private string language;
        public string Language { get
            {
                return this.language;
            }
            set 
            {
                this.language = value; }
                }
        private int semester;
        public int Semester { get
            {
                return this.semester;
            } set {
                this.semester = value;} 
        }
        public AptechBook()
        {
            
        }
        public AptechBook(string bookName, string bookAuthor, string producer, int yearPublishing, float price,string language,int semester) : base( bookName,  bookAuthor,  producer,  yearPublishing,  price)
        {
            this.Language = language;
            this.Semester = semester;
        }
        public override void input()
        {
                base.input();
                Console.WriteLine("Enter language :");
                Language = Console.ReadLine();
                Console.WriteLine("Enter semester :");
                Semester = int.Parse(Console.ReadLine());
           
        }
        public override void display()
        {
                Console.WriteLine("BookName :{0}, BookAuthor :{1}, Producer :{2}, YearPublishing :{3}, Price :{4}, Language :{5}, Semester :{6}", 
                    base.BookName, base.BookAuthor, base.Producer, base.YearPublishing, base.Price, this.Language, this.Semester);
           
        }
       


    }
}


#Book.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ss3
{
    [Serializable]
    class Book
    {
        private string bookName;
        public string BookName
        {
            get
            {
                return this.bookName;
            }
            set
            {
                this.bookName = value;
            }
        }
        private string bookAuthor;
        public string BookAuthor
        {
            get
            {
                return this.bookAuthor;
            }
            set
            {
                this.bookAuthor = value;
            }
        }
        private string producer;
        public string Producer
        {
            get
            {
                return this.producer;
            }
            set
            {
                this.producer = value;
            }
        }
        private int yearPublishing;
        public int YearPublishing
        {
            get
            {
                return this.yearPublishing;
            }
            set
            {
                this.yearPublishing = value;
            }
        }
        private float price;
        public float Price
        {
            get
            {
                return this.price;
            }
            set
            {
                this.price = value;
            }
        }

        public Book()
    {

    }
    public Book(string bookName,string bookAuthor, string producer, int yearPublishing, float price)
    {
            this.bookName = bookName;
            this.bookAuthor = bookAuthor;
            this.producer = producer;
            this.yearPublishing = yearPublishing;
            this.price = price;
    }
        public virtual void input()
        {
            Console.WriteLine("Enter bookName :");
            BookName = Console.ReadLine();
            Console.WriteLine("Enter bookAuthor :");
            BookAuthor = Console.ReadLine();
            Console.WriteLine("Enter producer :");
            Producer = Console.ReadLine();
            Console.WriteLine("Enter yearPublishing :");
            YearPublishing = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter price :");
            Price = float.Parse(Console.ReadLine());

        }
        public virtual void display()
        {
            Console.WriteLine("BookName :{0}, BookAuthor :{1}, Producer :{2}, YearPublishing :{3}, Price :{4}", BookName, BookAuthor, Producer, YearPublishing, Price);
        }
       

    }
  
}


#Program.cs


using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace Ss3
{
    class Program
    {
        static List<Book> save = new List<Book>();
        static void showMenu()
        {
            Console.WriteLine("1.Enter n Aptech books : ");
            Console.WriteLine("2.Display Information");
            Console.WriteLine("3.Sort by YearPublishing des and display");
            Console.WriteLine("4.Find bookName : ");
            Console.WriteLine("5.Find AuthorName : ");
            Console.WriteLine("6.Save information to file");
            Console.WriteLine("7.Read to file and save list books");
            Console.WriteLine("8.Exits");
        }
        static void Input()
        {
            int sum,count;
            Console.WriteLine("Enter Sum of Books :");
            sum = int.Parse(Console.ReadLine());

            for(int i = 0; i < sum; i++)
            {
                count = i + 1;
                Console.WriteLine("Enter Book[" + count + "]");
                Book b = new AptechBook();
                b.input();
                save.Add(b);
   
            }
        }
        static void Display_by_des_yearPublishing()
        {
            Console.WriteLine("Sort by des yearPublishing :");
            save.Sort(
                   (p1, p2) => (p1.YearPublishing < p2.YearPublishing) ? 1 : -1
               );
            foreach (AptechBook i in save)
            {
                i.display();
            }
        }
        static void Display()
        {
            Console.WriteLine("Books :");
            foreach(AptechBook a in save)
             {
                a.display();
            }

        }
        static void Find_by_bookName()
        {
            string pr;
            int count = 0;
            Console.WriteLine("Enter find BookName :");
            pr = Console.ReadLine();
            foreach(Book a in save)
            {
                if(a.BookName == pr)
                {
                    a.display();
                    count++;
                }
            }
            if(count == 0)
            {
                Console.WriteLine("No Book finded ");
            }
        }
        static void Find_by_bookAuthor()
        {
            string pr;
            int count = 0;
            Console.WriteLine("Enter find BookAuthor :");
            pr = Console.ReadLine();
            foreach (Book a in save)
            {
                if (a.BookAuthor == pr)
                {
                    a.display();
                    count++;
                }
            }
            if (count == 0)
            {
                Console.WriteLine("No Book finded ");
            }
        }

        private static void Save_Inf()
        {
            bool append = false;
            using (Stream stream = File.Open(@"Book.txt", append ? FileMode.Append : FileMode.Create))
            {
                var format1 = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                format1.Serialize(stream, save);
                Console.WriteLine("Success");
            }
        }
        static void Read_file_and_save()
        {
            using (Stream filepath1 = File.Open(@"Book.txt", FileMode.Open))
            {
                var format = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                save = (List<Book>)format.Deserialize(filepath1);
            }
        }
        static void listMenu()
        {
            int choose;
            do
            {
                showMenu();
                Console.WriteLine("Enter value of showMenu :");
                choose = int.Parse(Console.ReadLine());
                switch (choose)
                {
                    case 1:
                        Input();
                        break;
                    case 2:
                        Display();
                        break;
                    case 3:
                        Display_by_des_yearPublishing();
                        break;
                    case 4:
                        Find_by_bookName();
                        break;
                    case 5:
                        Find_by_bookAuthor();
                        break;
                    case 6:
                        Save_Inf();
                        break;
                    case 7:
                        Read_file_and_save();
                        Display();
                        break;
                    case 8:
                        Console.WriteLine("Exits");
                        return;
                    default:
                        Console.WriteLine("Must be value of 1 to 4");
                        break;
                }


            } while (choose != 8);
        }


        static void Main(string[] args)
        {
            listMenu();
        }
    }
}


avatar
Triệu Văn Lăng [T2008A]
2021-05-29 01:44:33


#AptechBook.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace bai1458
{
    [Serializable]
    class AptechBook : Book
    {
        private string language { get; set; }

        private int semester { get; set; }

        public AptechBook() {}

        public AptechBook(string bookName, string bookAuthor, string producer, 
            int yearPublishing, float price, string language, int semester) 
            : base( bookName, bookAuthor, producer, yearPublishing, price)
        {
            this.language = language;
            this.semester = semester;
        }

        public override void input()
        {
            base.input();
            Console.WriteLine("Nhap ngon ngu: ");
            language = Console.ReadLine();

            Console.WriteLine("Nhap hoc ki: ");
            semester = Convert.ToInt32(Console.ReadLine());
        }

        public override void display()
        {
            //base.display();
            //Console.WriteLine("Ngon Ngu: {0}, Hoc ki: {1}", language, semester);
            Console.WriteLine("Ten sach: {0}, Ten tac gia: {1}, Ten NXB: {2}, Nam XB: {3}, Gia: {4}, Ngon ngu: {5}, Hoc ki: {6}",
                                bookName, bookAuthor, producer, yearPublishing, price, language, semester);

        }

    }
}


#Book.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace bai1458
{
    [Serializable]
    class Book
    {
        public string bookName { get; set; }

        public string bookAuthor { get; set; }

        public string producer { get; set; }

        public int yearPublishing { get; set; }

        public float price { get; set; }

        public Book() { }

        public Book(string bookName, string bookAuthor, string producer, int yearPublishing, float price)
        {
            this.bookName = bookName;
            this.bookAuthor = bookAuthor;
            this.producer = producer;
            this.yearPublishing = yearPublishing;
            this.price = price;
        }

        public virtual void input()
        {
            Console.WriteLine("Nhap ten sach: ");
            bookName = Console.ReadLine();

            Console.WriteLine("Nhap ten tac gia: ");
            bookAuthor = Console.ReadLine();

            Console.WriteLine("Nhap ten NXB: ");
            producer = Console.ReadLine();

            Console.WriteLine("Nhap nam XB: ");
            yearPublishing = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Nhap gia: ");
            price = float.Parse(Console.ReadLine());
        }

        public virtual void display()
        {
            Console.WriteLine("Ten sach: {0}, Ten tac gia: {1}, Ten NXB: {2}, Nam XB: {3}, Gia: {4}",
                                bookName, bookAuthor, producer, yearPublishing, price);
        }
    }
}


#Program.cs


using System;
using System.Collections.Generic;
using bai1458;
using System.IO;
namespace bai1458
{
    class Program
    {
        static List<AptechBook> apList = new List<AptechBook>();
        static void Main(string[] args)
        {
            int choose = 0;

            do
            {
                
                ShowMenu();
                choose = Convert.ToInt32(Console.ReadLine());
                switch(choose)
                {
                    case 1:
                        Console.WriteLine("Nhap so quyen sach muon them:");
                        int n = Convert.ToInt32(Console.ReadLine());

                        for(int i = 0; i < n; i++)
                        {
                            Console.WriteLine("Nhap thong tin quyen sach thu {0}", i + 1);
                            AptechBook aptech = new AptechBook();
                            aptech.input();
                            apList.Add(aptech);
                        }
                        break;
                    case 2:
                        foreach(AptechBook ap in apList)
                        {
                            ap.display();
                        }
                        break;
                    case 3:
                        apList.Sort((o1, o2) =>
                        {
                            return -o1.yearPublishing.CompareTo(o2.yearPublishing);
                        });

                        for (int i = 0; i < apList.Count; i++)
                        {
                            Console.WriteLine("Thong tin quyen sach thu " + (i + 1) + ":");
                            apList[i].display();
                        }
                        break;
                    case 4:
                        Console.WriteLine("Nhap ten sach can tim: ");
                        string searchbook = Console.ReadLine();
                        int k = 0;
                        foreach(AptechBook ap in apList )
                        {
                            if(ap.bookName == searchbook)
                            {
                                ap.display();
                                k++;
                            }
                        }

                        if(k == 0)
                        {
                            Console.WriteLine("Khong co ket qua");
                        }
                        
                        break;
                    case 5:
                        Console.WriteLine("Nhap ten tac gia: ");
                        string searchAuthor = Console.ReadLine();
                        int ck = 0;
                        foreach (AptechBook ap in apList)
                        {
                            if (ap.bookAuthor == searchAuthor)
                            {
                                ap.display();
                                ck++;
                            }
                        }

                        if (ck == 0)
                        {
                            Console.WriteLine("Khong co ket qua");
                        }
                        break;
                    case 6:
                        using (Stream filepath = File.Open(@"Book.dat", FileMode.Create))
                        {
                            var format1 = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                            format1.Serialize(filepath, apList);
                        }

                        Console.WriteLine("Luu xong ");
                        break;
                    case 7:
                        using (Stream filepath1 = File.Open(@"Book.dat", FileMode.Open))
                        {
                            var format = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                            apList = (List<AptechBook>)format.Deserialize(filepath1);
                        }


                        Console.WriteLine("Doc xong ");
                        break;
                    case 8:
                        Console.WriteLine("Ket thuc chuong trinh");
                        break;
                    default:
                        Console.WriteLine("Nhap lai");
                        break;
                }

            } while (choose != 8);
        }

        private static void ShowMenu()
        {
            Console.WriteLine("1. Nhap thong tin n cuon sach");
            Console.WriteLine("2. Hien thi thong tin vua nhap");
            Console.WriteLine("3. Sap xep thong tin giam dan theo nam xuat ban va hien thi");
            Console.WriteLine("4. Tim kiem theo ten sach");
            Console.WriteLine("5. Tim kiem theo ten tac gia");
            Console.WriteLine("6. Luu vao file");
            Console.WriteLine("7. Doc file");
            Console.WriteLine("8. Thoat");
        }
    }
}


avatar
Do Trung Duc [T2008A]
2021-05-28 15:55:05



using System;
using System.Collections.Generic;
using System.Text;

namespace Lesson7.BookProject
{
    [Serializable]
    class AptechBook : Book
    {
        public string Language { get; set; }
        public string Semester { get; set; }

        public AptechBook(){}

        public AptechBook(string BookName, string BookAuthor, string Producer, int YearPublishing, float Price, string Language, string Semester) :base( BookName,  BookAuthor,Producer,  YearPublishing, Price)
        {
            this.Language = Language;
            this.Semester = Semester;
        }

        public override void Display()
        {
            Console.WriteLine("Ten: {0}, Tacgia: {1}, NXB: {2}, Nam xuat ban: {3}, Gia {4}, Ngon ngu: {5}, Hoc ky: {6}", BookName, BookAuthor, Producer, YearPublishing, Price, Language, Semester);
        }

        public override void Input()
        {
            base.Input();
            Console.WriteLine("Nhap ngonngu sach:");
            Language= Console.ReadLine();

            Console.WriteLine("Nhap hoc ky sach:");
            Semester = Console.ReadLine();
        }
    }
}


avatar
Do Trung Duc [T2008A]
2021-05-28 15:54:52



using System;
using System.Collections.Generic;
using System.Text;

namespace Lesson7.BookProject
{
    [Serializable]
    class Book
    {
        public string BookName { get; set; }
        public string BookAuthor { get; set; }

        public string Producer { get; set; }

        public int YearPublishing { get; set; }

        public float Price { get; set; }

        public Book() { }

        public Book(string BookName, string BookAuthor,string Producer, int YearPublishing, float Price) {
            this.BookName = BookName;
            this.BookAuthor = BookAuthor;
            this.Producer = Producer;
            this.YearPublishing = YearPublishing;
            this.Price = Price;
        }

        public virtual void Input()
        {
            Console.WriteLine("Nhap ten sach:");
            BookName = Console.ReadLine();

            Console.WriteLine("Nhap tac gia sach:");
            BookAuthor = Console.ReadLine();

            Console.WriteLine("Nhap ten nha xuat ban:");
            Producer = Console.ReadLine();

            Console.WriteLine("Nhap nam xuat ban:");
            YearPublishing = Int32.Parse(Console.ReadLine());

            Console.WriteLine("Nhap gia tien:");
            Price = Int32.Parse(Console.ReadLine());
        }

        public virtual void Display()
        {
            Console.WriteLine("Ten: {0}, Tacgia: {1}, NXB: {2}, Nam xuat ban: {3}, Gia {4}", BookName, BookAuthor, Producer, YearPublishing, Price);
        }

    }
}


avatar
Do Trung Duc [T2008A]
2021-05-28 15:54:36



using System;
using System.Collections.Generic;
using System.IO;

namespace Lesson7.BookProject
{
    class Program
        
    {
        static List<AptechBook> BookAptechList = new List<AptechBook>();
        static void Main(string[] args)
            
        {
            int choose;
            do
            {
                Menu();

                choose = Int32.Parse(Console.ReadLine());

                switch (choose)
                {
                    case 1:
                        InputBook();
                        break;

                    case 2:
                        DisplayAllBook();
                        break;

                    case 3:
                        BookAptechList.Sort((o1, o2) =>
                        {
                            return -o1.YearPublishing.CompareTo(o2.YearPublishing);
                        });
                        foreach (AptechBook aptechbook in BookAptechList)
                        {
                            aptechbook.Display();
                        }
                        break;

                    case 4:
                        FindBookByBookName();
                        break;

                    case 5:
                        FindBookByAuthorName();
                        break;

                    case 6:
                        SaveInFile();
                        break;

                    case 7:
                        ReadFile();
                        break;

                    case 8:
                        Console.WriteLine("Thoat...");
                        break;

                }

            } while (choose!=8);
        }

        private static void ReadFile()
        {   
            using (Stream stream = File.Open("Books.dat", FileMode.Open))
            {
                var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                BookAptechList = (List<AptechBook>)binaryFormatter.Deserialize(stream);
            }
            Console.WriteLine("Doc file thanh cong");
        }

        private static void SaveInFile()
        {
            string filePath = "Books.dat";
            using (Stream stream = File.Open(filePath, FileMode.Create))
            {
                var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                //foreach(ClassRoom c in list)
                //{
                //    binaryFormatter.Serialize(stream, c);
                //}
                binaryFormatter.Serialize(stream, BookAptechList);
            }
            Console.WriteLine("Luu file thanh cong");
        }



        private static void FindBookByBookName()
        {
            Console.WriteLine("Nhap ten sach can tim:");
            string FindBookName = Console.ReadLine();
            foreach(AptechBook aptechbook in BookAptechList)
            {
                if(aptechbook.BookName == FindBookName)
                {
                    aptechbook.Display();
                }
            }
        }

        private static void FindBookByAuthorName()
        {
            Console.WriteLine("Nhap ten sach can tim:");
            string FindAuthorName = Console.ReadLine();
            foreach (AptechBook aptechbook in BookAptechList)
            {
                if (aptechbook.BookAuthor == FindAuthorName)
                {
                    aptechbook.Display();
                }
            }
        }

        private static void InputBook()
        {
            Console.WriteLine("Nhap so luong cuon sach muon nhap:");
            int N= Int32.Parse(Console.ReadLine());
            for(int i =0 ; i < N; i++)
            {
                AptechBook aptechbook = new AptechBook();
                aptechbook.Input();
                BookAptechList.Add(aptechbook);
            }

        }

        private static void DisplayAllBook()
        {
            for(int i = 0 ; i < BookAptechList.Count ; i++)
            {
                BookAptechList[i].Display();
            }

        }

        public static void Menu()
        {
            Console.WriteLine("1.Nhập thông tin n cuốn sách của Aptech");
            Console.WriteLine("2.Hiển thị thông tin vừa nhập");
            Console.WriteLine("3.Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị");
            Console.WriteLine("4.Tìm kiếm theo tên sách");
            Console.WriteLine("5.Tìm kiếm theo tên tác giả");
            Console.WriteLine("6.Lưu thông tin sách đã nhập vào file");
            Console.WriteLine("7. Đọc nội dung từ file và lưu vào mang quản lý sách");
            Console.WriteLine("8. Thoat");
            Console.WriteLine("Chon: ");
        }
    }
}


avatar
Nguyễn Anh Vũ [T2008A]
2021-05-28 10:27:38


#Program
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace QuanLySach
{
    class Program
    {
        static void Main(string[] args)
        {
            Test();
        }

        static public void Test()
        {
            List<AptechBook> listbook = new List<AptechBook>();
            int choose;

            do
            {
                Menu();
                Console.Write("Choose: ");
                choose = int.Parse(Console.ReadLine());
                switch (choose)
                {
                    case 1:
                        Console.Write("Enter n: ");
                        int n = int.Parse(Console.ReadLine());
                        for (int i = 1; i <= n; i++)
                        {
                            AptechBook aptechBook = new AptechBook();
                            Console.WriteLine("Nhao sach {0}: ", i);
                            aptechBook.input();
                            listbook.Add(aptechBook);
                        }
                        break;
                    case 2:
                        Console.WriteLine("hien thi info:");
                        showInfor(listbook);
                        break;
                    case 3:
                        Sort(listbook);
                        showInfor(listbook);
                        break;
                    case 4:
                        Console.Write("Nhap ten sach: ");
                        string search = Console.ReadLine();
                        AptechBook book = findBybookName(search, listbook);
                        book.output();
                        break;
                    case 5:
                        Console.Write("Nhap gia ban: ");
                        search = Console.ReadLine();
                        AptechBook author = findBybookAuthor(search, listbook);
                        author.output();
                        break;
                    case 6:
                        FileStream fs = new FileStream("E:/C#/quanlisach.txt", FileMode.Create);
                        StreamWriter sWriter = new StreamWriter(fs, Encoding.UTF8);
                        foreach (var item in listbook)
                        {
                            sWriter.WriteLine(item.toString());
                        }
                        sWriter.Flush();
                        fs.Close();
                        break;
                    case 7:
                        string[] lines = File.ReadAllLines(@"E:/C#/quanlisach.txt");
                        foreach (string s in lines)
                        {
                            Console.WriteLine(s);
                        }
                        Console.ReadLine();
                        break;
                    case 8:
                        Console.WriteLine("Exit");
                        break;
                    default:
                        Console.WriteLine("ERROR");
                        break;

                }
            } while (choose != 8);
        }
        static public void Menu()
        {
           
            Console.WriteLine("1. Nhập thông tin n cuốn sách của Aptech");
            Console.WriteLine("2. Hiển thị thông tin vừa nhập");
            Console.WriteLine("3. Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị");
            Console.WriteLine("4. Tìm kiếm theo tên sách");
            Console.WriteLine("5. Tìm kiếm theo tên tác giả");
            Console.WriteLine("6. Lưu thông tin sách đã nhập vào file");
            Console.WriteLine("7. Đọc nội dung từ file và lưu vào mang quản lý sách");
            Console.WriteLine("8. Thoat");
            
        }
        static public void showInfor(List<AptechBook> listbook)
        {
            int showinfor = 0;
            foreach (var item in listbook)
            {
                ++showinfor;
                Console.WriteLine("Information book {0}: ", showinfor);
                item.output();
            }
        }
        static public void Sort(List<AptechBook> listbook)
        {
            listbook.Sort((x, y) => x.yearPublishing.CompareTo(y.yearPublishing));
        }
        static AptechBook findBybookName(String search, List<AptechBook> listbook)
        {
            AptechBook aptechBook = new AptechBook();
            foreach (var item in listbook)
            {
                if (item.bookName.Equals(search))
                {
                    aptechBook = item;
                    break;
                }
            }
            return aptechBook;
        }
        static AptechBook findBybookAuthor(String search, List<AptechBook> listbook)
        {
            AptechBook aptachBook = new AptechBook();
            foreach (var item in listbook)
            {
                if (item.bookAuthor.Equals(search))
                {
                    aptachBook = item;
                    break;
                }
            }
            return aptachBook;
        }
    }
}
#Book.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace QuanLySach
{
    class Book
    {
        private string _bookName;
        private string _bookAuthor;
        private string _producer;
        private int _yearPublishing;
        private float _price;

        public string bookName { get; set; }
        public string bookAuthor { get; set; }
        public string producer { get; set; }
        public int yearPublishing { get; set; }
        public float price { get; set; }

        public Book()
        {

        }
        public Book(String bookName, String bookAuthor, String producer, int yearPublishing, float price)
        {
            this.bookName = bookName;
            this.bookAuthor = bookAuthor;
            this.producer = producer;
            this.yearPublishing = yearPublishing;
            this.price = price;
        }
        public void input()
        {
            Console.WriteLine("1: Nhap ten sach: ");
            bookName = Console.ReadLine();
            Console.WriteLine("1: Nhap sach: ");
            bookAuthor = Console.ReadLine();
            Console.WriteLine("1: Nhap nha san xuat: ");
            producer = Console.ReadLine();
            Console.WriteLine("1: Nhap nam san xuat: ");
            yearPublishing = int.Parse(Console.ReadLine());
            Console.WriteLine("1: Nhap gia ban.: ");
            price = float.Parse(Console.ReadLine());
        }
        public void output()
        {

        }
    }
}



#Aptechbook
using System;
using System.Collections.Generic;
using System.Text;


namespace QuanLySach
{
    class AptechBook
    {
        private string _language;
        private int _semester;

        public string language { get; set; }
        public int semester { get; set; }

        public AptechBook()
        {

        }
        public AptechBook(String laguage, int semester)
        {
            this.language = language;
            this.semester = semester;
        }
        public override void input()
        {
            base.input();
            Console.Write("Enter language: ");
            language = Console.ReadLine();
            Console.Write("Enter semester: ");
            semester = int.Parse(Console.ReadLine());
        }
        public override void output()
        {
            base.output();
            Console.WriteLine("Language: {0} \nSemester: {1}", language, semester);
        }
        public string toString()
        {
            return "bookName: " + bookName + "\nbookAuthor: " + bookAuthor + "\nProducer: " + producer + "\nYearPublishing: " + yearPublishing + "\nPrice: " + price;
        }

    }
}


avatar
vuong huu phu [T2008A]
2021-05-28 10:12:18



using System;
using System.Collections.Generic;
using System.IO;

namespace quanlysach
{
    class Program
    {
        public static List<Book> booklist = new List<Book>();
        static void Main(string[] args)
        {
            Book b1 = new Book();
            int lc;
            do
            {
                menu();
                Console.WriteLine("Nhap lua chon: ");
                lc = Int32.Parse(Console.ReadLine());
                switch (lc) {
                    case 1:
                        int n;
                        Console.WriteLine("Nhap so luong quyen sach: ");
                        n = Int32.Parse(Console.ReadLine());
                        for (int i = 0; i < n; i++) {
                            Book b = new Book();
                            b.input();
                            booklist.Add(b);
                        }
                        break;
                    case 2:
                        foreach (Book b in booklist) {
                            b.display();
                        }
                        break;
                    case 3:
                        booklist.Sort((o1, o2) =>
                        {
                            return -o1.yearPublishing.CompareTo(o2.yearPublishing);
                        }
                        );
                        foreach (Book b in booklist) {
                            b.display();
                        }
                        break;
                    case 4:
                        b1.tim_ten_sach(booklist);
                        break;
                    case 5:
                        b1.tim_tac_gia(booklist);
                        break;
                    case 6:
                            using (Stream tr = File.Open(@"Book.dat", FileMode.Create)) {
                                var format1 = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                                format1.Serialize(tr, booklist);
                            }
                        break;
                    case 7:
                        using (Stream tr1 = File.Open(@"Book.dat",FileMode.Open))
                        {
                            var format = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                            booklist = (List<Book>)format.Deserialize(tr1);
                        }
                        break;
                    case 8:
                        Console.WriteLine("Thoat !!!!");
                        break;
                    default:
                        Console.WriteLine("Nhap lai !!! ");
                        break;
                }
            } while (lc > 0);
        }
        public static void menu()
        {
            Console.WriteLine(" 1 Nhap so luong n quyen sach");
            Console.WriteLine(" 2 Hien thi thong tin");
            Console.WriteLine(" 3 sap xep theo thu tu giam dan");
            Console.WriteLine(" 4 Tim kiem theo ten sach");
            Console.WriteLine(" 5 Tim kiem theo tac gia");
            Console.WriteLine(" 6 Luu vao file");
            Console.WriteLine(" 7 Doc noi dung file");
            Console.WriteLine(" 8 Thoat !!");
        }
        
    }
}



using System;
using System.Collections.Generic;
using System.Text;

namespace quanlysach
{
    [Serializable]
    class Book
    {
        public String bookName { set; get; }

        public String bookAuthor { set; get; }

        public String producer { set; get; }

        public int yearPublishing { set; get; }

        public float price { set; get; }
    
        public Book() { }

        public Book(String bookname, String bookAuthor, String producer,int yearPublishing,float price) {
            this.bookAuthor = bookAuthor;
            this.bookName = bookName;
            this.producer = producer;
            this.yearPublishing = yearPublishing;
            this.price = price;
        }
        public virtual void input( ) {
            Console.WriteLine( "Nhap ten sach: " );
            bookName = Console.ReadLine();
            Console.WriteLine( "Nhap ten tac gia: ");
            bookAuthor = Console.ReadLine();
            Console.WriteLine("Nhap nha xuat ban: ");
            producer = Console.ReadLine();
            Console.WriteLine("Nhap nam xuat ban: ");
            yearPublishing = Int32.Parse(Console.ReadLine());
            Console.WriteLine("Nhap gia ban: ");
            price = float.Parse(Console.ReadLine());
        }
        public virtual void display() {
            Console.WriteLine("Ten sach: " + bookName + ",Ten tac gia: " + bookAuthor + ",Nha xuat ban: " + producer + ",Nam xuat ban: " + yearPublishing + ",gia ban: " + price);
        }
        public void tim_ten_sach(List<Book> booklist) {
            String tensach;
            Console.WriteLine("Nhap ten sach can tim ");
            tensach = Console.ReadLine();
            foreach (Book b in booklist)
            {
                if (b.bookName == tensach) {
                    b.display();
                }
                        }
        }

        public void tim_tac_gia(List<Book> booklist)
        {
            String ten;
            Console.WriteLine("Nhap ten tac gia can tim ");
            ten = Console.ReadLine();
            foreach (Book b in booklist)
            {
                if (b.bookAuthor == ten)
                {
                    b.display();
                }
            }
        }
      
    }
}



using System;
using System.Collections.Generic;
using System.Text;

namespace quanlysach
{
    [Serializable]
    class AptechBook : Book
    {
        private String language { set; get; }

        private int semester { set; get; }

        public AptechBook() { }
        public AptechBook(String bookname, String bookAuthor, String producer, int yearPublishing, float price,String language, int semester) : base(bookname,bookAuthor,producer,yearPublishing,price)
        {
            this.language = language;
            this.semester = semester;
        }
        public override void input()
        {
            base.input();
            Console.WriteLine("Nhap ngon ngu ");
            language = Console.ReadLine();
            Console.WriteLine("Nhap hoc ki");
            semester = Int32.Parse(Console.ReadLine());
        }
        public override void display()
        {
            base.display();
            Console.WriteLine("Ngon ngu: "+ language + ", hoc ki: " + semester);
        }

    }
}


avatar
hainguyen [T2008A]
2021-05-28 10:08:20


#AptechBook.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace Bt1458
{
    class AptechBook : Book
    {
        public string language { get; set; }
        public int semester { get; set; }

        public AptechBook() { }

        public AptechBook(string bookName, string bookAuthor, string producer, int yearPublishing, float price)
        {
            this.language = language;
            this.semester = semester;
        }

        public override void input()
        {
            base.input();
            Console.WriteLine("Nhap language: ");
            language = Console.ReadLine();
            Console.WriteLine("Nhap semester: ");
            semester = int.Parse(Console.ReadLine());
        }

        public override void display()
        {
            base.display();
            Console.WriteLine("language: = {0}", language);
            Console.WriteLine("semester: = {0}", semester);
        }
    }
}


#Book.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace Bt1458
{
    class Book
    {
        public string bookName { get; set; }
        public string bookAuthor { get; set; }
        public string producer { get; set; }
        public int yearPublishing { get; set; }
        public float price { get; set; }

        public Book() { }

        public Book(string bookName, string bookAuthor, string producer, int yearPublishing, float price)
        {
            this.bookName = bookName;
            this.bookAuthor = bookAuthor;
            this.producer = producer;
            this.yearPublishing = yearPublishing;
            this.price = price;
        }

        public virtual void input()
        {
            Console.WriteLine("Nhap bookName: ");
            bookName = Console.ReadLine();
            Console.WriteLine("Nhap bookAuthor: ");
            bookAuthor = Console.ReadLine();
            Console.WriteLine("Nhap producer: ");
            producer = Console.ReadLine();
            Console.WriteLine("Nhap yearPublishing: ");
            yearPublishing = int.Parse(Console.ReadLine());
            Console.WriteLine("Nhap price: ");
            price = float.Parse(Console.ReadLine());
        }

        public virtual void display()
        {
            Console.WriteLine("bookName: = {0}", bookName);
            Console.WriteLine("bookAuthor: = {0}", bookAuthor);
            Console.WriteLine("producer: = {0}", producer);
            Console.WriteLine("yearPublishing: = {0}", yearPublishing);
            Console.WriteLine("price: = {0}", price);
        }
    }
}


#Program.cs


using System;
using System.Collections.Generic;
using System.IO;

namespace Bt1458
{
    class Program
    {
        static void Main(string[] args)
        {
            List<AptechBook> booklist = new List<AptechBook>();
            int choose;

            do
            {
                showMenu();
                choose = int.Parse(Console.ReadLine());

                switch (choose)
                {
                    case 1:
                        Console.WriteLine("Nhap so luong can them: ");
                        int n = int.Parse(Console.ReadLine());
                        for (int i = 0; i < n; i++)
                        {
                            AptechBook book = new AptechBook();
                            book.input();
                            booklist.Add(book);
                        }
                        break;
                    case 2:
                        for (int i = 0; i < booklist.Count; i++)
                        {
                            booklist[i].display();
                        }
                        break;
                    case 3:
                        for (int i = 0; i < booklist.Count - 1; i++)
                        {
                            for (int j = 1; j < booklist.Count; j++)
                            {
                                if (booklist[i].yearPublishing < booklist[j].yearPublishing)
                                {
                                    AptechBook temp = booklist[i];
                                    booklist[i] = booklist[j];
                                    booklist[j] = temp;
                                }
                            }
                        }
                        for (int i = 0; i < booklist.Count; i++)
                        {
                            booklist[i].display();
                        }
                        break;
                    case 4:
                        Console.WriteLine("Nhap ten sach can tim: ");
                        string name = Console.ReadLine();
                        int count = 0;
                        foreach (AptechBook i in booklist)
                        {
                            if (i.bookName == name)
                            {
                                i.display();
                                count++;
                            }
                        }
                        if (count == 0)
                        {
                            Console.WriteLine("ko tim thay sach");
                        }
                        break;
                    case 5:
                        Console.WriteLine("Nhap ten tac gia can tim: ");
                        string author = Console.ReadLine();
                        int num = 0;
                        foreach (AptechBook i in booklist)
                        {
                            if (i.bookAuthor == author)
                            {
                                i.display();
                                num++;
                            }
                        } 
                        if (num == 0)
                        {
                            Console.WriteLine("ko tim thay tac gia");
                        }
                        break;
                    case 6:
                        foreach (AptechBook i in booklist)
                        {
                            using (Stream stream = File.Open(i.bookName + ".obj", FileMode.Create))
                            {
                                var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                                binaryFormatter.Serialize(stream, i);
                            }
                        }
                        Console.WriteLine("Thanh cong");
                        break;
                    case 7:

                        break;
                    case 8:
                        Environment.Exit(0);
                        break;
                    default:
                        Console.WriteLine("Fail!");
                        break;
                }
            } while (choose != 8);
        }

        static void showMenu()
        {
            Console.WriteLine("1. Nhập thông tin n cuốn sách của Aptech");
            Console.WriteLine("2. Hiển thị thông tin vừa nhập");
            Console.WriteLine("3. Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị");
            Console.WriteLine("4. Tìm kiếm theo tên sách");
            Console.WriteLine("5. Tìm kiếm theo tên tác giả");
            Console.WriteLine("6. Lưu thông tin sách đã nhập vào file");
            Console.WriteLine("7. Đọc nội dung từ file và lưu vào mang quản lý sách");
            Console.WriteLine("8. Thoát.");
            Console.WriteLine("Chon: ");
        }
    }
}


avatar
Trần Văn Lâm [T2008A]
2021-05-28 09:32:31


#AptechBook.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace les7bt2
{
    class AptechBook : Book
    {
        private String Language { get; set; }

        private int Semester { get; set; }

        public AptechBook()
        {

        }
        public AptechBook(string BookName, string BookAuthor, string Producer, int YearPearPublishing, float Price, string Language, int Semester)
            : base(BookName, BookAuthor, Producer, YearPearPublishing, Price)
        {
            this.Language = Language;
            this.Semester = Semester;
        }
        public override void Input()
        {
            base.Input();
            Console.WriteLine("Nhap ngon ngu: ");
            Language = Console.ReadLine();
            Console.WriteLine("Nhap hoc ki:");
            Semester = Convert.ToInt32(Console.ReadLine());
        }
        public override void Display()
        {
            base.Display();
            Console.WriteLine("Ngon ngu : {0}, Hoc ki : {1}", Language, Semester);
        }
    }
}


#Book.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace les7bt2
{
    class Book
    {
        private string BookName { get; set; }
        private string BookAuthor { get; set; }
        private string Producer { get; set; }
        private int YearPearPublishing { get; set; }
        private float Price { get; set; }

        public Book()
        {

        }
        public Book(string BookName, string BookAuthor, string Producer, int YearPearPublishing, float Price)
        {
            this.BookName = BookName;
            this.BookAuthor = BookAuthor;
            this.Producer = Producer;
            this.YearPearPublishing = YearPearPublishing;
            this.Price = Price;
        }

        public virtual void Input()
        {
            Console.WriteLine("Nhap ten sach:");
            BookName = Console.ReadLine();
            Console.WriteLine("Nhap ten tac gia:");
            BookAuthor = Console.ReadLine();
            Console.WriteLine("Nhap nha xuat ban:");
            Producer = Console.ReadLine();
            Console.WriteLine("Nhap nam sx:");
            YearPearPublishing = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Nhap gia:");
            Price = float.Parse(Console.ReadLine());
        }
        public virtual void Display()
        {
            Console.WriteLine("Ten sach : {0}, Ten tac gia : {1}, Nha xuat ban : {2}, Nam sx : {3}, Gia : {4}", BookName, BookAuthor, Producer, YearPearPublishing, Price );
        }
    }
}


#Program.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace les7bt2
{
    class Program
    {
        static List<AptechBook> list = new List<AptechBook>();
        static AptechBook aptechbook = new AptechBook();
        static void Main(string[] args)
        {
            int choose;
            do
            {
                ShowMenu();
                Console.WriteLine("Lua chon chuong trinh:");
                choose = Convert.ToInt32(Console.ReadLine());

                switch (choose)
                {
                    case 1:
                        InputAptechBook();
                        break;
                    case 2:
                        DisplayAptechBook();
                        break;
                    case 3:
                        SortAptechBook();
                        break;
                    case 4:
                        SortAptechBook();
                        break;
                    case 5:
                        SearchNameBook();
                        break;
                    case 6:
                        SearchNameAuthor();
                        break;
                    case 7:
                        Save();
                        break;
                    case 8:
                        Console.WriteLine("Exit!!!");
                        break;
                    default:
                        Console.WriteLine("Nhap lai!!");
                        break;
                }

            } while (choose != 8);
        }

        private static void Save()
        {
            throw new NotImplementedException();
        }

        private static void SearchNameAuthor()
        {
            Console.WriteLine("Nhap ten cuon sach:");
            string namea = Console.ReadLine();
            foreach (AptechBook aptechbook in list)
            {
                if (aptechbook.NameBookAuthor.Equals(namea))
                {
                    aptechbook.Display();
                    return;
                }
            }
            Console.WriteLine("Khong tim thay!");
        }

        private static void SearchNameBook()
        {
            Console.WriteLine("Nhap ten cuon sach:");
            string name = Console.ReadLine();
            foreach (AptechBook aptechbook in list)
            {
                if (aptechbook.NameBook.Equals(name))
                {
                    aptechbook.Display();
                    return;
                }
            }
            Console.WriteLine("Khong tim thay!");
        }

        private static void SortAptechBook()
        {
            
            for (int i = 0; i < list.Count; i++)
            {
                for(int j = i + 1; j < list.Count; j++)
                {
                    if (list[i].YearPearPublishing < list[j].YearPearPublishing)
                    {
                        Book temp = list[i];
                        list[i] = list[j];
                        list[j] = temp;
                    }
                }
            }
            foreach (AptechBook aptechbook in list)
            {
                aptechbook.Display();
            }

        }

        private static void DisplayAptechBook()
        {
            foreach(AptechBook aptechbook in list)
            {
                aptechbook.Display();
            }
        }

        private static void InputAptechBook()
        {
            Console.WriteLine("Nhap thong tin N cuon sach:");
            int N = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < N; i++)
            {
                aptechbook.Input();
                list.Add(aptechbook);
            }
        }

        static void ShowMenu()
        {
            Console.WriteLine("1.Nhập thông tin n cuốn sách của Aptech");
            Console.WriteLine("2.Hiển thị thông tin vừa nhập");
            Console.WriteLine("3.Sắp xếp thông tin giảm dần theo năm xuất bản và hiển thị");
            Console.WriteLine("4.Tìm kiếm theo tên sách");
            Console.WriteLine("5.Tìm kiếm theo tên tác giả");
            Console.WriteLine("6.Lưu thông tin sách đã nhập vào file");
            Console.WriteLine("7.Đọc nội dung từ file và lưu vào mang quản lý sách");
            Console.WriteLine("8.Thoát.");
            Console.WriteLine("Chon:");
        }
    }
}